-
Notifications
You must be signed in to change notification settings - Fork 1
/
button.cpp
64 lines (53 loc) · 1.45 KB
/
button.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
#include "button.h"
#include "gui.h"
#include "utils.h"
#include "window.h"
#include <SPI.h>
#include <GD.h>
void CButton::coreDraw()
{
const SDimensions dim(getDimensions());
const uint8_t right = dim.x + dim.w - 1;
const uint8_t bottom = dim.y + dim.h - 1;
for (uint8_t x=dim.x+1; x<right; ++x)
{
GD.wr(atxy(x, dim.y),
(highlight) ? CHAR_BUTTON_HORIZ_TOP_HL : CHAR_BUTTON_HORIZ_TOP);
GD.wr(atxy(x, bottom),
(highlight) ? CHAR_BUTTON_HORIZ_BOTTOM_HL : CHAR_BUTTON_HORIZ_BOTTOM);
}
for (uint8_t y=dim.y+1; y<bottom; ++y)
{
GD.wr(atxy(dim.x, y),
(highlight) ? CHAR_BUTTON_VERT_LEFT_HL : CHAR_BUTTON_VERT_LEFT);
GD.wr(atxy(right, y),
(highlight) ? CHAR_BUTTON_VERT_RIGHT_HL : CHAR_BUTTON_VERT_RIGHT);
}
if (flashText)
putstr_P(dim.x + 2, dim.y + 1, text);
else
putstr(dim.x + 2, dim.y + 1, text);
}
bool CButton::coreHandleMouseClick(EMouseButton button)
{
if (getParentWindow())
getParentWindow()->callback(this);
return true;
}
void CButton::coreHandleMouseMove(uint8_t mx, uint8_t my)
{
const bool oldh = highlight;
highlight = inWidget(mx, my);
if (oldh != highlight)
GUI.redrawDesktop();
}
void CButton::setText(const char *t, bool ft)
{
text = t;
flashText = ft;
if (ft)
setWidth(strlen_P(t) + 4);
else
setWidth(strlen(t) + 4);
GUI.redrawDesktop();
}