diff options
author | Clyne <clyne@bitgloo.com> | 2022-05-24 17:38:05 -0400 |
---|---|---|
committer | Clyne <clyne@bitgloo.com> | 2022-05-24 17:38:05 -0400 |
commit | 5902a67796000c7546d07fa778b26619c4588c3a (patch) | |
tree | 1c1fa04635a3c248d07fde4dce8857885ca23952 /source/gui_code.cpp | |
parent | 1cf4908a23dc5537be0bab1089ffcaa7079d5434 (diff) | |
parent | dff847ff4455e7b8c5123167a7d01afe7c45f585 (diff) |
Merge pull request 'devel: Ready for pre-release' (#1) from devel into masterv0.1
Reviewed-on: https://code.bitgloo.com/clyne/stmdspgui/pulls/1
Diffstat (limited to 'source/gui_code.cpp')
-rw-r--r-- | source/gui_code.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/source/gui_code.cpp b/source/gui_code.cpp new file mode 100644 index 0000000..50fd0c8 --- /dev/null +++ b/source/gui_code.cpp @@ -0,0 +1,70 @@ +/** + * @file code.cpp + * @brief Contains code for algorithm-code-related UI elements and logic. + * + * Copyright (C) 2021 Clyne Sullivan + * + * Distributed under the GNU GPL v3 or later. You should have received a copy of + * the GNU General Public License along with this program. + * If not, see <https://www.gnu.org/licenses/>. + */ + +#include "imgui.h" +#include "backends/imgui_impl_sdl.h" +#include "backends/imgui_impl_opengl2.h" +#include "TextEditor.h" + +#include <string> + +extern void compileEditorCode(const std::string& code); +extern void disassembleCode(); + +TextEditor editor; // file.cpp + +static std::string editorCompiled; + +static void codeCompile(); +static void codeDisassemble(); + +void codeEditorInit() +{ + editor.SetLanguageDefinition(TextEditor::LanguageDefinition::CPlusPlus()); + editor.SetPalette(TextEditor::GetLightPalette()); +} + +void codeRenderMenu() +{ + if (ImGui::BeginMenu("Code")) { + if (ImGui::MenuItem("Compile")) + codeCompile(); + if (ImGui::MenuItem("Disassemble")) + codeDisassemble(); + + ImGui::EndMenu(); + } +} + +void codeRenderToolbar() +{ + if (ImGui::Button("Compile")) + codeCompile(); +} + +void codeRenderWidgets(const ImVec2& size) +{ + editor.Render("code", size, true); +} + +static void codeCompile() +{ + compileEditorCode(editor.GetText()); + editorCompiled = editor.GetText().compare(editorCompiled); +} + +static void codeDisassemble() +{ + if (editor.GetText().compare(editorCompiled) != 0) + codeCompile(); + disassembleCode(); +} + |