add: EaseFunction maker

This commit is contained in:
Haibo 2018-11-21 00:01:37 +08:00 committed by Nomango
parent 098167c606
commit d88fc5afbe
2 changed files with 22 additions and 13 deletions

View File

@ -22,7 +22,6 @@
#include "Geometry.h"
#include "base.hpp"
#include "Node.h"
#include "../math/ease.hpp"
#include <algorithm>
#include <cfloat>
@ -58,13 +57,13 @@ namespace easy2d
ease_func_ = math::Linear;
break;
case EaseFunc::EaseIn:
ease_func_ = std::bind(math::EaseIn, std::placeholders::_1, 2.f);
ease_func_ = MakeEaseIn(2.f);
break;
case EaseFunc::EaseOut:
ease_func_ = std::bind(math::EaseOut, std::placeholders::_1, 2.f);
ease_func_ = MakeEaseOut(2.f);
break;
case EaseFunc::EaseInOut:
ease_func_ = std::bind(math::EaseInOut, std::placeholders::_1, 2.f);
ease_func_ = MakeEaseInOut(2.f);
break;
case EaseFunc::EaseExponentialIn:
ease_func_ = math::EaseExponentialIn;
@ -85,13 +84,13 @@ namespace easy2d
ease_func_ = math::EaseBounceInOut;
break;
case EaseFunc::EaseElasticIn:
ease_func_ = std::bind(math::EaseElasticIn, std::placeholders::_1, 0.3f);
ease_func_ = MakeEaseElasticIn(0.3f);
break;
case EaseFunc::EaseElasticOut:
ease_func_ = std::bind(math::EaseElasticOut, std::placeholders::_1, 0.3f);
ease_func_ = MakeEaseElasticOut(0.3f);
break;
case EaseFunc::EaseElasticInOut:
ease_func_ = std::bind(math::EaseElasticInOut, std::placeholders::_1, 0.3f);
ease_func_ = MakeEaseElasticInOut(0.3f);
break;
case EaseFunc::EaseSineIn:
ease_func_ = math::EaseSineIn;
@ -107,7 +106,7 @@ namespace easy2d
}
}
void Tween::SetEaseFunction(std::function<float(float)> func)
void Tween::SetEaseFunction(EaseFunction func)
{
ease_func_ = func;
ease_type_ = EaseFunc(-1);

View File

@ -21,6 +21,7 @@
#pragma once
#include "Action.hpp"
#include "logs.h"
#include "../math/ease.hpp"
namespace easy2d
{
@ -44,6 +45,15 @@ namespace easy2d
EaseSineInOut, // 譚찹逞우, 疼譚우逞찹, 꽃痰攣菊긴뻣醵똑
};
using EaseFunction = std::function<float(float)>;
inline EaseFunction MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
inline EaseFunction MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
inline EaseFunction MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
inline EaseFunction MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
inline EaseFunction MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
inline EaseFunction MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
class Tween
: public Action
{
@ -62,7 +72,7 @@ namespace easy2d
// 菱땍屢醵똑긴뺏혓窟
void SetEaseFunction(
std::function<float(float)> func
EaseFunction func
);
virtual void Reset() override;
@ -79,10 +89,10 @@ namespace easy2d
virtual void UpdateStep(Node* target, float step) = 0;
protected:
Duration duration_;
Duration elapsed_;
EaseFunc ease_type_;
std::function<float(float)> ease_func_;
Duration duration_;
Duration elapsed_;
EaseFunc ease_type_;
EaseFunction ease_func_;
};