forked from alimb2/Ayyware-Full-Fixed-Updated-2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI.h
169 lines (136 loc) · 2.73 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
/*
Syn's AyyWare Framework 2015
*/
#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
};
// 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);
bool Flag(int f);
protected:
int m_x, m_y;
int m_iWidth, m_iHeight;
int m_Flags;
CWindow* parent;
std::string FileIdentifier;
int FileControlType;
virtual void Draw(bool) = 0;
virtual void OnUpdate() = 0;
virtual void OnClick() = 0;
POINT GetAbsolutePos();
};
// 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);
private:
std::string Title;
std::vector<CControl*> Controls;
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();
CControl* GetFocus();
void RegisterTab(CTab* Tab);
RECT GetClientArea();
RECT GetTabArea();
private:
void DrawControls();
std::vector<CTab*> Tabs;
CTab* SelectedTab;
bool IsFocusingControl;
CControl* FocusedControl;
std::string Title;
int m_x;
int m_y;
int m_iWidth;
int m_iHeight;
};
extern bool m_bIsOpen;
// 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);
// 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;
};