2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-26 15:17:35 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-26 15:17:35 +00:00
|
|
|
// AnimationController.cpp
|
|
|
|
//
|
|
|
|
// Basic animation controls.
|
|
|
|
//
|
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "animations/AnimationController.h"
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "animations/Animation.h"
|
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
AnimationController::AnimationController(
|
|
|
|
Animation* anim,
|
|
|
|
int delay,
|
|
|
|
std::function<void()> finishedCallback,
|
|
|
|
bool reverse)
|
|
|
|
: mAnimation(anim),
|
|
|
|
mFinishedCallback(finishedCallback),
|
|
|
|
mReverse(reverse),
|
|
|
|
mTime(-delay),
|
|
|
|
mDelay(delay)
|
2013-12-08 17:35:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimationController::~AnimationController()
|
|
|
|
{
|
2020-06-26 15:17:35 +00:00
|
|
|
if (mFinishedCallback)
|
|
|
|
mFinishedCallback();
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
delete mAnimation;
|
2013-12-08 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 03:17:59 +00:00
|
|
|
bool AnimationController::update(int deltaTime)
|
2013-12-08 17:35:43 +00:00
|
|
|
{
|
2020-06-26 15:17:35 +00:00
|
|
|
mTime += deltaTime;
|
2014-04-18 17:19:46 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (mTime < 0) // Are we still in delay?
|
2020-06-26 15:17:35 +00:00
|
|
|
return false;
|
2014-04-18 17:19:46 +00:00
|
|
|
|
2020-11-17 22:06:54 +00:00
|
|
|
float t = static_cast<float>(mTime) / mAnimation->getDuration();
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
if (t > 1.0f)
|
|
|
|
t = 1.0f;
|
|
|
|
else if (t < 0.0f)
|
|
|
|
t = 0.0f;
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
mAnimation->apply(mReverse ? 1.0f - t : t);
|
2013-12-08 17:35:43 +00:00
|
|
|
|
2020-07-13 18:58:25 +00:00
|
|
|
if (t == 1.0f)
|
2020-06-26 15:17:35 +00:00
|
|
|
return true;
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
return false;
|
2013-12-08 17:35:43 +00:00
|
|
|
}
|