-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserInterface.h
136 lines (110 loc) · 2.66 KB
/
UserInterface.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
#include "WindowManager.h"
class button {
vec2d start;
vec2d end;
Color c;
Color cOnButton;
Color activeCol;
bool onButton=false;
int id = -1;
public:
bool meshButton=true;
button(int x1,int y1,int x2,int y2, Color cN, Color cPressed,int identificator) {
start = { x1,y1 };
end = { x2,y2 };
c = cN;
cOnButton = cPressed;
id = identificator;
activeCol = cN;
}
button() {
start = { 10,10 };
end = { 20,20 };
c = COLOR_WHITE;
cOnButton = COLOR_RED;
activeCol = c;
}
int getId() {
return id;
}
bool posInButton(vec2d pos) {
return (pos.x >= start.x && pos.x <= end.x)
&& (pos.y >= start.y && pos.y <= end.y);
}
void draw(WindowManager w) {
w.drawLine(start.x, start.y,end.x,start.y, activeCol);
w.drawLine(start.x, start.y, start.x, end.y, activeCol);
w.drawLine(end.x, start.y, end.x, end.y, activeCol);
w.drawLine(start.x, end.y, end.x, end.y, activeCol);
}
};
class UserInterface {
private:
void handleInput(SDL_Event e) {
}
public:
vector<button> buttonPool;
UserInterface() {
button add = button(1, 1 , 20, 20, COLOR_WHITE, COLOR_BLUE, -2);
add.meshButton = false;
button redRect = button(1, 21, 20, 39, COLOR_RED, COLOR_BLUE, 0);
redRect.meshButton = true;
buttonPool.insert(buttonPool.end(),add);
buttonPool.insert(buttonPool.end(), redRect);
}
void display(WindowManager w, int &selected) {
w.drawLine(1, 10, 20, 10, COLOR_WHITE);
w.drawLine(10, 1, 10, 20, COLOR_WHITE);
for (auto but : buttonPool) {
but.draw(w);
}
}
void checkInputButton(int& selected, WindowManager &w) {
for (auto but : buttonPool) {
if (but.posInButton(mousePos)) {
if (but.getId() == -2) {
int size= w.getObjPoolSize();
Color k;
switch (size % 7) {
case 0:
k = COLOR_GREEN;
break;
case 1 :
k = COLOR_BLUE;
break;
case 2:
k = COLOR_GREEN;
break;
case 3:
k = COLOR_PURPLE;
break;
case 4:
k = COLOR_YELLOW;
break;
case 5:
k = COLOR_RED;
break;
case 6:
k = COLOR_CELESTE;
break;
}
button newbut = button(0, 19 *(size+1)+2, 19, 19 * (size + 1)+ 21, k, k, size);
newbut.meshButton = true;
buttonPool.insert(buttonPool.end(), newbut);
meshGenerator m;
Mesh newMesh = m.creatCube(0.5f);
newMesh.color = k;
gameObject g("");
g.mesh = newMesh;
g.position = {0,0,3}; g.rotation = { 0,0,0 };
w.addObjToPool(g);
break;
}
if (but.meshButton) {
selected = but.getId();
break;
}
}
}
}
};