Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 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 | |
Mike Reed | 46f5c5f | 2020-02-20 15:42:29 -0500 | [diff] [blame] | 11 | #include "include/core/SkM44.h" |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 12 | #include "include/core/SkMatrix.h" |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 13 | #include "include/core/SkPoint.h" |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 14 | #include "modules/skottie/src/Adapter.h" |
Florin Malita | d960cc3 | 2020-01-29 09:47:00 -0500 | [diff] [blame] | 15 | #include "modules/skottie/src/SkottieValue.h" |
| 16 | #include "modules/sksg/include/SkSGTransform.h" |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 17 | |
| 18 | namespace skjson { |
| 19 | |
| 20 | class ObjectValue; |
| 21 | |
| 22 | } // namespace skjson |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 23 | |
| 24 | namespace skottie { |
| 25 | namespace internal { |
| 26 | |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 27 | class TransformAdapter2D final : public DiscardableAdapterBase<TransformAdapter2D, |
| 28 | sksg::Matrix<SkMatrix>> { |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 29 | public: |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 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, |
Florin Malita | 6a414b2 | 2020-05-25 11:46:50 -0400 | [diff] [blame] | 36 | const skjson::ObjectValue* jskew_axis, |
| 37 | bool auto_orient = false); |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 38 | ~TransformAdapter2D() override; |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 39 | |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 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 ); |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 59 | |
| 60 | SkMatrix totalMatrix() const; |
| 61 | |
| 62 | private: |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 63 | void onSync() override; |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 64 | |
Florin Malita | 92ec801 | 2020-03-10 13:21:19 -0400 | [diff] [blame] | 65 | Vec2Value fAnchorPoint = { 0, 0 }, |
| 66 | fPosition = { 0, 0 }, |
| 67 | fScale = { 100, 100 }; |
| 68 | ScalarValue fRotation = 0, |
| 69 | fSkew = 0, |
Florin Malita | 6a414b2 | 2020-05-25 11:46:50 -0400 | [diff] [blame] | 70 | fSkewAxis = 0, |
| 71 | fOrientation = 0; // additional rotation component controlled by auto-orient |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 72 | |
| 73 | using INHERITED = DiscardableAdapterBase<TransformAdapter2D, sksg::Matrix<SkMatrix>>; |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 74 | }; |
| 75 | |
Florin Malita | b67ca74 | 2020-01-27 16:13:18 -0500 | [diff] [blame] | 76 | class TransformAdapter3D : public DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>> { |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 77 | public: |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 78 | TransformAdapter3D(const skjson::ObjectValue&, const AnimationBuilder&); |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 79 | ~TransformAdapter3D() override; |
| 80 | |
Florin Malita | b67ca74 | 2020-01-27 16:13:18 -0500 | [diff] [blame] | 81 | virtual SkM44 totalMatrix() const; |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 82 | |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 83 | protected: |
Florin Malita | b67ca74 | 2020-01-27 16:13:18 -0500 | [diff] [blame] | 84 | SkV3 anchor_point() const; |
| 85 | SkV3 position() const; |
| 86 | SkV3 rotation() const; |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 87 | |
Florin Malita | e7bd58f | 2020-01-27 11:58:49 -0500 | [diff] [blame] | 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 | |
Florin Malita | b67ca74 | 2020-01-27 16:13:18 -0500 | [diff] [blame] | 99 | using INHERITED = DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>>; |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | } // namespace internal |
| 103 | } // namespace skottie |
| 104 | |
| 105 | #endif // SkottieTransform_DEFINED |