-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGUI.h
198 lines (161 loc) · 3.08 KB
/
GUI.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
#pragma once
#include "CommonIncludes.h"
#include <map>
class CControl;
class CTab;
class CWindow;
class CGUI;
extern CGUI GUI;
enum UIFlags
{
UI_None = 0x00,
UI_Drawable = 0x01,
UI_Clickable = 0x02,
UI_Focusable = 0x04,
UI_RenderFirst = 0x08,
UI_SaveFile = 0x10
};
enum UIControlTypes
{
UIC_CheckBox = 1,
UIC_Slider,
UIC_KeyBind,
UIC_ComboBox,
UIC_ItemSelector,
UIC_Button,
UIC_MultiBox,
UIC_GroupBox,
UIC_ListBox,
UIC_ColorSelector,
UIC_Label,
UIC_TextField
};
// Base class for GUI controls
class CControl
{
friend class CGUI;
friend class CTab;
friend class CWindow;
public:
void SetPosition(int x, int y);
void SetSize(int w, int h);
void GetSize(int &w, int &h);
void SetFileId(std::string fid);
int FileControlType;
int m_iWidth, m_iHeight;
POINT GetAbsolutePos();
bool Flag(int f);
int m_x, m_y;
CControl* parent_group;
int g_tab = 0;
bool should_function = true;
protected:
int m_Flags;
CWindow* parent;
std::string FileIdentifier;
virtual void Draw(bool) = 0;
virtual void OnUpdate() = 0;
virtual void OnClick() = 0;
};
// A GUI Control Container
class CTab
{
friend class CControl;
friend class CGUI;
friend class CWindow;
public:
void SetTitle(std::string name);
void RegisterControl(CControl* control);
std::vector<CControl*> Controls;
private:
std::string Title;
CWindow* parent;
};
// Base class for a simple GUI window
class CWindow
{
friend class CControl;
friend class CGUI;
public:
void SetPosition(int x, int y);
void SetSize(int w, int h);
void SetTitle(std::string title);
void Open();
void Close();
void Toggle();
bool isOpen();
int get_iWidth()
{
return m_iWidth;
}
int get_iHeight()
{
return m_iHeight;
}
int get_x()
{
return m_x;
}
int get_y()
{
return m_y;
}
CControl* GetFocus();
void RegisterTab(CTab* Tab);
RECT GetClientArea();
RECT GetTabArea();
RECT GetDragArea();
CControl* FocusedControl;
private:
void DrawControls();
bool m_bIsOpen = false;
std::vector<CTab*> Tabs;
CTab* SelectedTab;
bool IsFocusingControl;
std::string Title;
int m_x;
int m_y;
int m_iWidth;
int m_iHeight;
};
// User interface manager
class CGUI
{
public:
CGUI();
// Draws all windows
void Draw();
// Handle all input etc
void Update();
// Draws a single window
bool DrawWindow(CWindow* window, int menu);
// Registers a window
void RegisterWindow(CWindow* window);
// Config saving/loading
void SaveWindowState(CWindow* window, std::string Filename);
void LoadWindowState(CWindow* window, std::string Filename);
// Window Binds
void BindWindow(unsigned char Key, CWindow* window);
// Input
bool GetKeyPress(unsigned int key);
bool GetKeyState(unsigned int key);
bool IsMouseInRegion(int x, int y, int x2, int y2);
bool IsMouseInRegion(RECT region);
POINT GetMouse();
private:
// Input
// keyboard
bool keys[256];
bool oldKeys[256];
// Mouse
POINT Mouse;
bool MenuOpen;
// Window Dragging
bool IsDraggingWindow;
CWindow* DraggingWindow;
int DragOffsetX; int DragOffsetY;
// Windows
std::vector<CWindow*> Windows;
// KeyBinds -> Windows Map
std::map<int, CWindow*> WindowBinds;
};