Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "modules/skottie/include/SkottieProperty.h" |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 9 | |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 10 | #include "modules/skottie/src/Transform.h" |
Avinash Parchuri | 3a543aa | 2019-08-05 18:30:25 -0700 | [diff] [blame] | 11 | #include "modules/skottie/src/text/TextAdapter.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "modules/sksg/include/SkSGOpacityEffect.h" |
| 13 | #include "modules/sksg/include/SkSGPaint.h" |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 14 | |
| 15 | namespace skottie { |
| 16 | |
Avinash Parchuri | fe125a1 | 2019-07-30 17:52:35 -0700 | [diff] [blame] | 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 |
Florin Malita | ad91100 | 2020-01-28 13:21:47 -0500 | [diff] [blame] | 25 | && fResize == other.fResize |
Avinash Parchuri | fe125a1 | 2019-07-30 17:52:35 -0700 | [diff] [blame] | 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 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 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; |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 43 | } |
| 44 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 45 | bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const { |
| 46 | return !(*this == other); |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 47 | } |
| 48 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 49 | template <> |
| 50 | PropertyHandle<ColorPropertyValue, sksg::Color>::~PropertyHandle() {} |
| 51 | |
| 52 | template <> |
| 53 | ColorPropertyValue PropertyHandle<ColorPropertyValue, sksg::Color>::get() const { |
| 54 | return fNode->getColor(); |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 55 | } |
| 56 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 57 | template <> |
| 58 | void PropertyHandle<ColorPropertyValue, sksg::Color>::set(const ColorPropertyValue& c) { |
| 59 | fNode->setColor(c); |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 60 | } |
| 61 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 62 | template <> |
| 63 | PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::~PropertyHandle() {} |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 64 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 65 | template <> |
| 66 | OpacityPropertyValue PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::get() const { |
| 67 | return fNode->getOpacity() * 100; |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 70 | template <> |
| 71 | void PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::set(const OpacityPropertyValue& o) { |
| 72 | fNode->setOpacity(o / 100); |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 75 | template <> |
Avinash Parchuri | 3a543aa | 2019-08-05 18:30:25 -0700 | [diff] [blame] | 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 <> |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 89 | PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::~PropertyHandle() {} |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 90 | |
| 91 | template <> |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 92 | TransformPropertyValue PropertyHandle<TransformPropertyValue, |
| 93 | internal::TransformAdapter2D>::get() const { |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 94 | return { |
| 95 | fNode->getAnchorPoint(), |
| 96 | fNode->getPosition(), |
| 97 | fNode->getScale(), |
| 98 | fNode->getRotation(), |
| 99 | fNode->getSkew(), |
| 100 | fNode->getSkewAxis() |
| 101 | }; |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 102 | } |
| 103 | |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 104 | template <> |
Florin Malita | a3936c8 | 2020-01-06 12:17:27 -0500 | [diff] [blame] | 105 | void PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::set( |
Florin Malita | 8ac81b7 | 2018-11-28 11:39:39 -0500 | [diff] [blame] | 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); |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void PropertyObserver::onColorProperty(const char[], |
| 116 | const LazyHandle<ColorPropertyHandle>&) {} |
| 117 | |
| 118 | void PropertyObserver::onOpacityProperty(const char[], |
| 119 | const LazyHandle<OpacityPropertyHandle>&) {} |
| 120 | |
Avinash Parchuri | 3a543aa | 2019-08-05 18:30:25 -0700 | [diff] [blame] | 121 | void PropertyObserver::onTextProperty(const char[], |
| 122 | const LazyHandle<TextPropertyHandle>&) {} |
| 123 | |
Florin Malita | a85f3a1 | 2018-09-24 17:24:59 -0400 | [diff] [blame] | 124 | void PropertyObserver::onTransformProperty(const char[], |
| 125 | const LazyHandle<TransformPropertyHandle>&) {} |
| 126 | |
Shachar Langbeheim | be28d2e | 2020-02-11 09:48:50 +0200 | [diff] [blame] | 127 | void PropertyObserver::onEnterNode(const char node_name[]) {} |
| 128 | |
| 129 | void PropertyObserver::onLeavingNode(const char node_name[]) {} |
| 130 | |
Florin Malita | c1f0e16 | 2020-05-11 15:51:33 +0000 | [diff] [blame^] | 131 | } // namespace skottie |