29class ScalarKeyframeAnimator final :
public KeyframeAnimator {
31 ScalarKeyframeAnimator(std::vector<Keyframe> kfs,
32 std::vector<SkCubicMap> cms,
35 , fTarget(target_value) {}
39 StateChanged onSeek(
float t)
override {
40 const auto& lerp_info = this->getLERPInfo(t);
41 const auto old_value = *fTarget;
43 *fTarget =
Lerp(lerp_info.vrec0.flt, lerp_info.vrec1.flt, lerp_info.weight);
45 return *fTarget != old_value;
54class ScalarExpressionAnimator final :
public Animator {
56 ScalarExpressionAnimator(
sk_sp<ExpressionEvaluator<ScalarValue>> expression_evaluator,
58 : fExpressionEvaluator(
std::move(expression_evaluator))
59 , fTarget(target_value) {}
63 StateChanged onSeek(
float t)
override {
64 auto old_value = *fTarget;
66 *fTarget = fExpressionEvaluator->evaluate(t);
68 return *fTarget != old_value;
75class ScalarAnimatorBuilder final :
public AnimatorBuilder {
84 if (!this->parseKeyframes(abuilder, jkfs)) {
89 new ScalarKeyframeAnimator(std::move(fKFs), std::move(fCMs), fTarget));
92 sk_sp<Animator> makeFromExpression(ExpressionManager& em,
const char* expr)
override {
94 em.createNumberExpressionEvaluator(expr);
95 return sk_make_sp<ScalarExpressionAnimator>(expression_evaluator, fTarget);
99 bool parseValue(
const AnimationBuilder&,
const skjson::Value& jv)
const override {
104 bool parseKFValue(
const AnimationBuilder&,
107 Keyframe::Value* v)
override {
124 abuilder.fSlotManager->trackScalarValue(
SkString(sid->begin()), v,
sk_ref_sp(
this));
126 ScalarAnimatorBuilder
builder(v);
128 return this->bindImpl(abuilder, jprop,
builder);
#define INHERITED(method,...)
sk_sp< T > sk_ref_sp(T *obj)
void SK_API Parse(Metadata &metadata, const SkData *data)
T Lerp(const T &a, const T &b, float t)
const skjson::StringValue * ParseSlotID(const skjson::ObjectValue *jobj)