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
48
49
56
57
61
62
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
89
93
94
95
96
97
98
99
100
104
105
106
107
114
115
/* ... */
#include <gui/home_automation_screen/TemperatureSlider.hpp>
TemperatureSlider::TemperatureSlider() :
valueChangedCallback(0)
{
setTouchable(true);
slider.setBitmap(Bitmap(BITMAP_TEMPERATURE_SLIDER_KNOP_ID));
slider.setXY(0, 0);
sliderRadius = slider.getWidth() / 2;
sliderBackground.setBitmap(Bitmap(BITMAP_TEMPERATURE_SLIDER_ID));
sliderBackground.setXY(0, sliderRadius - sliderBackground.getHeight() / 2);
setWidth(sliderBackground.getWidth());
setHeight(slider.getHeight());
add(sliderBackground);
add(slider);
setSlider(30, true);
}{ ... }
TemperatureSlider::~TemperatureSlider()
{
}{ ... }
void TemperatureSlider::handleClickEvent(const ClickEvent& evt)
{
if (evt.getType() == ClickEvent::PRESSED)
{
setSlider(evt.getX(), true);
}if (evt.getType() == ClickEvent::PRESSED) { ... }
}{ ... }
void TemperatureSlider::handleDragEvent(const DragEvent& evt)
{
setSlider(evt.getNewX(), true);
}{ ... }
void TemperatureSlider::setLimits(int16_t min, int16_t max)
{
assert(min < max);
minLimit = min;
maxLimit = max;
}{ ... }
void TemperatureSlider::setValue(int16_t value)
{
value = (value < minLimit) ? minLimit : value;
value = (value > maxLimit) ? maxLimit : value;
float placementPercentage = ((float)(value - minLimit) / (maxLimit - minLimit));
int16_t interval = getWidth() - sliderRadius - sliderRadius;
setSlider(sliderRadius + (int16_t)(placementPercentage * interval), false);
}{ ... }
void TemperatureSlider::setSlider(int16_t x, bool callback)
{
if (x < sliderRadius)
{
x = sliderRadius;
}if (x < sliderRadius) { ... }
else if (x > getWidth() - sliderRadius)
{
x = getWidth() - sliderRadius;
}else if (x > getWidth() - sliderRadius) { ... }
invalidate();
slider.moveTo(x - sliderRadius, 0);
invalidate();
if (valueChangedCallback && callback)
{
valueChangedCallback->execute(getValue());
}if (valueChangedCallback && callback) { ... }
}{ ... }
int16_t TemperatureSlider::getValue()
{
int16_t interval = getWidth() - sliderRadius - sliderRadius;
float placementPercentage = (float) slider.getX() / interval;
return minLimit + ((int16_t)(placementPercentage * (maxLimit - minLimit)));
}{ ... }
void TemperatureSlider::setAlpha(uint8_t alpha)
{
sliderBackground.setAlpha(alpha);
slider.setAlpha(alpha);
sliderBackground.invalidate();
slider.invalidate();
}{ ... }