diff options
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(); +} + |