Select one of the symbols to view example projects that use it.
 
Outline
#define MVPAPPLICATION_HPP
#include <touchgfx/Application.hpp>
#include <touchgfx/Callback.hpp>
#include <touchgfx/hal/HAL.hpp>
#include <common/Meta.hpp>
#include <common/Partition.hpp>
#include <mvp/View.hpp>
#include <mvp/MVPHeap.hpp>
#include <new>
#include <cassert>
touchgfx
Files
loading...
CodeScopeSTM32 Libraries and SamplesTouchGFXtouchgfx/framework/include/mvp/MVPApplication.hpp
 
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
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
210
211
212
213
214
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * This file is part of the TouchGFX 4.10.0 distribution. * * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under Ultimate Liberty license * SLA0044, the "License"; You may not use this file except in compliance with * the License. You may obtain a copy of the License at: * www.st.com/SLA0044 * ****************************************************************************** *//* ... */ #ifndef MVPAPPLICATION_HPP #define MVPAPPLICATION_HPP #include <touchgfx/Application.hpp> #include <touchgfx/Callback.hpp> #include <touchgfx/hal/HAL.hpp> #include <common/Meta.hpp> #include <common/Partition.hpp> #include <mvp/View.hpp> #include <mvp/MVPHeap.hpp> #include <new> #include <cassert> 9 includes namespace touchgfx { class Presenter; /** * @class MVPApplication MVPApplication.hpp mvp\MVPApplication.hpp * * @brief A specialization of the TouchGFX Application class. * * A specialization of the TouchGFX Application class that provides the necessary glue * for transitioning between presenter/view pairs. * * It maintains a callback for transitioning and evaluates this at each tick. * * @see Application *//* ... */ class MVPApplication : public Application { public: /** * @fn MVPApplication::MVPApplication() * * @brief Default constructor. * * Default constructor. *//* ... */ MVPApplication() : currentPresenter(0), pendingScreenTransitionCallback(0) { instance = this; }{ ... } /** * @fn virtual MVPApplication::~MVPApplication() * * @brief Destructor. * * Destructor. *//* ... */ virtual ~MVPApplication() { } /** * @fn void MVPApplication::handlePendingScreenTransition() * * @brief Handles the pending screen transition. * * Delegates the work to evaluatePendingScreenTransition() *//* ... */ virtual void handlePendingScreenTransition() { evaluatePendingScreenTransition(); }{ ... } public:protected: Presenter* currentPresenter; ///< Pointer to the currently active presenter. GenericCallback<>* pendingScreenTransitionCallback; ///< Callback for screen transitions. Will be set to something valid when a transition request is made. /** * @fn void MVPApplication::evaluatePendingScreenTransition() * * @brief Evaluates the pending Callback instances. * * Evaluates the pending Callback instances. If a callback is valid, it is executed * and a Screen transition is executed. *//* ... */ void evaluatePendingScreenTransition() { if (pendingScreenTransitionCallback && pendingScreenTransitionCallback->isValid()) { pendingScreenTransitionCallback->execute(); pendingScreenTransitionCallback = 0; }if (pendingScreenTransitionCallback && pendingScreenTransitionCallback->isValid()) { ... } }{ ... } }protected:;... /** * @fn static inline void prepareTransition(Screen** currentScreen, Presenter** currentPresenter, Transition** currentTrans) * * @brief Prepare screen transition. Private helper function for makeTransition. Do not use. * * @param [in] currentScreen If non-null, the current screen. * @param [in] currentPresenter If non-null, the current presenter. * @param [in] currentTrans If non-null, the current transaction. *//* ... */ static inline void prepareTransition(Screen** currentScreen, Presenter** currentPresenter, Transition** currentTrans) { Application::getInstance()->clearAllTimerWidgets(); if (*currentTrans) { (*currentTrans)->tearDown(); }if (*currentTrans) { ... } if (*currentTrans) { (*currentTrans)->~Transition(); }if (*currentTrans) { ... } if (*currentScreen) { (*currentScreen)->tearDownScreen(); }if (*currentScreen) { ... } if (*currentPresenter) { (*currentPresenter)->deactivate(); }if (*currentPresenter) { ... } if (*currentScreen) { (*currentScreen)->~Screen(); }if (*currentScreen) { ... } if (*currentPresenter) { (*currentPresenter)->~Presenter(); }if (*currentPresenter) { ... } }{ ... } /** * @fn static inline void finalizeTransition(Screen* newScreen, Presenter* newPresenter, Transition* newTransition) * * @brief Finalize screen transition. Private helper function for makeTransition. Do not use. * * @param [in] newScreen If non-null, the new screen. * @param [in] newPresenter If non-null, the new presenter. * @param [in] newTransition If non-null, the new transition. *//* ... */ static inline void finalizeTransition(Screen* newScreen, Presenter* newPresenter, Transition* newTransition) { newScreen->setupScreen(); newPresenter->activate(); newScreen->bindTransition(*newTransition); newTransition->init(); Application::getInstance()->draw(); }{ ... } /** * @fn template< class ScreenType, class PresenterType, class TransType, class ModelType > PresenterType* makeTransition(Screen** currentScreen, Presenter** currentPresenter, MVPHeap& heap, Transition** currentTrans, ModelType* model) * * @brief Function for effectuating a screen transition (i.e. makes the requested new presenter/view * pair active). Once this function has returned, the new screen has been transitioned * to. Due to the memory allocation strategy of using the same memory area for all * screens, the old view/presenter will no longer exist when this function returns. * * Will properly clean up old screen (tearDownScreen, Presenter::deactivate) and call * setupScreen/activate on new view/presenter pair. Will also make sure the view, * presenter and model are correctly bound to each other. * * @tparam ScreenType Class type for the View. * @tparam PresenterType Class type for the Presenter. * @tparam TransType Class type for the Transition. * @tparam ModelType Class type for the Model. * @param [in] currentScreen Pointer to pointer to the current view. * @param [in] currentPresenter Pointer to pointer to the current presenter. * @param [in] heap Reference to the heap containing the memory storage in which * to allocate. * @param [in] currentTrans Pointer to pointer to the current transition. * @param [in] model Pointer to model. * * @return Pointer to the new Presenter of the requested type. Incidentally it will be the same * value as the old presenter due to memory reuse. *//* ... */ template< class ScreenType, class PresenterType, class TransType, class ModelType > PresenterType* makeTransition(Screen** currentScreen, Presenter** currentPresenter, MVPHeap& heap, Transition** currentTrans, ModelType* model) { assert(sizeof(ScreenType) <= heap.screenStorage.element_size() && "View allocation error: Check that all views are added to FrontendHeap::ViewTypes"); assert(sizeof(PresenterType) <= heap.presenterStorage.element_size() && "Presenter allocation error: Check that all presenters are added to FrontendHeap::PresenterTypes"); assert(sizeof(TransType) <= heap.transitionStorage.element_size() && "Transition allocation error: Check that all transitions are added to FrontendHeap::TransitionTypes"); prepareTransition(currentScreen, currentPresenter, currentTrans); TransType* newTransition = new (&heap.transitionStorage.at< TransType >(0)) TransType; ScreenType* newScreen = new (&heap.screenStorage.at< ScreenType >(0)) ScreenType; PresenterType* newPresenter = new (&heap.presenterStorage.at< PresenterType >(0)) PresenterType(*newScreen); *currentTrans = newTransition; *currentPresenter = newPresenter; *currentScreen = newScreen; model->bind(newPresenter); newPresenter->bind(model); newScreen->bind(*newPresenter); finalizeTransition((Screen*)newScreen, (Presenter*)newPresenter, (Transition*)newTransition); return newPresenter; } } // namespace touchgfx #endif // MVPAPPLICATION_HPP