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
4Animation::Animation(int startTime, int duration, std::function<void(float)> onStep, std::function<void()> onFinish) {
5 this->startTime = startTime;
6 this->duration = duration;
7 this->onStep = onStep;
8 this->onFinish = onFinish;
9}
10
11bool Animation::isFinished() {
12 return CST_GetTicks() > startTime + duration;
13}
14
15bool Animation::step() {
16 if (isFinished()) {
17 onFinish();
18 return true;
19 }
20
21 if (onStep != NULL) {
22 float progress = (float)(CST_GetTicks() - startTime) / (float)duration;
23 onStep(progress);
24 }
25 return false;
26}