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