1/*
2 * Copyright 2020 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkottieTransform_DEFINED
9#define SkottieTransform_DEFINED
10
11#include "include/core/SkM44.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkPoint.h"
14#include "modules/skottie/src/Adapter.h"
15#include "modules/skottie/src/SkottieValue.h"
16#include "modules/sksg/include/SkSGTransform.h"
17
18namespace skjson {
19
20class ObjectValue;
21
22} // namespace skjson
23
24namespace skottie {
25namespace internal {
26
27class TransformAdapter2D final : public DiscardableAdapterBase<TransformAdapter2D,
28 sksg::Matrix<SkMatrix>> {
29public:
30 TransformAdapter2D(const AnimationBuilder&,
31 const skjson::ObjectValue* janchor_point,
32 const skjson::ObjectValue* jposition,
33 const skjson::ObjectValue* jscale,
34 const skjson::ObjectValue* jrotation,
35 const skjson::ObjectValue* jskew,
36 const skjson::ObjectValue* jskew_axis);
37 ~TransformAdapter2D() override;
38
39 // Accessors needed for public property APIs.
40 // TODO: introduce a separate public type.
41 SkPoint getAnchorPoint() const;
42 void setAnchorPoint(const SkPoint&);
43
44 SkPoint getPosition() const;
45 void setPosition(const SkPoint&);
46
47 SkVector getScale() const;
48 void setScale(const SkVector&);
49
50 float getRotation() const { return fRotation; }
51 void setRotation(float r);
52
53 float getSkew() const { return fSkew; }
54 void setSkew(float sk);
55
56 float getSkewAxis() const { return fSkewAxis; }
57 void setSkewAxis(float sa );
58
59 SkMatrix totalMatrix() const;
60
61private:
62 void onSync() override;
63
64 Vec2Value fAnchorPoint = { 0, 0 },
65 fPosition = { 0, 0 },
66 fScale = { 100, 100 };
67 ScalarValue fRotation = 0,
68 fSkew = 0,
69 fSkewAxis = 0;
70
71 using INHERITED = DiscardableAdapterBase<TransformAdapter2D, sksg::Matrix<SkMatrix>>;
72};
73
74class TransformAdapter3D : public DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>> {
75public:
76 TransformAdapter3D(const skjson::ObjectValue&, const AnimationBuilder&);
77 ~TransformAdapter3D() override;
78
79 virtual SkM44 totalMatrix() const;
80
81protected:
82 SkV3 anchor_point() const;
83 SkV3 position() const;
84 SkV3 rotation() const;
85
86private:
87 void onSync() final;
88
89 VectorValue fAnchorPoint,
90 fPosition,
91 fOrientation,
92 fScale = { 100, 100, 100 };
93 ScalarValue fRx = 0,
94 fRy = 0,
95 fRz = 0;
96
97 using INHERITED = DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>>;
98};
99
100} // namespace internal
101} // namespace skottie
102
103#endif // SkottieTransform_DEFINED
104