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 "SkColor.h" 12 #include "SkPaint.h" 13 #include "SkPath.h" 14 #include "SkScalar.h" 15 #include "SkString.h" 16 #include "SkTextUtils.h" 17 #include "SkTypeface.h" 18 19 #include <vector> 20 21 namespace skjson { class Value; } 22 23 namespace skottie { 24 namespace internal { 25 class AnimationBuilder; 26 } // namespace internal 27 28 template <typename T> 29 struct ValueTraits { 30 static bool FromJSON(const skjson::Value&, const internal::AnimationBuilder*, T*); 31 32 template <typename U> 33 static U As(const T&); 34 35 static bool CanLerp(const T&, const T&); 36 static void Lerp(const T&, const T&, float, T*); 37 }; 38 39 using ScalarValue = SkScalar; 40 using VectorValue = std::vector<ScalarValue>; 41 42 struct BezierVertex { 43 SkPoint fInPoint, // "in" control point, relative to the vertex 44 fOutPoint, // "out" control point, relative to the vertex 45 fVertex; 46 47 bool operator==(const BezierVertex& other) const { 48 return fInPoint == other.fInPoint 49 && fOutPoint == other.fOutPoint 50 && fVertex == other.fVertex; 51 } 52 53 bool operator!=(const BezierVertex& other) const { return !(*this == other); } 54 }; 55 56 struct ShapeValue { 57 std::vector<BezierVertex> fVertices; 58 bool fClosed : 1, 59 fVolatile : 1; 60 ShapeValueShapeValue61 ShapeValue() : fClosed(false), fVolatile(false) {} 62 ShapeValue(const ShapeValue&) = default; 63 ShapeValue(ShapeValue&&) = default; 64 ShapeValue& operator=(const ShapeValue&) = default; 65 66 bool operator==(const ShapeValue& other) const { 67 return fVertices == other.fVertices && fClosed == other.fClosed; 68 } 69 70 bool operator!=(const ShapeValue& other) const { return !(*this == other); } 71 }; 72 73 struct TextValue { 74 sk_sp<SkTypeface> fTypeface; 75 SkString fText; 76 float fTextSize = 0, 77 fStrokeWidth = 0; 78 SkTextUtils::Align fAlign = SkTextUtils::kLeft_Align; 79 SkColor fFillColor = SK_ColorTRANSPARENT, 80 fStrokeColor = SK_ColorTRANSPARENT; 81 bool fHasFill : 1, 82 fHasStroke : 1; 83 84 bool operator==(const TextValue& other) const { 85 return fTypeface == other.fTypeface 86 && fText == other.fText 87 && fTextSize == other.fTextSize 88 && fStrokeWidth == other.fStrokeWidth 89 && fAlign == other.fAlign 90 && fFillColor == other.fFillColor 91 && fStrokeColor == other.fStrokeColor 92 && fHasFill == other.fHasFill 93 && fHasStroke == other.fHasStroke; 94 } 95 96 bool operator!=(const TextValue& other) const { return !(*this == other); } 97 }; 98 99 } // namespace skottie 100 101 #endif // SkottieValue_DEFINED 102