Chesto 0.9
A declarative and element-based library for creating GUIs on homebrew'd consoles
Animation.cpp
1#include "Animation.hpp"
2#include "./DrawUtils.hpp"
3
4namespace Chesto {
5
6Animation::Animation(int startTime, int duration, std::function<void(float)> onStep, std::function<void()> onFinish) {
7 this->startTime = startTime;
8 this->duration = duration;
9 this->onStep = onStep;
10 this->onFinish = onFinish;
11}
12
13bool Animation::isFinished() {
14 return CST_GetTicks() > startTime + duration;
15}
16
17bool Animation::step() {
18 if (isFinished()) {
19 onFinish();
20 return true;
21 }
22
23 if (onStep != NULL) {
24 float progress = (float)(CST_GetTicks() - startTime) / (float)duration;
25 onStep(progress);
26 }
27 return false;
28}
29
30} // namespace Chesto