1#ifndef NEFORCE_TUI_COMPONENT_ANIMATION_HPP__
2#define NEFORCE_TUI_COMPONENT_ANIMATION_HPP__
13NEFORCE_BEGIN_NAMESPACE__
29 return [](
const float t) {
return t; };
33 return [](
const float t) {
return t * t; };
36 inline function quadratic_out() {
37 return [](
const float t) {
return t * (2.0F - t); };
41 return [](
const float t) {
return (t < 0.5F) ? 2.0F * t * t : -1.0F + (4.0F - 2.0F * t) * t; };
45 return [](
const float t) {
return t * t * t; };
49 return [](
const float t) {
50 const float t1 = t - 1.0F;
51 return t1 * t1 * t1 + 1.0F;
56 return [](
const float t) {
57 return (t < 0.5F) ? 4.0F * t * t * t : (t - 1.0F) * (2.0F * t - 2.0F) * (2.0F * t - 2.0F) + 1.0F;
62 return [](
const float t) {
return 1.0F -
cosine(t * 3.14159265F / 2.0F); };
66 return [](
const float t) {
return sine(t * 3.14159265F / 2.0F); };
70 return [](
const float t) {
return -(
cosine(3.14159265F * t) - 1.0F) / 2.0F; };
74 return [](
const float t) ->
float {
75 if (t == 0.0F || t == 1.0F) {
78 return static_cast<float>(
power(2.0F,
static_cast<uint32_t>(-10.0F * t)) *
79 sine((t - 0.075F) * 6.2831853F / 0.3F)) +
86 if (t < 1.0F / 2.75F) {
87 return 7.5625F * t * t;
89 if (t < 2.0F / 2.75F) {
91 return 7.5625F * t * t + 0.75F;
93 if (t < 2.5F / 2.75F) {
95 return 7.5625F * t * t + 0.9375F;
98 return 7.5625F * t * t + 0.984375F;
134 NEFORCE_NODISCARD
float to() const noexcept {
return to_; }
140 NEFORCE_NODISCARD
bool is_done() const noexcept {
return done_; }
157 bool started_ =
false;
164NEFORCE_END_NAMESPACE__
animator(float *value, float to, milliseconds dur, easing::function easing_fn=easing::quadratic_out(), milliseconds delay=0_ms)
构造函数
bool is_done() const noexcept
检查动画是否已完成
bool on_animation(milliseconds delta)
每帧调用以推进动画
float to() const noexcept
获取目标值
void reset(float to, milliseconds dur)
重置动画
unsigned int uint32_t
32位无符号整数类型
duration< int64_t, milli > milliseconds
毫秒持续时间
constexpr decimal_t sine(decimal_t x) noexcept
计算正弦值
constexpr decimal_t cosine(decimal_t x) noexcept
计算余弦值
constexpr T power(const T &x, uint32_t n) noexcept
幂运算
function< float(float)> function
缓动函数类型:输入归一化时间 [0,1],输出进度 [0,1]