forked from funkey/gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchPainter.cpp
72 lines (51 loc) · 942 Bytes
/
SwitchPainter.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
#include <gui/OpenGl.h>
#include "SwitchPainter.h"
namespace gui {
SwitchPainter::SwitchPainter(bool value) :
_value(value),
_highlight(false) {
setSize(0, 0, 10, 10);
}
void
SwitchPainter::setValue(bool value) {
_value = value;
}
bool
SwitchPainter::getValue() {
return _value;
}
void
SwitchPainter::setHighlight(bool highlight) {
_highlight = highlight;
}
void
SwitchPainter::draw(
const util::rect<double>& roi,
const util::point<double>& resolution) {
double r, g, b, a;
if (_value) {
r = 0.1;
g = 0.5;
b = 0.0;
a = 0.5;
} else {
r = 0.5;
g = 0.1;
b = 0.0;
a = 0.5;
}
if (_highlight) {
r *= 2.0;
g *= 2.0;
b *= 2.0;
}
const util::rect<double>& size = getSize();
glColor4f(r, g, b, a);
glBegin(GL_QUADS);
glVertex2d(size.minX, size.minY);
glVertex2d(size.maxX, size.minY);
glVertex2d(size.maxX, size.maxY);
glVertex2d(size.minX, size.maxY);
glEnd();
}
} // namespace gui