1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26
27
28
29
30
33
34
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
122
123
126
127
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
225
226
239
240
253
254
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* ... */
#include <gui/product_presenter_screen/ProductPresenterView.hpp>
#include "BitmapDatabase.hpp"
#include <touchgfx/Color.hpp>
#include <touchgfx/EasingEquations.hpp>
#include <texts/TextKeysAndLanguages.hpp>
5 includes
ProductPresenterView::ProductPresenterView() :
DemoView<ProductPresenterPresenter>(),
selectedPoster(0),
onButtonPressed(this, &ProductPresenterView::buttonPressedHandler),
languageSelectorStateChanged(this, &ProductPresenterView::languageSelectorStateChangedHandler),
onFadeAnimationEnded(this, &ProductPresenterView::fadeAnimationEndedHandler)
{
}{ ... }
ProductPresenterView::~ProductPresenterView()
{
Texts::setLanguage(GBR);
}{ ... }
void ProductPresenterView::setupScreen()
{
posterContainer.setPosition(0, 0, Bitmap(BITMAP_POSTER_IMAGE_00_ID).getWidth(), Bitmap(BITMAP_POSTER_IMAGE_00_ID).getHeight());
poster.setXY(0, 0);
posterContainer.add(poster);
posterContainer.add(posterSwap);
shadowBox.setColor(Color::getColorFrom24BitRGB(0x0, 0x0, 0x0));
shadowBox.setPosition(posterContainer.getRect().right(), posterContainer.getY(), 1, posterContainer.getHeight());
add(shadowBox);
textBackground.setColor(Color::getColorFrom24BitRGB(0xFF, 0xFF, 0xFF));
textBackground.setPosition(shadowBox.getRect().right(), 0, HAL::DISPLAY_WIDTH - shadowBox.getRect().right(), posterContainer.getHeight());
add(textBackground);
nextButton.setBitmaps(Bitmap(BITMAP_PRODUCT_PRESENTER_NEXT_ID), Bitmap(BITMAP_PRODUCT_PRESENTER_NEXT_PRESSED_ID));
nextButton.setXY(HAL::DISPLAY_WIDTH - nextButton.getWidth(), 0);
nextButton.setAction(onButtonPressed);
headlineText.setPosition(textBackground.getX() + BODY_TEXT_MARGIN, textBackground.getY() + 20, nextButton.getX() - textBackground.getX(), 30);
headlineText.setColor(Color::getColorFrom24BitRGB(0x76, 0x76, 0x76));
headlineTextSwap.setWidth(headlineText.getWidth());
headlineTextSwap.setHeight(headlineText.getHeight());
headlineTextSwap.setColor(headlineText.getColor());
add(headlineText);
add(headlineTextSwap);
add(nextButton);
textAreaContainer.setPosition(textBackground.getX(), nextButton.getRect().bottom(), textBackground.getWidth(), textBackground.getHeight() - nextButton.getRect().bottom());
bodyText.setPosition(BODY_TEXT_MARGIN, 0, textAreaContainer.getWidth() - 2 * BODY_TEXT_MARGIN, textAreaContainer.getWidth() - BODY_TEXT_MARGIN);
bodyText.setColor(headlineText.getColor());
bodyText.setFadeAnimationEndedAction(onFadeAnimationEnded);
textAreaContainer.add(bodyText);
add(textAreaContainer);
add(posterContainer);
navigationBar.setBitmap(Bitmap(BITMAP_PRODUCT_PRESENTER_NAV_BAR_ID));
navigationBar.setXY(posterContainer.getX(), posterContainer.getRect().bottom());
add(navigationBar);
gotoMenuButton.setBitmaps(Bitmap(BITMAP_PRODUCT_PRESENTER_MENU_BUTTON_ID), Bitmap(BITMAP_PRODUCT_PRESENTER_MENU_BUTTON_PRESSED_ID));
gotoMenuButton.setXY(0, navigationBar.getY());
add(gotoMenuButton);
mcuLoadTxt.setXY(8, 208 - mcuLoadTxt.getTypedText().getFont()->getFontHeight());
mcuLoadValueTxt.setPosition(mcuLoadTxt.getRect().right(), mcuLoadTxt.getY(), 34, 14);
add(mcuLoadTxt);
add(mcuLoadValueTxt);
activateLanguageSelectorButton.setXY(419, 231);
activateLanguageSelectorButton.setAction(onButtonPressed);
add(activateLanguageSelectorButton);
languages[0] = GBR;
inactiveLanguageButtons[0] = BITMAP_FLAG_GBR_INACTIVE_ID;
languages[1] = DNK;
inactiveLanguageButtons[1] = BITMAP_FLAG_DNK_INACTIVE_ID;
languages[2] = JPN;
inactiveLanguageButtons[2] = BITMAP_FLAG_JPN_INACTIVE_ID;
languages[3] = UKR;
inactiveLanguageButtons[3] = BITMAP_FLAG_UKR_INACTIVE_ID;
languages[4] = NLD;
inactiveLanguageButtons[4] = BITMAP_FLAG_NLD_INACTIVE_ID;
languageSelector.addMenuElement(Bitmap(BITMAP_FLAG_GBR_ACTIVE_ID), Bitmap(BITMAP_FLAG_GBR_ACTIVE_ID));
languageSelector.addMenuElement(Bitmap(BITMAP_FLAG_DNK_ACTIVE_ID), Bitmap(BITMAP_FLAG_DNK_ACTIVE_ID));
languageSelector.addMenuElement(Bitmap(BITMAP_FLAG_JPN_ACTIVE_ID), Bitmap(BITMAP_FLAG_JPN_ACTIVE_ID));
languageSelector.addMenuElement(Bitmap(BITMAP_FLAG_UKR_ACTIVE_ID), Bitmap(BITMAP_FLAG_UKR_ACTIVE_ID));
languageSelector.addMenuElement(Bitmap(BITMAP_FLAG_NLD_ACTIVE_ID), Bitmap(BITMAP_FLAG_NLD_ACTIVE_ID));
languageSelector.setElementSpace(20);
languageSelector.setExpandDirection(CollapsibleMenu::LEFT);
languageSelector.setStateChangedCallback(languageSelectorStateChanged);
languageSelector.setTimeout(300);
languageSelector.finilizeInitialization();
languageSelector.setXY(469 - languageSelector.getWidth(), 227);
languageSelector.fadeOut(10);
add(languageSelector);
setLanguage();
animateToPoster(0, 1);
}{ ... }
void ProductPresenterView::tearDownScreen()
{
}{ ... }
void ProductPresenterView::buttonPressedHandler(const AbstractButton& button)
{
if (&button == &activateLanguageSelectorButton)
{
if (languageSelector.isFadedOut())
{
languageSelector.fadeInAndExpand();
}if (languageSelector.isFadedOut()) { ... }
}if (&button == &activateLanguageSelectorButton) { ... }
else if (&button == &nextButton)
{
animateToPoster((selectedPoster + 1) % NUMBER_OF_POSTERS, 10);
}else if (&button == &nextButton) { ... }
}{ ... }
void ProductPresenterView::animateToPoster(int posterIndex, int duration)
{
if (duration < 2)
{
headlineText.setTypedText(TypedText(getHeadline(posterIndex)));
headlineText.invalidate();
bodyText.setTypedText(TypedText(getBodyText(posterIndex)));
bodyText.invalidate();
poster.setBitmap(Bitmap(getPosterBitmap(posterIndex)));
}if (duration < 2) { ... }
else
{
nextButton.setTouchable(false);
headlineTextSwap.setTypedText(headlineText.getTypedText());
headlineTextSwap.setXY(headlineText.getX(), headlineText.getY());
headlineTextSwap.invalidate();
headlineText.setTypedText(TypedText(getHeadline(posterIndex)));
headlineText.moveTo(headlineTextSwap.getRect().right(), headlineTextSwap.getY());
headlineText.invalidate();
headlineTextSwap.startMoveAnimation(headlineTextSwap.getX() - headlineTextSwap.getWidth(), headlineTextSwap.getY(), duration, EasingEquations::cubicEaseInOut);
headlineText.startMoveAnimation(headlineTextSwap.getX(), headlineTextSwap.getY(), duration, EasingEquations::cubicEaseInOut);
bodyText.startFadeAnimation(0, duration);
fadeDuration = duration;
nextTextIndex = posterIndex;
posterSwap.setBitmap(Bitmap(poster.getBitmap()));
posterSwap.setXY(poster.getX(), poster.getY());
posterSwap.invalidate();
poster.setBitmap(Bitmap(getPosterBitmap(posterIndex)));
poster.moveTo(posterSwap.getRect().right(), posterSwap.getY());
poster.invalidate();
posterSwap.startMoveAnimation(posterSwap.getX() - posterSwap.getWidth(), posterSwap.getY(), duration, EasingEquations::cubicEaseInOut);
poster.startMoveAnimation(posterSwap.getX(), posterSwap.getY(), duration, EasingEquations::cubicEaseInOut);
}else { ... }
selectedPoster = posterIndex;
}{ ... }
void ProductPresenterView::languageSelectorStateChangedHandler(const CollapsibleMenu& menu, const bool isExpanded)
{
if (!isExpanded)
{
languageSelector.fadeOut();
setLanguage();
}if (!isExpanded) { ... }
}{ ... }
void ProductPresenterView::setLanguage()
{
int languageIndex = languageSelector.getSelectedElementIndex();
activateLanguageSelectorButton.setBitmaps(Bitmap(inactiveLanguageButtons[languageIndex]), Bitmap(inactiveLanguageButtons[languageIndex]));
activateLanguageSelectorButton.setWidth(activateLanguageSelectorButton.getWidth() + 20);
activateLanguageSelectorButton.setHeight(activateLanguageSelectorButton.getHeight() + 20);
activateLanguageSelectorButton.invalidate();
Texts::setLanguage(languages[languageIndex]);
bodyText.resizeToCurrentText();
textAreaContainer.reset();
textAreaContainer.invalidate();
mcuLoadTxt.invalidate();
headlineText.invalidate();
bodyText.invalidate();
}{ ... }
void ProductPresenterView::screenSaverMinorTick()
{
}{ ... }
touchgfx::BitmapId ProductPresenterView::getPosterBitmap(int index)
{
switch (index)
{
default:
case 0:
return BITMAP_POSTER_IMAGE_00_ID;case 0:
case 1:
return BITMAP_POSTER_IMAGE_01_ID;case 1:
case 2:
return BITMAP_POSTER_IMAGE_02_ID;case 2:
}switch (index) { ... }
}{ ... }
TEXTS ProductPresenterView::getHeadline(int index)
{
switch (index)
{
default:
case 0:
return T_POSTER_HEADLINE_00;case 0:
case 1:
return T_POSTER_HEADLINE_01;case 1:
case 2:
return T_POSTER_HEADLINE_02;case 2:
}switch (index) { ... }
}{ ... }
TEXTS ProductPresenterView::getBodyText(int index)
{
switch (index)
{
default:
case 0:
return T_POSTER_TEXT_00;case 0:
case 1:
return T_POSTER_TEXT_01;case 1:
case 2:
return T_POSTER_TEXT_02;case 2:
}switch (index) { ... }
}{ ... }
void ProductPresenterView::fadeAnimationEndedHandler(const FadeAnimator<TextArea>& textArea)
{
if (&textArea == &bodyText)
{
if (bodyText.getAlpha() == 0)
{
bodyText.setTypedText(TypedText(getBodyText(nextTextIndex)));
bodyText.resizeToCurrentText();
bodyText.startFadeAnimation(255, fadeDuration);
textAreaContainer.reset();
textAreaContainer.invalidate();
nextButton.setTouchable(true);
}if (bodyText.getAlpha() == 0) { ... }
}if (&textArea == &bodyText) { ... }
}{ ... }