1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
24
25
26
27
28
29
30
31
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
63
64
95
96
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
216
217
218
219
220
224
225
247
248
255
256
/* ... */
#include <gui/main_menu_screen/MainMenuCarouselView.hpp>
#include <BitmapDatabase.hpp>
#include <texts/TextKeysAndLanguages.hpp>
#include <gui/common/FrontendApplication.hpp>
#include <touchgfx/Color.hpp>
5 includes
MainMenuCarouselView::MainMenuCarouselView() :
MainMenuView(),
currentState(NO_STATE),
carouselAnimationEnded(this, &MainMenuCarouselView::carouselAnimationEndedhandler),
dragDistance(0),
dragInsideCarousel(false),
dragInsideCenterButton(false),
hasAnimatedDrag(false)
{
}{ ... }
void MainMenuCarouselView::setupScreen()
{
background.setXY(0, 0);
background.setBitmap(Bitmap(BITMAP_CAROUSEL_BACKGROUND_ID));
add(background);
add(toggleMenuButton);
add(stMenuButton);
setupCarousel();
add(carousel);
demoHeadline.setPosition(0, 354, 800, 30);
demoHeadline.setColor(Color::getColorFrom24BitRGB(0xFF, 0xFF, 0xFF));
add(demoHeadline);
demoText.setPosition(50, 387, 700, 90);
demoText.setColor(Color::getColorFrom24BitRGB(0xFF, 0xFF, 0xFF));
add(demoText);
add(mcuLoadTxt);
add(mcuLoadValueTxt);
}{ ... }
void MainMenuCarouselView::tearDownScreen()
{
}{ ... }
void MainMenuCarouselView::handleClickEvent(const ClickEvent& evt)
{
if (evt.getType() == ClickEvent::PRESSED)
{
dragDistance = 0;
hasAnimatedDrag = false;
dragInsideCarousel = carousel.getAbsoluteRect().intersect(evt.getX(),evt.getY());
dragInsideCenterButton = Rect(carousel.getX() + ((carousel.getWidth() - 150) / 2), carousel.getY() + ((carousel.getHeight() - 150) / 2), 150, 150).intersect(evt.getX(), evt.getY());
}if (evt.getType() == ClickEvent::PRESSED) { ... }
else if (evt.getType() == ClickEvent::RELEASED)
{
if (dragInsideCarousel && !hasAnimatedDrag)
{
if (dragInsideCenterButton)
{
currentState = ELEMENT_SELECTED;
pauses = 4;
carousel.highlightSelectedElement();
}if (dragInsideCenterButton) { ... }
else if (evt.getX() < carousel.getX() + carousel.getWidth()/2)
{
carousel.selectedPrevious();
}else if (evt.getX() < carousel.getX() + carousel.getWidth()/2) { ... }
else
{
carousel.selectedNext();
}else { ... }
}if (dragInsideCarousel && !hasAnimatedDrag) { ... }
}else if (evt.getType() == ClickEvent::RELEASED) { ... }
View::handleClickEvent(evt);
}{ ... }
void MainMenuCarouselView::handleDragEvent(const DragEvent& evt)
{
View::handleDragEvent(evt);
if (dragInsideCarousel)
{
dragDistance += evt.getDeltaX();
if (abs(dragDistance) > 30)
{
dragDistance = 0;
hasAnimatedDrag = true;
if (abs(evt.getDeltaX()) > 0)
{
if (evt.getDeltaX() < 0)
{
carousel.selectedNext();
}if (evt.getDeltaX() < 0) { ... }
else
{
carousel.selectedPrevious();
}else { ... }
}if (abs(evt.getDeltaX()) > 0) { ... }
}if (abs(dragDistance) > 30) { ... }
}if (dragInsideCarousel) { ... }
}{ ... }
void MainMenuCarouselView::setupCarousel()
{
carousel.setPosition(172, 172, 450, 180);
carousel.setCarouselAnimationEndedCallback(carouselAnimationEnded);
uint16_t yDiff = 4;
uint16_t widthOfSmallElements = Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_SMALL_ID).getWidth();
uint16_t widthOfMediumElements = Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_MEDIUM_ID).getWidth();
uint16_t widthOfLargeElements = Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_LARGE_ID).getWidth();
uint16_t widthOfInvisibleElements = widthOfSmallElements - 30;
uint16_t heightOfSmallElements = Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_SMALL_ID).getHeight();
uint16_t heightOfMediumElements = Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_MEDIUM_ID).getHeight();
uint16_t heightOfLargeElements = Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_LARGE_ID).getHeight();
uint16_t heightOfInvisibleElements = heightOfSmallElements - 30;
uint16_t offsetWidthForInvisibleEndElements = 20;
uint16_t visibleWidthOfSmallElements = 50;
uint16_t visibleWidthOfMediumElements = 80;
carousel.setPositionOfCarouselElement(0, 0,
(3 * yDiff), widthOfInvisibleElements, heightOfInvisibleElements);
carousel.setPositionOfCarouselElement(1, offsetWidthForInvisibleEndElements,
(2* yDiff), widthOfSmallElements, heightOfSmallElements);
carousel.setPositionOfCarouselElement(2, carousel.getXPositionOfVisibleElement(1) + visibleWidthOfSmallElements,
yDiff + 4, widthOfMediumElements, heightOfMediumElements);
carousel.setPositionOfCarouselElement(3, carousel.getXPositionOfVisibleElement(2) + visibleWidthOfMediumElements,
0, widthOfLargeElements, heightOfLargeElements);
carousel.setPositionOfCarouselElement(4, carousel.getXPositionOfVisibleElement(3) + widthOfLargeElements - widthOfMediumElements + visibleWidthOfMediumElements,
yDiff + 4, widthOfMediumElements, heightOfMediumElements);
carousel.setPositionOfCarouselElement(5, carousel.getXPositionOfVisibleElement(4) + widthOfMediumElements - widthOfSmallElements + visibleWidthOfSmallElements,
(2 * yDiff), widthOfSmallElements, heightOfSmallElements);
carousel.setPositionOfCarouselElement(6, carousel.getXPositionOfVisibleElement(5) + offsetWidthForInvisibleEndElements + 20,
(3 * yDiff), widthOfInvisibleElements, heightOfInvisibleElements);
carousel.addElement(Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_SMALL_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_MEDIUM_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_2048_LARGE_ID));
carousel.addElement(Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GAUGE_SMALL_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GAUGE_MEDIUM_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GAUGE_LARGE_ID));
carousel.addElement(Bitmap(BITMAP_CAROUSEL_MENU_ICONS_POSTER_SMALL_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_POSTER_MEDIUM_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_POSTER_LARGE_ID));
carousel.addElement(Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GAME_2D_SMALL_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GAME_2D_MEDIUM_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GAME_2D_LARGE_ID));
carousel.addElement(Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GRAPH_SMALL_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GRAPH_MEDIUM_ID), Bitmap(BITMAP_CAROUSEL_MENU_ICONS_GRAPH_LARGE_ID));
carousel.setSelectedElement(presenter->getSelectedDemoScreenIndex());
demoIDs[0] = GAME2048;
headlines[0] = T_CAROUSEL_GAME_2048_HEADLINE;
texts[0] = T_CAROUSEL_GAME_2048_TEXT;
demoIDs[1] = CUSTOM_CONTROLS;
headlines[1] = T_CAROUSEL_CUSTOM_CONTROLS_HEADLINE;
texts[1] = T_CAROUSEL_CUSTOM_CONTROLS_TEXT;
demoIDs[2] = PRODUCT_PRESENTER;
headlines[2] = T_CAROUSEL_PRODUCT_PRESENTER_HEADLINE;
texts[2] = T_CAROUSEL_PRODUCT_PRESENTER_TEXT;
demoIDs[3] = GAME2D;
headlines[3] = T_CAROUSEL_GAME_2D_HEADLINE;
#if defined(ST)
texts[3] = T_CAROUSEL_GAME_2D_TEXT_ST;
#else
texts[3] = T_CAROUSEL_GAME_2D_TEXT;
#endif
demoIDs[4] = GRAPH;
headlines[4] = T_CAROUSEL_GRAPH_HEADLINE;
texts[4] = T_CAROUSEL_GRAPH_TEXT;
#ifdef SIMULATOR
carousel.setDuration(14);
#else
carousel.setDuration(4);
#endif
updateDemoText();
if (presenter->getPreviousSelectedMenuType() != MainMenuPresenter::NO_MENU)
{
carousel.setHighlightedNoAnimation();
carousel.cancelHighlightOfSelectedElement();
}if (presenter->getPreviousSelectedMenuType() != MainMenuPresenter::NO_MENU) { ... }
presenter->setPreviousSelectedMenuType(MainMenuPresenter::CAROUSEL_MENU);
}{ ... }
void MainMenuCarouselView::toggleMenu()
{
static_cast<FrontendApplication*>(Application::getInstance())->gotoMainMenuAnimatingButtonsScreen();
}{ ... }
void MainMenuCarouselView::carouselAnimationEndedhandler(const Carousel& c)
{
if (currentState == ELEMENT_SELECTED)
{
if (pauses-- > 0)
{
carousel.highlightSelectedElement();
}if (pauses-- > 0) { ... }
else
{
setSelectedDemoScreen(carousel.getSelectedElementIndex());
gotoSelectedDemoScreen();
}else { ... }
}if (currentState == ELEMENT_SELECTED) { ... }
else
{
updateDemoText();
}else { ... }
}{ ... }
void MainMenuCarouselView::updateDemoText()
{
demoHeadline.setTypedText(TypedText(headlines[carousel.getSelectedElementIndex()]));
demoText.setTypedText(TypedText(texts[carousel.getSelectedElementIndex()]));
demoHeadline.invalidate();
demoText.invalidate();
}{ ... }
void MainMenuCarouselView::screenSaverMinorTick()
{
carousel.selectedPrevious();
}{ ... }