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 | |
18 | namespace skjson { |
19 | |
20 | class ObjectValue; |
21 | |
22 | } // namespace skjson |
23 | |
24 | namespace skottie { |
25 | namespace internal { |
26 | |
27 | class TransformAdapter2D final : public DiscardableAdapterBase<TransformAdapter2D, |
28 | sksg::Matrix<SkMatrix>> { |
29 | public: |
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 | bool auto_orient = false); |
38 | ~TransformAdapter2D() override; |
39 | |
40 | // Accessors needed for public property APIs. |
41 | // TODO: introduce a separate public type. |
42 | SkPoint getAnchorPoint() const; |
43 | void setAnchorPoint(const SkPoint&); |
44 | |
45 | SkPoint getPosition() const; |
46 | void setPosition(const SkPoint&); |
47 | |
48 | SkVector getScale() const; |
49 | void setScale(const SkVector&); |
50 | |
51 | float getRotation() const { return fRotation; } |
52 | void setRotation(float r); |
53 | |
54 | float getSkew() const { return fSkew; } |
55 | void setSkew(float sk); |
56 | |
57 | float getSkewAxis() const { return fSkewAxis; } |
58 | void setSkewAxis(float sa ); |
59 | |
60 | SkMatrix totalMatrix() const; |
61 | |
62 | private: |
63 | void onSync() override; |
64 | |
65 | Vec2Value fAnchorPoint = { 0, 0 }, |
66 | fPosition = { 0, 0 }, |
67 | fScale = { 100, 100 }; |
68 | ScalarValue fRotation = 0, |
69 | fSkew = 0, |
70 | fSkewAxis = 0, |
71 | fOrientation = 0; // additional rotation component controlled by auto-orient |
72 | |
73 | using INHERITED = DiscardableAdapterBase<TransformAdapter2D, sksg::Matrix<SkMatrix>>; |
74 | }; |
75 | |
76 | class TransformAdapter3D : public DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>> { |
77 | public: |
78 | TransformAdapter3D(const skjson::ObjectValue&, const AnimationBuilder&); |
79 | ~TransformAdapter3D() override; |
80 | |
81 | virtual SkM44 totalMatrix() const; |
82 | |
83 | protected: |
84 | SkV3 anchor_point() const; |
85 | SkV3 position() const; |
86 | SkV3 rotation() const; |
87 | |
88 | private: |
89 | void onSync() final; |
90 | |
91 | VectorValue fAnchorPoint, |
92 | fPosition, |
93 | fOrientation, |
94 | fScale = { 100, 100, 100 }; |
95 | ScalarValue fRx = 0, |
96 | fRy = 0, |
97 | fRz = 0; |
98 | |
99 | using INHERITED = DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>>; |
100 | }; |
101 | |
102 | } // namespace internal |
103 | } // namespace skottie |
104 | |
105 | #endif // SkottieTransform_DEFINED |
106 | |