SkottieValue.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2017 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. #ifndef SkottieValue_DEFINED
  8. #define SkottieValue_DEFINED
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkPaint.h"
  11. #include "include/core/SkPath.h"
  12. #include "include/core/SkScalar.h"
  13. #include "include/core/SkString.h"
  14. #include <vector>
  15. namespace skjson { class Value; }
  16. namespace skottie {
  17. namespace internal {
  18. class AnimationBuilder;
  19. } // namespace internal
  20. template <typename T>
  21. struct ValueTraits {
  22. static bool FromJSON(const skjson::Value&, const internal::AnimationBuilder*, T*);
  23. template <typename U>
  24. static U As(const T&);
  25. static bool CanLerp(const T&, const T&);
  26. static void Lerp(const T&, const T&, float, T*);
  27. };
  28. using ScalarValue = SkScalar;
  29. using VectorValue = std::vector<ScalarValue>;
  30. struct BezierVertex {
  31. SkPoint fInPoint, // "in" control point, relative to the vertex
  32. fOutPoint, // "out" control point, relative to the vertex
  33. fVertex;
  34. bool operator==(const BezierVertex& other) const {
  35. return fInPoint == other.fInPoint
  36. && fOutPoint == other.fOutPoint
  37. && fVertex == other.fVertex;
  38. }
  39. bool operator!=(const BezierVertex& other) const { return !(*this == other); }
  40. };
  41. struct ShapeValue {
  42. std::vector<BezierVertex> fVertices;
  43. bool fClosed : 1,
  44. fVolatile : 1;
  45. ShapeValue() : fClosed(false), fVolatile(false) {}
  46. ShapeValue(const ShapeValue&) = default;
  47. ShapeValue(ShapeValue&&) = default;
  48. ShapeValue& operator=(const ShapeValue&) = default;
  49. bool operator==(const ShapeValue& other) const {
  50. return fVertices == other.fVertices && fClosed == other.fClosed;
  51. }
  52. bool operator!=(const ShapeValue& other) const { return !(*this == other); }
  53. };
  54. } // namespace skottie
  55. #endif // SkottieValue_DEFINED