-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawable.cpp
500 lines (425 loc) · 10.2 KB
/
Drawable.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
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#include "SSD1306.h"
#include "Fragments.h"
/**
* @author Saurav Sajeev
*/
Circle::Circle(uint8_t centerX, uint8_t centerY, uint8_t radius, uint8_t thickness)
: centreX(centerX), centreY(centerY), radius(radius), thickness(thickness) {}
void Circle::draw(OLED &oled)
{
oled.circle(centreX, centreY, radius, thickness);
}
const char *Circle::type() const
{
return "Circle";
}
void Circle::setChangeState()
{
changeState = false;
}
bool Circle::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
Circle &Circle::operator=(const Circle &other)
{
centreX = other.centreX;
centreY = other.centreY;
radius = other.radius;
thickness = other.thickness;
changeState = true;
return *this;
}
void Circle::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool Circle::getVisibility()
{
return visibility;
}
Circle::~Circle()
{
// delete this;
}
Rectangle::Rectangle(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t cornerRadius, uint8_t thickness, bool fill)
: x(x), y(y), width(width), height(height), cornerRadius(cornerRadius), thickness(thickness), fill(fill) {}
void Rectangle::draw(OLED &oled)
{
oled.rectangle(x, y, width, height, cornerRadius, thickness, fill);
}
const char *Rectangle::type() const
{
return "Rectangle";
}
void Rectangle::setChangeState()
{
changeState = false;
}
bool Rectangle::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
Rectangle &Rectangle::operator=(const Rectangle &other)
{
x = other.x;
y = other.y;
width = other.width;
height = other.height;
cornerRadius = other.cornerRadius;
thickness = other.thickness;
changeState = true;
fill = other.fill;
return *this;
}
void Rectangle::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool Rectangle::getVisibility()
{
return visibility;
}
Rectangle::~Rectangle()
{
// delete this;
}
Line::Line(uint8_t startX, uint8_t startY, uint8_t endX, uint8_t endY, uint8_t thickness)
: startX(startX), startY(startY), endX(endX), endY(endY), thickness(thickness) {}
void Line::draw(OLED &oled)
{
oled.line(startX, startY, endX, endY, thickness);
}
const char *Line::type() const
{
return "Line";
}
void Line::setChangeState()
{
changeState = false;
}
bool Line::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
Line &Line::operator=(const Line &other)
{
startX = other.startX;
startY = other.startY;
endX = other.endX;
endY = other.endY;
thickness = other.thickness;
changeState = true;
return *this;
}
void Line::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool Line::getVisibility()
{
return visibility;
}
Line::~Line()
{
// delete this;
}
Bitmap::Bitmap(const uint8_t *dataSet, uint8_t x, uint8_t y, uint8_t width, uint8_t height)
: dataSet(dataSet), x(x), y(y), width(width), height(height) {}
void Bitmap::draw(OLED &oled)
{
oled.draw(dataSet, x, y, width, height);
}
const char *Bitmap::type() const
{
return "Bitmap";
}
void Bitmap::setChangeState()
{
changeState = false;
}
bool Bitmap::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
Bitmap &Bitmap::operator=(const Bitmap &other)
{
dataSet = other.dataSet;
x = other.x;
y = other.y;
width = other.width;
height = other.height;
changeState = true;
return *this;
}
void Bitmap::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool Bitmap::getVisibility()
{
return visibility;
}
Bitmap::~Bitmap()
{
// delete this;
}
Text::Text(String text, uint8_t x, uint8_t y)
: text(text), x(x), y(y) {}
void Text::draw(OLED &oled)
{
oled.print(text, x, y);
}
const char *Text::type() const
{
return "Text";
}
void Text::setChangeState()
{
changeState = false;
}
bool Text::getChangeState()
{
bool temp = changeState;
changeState = false;
return temp;
}
Text &Text::operator=(const Text &other)
{
text = other.text;
x = other.x;
y = other.y;
changeState = true;
changeState = true;
return *this;
}
void Text::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool Text::getVisibility()
{
return visibility;
}
Text::~Text()
{
// delete this;
}
HighlightedText::HighlightedText(String text, uint8_t x, uint8_t y)
: text(text), x(x), y(y) {}
void HighlightedText::draw(OLED &oled)
{
oled.printHighlighted(text, x, y);
}
const char *HighlightedText::type() const
{
return "HighlightedText";
}
void HighlightedText::setChangeState()
{
changeState = false;
}
bool HighlightedText::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
HighlightedText &HighlightedText::operator=(const HighlightedText &other)
{
text = other.text;
x = other.x;
y = other.y;
changeState = true;
return *this;
}
void HighlightedText::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool HighlightedText::getVisibility()
{
return visibility;
}
HighlightedText::~HighlightedText()
{
// delete this;
}
AnimatedText::AnimatedText(String text, uint8_t x, uint8_t y, int delay, bool highlight)
: text(text), x(x), y(y), delay(delay), highlight(highlight) {}
void AnimatedText::draw(OLED &oled)
{
oled.printAnimated(text, x, y, delay, highlight);
}
const char *AnimatedText::type() const
{
return "AnimatedText";
}
void AnimatedText::setChangeState()
{
changeState = false;
}
bool AnimatedText::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
AnimatedText &AnimatedText::operator=(const AnimatedText &other)
{
text = other.text;
x = other.x;
y = other.y;
delay = other.delay;
highlight = other.highlight;
changeState = true;
return *this;
}
void AnimatedText::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool AnimatedText::getVisibility()
{
return visibility;
}
AnimatedText::~AnimatedText()
{
// delete this;
}
GridView::GridView(Drawable *drawable, uint8_t count, uint8_t countPerLine, uint8_t startX, uint8_t startY, uint8_t seperationX, uint8_t seperationY)
: drawable(drawable), count(count), countPerLine(countPerLine), startX(startX), startY(startY), seperationX(seperationX), seperationY(seperationY) {}
void GridView::draw(OLED &oled)
{
if (checkType())
{
uint8_t tempX;
if (drawable->type() == "Line")
{
Line *line = static_cast<Line *>(drawable);
uint8_t dX = abs(line->startX - line->endX);
uint8_t dY = abs(line->startY - line->endY);
tempX = startX;
for (uint8_t col = 0; col < count / countPerLine; col++)
{
startX = tempX;
for (uint8_t row = 0; row < countPerLine; row++)
{
line->startX = startX;
line->startY = startY;
line->endX = line->startX + dX;
line->endY = line->startY + dY;
startX += dX + seperationX;
line->draw(oled);
yield();
}
startY += dY + seperationY;
}
}
else if (drawable->type() == "Rectangle")
{
Rectangle *rectangle = static_cast<Rectangle *>(drawable);
tempX = startX;
for (uint8_t col = 0; col < count / countPerLine; col++)
{
startX = tempX;
for (uint8_t row = 0; row < countPerLine; row++)
{
rectangle->x = startX;
rectangle->y = startY;
startX += rectangle->width + seperationX;
rectangle->draw(oled);
yield();
}
startY += rectangle->height + seperationY;
}
}
else if (drawable->type() == "Circle")
{
Circle *circle = static_cast<Circle *>(drawable);
tempX = startX;
for (uint8_t col = 0; col < count / countPerLine; col++)
{
startX = tempX;
for (uint8_t row = 0; row < countPerLine; row++)
{
circle->centreX = startX;
circle->centreY = startY;
startX += circle->radius * 2 + seperationX;
circle->draw(oled);
yield();
}
startY += circle->radius * 2 + seperationY;
}
}
else if (drawable->type() == "Bitmap")
{
Bitmap *bitmap = static_cast<Bitmap *>(drawable);
tempX = startX;
for (uint8_t col = 0; col < count / countPerLine; col++)
{
startX = tempX;
for (uint8_t row = 0; row < countPerLine; row++)
{
bitmap->x = startX;
bitmap->y = startY;
startX += bitmap->width + seperationX;
bitmap->draw(oled);
yield();
}
startY += bitmap->height + seperationY;
}
}
}
delete drawable;
}
bool GridView::checkType()
{
return drawable->type() == "Line" || drawable->type() == "Rectangle" || drawable->type() == "Circle" || drawable->type() == "Bitmap";
}
const char *GridView::type() const
{
return "GridView";
}
void GridView::setChangeState()
{
changeState = false;
}
bool GridView::getChangeState()
{
bool temp = changeState;
changeState = false;
return changeState;
}
GridView &GridView::operator=(const GridView &other)
{
drawable = other.drawable;
count = other.count;
countPerLine = other.countPerLine;
startX = other.startX;
startY = other.startY;
seperationX = other.seperationX;
seperationY = other.seperationY;
changeState = true;
return *this;
}
void GridView::setVisibility(bool visibility)
{
this->visibility = visibility;
}
bool GridView::getVisibility()
{
return visibility;
}
GridView::~GridView()
{
// delete this;
}