forked from fughilli/GUILib
/
Label.cpp
103 lines (78 loc) · 1.95 KB
/
Label.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
#include "Label.h"
Label::Label(uint16_t _posX, uint16_t _posY, uint8_t _zDepth, char * _label)
{
posX = _posX;
posY = _posY;
zDepth = _zDepth;
label = _label;
textColor = LABEL_DEFAULT_TEXT_COLOR;
hasTouchEventCallback = false;
invalid = true;
textSize = LABEL_DEFAULT_TEXT_SIZE;
}
void Label::initialize(void)
{
width = strlen(label)*guiController->screen->fontSizeX();
height = guiController->screen->fontSizeY();
}
bool Label::checkBounds(int16_t touchX, int16_t touchY)
{
return true;
}
void Label::injectTouch(int16_t touchX, int16_t touchY, TouchType_e touchType)
{
GUIElement::injectTouch(touchX, touchY, touchType);
if(hasTouchEventCallback)
onTouchCallback();
}
void Label::draw(bool clearBeforeDraw)
{
// if(clearBeforeDraw)
// {
// guiController->screen->setPenSolid();
// guiController->screen->dRectangle(posX, posY, width, height, LABEL_DEFAULT_BACKGROUND_COLOR);
// guiController->screen->setPenSolid(false);
// }
uint8_t oldTextSize = guiController->screen->getFontSize();
uint8_t tempFontSize = (uint8_t)textSize;
guiController->screen->setFontSize(tempFontSize);
guiController->screen->gText(posX, posY, label, textColor, LABEL_DEFAULT_BACKGROUND_COLOR);
guiController->screen->setFontSize(oldTextSize);
invalid = false;
}
void Label::registerTouchEventCallback(void (*_onTouchCallback)(void))
{
hasTouchEventCallback = true;
onTouchCallback = _onTouchCallback;
}
void Label::setText(char * _label)
{
invalid = true;
label = _label;
initialize();
}
uint16_t Label::getWidth(void)
{
return width;
}
uint16_t Label::getHeight(void)
{
return height;
}
uint16_t Label::getPosX(void)
{
return posX;
}
uint16_t Label::getPosY(void)
{
return posY;
}
void Label::setColor(uint16_t _color)
{
invalid = true;
textColor = _color;
}
void Label::setTextSize(TextSize_e _textSize)
{
textSize = _textSize;
}