[Adaptation Layer] Added rive-tizen adaptation layer class.
[platform/core/uifw/rive-tizen.git] / submodule / src / animation / keyframe_double.cpp
1 #include "animation/keyframe_double.hpp"
2 #include "generated/core_registry.hpp"
3
4 using namespace rive;
5
6 // This whole class is intentionally misnamed to match our editor code. The
7 // editor uses doubles (float64) for numeric values but at runtime 32 bit
8 // floating point numbers suffice. So even though this is a "double keyframe" to
9 // match editor names, the actual values are stored and applied in 32 bits.
10
11 static void applyDouble(Core* object, int propertyKey, float mix, float value)
12 {
13         if (mix == 1.0f)
14         {
15                 CoreRegistry::setDouble(object, propertyKey, value);
16         }
17         else
18         {
19                 float mixi = 1.0 - mix;
20                 CoreRegistry::setDouble(
21                     object,
22                     propertyKey,
23                     CoreRegistry::getDouble(object, propertyKey) * mixi + value * mix);
24         }
25 }
26
27 void KeyFrameDouble::apply(Core* object, int propertyKey, float mix)
28 {
29         applyDouble(object, propertyKey, mix, value());
30 }
31
32 void KeyFrameDouble::applyInterpolation(Core* object,
33                                         int propertyKey,
34                                         float currentTime,
35                                         const KeyFrame* nextFrame,
36                                         float mix)
37 {
38         auto kfd = nextFrame->as<KeyFrameDouble>();
39         const KeyFrameDouble& nextDouble = *kfd;
40         float f = (currentTime - seconds()) / (nextDouble.seconds() - seconds());
41
42         if (CubicInterpolator* cubic = interpolator())
43         {
44                 f = cubic->transform(f);
45         }
46
47         applyDouble(
48             object, propertyKey, mix, value() + (nextDouble.value() - value()) * f);
49 }