• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 SkottieRangeSelector_DEFINED
9 #define SkottieRangeSelector_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "modules/skottie/src/SkottiePriv.h"
13 #include "modules/skottie/src/text/TextAnimator.h"
14 
15 #include <tuple>
16 #include <vector>
17 
18 namespace skottie {
19 namespace internal {
20 
21 class RangeSelector final : public SkNVRefCnt<RangeSelector> {
22 public:
23     static sk_sp<RangeSelector> Make(const skjson::ObjectValue*,
24                                      const AnimationBuilder*);
25 
26     enum class Units : uint8_t {
27         kPercentage,  // values are percentages of domain size
28         kIndex,       // values are direct domain indices
29     };
30 
31     enum class Domain : uint8_t {
32         kChars,                   // domain indices map to glyph indices
33         kCharsExcludingSpaces,    // domain indices map to glyph indices (ignoring spaces)
34         kWords,                   // domain indices map to word indices
35         kLines,                   // domain indices map to line indices
36     };
37 
38     enum class Mode : uint8_t {
39         kAdd,
40         // kSubtract,
41         // kIntersect,
42         // kMin,
43         // kMax,
44         // kDifference,
45     };
46 
47     enum class Shape : uint8_t {
48         kSquare,
49         kRampUp,
50         kRampDown,
51         kTriangle,
52         kRound,
53         kSmooth,
54     };
55 
56     void modulateCoverage(const TextAnimator::DomainMaps&, TextAnimator::ModulatorBuffer&) const;
57 
58 private:
59     RangeSelector(Units, Domain, Mode, Shape);
60 
61     // Resolves this selector to a range in the coverage buffer index domain.
62     std::tuple<float, float> resolve(size_t domain_size) const;
63 
64     const Units  fUnits;
65     const Domain fDomain;
66     const Mode   fMode;
67     const Shape  fShape;
68 
69     float        fStart,
70                  fEnd,
71                  fOffset,
72                  fAmount = 100;
73 };
74 
75 } // namespace internal
76 } // namespace skottie
77 
78 #endif // SkottieRangeSelector_DEFINED
79