-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
126 lines (113 loc) · 3.64 KB
/
main.cpp
File metadata and controls
126 lines (113 loc) · 3.64 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <cyfw/main.h>
#include <cyfw/Gui.h>
#include <Resource.h>
#include <Cyril/CyrilParser.h>
using namespace std;
using namespace cy;
class MyApp : public cy::App
{
Gui gui;
bool guiOpen;
char text[1024*16];
bool escPressed;
bool shouldQuit;
ImFont* font1;
public:
MyApp() : escPressed{false}, shouldQuit{false} {
char * t = "rotate\nbox\0";
memcpy(text, t, 11);
Resource fontdata = LOAD_RESOURCE(a_scp_r_ttf);
auto font_cfg_template = ImFontConfig();
font_cfg_template.FontDataOwnedByAtlas = false;
font1 = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(
(void*)fontdata.begin(), fontdata.size(), 32, &font_cfg_template);
}
void setup()
{
window->closeOnEscapeKey(false);
window->setClearColor({0,0,0,1});
gui.init(window);
ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 0;
style.WindowPadding = {0, 0};
style.Colors[ImGuiCol_Text] = {1,1,1,1};
style.Colors[ImGuiCol_WindowBg] = {0,0,0,0};
style.Colors[ImGuiCol_FrameBg] = {0,0,0,0};
}
void draw()
{
window->clear();
gui.clear();
doGui();
gui.draw();
}
void doGui()
{
ImGui::SetNextWindowPos(ImVec2(10,10));
ImGuiWindowFlags windowFlags =
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize
| ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse;
if (!ImGui::Begin("Buffer", &guiOpen, windowFlags))
{
ImGui::End();
return;
}
ImGui::PushFont(font1);
vec2i dim = window->getWindowSize();
ImGui::SetWindowSize(ImVec2(dim.x() - 20, dim.y() - 20));
ImGui::InputTextMultiline("source", text, sizeof(text), ImVec2(-1.0f, -1.0f), 0);
if (escPressed) ImGui::OpenPopup("Quit?");
if (ImGui::BeginPopupModal("Quit?", NULL, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoMove))
{
ImGui::SetWindowFontScale(0.5f);
ImGui::Text("Are you sure you want to quit?\n\n");
ImGui::Separator();
if (ImGui::Button("Quit", ImVec2(120,0))) {
escPressed = false;
shouldQuit = true;
window->quit();
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
if (ImGui::Button("Cancel", ImVec2(120,0))) {
escPressed = false;
window->quit(false);
ImGui::CloseCurrentPopup();
}
if (ImGui::IsKeyPressed(ImGuiKey_Escape))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
ImGui::PopFont();
ImGui::End();
}
bool quit()
{
escPressed = true;
return shouldQuit;
}
void key(window::KeyEvent e)
{
if (e.key == window::key::R && e.action == window::action::PRESSED && e.mods == window::mods::SUPER)
{
cout << "Program:" << endl << text << endl;
CyrilParser parser;
Cyril* prog = parser.parseString(text);
cout << "Compiled:" << endl;
prog->print();
}
if (e.key == window::key::ESCAPE && e.action == window::action::PRESSED)
{
escPressed = true;
}
gui.key(e);
}
void scroll(window::ScrollEvent e) { gui.scroll(e); }
void textInput(window::CharEvent e) { gui.character(e); }
void mouseButton(window::MouseButtonEvent e ) { gui.mouse(e); }
};
int main() {
cy::run<MyApp,ConsoleLogger>(640, 480, "testing editor");
}