Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / rive-cpp / src / animation / keyframe_double.cpp
1 #include "rive/animation/keyframe_double.hpp"
2 #include "rive/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     if (mix == 1.0f) {
13         CoreRegistry::setDouble(object, propertyKey, value);
14     } else {
15         float mixi = 1.0f - mix;
16         CoreRegistry::setDouble(
17             object, propertyKey, CoreRegistry::getDouble(object, propertyKey) * mixi + value * mix);
18     }
19 }
20
21 void KeyFrameDouble::apply(Core* object, int propertyKey, float mix) {
22     applyDouble(object, propertyKey, mix, value());
23 }
24
25 void KeyFrameDouble::applyInterpolation(
26     Core* object, int propertyKey, float currentTime, const KeyFrame* nextFrame, float mix) {
27     auto kfd = nextFrame->as<KeyFrameDouble>();
28     const KeyFrameDouble& nextDouble = *kfd;
29     float f = (currentTime - seconds()) / (nextDouble.seconds() - seconds());
30
31     if (CubicInterpolator* cubic = interpolator()) {
32         f = cubic->transform(f);
33     }
34
35     applyDouble(object, propertyKey, mix, value() + (nextDouble.value() - value()) * f);
36 }