-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.cpp
More file actions
66 lines (58 loc) · 1.73 KB
/
Copy pathanimation.cpp
File metadata and controls
66 lines (58 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Diego Lopes <diego95lopes@gmail.com>
#include "animation.h"
namespace animation {
AnimatedTransform EvaluateAnimation(const AnimationDef& def, double timer, bool isOut,
double width, double height)
{
AnimatedTransform out{};
double t = (timer - def.delay) / def.duration;
double p = animation::ApplyEasing(std::clamp(t, 0.0, 1.0), def.easing);
double rp = 1.0 - p;
auto fnFade = [&]() {
out.opacity = isOut ? rp : p;
};
switch (def.type) {
case AnimationType::None:
break;
case AnimationType::Fade: fnFade(); break;
case AnimationType::SlideUp:
out.offsetY = (isOut ? -p : rp) * height;
fnFade();
break;
case AnimationType::SlideDown:
out.offsetY = (isOut ? p : -rp) * height;
fnFade();
break;
case AnimationType::SlideLeft:
out.offsetX = (isOut ? -p : rp) * width;
fnFade();
break;
case AnimationType::SlideRight:
out.offsetX = (isOut ? p : -rp) * width;
fnFade();
break;
case AnimationType::WipeUp:
out.clipY = isOut ? 0.0 : rp;
out.clipH = isOut ? rp : p;
break;
case AnimationType::WipeDown:
out.clipY = isOut ? p : 0.0;
out.clipH = isOut ? rp : p;
break;
case AnimationType::WipeLeft:
out.clipX = isOut ? 0.0 : rp;
out.clipW = isOut ? rp : p;
break;
case AnimationType::WipeRight:
out.clipX = isOut ? p : 0.0;
out.clipW = isOut ? rp : p;
break;
case AnimationType::ScaleIn:
out.scale = isOut ? rp : p;
fnFade();
break;
}
return out;
}
} // namespace animation