1 /*
2  * Copyright 2018 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 #include "modules/skottie/include/SkottieProperty.h"
9 
10 #include "modules/skottie/src/Transform.h"
11 #include "modules/skottie/src/text/TextAdapter.h"
12 #include "modules/sksg/include/SkSGOpacityEffect.h"
13 #include "modules/sksg/include/SkSGPaint.h"
14 
15 namespace skottie {
16 
operator ==(const TextPropertyValue & other) const17 bool TextPropertyValue::operator==(const TextPropertyValue& other) const {
18     return fTypeface == other.fTypeface
19         && fText == other.fText
20         && fTextSize == other.fTextSize
21         && fStrokeWidth == other.fStrokeWidth
22         && fLineHeight == other.fLineHeight
23         && fLineShift == other.fLineShift
24         && fAscent == other.fAscent
25         && fHAlign == other.fHAlign
26         && fVAlign == other.fVAlign
27         && fResize == other.fResize
28         && fLineBreak == other.fLineBreak
29         && fDirection == other.fDirection
30         && fBox == other.fBox
31         && fFillColor == other.fFillColor
32         && fStrokeColor == other.fStrokeColor
33         && fHasFill == other.fHasFill
34         && fHasStroke == other.fHasStroke;
35 }
36 
operator !=(const TextPropertyValue & other) const37 bool TextPropertyValue::operator!=(const TextPropertyValue& other) const {
38     return !(*this== other);
39 }
40 
operator ==(const TransformPropertyValue & other) const41 bool TransformPropertyValue::operator==(const TransformPropertyValue& other) const {
42     return this->fAnchorPoint == other.fAnchorPoint
43         && this->fPosition    == other.fPosition
44         && this->fScale       == other.fScale
45         && this->fSkew        == other.fSkew
46         && this->fSkewAxis    == other.fSkewAxis;
47 }
48 
operator !=(const TransformPropertyValue & other) const49 bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const {
50     return !(*this == other);
51 }
52 
53 template <>
~PropertyHandle()54 PropertyHandle<ColorPropertyValue, sksg::Color>::~PropertyHandle() {}
55 
56 template <>
get() const57 ColorPropertyValue PropertyHandle<ColorPropertyValue, sksg::Color>::get() const {
58     return fNode->getColor();
59 }
60 
61 template <>
set(const ColorPropertyValue & c)62 void PropertyHandle<ColorPropertyValue, sksg::Color>::set(const ColorPropertyValue& c) {
63     fNode->setColor(c);
64 }
65 
66 template <>
~PropertyHandle()67 PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::~PropertyHandle() {}
68 
69 template <>
get() const70 OpacityPropertyValue PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::get() const {
71     return fNode->getOpacity() * 100;
72 }
73 
74 template <>
set(const OpacityPropertyValue & o)75 void PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::set(const OpacityPropertyValue& o) {
76     fNode->setOpacity(o / 100);
77 }
78 
79 template <>
~PropertyHandle()80 PropertyHandle<TextPropertyValue, internal::TextAdapter>::~PropertyHandle() {}
81 
82 template <>
get() const83 TextPropertyValue PropertyHandle<TextPropertyValue, internal::TextAdapter>::get() const {
84       return fNode->getText();
85 }
86 
87 template<>
set(const TextPropertyValue & t)88 void PropertyHandle<TextPropertyValue, internal::TextAdapter>::set(const TextPropertyValue& t) {
89       fNode->setText(t);
90 }
91 
92 template <>
~PropertyHandle()93 PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::~PropertyHandle() {}
94 
95 template <>
96 TransformPropertyValue PropertyHandle<TransformPropertyValue,
get() const97                                       internal::TransformAdapter2D>::get() const {
98     return {
99         fNode->getAnchorPoint(),
100         fNode->getPosition(),
101         fNode->getScale(),
102         fNode->getRotation(),
103         fNode->getSkew(),
104         fNode->getSkewAxis()
105     };
106 }
107 
108 template <>
set(const TransformPropertyValue & t)109 void PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::set(
110         const TransformPropertyValue& t) {
111     fNode->setAnchorPoint(t.fAnchorPoint);
112     fNode->setPosition(t.fPosition);
113     fNode->setScale(t.fScale);
114     fNode->setRotation(t.fRotation);
115     fNode->setSkew(t.fSkew);
116     fNode->setSkewAxis(t.fSkewAxis);
117 }
118 
onColorProperty(const char[],const LazyHandle<ColorPropertyHandle> &)119 void PropertyObserver::onColorProperty(const char[],
120                                        const LazyHandle<ColorPropertyHandle>&) {}
121 
onOpacityProperty(const char[],const LazyHandle<OpacityPropertyHandle> &)122 void PropertyObserver::onOpacityProperty(const char[],
123                                          const LazyHandle<OpacityPropertyHandle>&) {}
124 
onTextProperty(const char[],const LazyHandle<TextPropertyHandle> &)125 void PropertyObserver::onTextProperty(const char[],
126                                       const LazyHandle<TextPropertyHandle>&) {}
127 
onTransformProperty(const char[],const LazyHandle<TransformPropertyHandle> &)128 void PropertyObserver::onTransformProperty(const char[],
129                                            const LazyHandle<TransformPropertyHandle>&) {}
130 
onEnterNode(const char node_name[])131 void PropertyObserver::onEnterNode(const char node_name[]) {}
132 
onLeavingNode(const char node_name[])133 void PropertyObserver::onLeavingNode(const char node_name[]) {}
134 
135 }  // namespace skottie
136