2020-06-26 15:17:35 +00:00
|
|
|
//
|
|
|
|
// LambdaAnimation.h
|
|
|
|
//
|
|
|
|
// Basic animation controls, to be used in lambda expressions.
|
|
|
|
//
|
|
|
|
|
2013-12-13 03:17:59 +00:00
|
|
|
#pragma once
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_ANIMATIONS_LAMBDA_ANIMATION_H
|
|
|
|
#define ES_CORE_ANIMATIONS_LAMBDA_ANIMATION_H
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "animations/Animation.h"
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-09-13 11:21:38 +00:00
|
|
|
#include <functional>
|
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
// Useful for simple one-off animations, you can supply the animation's apply(t)
|
|
|
|
// function directly in the constructor as a lambda.
|
2013-12-13 03:17:59 +00:00
|
|
|
class LambdaAnimation : public Animation
|
|
|
|
{
|
|
|
|
public:
|
2020-06-26 15:17:35 +00:00
|
|
|
LambdaAnimation(const std::function<void(float t)>& func, int duration)
|
|
|
|
: mFunction(func), mDuration(duration) {}
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
virtual ~LambdaAnimation() = default;
|
2017-07-28 07:57:37 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
int getDuration() const override { return mDuration; }
|
2013-12-13 03:17:59 +00:00
|
|
|
|
2020-06-26 15:17:35 +00:00
|
|
|
void apply(float t) override
|
|
|
|
{
|
|
|
|
mFunction(t);
|
|
|
|
}
|
2013-12-13 03:17:59 +00:00
|
|
|
|
|
|
|
private:
|
2020-06-26 15:17:35 +00:00
|
|
|
std::function<void(float t)> mFunction;
|
|
|
|
int mDuration;
|
2013-12-13 03:17:59 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_ANIMATIONS_LAMBDA_ANIMATION_H
|