-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathButtonClass.h
More file actions
337 lines (290 loc) · 7.34 KB
/
ButtonClass.h
File metadata and controls
337 lines (290 loc) · 7.34 KB
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
*_________________________________________________________________________
*
*
* LCD Button Maker for VEX Robotics V5 brain
*
* By: Andrew Simonson from Team 96807B
*
*_________________________________________________________________________
*/
#include "vex.h"
void insertText(std::string text, int width, int height, int xi, int yi, int Ftype, int Fsize, int penHue, std::string penHex){
const char *string = text.c_str();
switch(Ftype){
case 0: switch(Fsize){
case 12: Brain.Screen.setFont(mono12);
break;
case 15: Brain.Screen.setFont(mono15);
break;
case 20: Brain.Screen.setFont(mono20);
break;
case 30: Brain.Screen.setFont(mono30);
break;
case 40: Brain.Screen.setFont(mono40);
break;
};
break;
case 1: switch(Fsize){
case 20: Brain.Screen.setFont(prop20);
break;
case 30: Brain.Screen.setFont(prop30);
break;
case 40: Brain.Screen.setFont(prop40);
break;
case 60: Brain.Screen.setFont(prop60);
break;
};
break;
case 2: switch(Fsize){
//case 15: Brain.Screen.setFont(cjk16);
break;
};
break;
}
//WHAT IS MONOXL I DID NOT SIGN UP FOR THIS
int x = xi - (vexDisplayStringWidthGet(string)/2);
int y = yi + (vexDisplayStringHeightGet(string)/4);
if(penHue != -1){
Brain.Screen.setPenColor(penHue);
}
else{
Brain.Screen.setPenColor(penHex.c_str());
}
Brain.Screen.printAt(x, y, string);
}
int nextId = 0;
class lcdButton {
public:
int buttonId;
int xPos = 100;
int yPos = 100;
int width = 20;
int height = 20;
int hue = -1;
std::string hex = "#353535";
std::string text = "";
int font = 0;
int fontsize = 20;
int penHue = -1;
std::string penHex = "#FFFFFF";
std::string outlinehex = "white";
int outlinehue = -1;
int thickness = 2;
int xMin;
int xMax;
int yMin;
int yMax;
//_________________________________________________________________________
//_________________________________________________________________________
//constructors
//_________________________________________________________________________
//_________________________________________________________________________
lcdButton(int x, int y, int wide, int tall, std::string chars, std::string colorHex){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
hex = colorHex;
draw();
}
lcdButton(int x, int y, int wide, int tall, std::string colorHex){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
hex = colorHex;
draw();
}
lcdButton(int x, int y, int wide, int tall, std::string chars, std::string colorHex, std::string outHex, int outThickness){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
hex = colorHex;
outlinehex = outHex;
thickness = outThickness;
draw();
}
lcdButton(int x, int y, int wide, int tall, std::string chars, int colorHue, std::string outHex, int outThickness){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
hue = colorHue;
hex = "using hue";
outlinehex = outHex;
thickness = outThickness;
draw();
}
lcdButton(int x, int y, int wide, int tall, std::string chars, std::string colorHex, int outHue, int outThickness){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
hex = colorHex;
outlinehue = outHue;
outlinehex = "using hue";
thickness = outThickness;
draw();
}
lcdButton(int x, int y, int wide, int tall, std::string chars, int colorHue, int outHue, int outThickness){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
hue = colorHue;
hex = "using hue";
outlinehue = outHue;
outlinehex = "using hue";
thickness = outThickness;
draw();
}
//end intended helper view --------------------------------
lcdButton(int x, int y, int tall, std::string chars){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = tall;
height = tall;
text = chars;
draw();
}
/*lcdButton(int x, int y, int wide, int tall, std::string chars){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
draw();
}*/
//string assumes color, not text
lcdButton(int x, int y, int wide, int tall, int colorHue){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
hue = colorHue;
hex = "using hue";
draw();
}
lcdButton(int x, int y, int wide, int tall, std::string chars, int colorHue){
buttonId = nextId;
nextId++;
xPos = x;
yPos = y;
width = wide;
height = tall;
text = chars;
hue = colorHue;
hex = "using hue";
draw();
}
//_________________________________________________________________________
//_________________________________________________________________________
//Functions
//_________________________________________________________________________
//_________________________________________________________________________
void setPenColor(std::string input){
penHex = input;
penHue = -1;
}
void setPenColor(int input){
penHue = input;
penHex = "using hue";
}
void setFont(int chosen){
font = chosen;
}
void setFontSize(int chosen){
fontsize = chosen;
}
void moveTo(int x, int y){
xPos = x;
yPos = y;
draw();
}
void setText(std::string chars){
text = chars;
draw();
}
void setSize(int wide, int tall){
height = tall;
width = wide;
draw();
}
void setColor(int colorHue){
hex = "using hue";
hue = colorHue;
draw();
}
void setColor(std::string colorHex){
hue = -1;
hex = colorHex;
draw();
}
void setOutlineThickness(int thick){
thickness = thick;
draw();
}
void setOutlineColor(std::string colored){
outlinehex = colored;
outlinehue = -1;
}
void setOutlineColor(int colored){
outlinehue = colored;
outlinehex = "using hue";
}
void draw(){
xMin = xPos - (width/2);
xMax = xPos + (width/2);
yMin = yPos - (height/2);
yMax = yPos + (height/2);
if(outlinehue != -1){
Brain.Screen.setPenColor(outlinehue);
}
else{
Brain.Screen.setPenColor(outlinehex.c_str());
}
Brain.Screen.setPenWidth(thickness);
if(hue != -1){ //determine if using hue int or hex string
Brain.Screen.drawRectangle(xPos - (width/2), yPos - (height/2), width, height, hue);
}
else{ //using hex
const char *string = hex.c_str();
Brain.Screen.drawRectangle(xPos - (width/2), yPos - (height/2), width, height, string);
}
insertText(text, width, height, xPos, yPos, font, fontsize, penHue, penHex);
}
//________________________________________________________________________________________________
bool pressing(){
if(Brain.Screen.pressing() && Brain.Screen.xPosition() < xMax && Brain.Screen.xPosition() > xMin && Brain.Screen.yPosition() < yMax && Brain.Screen.yPosition() > yMin){
return true;
}
else{
return false;
}
}
};