24class AnimationBuilder;
27class TextKeyframeAnimator final :
public KeyframeAnimator {
29 TextKeyframeAnimator(std::vector<Keyframe> kfs, std::vector<SkCubicMap> cms,
30 std::vector<TextValue> vs,
TextValue* target_value)
32 , fValues(
std::move(vs))
33 , fTarget(target_value) {}
36 StateChanged onSeek(
float t)
override {
37 const auto& lerp_info = this->getLERPInfo(t);
40 if (*fTarget != fValues[
SkToSizeT(lerp_info.vrec0.idx)]) {
41 *fTarget = fValues[
SkToSizeT(lerp_info.vrec0.idx)];
48 const std::vector<TextValue> fValues;
54class TextExpressionAnimator final :
public Animator {
56 TextExpressionAnimator(
sk_sp<ExpressionEvaluator<SkString>> expression_evaluator,
58 : fExpressionEvaluator(
std::move(expression_evaluator))
59 , fTarget(target_value) {}
63 StateChanged onSeek(
float t)
override {
66 fTarget->fText = fExpressionEvaluator->evaluate(t);
68 return fTarget->fText != old_value;
75class TextAnimatorBuilder final :
public AnimatorBuilder {
85 fValues.reserve(jkfs.
size());
86 if (!this->parseKeyframes(abuilder, jkfs)) {
89 fValues.shrink_to_fit();
92 new TextKeyframeAnimator(std::move(fKFs),
98 sk_sp<Animator> makeFromExpression(ExpressionManager& em,
const char* expr)
override {
100 em.createStringExpressionEvaluator(expr);
101 return sk_make_sp<TextExpressionAnimator>(expression_evaluator, fTarget);
105 return Parse(jv, abuilder, fTarget);
112 Keyframe::Value* v)
override {
114 if (!
Parse(jv, abuilder, &val)) {
119 if (fValues.empty() || val != fValues.back()) {
120 fValues.push_back(std::move(val));
123 v->idx =
SkToU32(fValues.size() - 1);
128 std::vector<TextValue> fValues;
140 TextAnimatorBuilder
builder(v);
141 return this->bindImpl(abuilder, jprop,
builder);
#define INHERITED(method,...)
constexpr size_t SkToSizeT(S x)
constexpr uint32_t SkToU32(S x)
AnimationBuilder(sk_sp< ResourceProvider >, sk_sp< SkFontMgr >, sk_sp< PropertyObserver >, sk_sp< Logger >, sk_sp< MarkerObserver >, sk_sp< PrecompInterceptor >, sk_sp< ExpressionManager >, sk_sp< SkShapers::Factory >, Animation::Builder::Stats *, const SkSize &comp_size, float duration, float framerate, uint32_t flags)
bool Parse(const skjson::Value &jv, const internal::AnimationBuilder &abuilder, TextValue *v)
TextPropertyValue TextValue