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
15namespace skottie {
16
17bool 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
33bool TextPropertyValue::operator!=(const TextPropertyValue& other) const {
34 return !(*this== other);
35}
36
37bool 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
45bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const {
46 return !(*this == other);
47}
48
49template <>
50PropertyHandle<ColorPropertyValue, sksg::Color>::~PropertyHandle() {}
51
52template <>
53ColorPropertyValue PropertyHandle<ColorPropertyValue, sksg::Color>::get() const {
54 return fNode->getColor();
55}
56
57template <>
58void PropertyHandle<ColorPropertyValue, sksg::Color>::set(const ColorPropertyValue& c) {
59 fNode->setColor(c);
60}
61
62template <>
63PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::~PropertyHandle() {}
64
65template <>
66OpacityPropertyValue PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::get() const {
67 return fNode->getOpacity() * 100;
68}
69
70template <>
71void PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::set(const OpacityPropertyValue& o) {
72 fNode->setOpacity(o / 100);
73}
74
75template <>
76PropertyHandle<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 <>
89PropertyHandle<TransformPropertyValue, internal::TransformAdapter2D>::~PropertyHandle() {}
90
91template <>
92TransformPropertyValue 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
104template <>
105void 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
115void PropertyObserver::onColorProperty(const char[],
116 const LazyHandle<ColorPropertyHandle>&) {}
117
118void PropertyObserver::onOpacityProperty(const char[],
119 const LazyHandle<OpacityPropertyHandle>&) {}
120
121void PropertyObserver::onTextProperty(const char[],
122 const LazyHandle<TextPropertyHandle>&) {}
123
124void PropertyObserver::onTransformProperty(const char[],
125 const LazyHandle<TransformPropertyHandle>&) {}
126
127void PropertyObserver::onEnterNode(const char node_name[]) {}
128
129void PropertyObserver::onLeavingNode(const char node_name[]) {}
130
131} // namespace skottie
132