1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
28
29
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
70
71
75
76
77
78
79
80
81
82
83
93
94
95
96
101
/* ... */
#include <gui/common/ZoomAnimationBox.hpp>
ZoomAnimationBox::ZoomAnimationBox() :
Box(),
currentState(NO_ANIMATION),
animationCounter(0),
animationEndedAction(0)
{
}{ ... }
ZoomAnimationBox::~ZoomAnimationBox()
{
}{ ... }
void ZoomAnimationBox::startZoomAnimation(int16_t endWidth, int16_t endHeight, uint16_t duration, touchgfx::EasingEquation widthProgressionEquation , EasingEquation heightProgressionEquation )
{
touchgfx::Application::getInstance()->registerTimerWidget(this);
zoomAnimationStartX = getX();
zoomAnimationStartY = getY();
zoomAnimationStartWidth = getWidth();
zoomAnimationStartHeight = getHeight();
zoomAnimationEndWidth = endWidth;
zoomAnimationEndHeight = endHeight;
animationDuration = duration;
zoomAnimationWidthEquation = widthProgressionEquation;
zoomAnimationHeightEquation = heightProgressionEquation;
zoomAnimationDeltaX = (zoomAnimationStartWidth - zoomAnimationEndWidth) / 2;
zoomAnimationDeltaY = (zoomAnimationStartHeight - zoomAnimationEndHeight) / 2;
setCurrentState(ANIMATE_ZOOM);
}{ ... }
void ZoomAnimationBox::handleTickEvent()
{
if (currentState == ANIMATE_ZOOM)
{
if (animationCounter <= animationDuration)
{
int16_t deltaWidth = zoomAnimationWidthEquation(animationCounter, 0, zoomAnimationEndWidth - zoomAnimationStartWidth, animationDuration);
int16_t deltaHeight = zoomAnimationHeightEquation(animationCounter, 0, zoomAnimationEndHeight - zoomAnimationStartHeight, animationDuration);
invalidate();
int16_t newWidth = zoomAnimationStartWidth + deltaWidth;
if (newWidth < 0)
{
newWidth = 0;
}if (newWidth < 0) { ... }
int16_t newHeight = zoomAnimationStartHeight + deltaHeight;
if (newHeight < 0)
{
newHeight = 0;
}if (newHeight < 0) { ... }
setWidth(newWidth);
setHeight(newHeight);
moveTo(zoomAnimationStartX - (deltaWidth/2), zoomAnimationStartY - (deltaHeight/2));
invalidate();
animationCounter++;
}if (animationCounter <= animationDuration) { ... }
else
{
touchgfx::Application::getInstance()->unregisterTimerWidget(this);
setCurrentState(NO_ANIMATION);
if (animationEndedAction && animationEndedAction->isValid())
{
animationEndedAction->execute(*this);
}if (animationEndedAction && animationEndedAction->isValid()) { ... }
}else { ... }
}if (currentState == ANIMATE_ZOOM) { ... }
}{ ... }
void ZoomAnimationBox::setCurrentState(States state)
{
currentState = state;
animationCounter = 0;
}{ ... }