• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkottieAdapter.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         && fHAlign == other.fHAlign
24         && fVAlign == other.fVAlign
25         && fBox == other.fBox
26         && fFillColor == other.fFillColor
27         && fStrokeColor == other.fStrokeColor
28         && fHasFill == other.fHasFill
29         && fHasStroke == other.fHasStroke;
30 }
31 
operator !=(const TextPropertyValue & other) const32 bool TextPropertyValue::operator!=(const TextPropertyValue& other) const {
33     return !(*this== other);
34 }
35 
operator ==(const TransformPropertyValue & other) const36 bool TransformPropertyValue::operator==(const TransformPropertyValue& other) const {
37     return this->fAnchorPoint == other.fAnchorPoint
38         && this->fPosition    == other.fPosition
39         && this->fScale       == other.fScale
40         && this->fSkew        == other.fSkew
41         && this->fSkewAxis    == other.fSkewAxis;
42 }
43 
operator !=(const TransformPropertyValue & other) const44 bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const {
45     return !(*this == other);
46 }
47 
48 template <>
~PropertyHandle()49 PropertyHandle<ColorPropertyValue, sksg::Color>::~PropertyHandle() {}
50 
51 template <>
get() const52 ColorPropertyValue PropertyHandle<ColorPropertyValue, sksg::Color>::get() const {
53     return fNode->getColor();
54 }
55 
56 template <>
set(const ColorPropertyValue & c)57 void PropertyHandle<ColorPropertyValue, sksg::Color>::set(const ColorPropertyValue& c) {
58     fNode->setColor(c);
59 }
60 
61 template <>
~PropertyHandle()62 PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::~PropertyHandle() {}
63 
64 template <>
get() const65 OpacityPropertyValue PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::get() const {
66     return fNode->getOpacity() * 100;
67 }
68 
69 template <>
set(const OpacityPropertyValue & o)70 void PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::set(const OpacityPropertyValue& o) {
71     fNode->setOpacity(o / 100);
72 }
73 
74 template <>
~PropertyHandle()75 PropertyHandle<TextPropertyValue, internal::TextAdapter>::~PropertyHandle() {}
76 
77 template <>
get() const78 TextPropertyValue PropertyHandle<TextPropertyValue, internal::TextAdapter>::get() const {
79       return fNode->getText();
80 }
81 
82 template<>
set(const TextPropertyValue & t)83 void PropertyHandle<TextPropertyValue, internal::TextAdapter>::set(const TextPropertyValue& t) {
84       fNode->setText(t);
85 }
86 
87 template <>
~PropertyHandle()88 PropertyHandle<TransformPropertyValue, TransformAdapter2D>::~PropertyHandle() {}
89 
90 template <>
get() const91 TransformPropertyValue PropertyHandle<TransformPropertyValue, TransformAdapter2D>::get() const {
92     return {
93         fNode->getAnchorPoint(),
94         fNode->getPosition(),
95         fNode->getScale(),
96         fNode->getRotation(),
97         fNode->getSkew(),
98         fNode->getSkewAxis()
99     };
100 }
101 
102 template <>
set(const TransformPropertyValue & t)103 void PropertyHandle<TransformPropertyValue, TransformAdapter2D>::set(
104         const TransformPropertyValue& t) {
105     fNode->setAnchorPoint(t.fAnchorPoint);
106     fNode->setPosition(t.fPosition);
107     fNode->setScale(t.fScale);
108     fNode->setRotation(t.fRotation);
109     fNode->setSkew(t.fSkew);
110     fNode->setSkewAxis(t.fSkewAxis);
111 }
112 
onColorProperty(const char[],const LazyHandle<ColorPropertyHandle> &)113 void PropertyObserver::onColorProperty(const char[],
114                                        const LazyHandle<ColorPropertyHandle>&) {}
115 
onOpacityProperty(const char[],const LazyHandle<OpacityPropertyHandle> &)116 void PropertyObserver::onOpacityProperty(const char[],
117                                          const LazyHandle<OpacityPropertyHandle>&) {}
118 
onTextProperty(const char[],const LazyHandle<TextPropertyHandle> &)119 void PropertyObserver::onTextProperty(const char[],
120                                       const LazyHandle<TextPropertyHandle>&) {}
121 
onTransformProperty(const char[],const LazyHandle<TransformPropertyHandle> &)122 void PropertyObserver::onTransformProperty(const char[],
123                                            const LazyHandle<TransformPropertyHandle>&) {}
124 
125 } // namespace skottie
126