1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
111
112
113
114
115
118
119
122
123
126
127
128
129
130
131
153
154
155
156
157
163
164
165
166
167
172
177
178
179
180
181
182
183
184
185
186
187
188
194
195
196
197
198
199
200
216
217
218
219
220
221
223
225
227
229
231
233
235
236
237
238
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
272
273
274
275
276
277
278
279
280
281
282
283
288
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
318
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/* ... */
#include <gui/custom_controls_screen/CustomControlsView.hpp>
#include "BitmapDatabase.hpp"
#include <texts/TextKeysAndLanguages.hpp>
#include <touchgfx/Color.hpp>
#include <touchgfx/EasingEquations.hpp>
#include <gui/common/Utils.hpp>
6 includes
CustomControlsView::CustomControlsView() :
DemoView<CustomControlsPresenter>(),
onButtonPressed(this, &CustomControlsView::buttonPressedHandler),
slideMenuElementSelectedCallback(this, &CustomControlsView::slideMenuElementSelectedHandler),
threeWayButtonPressedCallback(this, &CustomControlsView::threeWayButtonPressedHandler),
currentAnimationState(NO_ANIMATION),
tickCounter(0)
{
menuBackground.setBitmap(Bitmap(BITMAP_CONTROLS_MENU_BACKGROUND_ID));
menuBackground.setXY(0, 0);
add(menuBackground);
background.setBitmap(Bitmap(BITMAP_CONTROLS_BACKGROUND_ID));
background.setXY(menuBackground.getWidth(), 0);
add(background);
menuUp.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_ARROW_UP_ID), Bitmap(BITMAP_CONTROL_MENU_ARROW_UP_PRESSED_ID));
menuUp.setXY(menuBackground.getX(), menuBackground.getY());
menuUp.setAction(onButtonPressed);
add(menuUp);
menuDown.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_ARROW_DOWN_ID), Bitmap(BITMAP_CONTROL_MENU_ARROW_DOWN_PRESSED_ID));
menuDown.setXY(menuUp.getX(), menuBackground.getRect().bottom() - menuDown.getHeight());
menuDown.setAction(onButtonPressed);
add(menuDown);
int numberOfElements = (Utils::reducedPerformance()) ? 3 : 4;
slideMenu.setPosition(menuBackground.getX() + ((menuBackground.getWidth() - Bitmap(BITMAP_CONTROL_MENU_ICON_DATEPICKER_LARGE_ID).getWidth()) / 2) - 7, menuUp.getRect().bottom(), 60, menuDown.getY() - menuUp.getRect().bottom());
slideMenu.setup(numberOfElements, 0, Bitmap(BITMAP_CONTROL_MENU_ICON_DATEPICKER_SMALL_ID), Bitmap(BITMAP_CONTROL_MENU_ICON_DATEPICKER_LARGE_ID));
slideMenu.setBitmapsForElement(0, BITMAP_CONTROL_MENU_ICON_GAUGE_SMALL_ID, BITMAP_CONTROL_MENU_ICON_GAUGE_LARGE_ID);
slideMenu.setBitmapsForElement(1, BITMAP_CONTROL_MENU_ICON_THREE_WAY_SMALL_ID, BITMAP_CONTROL_MENU_ICON_THREE_WAY_LARGE_ID);
slideMenu.setBitmapsForElement(2, BITMAP_CONTROL_MENU_ICON_PERCENTAGE_SMALL_ID, BITMAP_CONTROL_MENU_ICON_PERCENTAGE_LARGE_ID);
if (!Utils::reducedPerformance())
{
slideMenu.setBitmapsForElement(3, BITMAP_CONTROL_MENU_ICON_DATEPICKER_SMALL_ID, BITMAP_CONTROL_MENU_ICON_DATEPICKER_LARGE_ID);
}if (!Utils::reducedPerformance()) { ... }
slideMenu.setAnimationDuration(8);
slideMenu.setElementSelectedCallback(slideMenuElementSelectedCallback);
add(slideMenu);
gotoMenuButton.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_BUTTON_ID), Bitmap(BITMAP_CONTROL_MENU_BUTTON_PRESSED_ID));
gotoMenuButton.setXY(HAL::DISPLAY_WIDTH - gotoMenuButton.getWidth() - 3, 2);
add(gotoMenuButton);
threeWayProgressBar.setXY(background.getX() + (background.getWidth() - threeWayProgressBar.getWidth()) / 2, background.getY() + (background.getHeight() - threeWayProgressBar.getHeight()) / 2);
threeWayProgressBar.setButtonClickedCallback(threeWayButtonPressedCallback);
threeWayProgressBar.setVisible(false);
add(threeWayProgressBar);
percentageBar.setXY(background.getX() + (background.getWidth() - percentageBar.getWidth()) / 2, background.getY() + (background.getHeight() - percentageBar.getHeight()) / 2);
percentageBar.setBarAngle(-40);
percentageBar.setVisible(false);
add(percentageBar);
datePicker.setXY(background.getX() + (background.getWidth() - datePicker.getWidth()) / 2, background.getY() + (background.getHeight() - datePicker.getHeight()) / 2);
datePicker.setVisible(false);
add(datePicker);
gauge.setBitmaps(Bitmap(BITMAP_GAUGE_BACKGROUND_ID), Bitmap(BITMAP_GAUGE_NEEDLE_PIN_ID));
gauge.setXY(background.getX() + (background.getWidth() - gauge.getWidth()) / 2, background.getY() + (background.getHeight() - gauge.getHeight()) / 2);
gauge.setLimits(0, 60, 240, 480);
gauge.setValue(40);
gauge.setAnimationDuration(20);
gauge.setVisible(false);
add(gauge);
statusMessage.setPosition(background.getX() + 6, 20, 100, 48);
statusMessage.setColor(Color::getColorFrom24BitRGB(0xFF, 0xFF, 0xFF));
statusMessage.setVisible(false);
add(statusMessage);
mcuLoadTxt.setXY(HAL::DISPLAY_WIDTH - 106, 258 - mcuLoadTxt.getTypedText().getFont()->getFontHeight());
mcuLoadTxt.setColor(Color::getColorFrom24BitRGB(0x17, 0x3C, 0x51));
mcuLoadValueTxt.setPosition(mcuLoadTxt.getRect().right(), mcuLoadTxt.getY(), 34, 14);
mcuLoadValueTxt.setColor(mcuLoadTxt.getColor());
add(mcuLoadTxt);
add(mcuLoadValueTxt);
for (int i = 0; i < NUMBER_OF_BARS; i++)
{
barAnimationState[i] = NO_ANIMATION;
}for (int i = 0; i < NUMBER_OF_BARS; i++) { ... }
slideMenuElementSelectedHandler(slideMenu);
}{ ... }
CustomControlsView::~CustomControlsView()
{
}{ ... }
void CustomControlsView::setupScreen()
{
}{ ... }
void CustomControlsView::tearDownScreen()
{
}{ ... }
void CustomControlsView::handleTickEvent()
{
tickCounter++;
if (getAnimationState() == ANIMATION_THREE_WAY_RUNNING)
{
for (int i = 0; i < NUMBER_OF_BARS; i++)
{
if (animationCounter < animationDuration[i])
{
int percentage = animationEquation[i](animationCounter, 0, 103, animationDuration[i]);
threeWayProgressBar.setBarPercentage(i, percentage);
}if (animationCounter < animationDuration[i]) { ... }
else
{
barAnimationState[i] = NO_ANIMATION;
}else { ... }
if (getAnimationState() != ANIMATION_THREE_WAY_RUNNING)
{
stopThreeWayProgressBarAnimation();
}if (getAnimationState() != ANIMATION_THREE_WAY_RUNNING) { ... }
}for (int i = 0; i < NUMBER_OF_BARS; i++) { ... }
animationCounter++;
}if (getAnimationState() == ANIMATION_THREE_WAY_RUNNING) { ... }
else if (getAnimationState() == ANIMATION_GAUGE)
{
if (tickCounter % 60 == 0)
{
if (gauge.getValue() > 50)
{
gauge.setEasingEquation(EasingEquations::backEaseOut);
gauge.setAnimationDuration(20);
gauge.setValue(0);
}if (gauge.getValue() > 50) { ... }
else
{
int value = gauge.getValue();
int newValue = value + Utils::randomNumberBetween(-6, 18);
if (newValue < value)
{
gauge.setEasingEquation(EasingEquations::backEaseOut);
gauge.setAnimationDuration((newValue - value) * 2);
}if (newValue < value) { ... }
else
{
gauge.setEasingEquation(EasingEquations::quadEaseOut);
gauge.setAnimationDuration(newValue - value);
}else { ... }
gauge.setValue(newValue);
}else { ... }
}if (tickCounter % 60 == 0) { ... }
}else if (getAnimationState() == ANIMATION_GAUGE) { ... }
}{ ... }
void CustomControlsView::startThreeWayProgressBarAnimation()
{
animationCounter = 0;
for (int i = 0; i < NUMBER_OF_BARS; i++)
{
animationEquation[i] = getRandomEasingEquation();
animationDuration[i] = Utils::randomNumberBetween(100, 200);
barAnimationState[i] = ANIMATION_THREE_WAY_RUNNING;
}for (int i = 0; i < NUMBER_OF_BARS; i++) { ... }
currentAnimationState = ANIMATION_THREE_WAY_RUNNING;
statusMessage.setVisible(false);
statusMessage.invalidate();
}{ ... }
CustomControlsView::AnimationState CustomControlsView::getAnimationState()
{
if (currentAnimationState == ANIMATION_THREE_WAY_RUNNING)
{
for (int i = 0; i < NUMBER_OF_BARS; i++)
{
if (barAnimationState[i] == ANIMATION_THREE_WAY_RUNNING)
{
return ANIMATION_THREE_WAY_RUNNING;
}if (barAnimationState[i] == ANIMATION_THREE_WAY_RUNNING) { ... }
}for (int i = 0; i < NUMBER_OF_BARS; i++) { ... }
return NO_ANIMATION;
}if (currentAnimationState == ANIMATION_THREE_WAY_RUNNING) { ... }
return currentAnimationState;
}{ ... }
touchgfx::EasingEquation CustomControlsView::getRandomEasingEquation()
{
switch (Utils::randomNumberBetween(0, 6))
{
case 0:
return EasingEquations::sineEaseIn;case 0:
case 1:
return EasingEquations::linearEaseInOut;case 1:
case 2:
return EasingEquations::quadEaseIn;case 2:
case 3:
return EasingEquations::cubicEaseOut;case 3:
case 4:
return EasingEquations::cubicEaseInOut;case 4:
case 5:
return EasingEquations::linearEaseNone;case 5:
default:
return EasingEquations::sineEaseIn;default
}switch (Utils::randomNumberBetween(0, 6)) { ... }
}{ ... }
void CustomControlsView::threeWayButtonPressedHandler(const ThreeWayProgressBar& button)
{
threeWayProgressBar.setActive(true);
startThreeWayProgressBarAnimation();
}{ ... }
void CustomControlsView::stopThreeWayProgressBarAnimation()
{
threeWayProgressBar.setActive(false);
statusMessage.setVisible(true);
statusMessage.setAlpha(255);
statusMessage.setTypedText(TypedText(T_THREE_WAY_PROGRESS_BAR_STATUS));
statusMessage.setFadeAnimationDelay(80);
statusMessage.startFadeAnimation(0, 40, EasingEquations::cubicEaseIn);
statusMessage.invalidate();
currentAnimationState = NO_ANIMATION;
}{ ... }
void CustomControlsView::buttonPressedHandler(const AbstractButton& button)
{
threeWayProgressBar.stopAnimation();
if (&button == &menuUp)
{
currentAnimationState = NO_ANIMATION;
slideMenu.animateDown();
}if (&button == &menuUp) { ... }
else if (&button == &menuDown)
{
currentAnimationState = NO_ANIMATION;
slideMenu.animateUp();
}else if (&button == &menuDown) { ... }
}{ ... }
void CustomControlsView::slideMenuElementSelectedHandler(const VerticalSlideMenu& menu)
{
int selectedElement = slideMenu.getSelectedElementIndex();
menuUp.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_ARROW_UP_ID), Bitmap(BITMAP_CONTROL_MENU_ARROW_UP_PRESSED_ID));
menuDown.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_ARROW_DOWN_ID), Bitmap(BITMAP_CONTROL_MENU_ARROW_DOWN_PRESSED_ID));
menuUp.setTouchable(true);
menuDown.setTouchable(true);
if (selectedElement == 0)
{
menuUp.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_ARROW_UP_INACTIVE_ID), Bitmap(BITMAP_CONTROL_MENU_ARROW_UP_INACTIVE_ID));
menuUp.setTouchable(false);
}if (selectedElement == 0) { ... }
else if (selectedElement == slideMenu.getSize() - 1)
{
menuDown.setBitmaps(Bitmap(BITMAP_CONTROL_MENU_ARROW_DOWN_INACTIVE_ID), Bitmap(BITMAP_CONTROL_MENU_ARROW_DOWN_INACTIVE_ID));
menuDown.setTouchable(false);
}else if (selectedElement == slideMenu.getSize() - 1) { ... }
menuUp.setWidth(menuUp.getWidth() + 30);
menuDown.setWidth(menuDown.getWidth() + 30);
menuUp.invalidate();
menuDown.invalidate();
gauge.setVisible(selectedElement == 0);
threeWayProgressBar.setVisible(selectedElement == 1);
percentageBar.setVisible(selectedElement == 2);
datePicker.setVisible(selectedElement == 3);
statusMessage.setVisible(false);
datePicker.invalidate();
gauge.invalidate();
threeWayProgressBar.invalidate();
percentageBar.invalidate();
statusMessage.invalidate();
currentAnimationState = NO_ANIMATION;
if (gauge.isVisible())
{
currentAnimationState = ANIMATION_GAUGE;
}if (gauge.isVisible()) { ... }
else if (threeWayProgressBar.isVisible())
{
threeWayProgressBar.reset();
}else if (threeWayProgressBar.isVisible()) { ... }
else if (datePicker.isVisible())
{
datePicker.reset();
datePicker.setday(14, 0, EasingEquations::backEaseInOut);
datePicker.setMonth(6, 0, EasingEquations::backEaseInOut);
datePicker.setYear(8, 0, EasingEquations::backEaseInOut);
datePicker.setday(23, 40, EasingEquations::backEaseInOut);
datePicker.setMonth(1, 42, EasingEquations::backEaseInOut);
datePicker.setYear(3, 38, EasingEquations::backEaseInOut);
}else if (datePicker.isVisible()) { ... }
}{ ... }
void CustomControlsView::screenSaverMinorTick()
{
if (slideMenu.getSelectedElementIndex() == 0)
{
buttonPressedHandler(menuDown);
}if (slideMenu.getSelectedElementIndex() == 0) { ... }
else if (slideMenu.getSelectedElementIndex() == slideMenu.getSize() - 1)
{
buttonPressedHandler(menuUp);
}else if (slideMenu.getSelectedElementIndex() == slideMenu.getSize() - 1) { ... }
else
{
if (Utils::randomNumberBetween(0, 100) < 50)
{
buttonPressedHandler(menuUp);
}if (Utils::randomNumberBetween(0, 100) < 50) { ... }
else
{
buttonPressedHandler(menuDown);
}else { ... }
}else { ... }
}{ ... }