aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/skottie/src/Skottie.cpp40
-rw-r--r--modules/skottie/src/SkottieAnimator.h10
2 files changed, 26 insertions, 24 deletions
diff --git a/modules/skottie/src/Skottie.cpp b/modules/skottie/src/Skottie.cpp
index 60009b9bc0..e59ace86ac 100644
--- a/modules/skottie/src/Skottie.cpp
+++ b/modules/skottie/src/Skottie.cpp
@@ -77,20 +77,24 @@ bool LogFail(const skjson::Value& json, const char* msg) {
sk_sp<sksg::Matrix> AttachMatrix(const skjson::ObjectValue& t, AttachContext* ctx,
sk_sp<sksg::Matrix> parentMatrix) {
+ static const VectorValue g_default_vec_0 = { 0, 0},
+ g_default_vec_100 = {100, 100};
+
auto matrix = sksg::Matrix::Make(SkMatrix::I(), std::move(parentMatrix));
auto adapter = sk_make_sp<TransformAdapter>(matrix);
- auto anchor_attached = BindProperty<VectorValue>(t["a"], &ctx->fAnimators,
+
+ auto bound = BindProperty<VectorValue>(t["a"], &ctx->fAnimators,
[adapter](const VectorValue& a) {
adapter->setAnchorPoint(ValueTraits<VectorValue>::As<SkPoint>(a));
- });
- auto position_attached = BindProperty<VectorValue>(t["p"], &ctx->fAnimators,
+ }, g_default_vec_0);
+ bound |= BindProperty<VectorValue>(t["p"], &ctx->fAnimators,
[adapter](const VectorValue& p) {
adapter->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p));
- });
- auto scale_attached = BindProperty<VectorValue>(t["s"], &ctx->fAnimators,
+ }, g_default_vec_0);
+ bound |= BindProperty<VectorValue>(t["s"], &ctx->fAnimators,
[adapter](const VectorValue& s) {
adapter->setScale(ValueTraits<VectorValue>::As<SkVector>(s));
- });
+ }, g_default_vec_100);
const auto* jrotation = &t["r"];
if (jrotation->is<skjson::NullValue>()) {
@@ -98,30 +102,20 @@ sk_sp<sksg::Matrix> AttachMatrix(const skjson::ObjectValue& t, AttachContext* ct
// we can still make use of rz.
jrotation = &t["rz"];
}
- auto rotation_attached = BindProperty<ScalarValue>(*jrotation, &ctx->fAnimators,
+ bound |= BindProperty<ScalarValue>(*jrotation, &ctx->fAnimators,
[adapter](const ScalarValue& r) {
adapter->setRotation(r);
- });
- auto skew_attached = BindProperty<ScalarValue>(t["sk"], &ctx->fAnimators,
+ }, 0.0f);
+ bound |= BindProperty<ScalarValue>(t["sk"], &ctx->fAnimators,
[adapter](const ScalarValue& sk) {
adapter->setSkew(sk);
- });
- auto skewaxis_attached = BindProperty<ScalarValue>(t["sa"], &ctx->fAnimators,
+ }, 0.0f);
+ bound |= BindProperty<ScalarValue>(t["sa"], &ctx->fAnimators,
[adapter](const ScalarValue& sa) {
adapter->setSkewAxis(sa);
- });
-
- if (!anchor_attached &&
- !position_attached &&
- !scale_attached &&
- !rotation_attached &&
- !skew_attached &&
- !skewaxis_attached) {
- LogFail(t, "Could not parse transform");
- return nullptr;
- }
+ }, 0.0f);
- return matrix;
+ return bound ? matrix : nullptr;
}
sk_sp<sksg::RenderNode> AttachOpacity(const skjson::ObjectValue& jtransform, AttachContext* ctx,
diff --git a/modules/skottie/src/SkottieAnimator.h b/modules/skottie/src/SkottieAnimator.h
index c4464e3138..23bd9aa500 100644
--- a/modules/skottie/src/SkottieAnimator.h
+++ b/modules/skottie/src/SkottieAnimator.h
@@ -22,7 +22,15 @@ template <typename T>
bool BindProperty(const skjson::Value&,
sksg::AnimatorList*,
std::function<void(const T&)>&&,
- const T* noop = nullptr);
+ const T* default_igore = nullptr);
+
+template <typename T>
+bool BindProperty(const skjson::Value& jv,
+ sksg::AnimatorList* animators,
+ std::function<void(const T&)>&& apply,
+ const T& default_ignore) {
+ return BindProperty(jv, animators, std::move(apply), &default_ignore);
+}
} // namespace skottie