-
Notifications
You must be signed in to change notification settings - Fork 1
/
ModuleGUI.h
239 lines (180 loc) · 5.43 KB
/
ModuleGUI.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef MODULEGUI_H
#define MODULEGUI_H
#include "Module.h"
#include "Application.h"
#include "imgui.h"
#include "imgui_impl_sdl.h"
#include "imgui_impl_opengl3.h"
#include <GL/glew.h>
#include <iostream>
#include <list>
#include <iterator>
#include "WindowInspector.h"
#include "WindowGame.h"
#include "WindowEngineStats.h"
#include "WindowFileSystem.h"
using namespace std;
class About;
struct MercuryEngineConsole
{
char InputBuf[256];
ImVector<char*> Items;
ImVector<const char*> Commands;
ImVector<char*> History;
int HistoryPos; // -1: new line, 0..History.Size-1 browsing history --->???
ImGuiTextFilter Filter;
bool AutoScroll;
bool ScrollToBottom;
MercuryEngineConsole()
{
ClearLog();
memset(InputBuf, 0, sizeof(InputBuf));
HistoryPos = -1;
Commands.push_back("HELP");
Commands.push_back("HISTORY");
Commands.push_back("CLEAR");
Commands.push_back("CLASSIFY");
AutoScroll = true;
ScrollToBottom = false;
//AddLog("");
}
~MercuryEngineConsole()
{
ClearLog();
for (int i = 0; i < History.Size; i++)
free(History[i]);
}
// Portable helpers
static int Stricmp(const char* str1, const char* str2) { int d; while ((d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; } return d; }
static int Strnicmp(const char* str1, const char* str2, int n) { int d = 0; while (n > 0 && (d = toupper(*str2) - toupper(*str1)) == 0 && *str1) { str1++; str2++; n--; } return d; }
static char* Strdup(const char *str) { size_t len = strlen(str) + 1; void* buf = malloc(len); IM_ASSERT(buf); return (char*)memcpy(buf, (const void*)str, len); }
static void Strtrim(char* str) { char* str_end = str + strlen(str); while (str_end > str && str_end[-1] == ' ') str_end--; *str_end = 0; }
void ClearLog()
{
for (int i = 0; i < Items.Size; i++)
free(Items[i]);
Items.clear();
}
void AddLog(const char* fmt, ...) IM_FMTARGS(2)
{
// FIXME-OPT
char buf[1024];
va_list args;
va_start(args, fmt);
vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args);
buf[IM_ARRAYSIZE(buf) - 1] = 0;
va_end(args);
Items.push_back(Strdup(buf));
}
void Draw(const char* title, bool* p_open)
{
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
if (!ImGui::Begin(title, p_open, ImGuiWindowFlags_MenuBar))
{
ImGui::End();
return;
}
if (ImGui::BeginPopupContextItem())
{
if (ImGui::MenuItem("Close Console"))
*p_open = false;
ImGui::EndPopup();
}
if (ImGui::BeginMenuBar())
{
if (ImGui::MenuItem("Clear"))
{
ClearLog();
}
ImGui::EndMenuBar();
}
ImGui::TextWrapped("Messages:");
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
ImGui::Separator();
// Options menu
if (ImGui::BeginPopup("Options"))
{
ImGui::Checkbox("Auto-scroll", &AutoScroll);
ImGui::EndPopup();
}
ImGui::Separator();
const float footer_height_to_reserve = ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing(); // 1 separator, 1 input text
ImGui::BeginChild("ScrollingRegion", ImVec2(0, -footer_height_to_reserve), false, ImGuiWindowFlags_HorizontalScrollbar); // Leave room for 1 separator + 1 InputText
if (ImGui::BeginPopupContextWindow())
{
if (ImGui::Selectable("Clear")) ClearLog();
ImGui::EndPopup();
}
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1)); // Tighten spacing
//THIS SHIT DRAWS THE TEXT STORED IN LIST "Items"
for (int i = 0; i < Items.Size; i++)
{
const char* item = Items[i];
if (!Filter.PassFilter(item))
continue;
bool pop_color = false;
if (strstr(item, "[error]")) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.4f, 0.4f, 1.0f)); pop_color = true; }
else if (strncmp(item, "# ", 2) == 0) { ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.8f, 0.6f, 1.0f)); pop_color = true; }
ImGui::TextUnformatted(item);
if (pop_color)
ImGui::PopStyleColor();
}
if (ScrollToBottom || (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()))
ImGui::SetScrollHereY(1.0f);
ScrollToBottom = false;
ImGui::PopStyleVar();
ImGui::EndChild();
ImGui::Separator();
ImGui::End();
}
};
class ModuleGUI : public Module {
public:
ModuleGUI(Application* app, bool start_enabled = true);
~ModuleGUI();
bool Init();
bool Start();
update_status PreUpdate(float dt);
update_status Update(float dt);
update_status PostUpdate(float dt);
bool Draw();
bool CleanUp();
bool CreateMenuBar();
void ShowConsole();
void LoadScenesPopUp();
void ShowWindowSettings();
ImVec4 clear_color = ImVec4(0.0f, 0.0f, 0.0f, 0.00f);
ImGuiIO* io = nullptr;
bool show_demo_window = true;
bool show_another_window = false;
MercuryEngineConsole console;
WindowInspector* inspector;
WindowEngineStats *EngineStats;
WindowGame* game;
WindowFileSystem* filesystem;
About* about;
int MouseX;
int MouseY;
private:
bool openWindowSettings = false;
bool fullscreen = false;
bool borderless = false;
bool resizable = true;
bool fulldesktop = false;
bool openDebug = false;
bool p_open = true;
bool quit = false;
list<Module*> windows;
public:
bool openGame = true;
bool openConsole = true;
bool openInspector = true;
bool openHirearchy = true;
bool ShowFPS = true;
bool openAbout = false;
bool openFileSystem = true;
bool savePopUp = false;
int screen_width = SCREEN_WIDTH;
int screen_height = SCREEN_HEIGHT;
};
#endif