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