SkottieProperty.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "modules/skottie/include/SkottieProperty.h"
  8. #include "modules/skottie/src/SkottieAdapter.h"
  9. #include "modules/sksg/include/SkSGOpacityEffect.h"
  10. #include "modules/sksg/include/SkSGPaint.h"
  11. namespace skottie {
  12. bool TransformPropertyValue::operator==(const TransformPropertyValue& other) const {
  13. return this->fAnchorPoint == other.fAnchorPoint
  14. && this->fPosition == other.fPosition
  15. && this->fScale == other.fScale
  16. && this->fSkew == other.fSkew
  17. && this->fSkewAxis == other.fSkewAxis;
  18. }
  19. bool TransformPropertyValue::operator!=(const TransformPropertyValue& other) const {
  20. return !(*this == other);
  21. }
  22. template <>
  23. PropertyHandle<ColorPropertyValue, sksg::Color>::~PropertyHandle() {}
  24. template <>
  25. ColorPropertyValue PropertyHandle<ColorPropertyValue, sksg::Color>::get() const {
  26. return fNode->getColor();
  27. }
  28. template <>
  29. void PropertyHandle<ColorPropertyValue, sksg::Color>::set(const ColorPropertyValue& c) {
  30. fNode->setColor(c);
  31. }
  32. template <>
  33. PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::~PropertyHandle() {}
  34. template <>
  35. OpacityPropertyValue PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::get() const {
  36. return fNode->getOpacity() * 100;
  37. }
  38. template <>
  39. void PropertyHandle<OpacityPropertyValue, sksg::OpacityEffect>::set(const OpacityPropertyValue& o) {
  40. fNode->setOpacity(o / 100);
  41. }
  42. template <>
  43. PropertyHandle<TransformPropertyValue, TransformAdapter2D>::~PropertyHandle() {}
  44. template <>
  45. TransformPropertyValue PropertyHandle<TransformPropertyValue, TransformAdapter2D>::get() const {
  46. return {
  47. fNode->getAnchorPoint(),
  48. fNode->getPosition(),
  49. fNode->getScale(),
  50. fNode->getRotation(),
  51. fNode->getSkew(),
  52. fNode->getSkewAxis()
  53. };
  54. }
  55. template <>
  56. void PropertyHandle<TransformPropertyValue, TransformAdapter2D>::set(
  57. const TransformPropertyValue& t) {
  58. fNode->setAnchorPoint(t.fAnchorPoint);
  59. fNode->setPosition(t.fPosition);
  60. fNode->setScale(t.fScale);
  61. fNode->setRotation(t.fRotation);
  62. fNode->setSkew(t.fSkew);
  63. fNode->setSkewAxis(t.fSkewAxis);
  64. }
  65. void PropertyObserver::onColorProperty(const char[],
  66. const LazyHandle<ColorPropertyHandle>&) {}
  67. void PropertyObserver::onOpacityProperty(const char[],
  68. const LazyHandle<OpacityPropertyHandle>&) {}
  69. void PropertyObserver::onTransformProperty(const char[],
  70. const LazyHandle<TransformPropertyHandle>&) {}
  71. } // namespace skottie