Select one of the symbols to view example projects that use it.
 
Outline
#include <gui/home_automation_screen/TemperatureSlider.hpp>
TemperatureSlider::TemperatureSlider()
TemperatureSlider::~TemperatureSlider()
TemperatureSlider::handleClickEvent(const ClickEvent &)
TemperatureSlider::handleDragEvent(const DragEvent &)
TemperatureSlider::setLimits(int16_t, int16_t)
TemperatureSlider::setValue(int16_t)
TemperatureSlider::setSlider(int16_t, bool)
TemperatureSlider::getValue()
TemperatureSlider::setAlpha(uint8_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesTouchGFXGui/gui/src/home_automation_screen/TemperatureSlider.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * This file is part of the TouchGFX 4.10.0 distribution. * * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ #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); // Set the containers dimensions 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) { // Round value to the limits if necessary 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) { // Cut off x values outside the slider area 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(); // Communicate the new value if a listener is registered 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(); }{ ... }