1 #include "rive/animation/keyframe_double.hpp"
2 #include "rive/generated/core_registry.hpp"
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.
11 static void applyDouble(Core* object, int propertyKey, float mix, float value) {
13 CoreRegistry::setDouble(object, propertyKey, value);
15 float mixi = 1.0f - mix;
16 CoreRegistry::setDouble(
17 object, propertyKey, CoreRegistry::getDouble(object, propertyKey) * mixi + value * mix);
21 void KeyFrameDouble::apply(Core* object, int propertyKey, float mix) {
22 applyDouble(object, propertyKey, mix, value());
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());
31 if (CubicInterpolator* cubic = interpolator()) {
32 f = cubic->transform(f);
35 applyDouble(object, propertyKey, mix, value() + (nextDouble.value() - value()) * f);