Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
skottie::internal::RangeSelector Class Referencefinal

#include <RangeSelector.h>

Inheritance diagram for skottie::internal::RangeSelector:
SkNVRefCnt< RangeSelector >

Public Types

enum class  Units : uint8_t { kPercentage , kIndex }
 
enum class  Domain : uint8_t { kChars , kCharsExcludingSpaces , kWords , kLines }
 
enum class  Mode : uint8_t { kAdd }
 
enum class  Shape : uint8_t {
  kSquare , kRampUp , kRampDown , kTriangle ,
  kRound , kSmooth
}
 

Public Member Functions

void modulateCoverage (const TextAnimator::DomainMaps &, TextAnimator::ModulatorBuffer &) const
 
- Public Member Functions inherited from SkNVRefCnt< RangeSelector >
 SkNVRefCnt ()
 
 ~SkNVRefCnt ()
 
bool unique () const
 
void ref () const
 
void unref () const
 
void deref () const
 
bool refCntGreaterThan (int32_t threadIsolatedTestCnt) const
 

Static Public Member Functions

static sk_sp< RangeSelectorMake (const skjson::ObjectValue *, const AnimationBuilder *, AnimatablePropertyContainer *)
 

Detailed Description

Definition at line 26 of file RangeSelector.h.

Member Enumeration Documentation

◆ Domain

enum class skottie::internal::RangeSelector::Domain : uint8_t
strong
Enumerator
kChars 
kCharsExcludingSpaces 
kWords 
kLines 

Definition at line 37 of file RangeSelector.h.

37 : uint8_t {
38 kChars, // domain indices map to glyph indices
39 kCharsExcludingSpaces, // domain indices map to glyph indices (ignoring spaces)
40 kWords, // domain indices map to word indices
41 kLines, // domain indices map to line indices
42 };

◆ Mode

enum class skottie::internal::RangeSelector::Mode : uint8_t
strong
Enumerator
kAdd 

Definition at line 44 of file RangeSelector.h.

44 : uint8_t {
45 kAdd,
46 // kSubtract,
47 // kIntersect,
48 // kMin,
49 // kMax,
50 // kDifference,
51 };

◆ Shape

enum class skottie::internal::RangeSelector::Shape : uint8_t
strong

◆ Units

enum class skottie::internal::RangeSelector::Units : uint8_t
strong
Enumerator
kPercentage 
kIndex 

Definition at line 32 of file RangeSelector.h.

32 : uint8_t {
33 kPercentage, // values are percentages of domain size
34 kIndex, // values are direct domain indices
35 };

Member Function Documentation

◆ Make()

sk_sp< RangeSelector > skottie::internal::RangeSelector::Make ( const skjson::ObjectValue jrange,
const AnimationBuilder abuilder,
AnimatablePropertyContainer acontainer 
)
static

Definition at line 239 of file RangeSelector.cpp.

241 {
242 if (!jrange) {
243 return nullptr;
244 }
245
246 enum : int32_t {
247 kRange_SelectorType = 0,
248 kExpression_SelectorType = 1,
249
250 // kWiggly_SelectorType = ? (not exported)
251 };
252
253 {
254 const auto type = ParseDefault<int>((*jrange)["t"], kRange_SelectorType);
255 if (type != kRange_SelectorType) {
256 abuilder->log(Logger::Level::kWarning, nullptr,
257 "Ignoring unsupported selector type '%d'", type);
258 return nullptr;
259 }
260 }
261
262 static constexpr Units gUnitMap[] = {
263 Units::kPercentage, // 'r': 1
264 Units::kIndex, // 'r': 2
265 };
266
267 static constexpr Domain gDomainMap[] = {
268 Domain::kChars, // 'b': 1
270 Domain::kWords, // 'b': 3
271 Domain::kLines, // 'b': 4
272 };
273
274 static constexpr Mode gModeMap[] = {
275 Mode::kAdd, // 'm': 1
276 };
277
278 static constexpr Shape gShapeMap[] = {
279 Shape::kSquare, // 'sh': 1
280 Shape::kRampUp, // 'sh': 2
281 Shape::kRampDown, // 'sh': 3
282 Shape::kTriangle, // 'sh': 4
283 Shape::kRound, // 'sh': 5
284 Shape::kSmooth, // 'sh': 6
285 };
286
287 auto selector = sk_sp<RangeSelector>(
288 new RangeSelector(ParseEnum<Units> (gUnitMap , (*jrange)["r" ], abuilder, "units" ),
289 ParseEnum<Domain>(gDomainMap, (*jrange)["b" ], abuilder, "domain"),
290 ParseEnum<Mode> (gModeMap , (*jrange)["m" ], abuilder, "mode" ),
291 ParseEnum<Shape> (gShapeMap , (*jrange)["sh"], abuilder, "shape" )));
292
293 acontainer->bind(*abuilder, (*jrange)["s" ], &selector->fStart );
294 acontainer->bind(*abuilder, (*jrange)["e" ], &selector->fEnd );
295 acontainer->bind(*abuilder, (*jrange)["o" ], &selector->fOffset);
296 acontainer->bind(*abuilder, (*jrange)["a" ], &selector->fAmount);
297 acontainer->bind(*abuilder, (*jrange)["ne"], &selector->fEaseLo);
298 acontainer->bind(*abuilder, (*jrange)["xe"], &selector->fEaseHi);
299
300 // Optional square "smoothness" prop.
301 if (selector->fShape == Shape::kSquare) {
302 acontainer->bind(*abuilder, (*jrange)["sm" ], &selector->fSmoothness);
303 }
304
305 return selector;
306}
Shape

◆ modulateCoverage()

void skottie::internal::RangeSelector::modulateCoverage ( const TextAnimator::DomainMaps maps,
TextAnimator::ModulatorBuffer mbuf 
) const

Definition at line 355 of file RangeSelector.cpp.

356 {
357 const CoverageProcessor coverage_proc(maps, fDomain, fMode, mbuf);
358 if (coverage_proc.size() == 0) {
359 return;
360 }
361
362 // Amount, ease-low and ease-high are percentage-based [-100% .. 100%].
363 const auto amount = SkTPin<float>(fAmount / 100, -1, 1),
364 ease_lo = SkTPin<float>(fEaseLo / 100, -1, 1),
365 ease_hi = SkTPin<float>(fEaseHi / 100, -1, 1);
366
367 // Resolve to a float range in the given domain.
368 const auto range = this->resolve(coverage_proc.size());
369 auto r0 = std::get<0>(range),
370 len = std::max(std::get<1>(range) - r0, std::numeric_limits<float>::epsilon());
371
372 SkASSERT(static_cast<size_t>(fShape) < std::size(gShapeInfo));
373 ShapeGenerator gen(gShapeInfo[static_cast<size_t>(fShape)], ease_lo, ease_hi);
374
375 if (fShape == Shape::kSquare) {
376 // Canonical square generators have collapsed ramps, but AE square selectors have
377 // an additional "smoothness" property (0..1) which introduces a non-zero transition.
378 // We achieve this by moving the range edges outward by |smoothness|/2, and adjusting
379 // the generator cubic ramp size.
380
381 // smoothness is percentage-based [0..100]
382 const auto smoothness = SkTPin<float>(fSmoothness / 100, 0, 1);
383
384 r0 -= smoothness / 2;
385 len += smoothness;
386
387 gen.crs += smoothness / len;
388 }
389
390 SkASSERT(len > 0);
391 const auto dt = 1 / len;
392 auto t = (0.5f - r0) / len; // sampling bias: mid-unit
393
394 for (size_t i = 0; i < coverage_proc.size(); ++i, t += dt) {
395 coverage_proc(amount * gen(t), i, 1);
396 }
397}
#define SkASSERT(cond)
Definition SkAssert.h:116
Definition gen.py:1

The documentation for this class was generated from the following files: