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 | |
| 8 | #include "SkottieProperty.h" |
| 9 | |
| 10 | #include "SkottieAdapter.h" |
| 11 | #include "SkSGColor.h" |
| 12 | #include "SkSGOpacityEffect.h" |
| 13 | |
| 14 | namespace skottie { |
| 15 | |
| 16 | ColorPropertyHandle::ColorPropertyHandle(sk_sp<sksg::Color> color) |
| 17 | : fColor(std::move(color)) { |
| 18 | SkASSERT(fColor); |
| 19 | } |
| 20 | |
| 21 | ColorPropertyHandle::~ColorPropertyHandle() = default; |
| 22 | |
| 23 | SkColor ColorPropertyHandle::getColor() const { |
| 24 | return fColor->getColor(); |
| 25 | } |
| 26 | |
| 27 | void ColorPropertyHandle::setColor(SkColor color) { |
| 28 | fColor->setColor(color); |
| 29 | } |
| 30 | |
| 31 | OpacityPropertyHandle::OpacityPropertyHandle(sk_sp<sksg::OpacityEffect> opacity) |
| 32 | : fOpacity(std::move(opacity)) { |
| 33 | SkASSERT(fOpacity); |
| 34 | } |
| 35 | |
| 36 | OpacityPropertyHandle::~OpacityPropertyHandle() = default; |
| 37 | |
| 38 | float OpacityPropertyHandle::getOpacity() const { |
| 39 | return fOpacity->getOpacity() * 100; |
| 40 | } |
| 41 | |
| 42 | void OpacityPropertyHandle::setOpacity(float opacity) { |
| 43 | fOpacity->setOpacity(opacity / 100); |
| 44 | } |
| 45 | |
| 46 | TransformPropertyHandle::TransformPropertyHandle(sk_sp<TransformAdapter> transform) |
| 47 | : fTransform(std::move(transform)) { |
| 48 | SkASSERT(fTransform); |
| 49 | } |
| 50 | |
| 51 | TransformPropertyHandle::~TransformPropertyHandle() = default; |
| 52 | |
| 53 | SkPoint TransformPropertyHandle::getAnchorPoint() const { |
| 54 | return fTransform->getAnchorPoint(); |
| 55 | } |
| 56 | |
| 57 | void TransformPropertyHandle::setAnchorPoint(const SkPoint& ap) { |
| 58 | fTransform->setAnchorPoint(ap); |
| 59 | } |
| 60 | |
| 61 | SkPoint TransformPropertyHandle::getPosition() const { |
| 62 | return fTransform->getPosition(); |
| 63 | } |
| 64 | |
| 65 | void TransformPropertyHandle::setPosition(const SkPoint& position) { |
| 66 | fTransform->setPosition(position); |
| 67 | } |
| 68 | |
| 69 | SkVector TransformPropertyHandle::getScale() const { |
| 70 | return fTransform->getScale(); |
| 71 | } |
| 72 | |
| 73 | void TransformPropertyHandle::setScale(const SkVector& scale) { |
| 74 | fTransform->setScale(scale); |
| 75 | } |
| 76 | |
| 77 | SkScalar TransformPropertyHandle::getRotation() const { |
| 78 | return fTransform->getRotation(); |
| 79 | } |
| 80 | |
| 81 | void TransformPropertyHandle::setRotation(SkScalar rotation) { |
| 82 | fTransform->setRotation(rotation); |
| 83 | } |
| 84 | |
| 85 | SkScalar TransformPropertyHandle::getSkew() const { |
| 86 | return fTransform->getSkew(); |
| 87 | } |
| 88 | |
| 89 | void TransformPropertyHandle::setSkew(SkScalar skew) { |
| 90 | fTransform->setSkew(skew); |
| 91 | } |
| 92 | |
| 93 | SkScalar TransformPropertyHandle::getSkewAxis() const { |
| 94 | return fTransform->getSkewAxis(); |
| 95 | } |
| 96 | |
| 97 | void TransformPropertyHandle::setSkewAxis(SkScalar sa) { |
| 98 | fTransform->setSkewAxis(sa); |
| 99 | } |
| 100 | |
| 101 | SkMatrix TransformPropertyHandle::getTotalMatrix() const { |
| 102 | return fTransform->totalMatrix(); |
| 103 | } |
| 104 | |
| 105 | void PropertyObserver::onColorProperty(const char[], |
| 106 | const LazyHandle<ColorPropertyHandle>&) {} |
| 107 | |
| 108 | void PropertyObserver::onOpacityProperty(const char[], |
| 109 | const LazyHandle<OpacityPropertyHandle>&) {} |
| 110 | |
| 111 | void PropertyObserver::onTransformProperty(const char[], |
| 112 | const LazyHandle<TransformPropertyHandle>&) {} |
| 113 | |
| 114 | } // namespace skottie |