blob: 9702bf1c6c32e6522fd498af570a21e7d9720212 [file] [log] [blame]
Florin Malitaa85f3a12018-09-24 17:24:59 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "modules/skottie/include/SkottieProperty.h"
Florin Malitaa85f3a12018-09-24 17:24:59 -04009
Florin Malitaa3936c82020-01-06 12:17:27 -050010#include "modules/skottie/src/Transform.h"
Avinash Parchuri3a543aa2019-08-05 18:30:25 -070011#include "modules/skottie/src/text/TextAdapter.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "modules/sksg/include/SkSGOpacityEffect.h"
13#include "modules/sksg/include/SkSGPaint.h"
Florin Malitaa85f3a12018-09-24 17:24:59 -040014
15namespace skottie {
16
Avinash Parchurife125a12019-07-30 17:52:35 -070017bool 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 Malitaad911002020-01-28 13:21:47 -050025 && fResize == other.fResize
Avinash Parchurife125a12019-07-30 17:52:35 -070026 && fBox == other.fBox
27 && fFillColor == other.fFillColor
28 && fStrokeColor == other.fStrokeColor
29 && fHasFill == other.fHasFill
30 && fHasStroke == other.fHasStroke;
31}
32
33bool TextPropertyValue::operator!=(const TextPropertyValue& other) const {
34 return !(*this== other);
35}
36
Florin Malita8ac81b72018-11-28 11:39:39 -050037bool 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 Malitaa85f3a12018-09-24 17:24:59 -040043}
44
Florin Malita8ac81b72018-11-28 11:39:39 -050045bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const {
46 return !(*this == other);
Florin Malitaa85f3a12018-09-24 17:24:59 -040047}
48
Florin Malita8ac81b72018-11-28 11:39:39 -050049template <>
50PropertyHandle<ColorPropertyValue, sksg::Color>::~PropertyHandle() {}
51
52template <>
53ColorPropertyValue PropertyHandle<ColorPropertyValue, sksg::Color>::get() const {
54 return fNode->getColor();
Florin Malitaa85f3a12018-09-24 17:24:59 -040055}
56
Florin Malita8ac81b72018-11-28 11:39:39 -050057template <>
58void PropertyHandle<ColorPropertyValue, sksg::Color>::set(const ColorPropertyValue& c) {
59 fNode->setColor(c);
Florin Malitaa85f3a12018-09-24 17:24:59 -040060}
61
Florin Malita8ac81b72018-11-28 11:39:39 -050062template <>
63PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::~PropertyHandle() {}
Florin Malitaa85f3a12018-09-24 17:24:59 -040064
Florin Malita8ac81b72018-11-28 11:39:39 -050065template <>
66OpacityPropertyValue PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::get() const {
67 return fNode->getOpacity() * 100;
Florin Malitaa85f3a12018-09-24 17:24:59 -040068}
69
Florin Malita8ac81b72018-11-28 11:39:39 -050070template <>
71void PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::set(const OpacityPropertyValue& o) {
72 fNode->setOpacity(o / 100);
Florin Malitaa85f3a12018-09-24 17:24:59 -040073}
74
Florin Malita8ac81b72018-11-28 11:39:39 -050075template <>
Avinash Parchuri3a543aa2019-08-05 18:30:25 -070076PropertyHandle<TextPropertyValue, internal::TextAdapter>::~PropertyHandle() {}
77
78template <>
79TextPropertyValue PropertyHandle<TextPropertyValue, internal::TextAdapter>::get() const {
80 return fNode->getText();
81}
82
83template<>
84void PropertyHandle<TextPropertyValue, internal::TextAdapter>::set(const TextPropertyValue& t) {
85 fNode->setText(t);
86}
87
88template <>
Florin Malitaa3936c82020-01-06 12:17:27 -050089PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::~PropertyHandle() {}
Florin Malita8ac81b72018-11-28 11:39:39 -050090
91template <>
Florin Malitaa3936c82020-01-06 12:17:27 -050092TransformPropertyValue PropertyHandle<TransformPropertyValue,
93 internal::TransformAdapter2D>::get() const {
Florin Malita8ac81b72018-11-28 11:39:39 -050094 return {
95 fNode->getAnchorPoint(),
96 fNode->getPosition(),
97 fNode->getScale(),
98 fNode->getRotation(),
99 fNode->getSkew(),
100 fNode->getSkewAxis()
101 };
Florin Malitaa85f3a12018-09-24 17:24:59 -0400102}
103
Florin Malita8ac81b72018-11-28 11:39:39 -0500104template <>
Florin Malitaa3936c82020-01-06 12:17:27 -0500105void PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::set(
Florin Malita8ac81b72018-11-28 11:39:39 -0500106 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 Malitaa85f3a12018-09-24 17:24:59 -0400113}
114
115void PropertyObserver::onColorProperty(const char[],
116 const LazyHandle<ColorPropertyHandle>&) {}
117
118void PropertyObserver::onOpacityProperty(const char[],
119 const LazyHandle<OpacityPropertyHandle>&) {}
120
Avinash Parchuri3a543aa2019-08-05 18:30:25 -0700121void PropertyObserver::onTextProperty(const char[],
122 const LazyHandle<TextPropertyHandle>&) {}
123
Florin Malitaa85f3a12018-09-24 17:24:59 -0400124void PropertyObserver::onTransformProperty(const char[],
125 const LazyHandle<TransformPropertyHandle>&) {}
126
Shachar Langbeheimbe28d2e2020-02-11 09:48:50 +0200127void PropertyObserver::onEnterNode(const char node_name[]) {}
128
129void PropertyObserver::onLeavingNode(const char node_name[]) {}
130
Florin Malitac1f0e162020-05-11 15:51:33 +0000131} // namespace skottie