blob: 16a6ebee9a09e6a64538f9324e450d40637a387b [file] [log] [blame]
Florin Malitaa3936c82020-01-06 12:17:27 -05001/*
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 Reed46f5c5f2020-02-20 15:42:29 -050011#include "include/core/SkM44.h"
Florin Malitaa3936c82020-01-06 12:17:27 -050012#include "include/core/SkMatrix.h"
Florin Malitae7bd58f2020-01-27 11:58:49 -050013#include "include/core/SkPoint.h"
Florin Malitae7bd58f2020-01-27 11:58:49 -050014#include "modules/skottie/src/Adapter.h"
Florin Malitad960cc32020-01-29 09:47:00 -050015#include "modules/skottie/src/SkottieValue.h"
16#include "modules/sksg/include/SkSGTransform.h"
Florin Malitae7bd58f2020-01-27 11:58:49 -050017
18namespace skjson {
19
20class ObjectValue;
21
22} // namespace skjson
Florin Malitaa3936c82020-01-06 12:17:27 -050023
24namespace skottie {
25namespace internal {
26
Florin Malitae7bd58f2020-01-27 11:58:49 -050027class TransformAdapter2D final : public DiscardableAdapterBase<TransformAdapter2D,
28 sksg::Matrix<SkMatrix>> {
Florin Malitaa3936c82020-01-06 12:17:27 -050029public:
Florin Malitae7bd58f2020-01-27 11:58:49 -050030 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 Malita6a414b22020-05-25 11:46:50 -040036 const skjson::ObjectValue* jskew_axis,
37 bool auto_orient = false);
Florin Malitae7bd58f2020-01-27 11:58:49 -050038 ~TransformAdapter2D() override;
Florin Malitaa3936c82020-01-06 12:17:27 -050039
Florin Malitae7bd58f2020-01-27 11:58:49 -050040 // 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 Malitaa3936c82020-01-06 12:17:27 -050059
60 SkMatrix totalMatrix() const;
61
62private:
Florin Malitae7bd58f2020-01-27 11:58:49 -050063 void onSync() override;
Florin Malitaa3936c82020-01-06 12:17:27 -050064
Florin Malita92ec8012020-03-10 13:21:19 -040065 Vec2Value fAnchorPoint = { 0, 0 },
66 fPosition = { 0, 0 },
67 fScale = { 100, 100 };
68 ScalarValue fRotation = 0,
69 fSkew = 0,
Florin Malita6a414b22020-05-25 11:46:50 -040070 fSkewAxis = 0,
71 fOrientation = 0; // additional rotation component controlled by auto-orient
Florin Malitae7bd58f2020-01-27 11:58:49 -050072
73 using INHERITED = DiscardableAdapterBase<TransformAdapter2D, sksg::Matrix<SkMatrix>>;
Florin Malitaa3936c82020-01-06 12:17:27 -050074};
75
Florin Malitab67ca742020-01-27 16:13:18 -050076class TransformAdapter3D : public DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>> {
Florin Malitaa3936c82020-01-06 12:17:27 -050077public:
Florin Malitae7bd58f2020-01-27 11:58:49 -050078 TransformAdapter3D(const skjson::ObjectValue&, const AnimationBuilder&);
Florin Malitaa3936c82020-01-06 12:17:27 -050079 ~TransformAdapter3D() override;
80
Florin Malitab67ca742020-01-27 16:13:18 -050081 virtual SkM44 totalMatrix() const;
Florin Malitaa3936c82020-01-06 12:17:27 -050082
Florin Malitae7bd58f2020-01-27 11:58:49 -050083protected:
Florin Malitab67ca742020-01-27 16:13:18 -050084 SkV3 anchor_point() const;
85 SkV3 position() const;
86 SkV3 rotation() const;
Florin Malitaa3936c82020-01-06 12:17:27 -050087
Florin Malitae7bd58f2020-01-27 11:58:49 -050088private:
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 Malitab67ca742020-01-27 16:13:18 -050099 using INHERITED = DiscardableAdapterBase<TransformAdapter3D, sksg::Matrix<SkM44>>;
Florin Malitaa3936c82020-01-06 12:17:27 -0500100};
101
102} // namespace internal
103} // namespace skottie
104
105#endif // SkottieTransform_DEFINED