-
Notifications
You must be signed in to change notification settings - Fork 0
/
gui.cpp
155 lines (126 loc) · 3.53 KB
/
gui.cpp
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
#include "gui.h"
#include <iostream>
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"
#define TEXTBOX_BUFFER_LENGTH 2048
void FBGuiLabel::draw()
{
if (enabled) GuiEnable();
else GuiDisable();
GuiSetStyle(GuiControl::LABEL, GuiControlProperty::TEXT_ALIGNMENT, horizontal_align);
GuiSetStyle(GuiControl::DEFAULT, GuiDefaultProperty::TEXT_ALIGNMENT_VERTICAL, vertical_align);
GuiLabel(rect, ((icon > 0 ? ("#" + to_string(icon) + "#") : "") + text).c_str());
}
bool FBGuiButton::wasPressed()
{
return pressed;
}
void FBGuiButton::draw()
{
if (enabled) GuiEnable();
else GuiDisable();
GuiSetStyle(GuiControl::LABEL, GuiControlProperty::TEXT_ALIGNMENT, horizontal_align);
GuiSetStyle(GuiControl::DEFAULT, GuiDefaultProperty::TEXT_ALIGNMENT_VERTICAL, vertical_align);
pressed = GuiButton(rect, ((icon > 0 ? ("#" + to_string(icon) + "#") : "") + text).c_str());
}
bool FBGuiTextBox::wasFocusLost()
{
return focus_lost;
}
void FBGuiTextBox::setText(const char* str)
{
memset(buffer, '\0', TEXTBOX_BUFFER_LENGTH);
memcpy(buffer, str, strlen(str));
}
string FBGuiTextBox::getText()
{
return string(buffer);
}
void FBGuiTextBox::draw()
{
if (enabled) GuiEnable();
else GuiDisable();
GuiSetStyle(GuiControl::LABEL, GuiControlProperty::TEXT_ALIGNMENT, horizontal_align);
GuiSetStyle(GuiControl::TEXTBOX, GuiTextBoxProperty::TEXT_READONLY, !editable);
GuiSetStyle(GuiControl::DEFAULT, GuiDefaultProperty::TEXT_ALIGNMENT_VERTICAL, vertical_align);
focus_lost = false;
if (GuiTextBox(rect, buffer, TEXTBOX_BUFFER_LENGTH, focussed))
{
focussed = !focussed;
if (!focussed)
{
focus_lost = true;
}
}
}
FBGuiTextBox::FBGuiTextBox()
{
buffer = new char[TEXTBOX_BUFFER_LENGTH];
memset(buffer, '\0', TEXTBOX_BUFFER_LENGTH);
}
FBGuiTextBox::~FBGuiTextBox()
{
delete buffer;
}
int FBGuiListView::getState()
{
return result;
}
void FBGuiListView::reset()
{
active_index = -1;
result = -1;
scroll_index = 0;
}
void FBGuiListView::draw()
{
if (enabled) GuiEnable();
else GuiDisable();
GuiSetStyle(GuiControl::LABEL, GuiControlProperty::TEXT_ALIGNMENT, GuiTextAlignment::TEXT_ALIGN_CENTER);
GuiSetStyle(GuiControl::DEFAULT, GuiDefaultProperty::TEXT_ALIGNMENT_VERTICAL, GuiTextAlignmentVertical::TEXT_ALIGN_MIDDLE);
bool clicked = GuiButton(rect, "");
GuiListView(rect, options.c_str(), &scroll_index, &active_index);
result = clicked ? active_index : -1;
}
int FBGuiInfoModal::getState()
{
return result;
}
void FBGuiInfoModal::draw()
{
result = GuiMessageBox(rect, title.c_str(), message.c_str(), "ok");
}
void FBGuiMessageModal::draw()
{
result = GuiMessageBox(rect, title.c_str(), message.c_str(), options.c_str());
}
string FBGuiTextModal::getText()
{
return string(buffer);
}
void FBGuiTextModal::clearBuffer()
{
memset(buffer, '\0', TEXTBOX_BUFFER_LENGTH);
}
void FBGuiTextModal::draw()
{
if (enabled) GuiEnable();
else GuiDisable();
GuiSetStyle(GuiControl::TEXTBOX, GuiTextBoxProperty::TEXT_READONLY, false);
result = GuiTextInputBox(rect, title.c_str(), message.c_str(), options.c_str(), buffer, TEXTBOX_BUFFER_LENGTH, &secret_view_active);
}
FBGuiTextModal::FBGuiTextModal()
{
buffer = new char[TEXTBOX_BUFFER_LENGTH];
memset(buffer, '\0', TEXTBOX_BUFFER_LENGTH);
}
FBGuiTextModal::~FBGuiTextModal()
{
delete buffer;
}
void FBGuiPanel::draw()
{
if (enabled) GuiEnable();
else GuiDisable();
GuiDrawRectangle(rect, border_width, border, background);
}