blob: 19fa572910b1e2f537548fe92d8e04d0d403210c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
/**
* @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 "config.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()
{
editor.Render("code", {WINDOW_WIDTH - 15, 450}, true);
}
static void codeCompile()
{
compileEditorCode(editor.GetText());
editorCompiled = editor.GetText().compare(editorCompiled);
}
static void codeDisassemble()
{
if (editor.GetText().compare(editorCompiled) != 0)
codeCompile();
disassembleCode();
}
|