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