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
56
57
58
62
63
70
71
72
79
83
84
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
124
128
132
136
140
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
/* ... */
#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 : public Application
{
public:
/* ... */
MVPApplication() :
currentPresenter(0),
pendingScreenTransitionCallback(0)
{
instance = this;
}{ ... }
/* ... */
virtual ~MVPApplication() { }
/* ... */
virtual void handlePendingScreenTransition()
{
evaluatePendingScreenTransition();
}{ ... }
public:protected:
Presenter* currentPresenter;
GenericCallback<>* pendingScreenTransitionCallback;
/* ... */
void evaluatePendingScreenTransition()
{
if (pendingScreenTransitionCallback && pendingScreenTransitionCallback->isValid())
{
pendingScreenTransitionCallback->execute();
pendingScreenTransitionCallback = 0;
}if (pendingScreenTransitionCallback && pendingScreenTransitionCallback->isValid()) { ... }
}{ ... }
}protected:;...
/* ... */
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) { ... }
}{ ... }
/* ... */
static inline void finalizeTransition(Screen* newScreen, Presenter* newPresenter, Transition* newTransition)
{
newScreen->setupScreen();
newPresenter->activate();
newScreen->bindTransition(*newTransition);
newTransition->init();
Application::getInstance()->draw();
}{ ... }
/* ... */
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;
}
}
#endif