Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Attributes | List of all members
PathTextSlide Class Reference
Inheritance diagram for PathTextSlide:
Slide SkRefCnt SkRefCntBase

Classes

struct  Glyph
 
class  GlyphAnimator
 
class  MovingGlyphAnimator
 
class  WavyGlyphAnimator
 

Public Member Functions

 PathTextSlide ()
 
virtual void reset ()
 
void load (SkScalar w, SkScalar h) final
 
void resize (SkScalar w, SkScalar h) final
 
bool onChar (SkUnichar) override
 
bool animate (double nanos) final
 
void draw (SkCanvas *canvas) override
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Attributes

Glyph fGlyphs [kNumPaths]
 
SkRandom fRand {25}
 
SkPath fClipPath = ToolUtils::make_star(SkRect{0, 0, 1, 1}, 11, 3)
 
bool fDoClip = false
 
std::unique_ptr< GlyphAnimatorfGlyphAnimator = std::make_unique<GlyphAnimator>(fGlyphs)
 
- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 25 of file PathTextSlide.cpp.

Constructor & Destructor Documentation

◆ PathTextSlide()

PathTextSlide::PathTextSlide ( )
inline

Definition at line 30 of file PathTextSlide.cpp.

30{ fName = "PathText"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ animate()

bool PathTextSlide::animate ( double  nanos)
inlinefinalvirtual

Reimplemented from Slide.

Definition at line 70 of file PathTextSlide.cpp.

70 {
71 return fGlyphAnimator->animate(nanos, fSize.width(), fSize.height());
72 }
std::unique_ptr< GlyphAnimator > fGlyphAnimator
SkScalar width() const
Definition: SkSize.h:76
SkScalar height() const
Definition: SkSize.h:77

◆ draw()

void PathTextSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 74 of file PathTextSlide.cpp.

74 {
75 if (fDoClip) {
76 SkPath deviceSpaceClipPath = fClipPath;
77 deviceSpaceClipPath.transform(SkMatrix::Scale(fSize.width(), fSize.height()));
78 canvas->save();
79 canvas->clipPath(deviceSpaceClipPath, SkClipOp::kDifference, true);
80 canvas->clear(SK_ColorBLACK);
81 canvas->restore();
82 canvas->clipPath(deviceSpaceClipPath, SkClipOp::kIntersect, true);
83 }
84 fGlyphAnimator->draw(canvas);
85 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void restore()
Definition: SkCanvas.cpp:461
void clear(SkColor color)
Definition: SkCanvas.h:1199
void clipPath(const SkPath &path, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1456
int save()
Definition: SkCanvas.cpp:447
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
Definition: SkPath.h:59
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.cpp:1711

◆ load()

void PathTextSlide::load ( SkScalar  w,
SkScalar  h 
)
inlinefinalvirtual

Reimplemented from Slide.

Definition at line 39 of file PathTextSlide.cpp.

39 {
40 fSize = {w, h};
41
42 SkFont defaultFont = ToolUtils::DefaultFont();
43 SkStrikeSpec strikeSpec = SkStrikeSpec::MakeWithNoDevice(defaultFont);
44 SkBulkGlyphMetricsAndPaths pathMaker{strikeSpec};
45 SkPath glyphPaths[52];
46 for (int i = 0; i < 52; ++i) {
47 // I and l are rects on OS X ...
48 char c = "aQCDEFGH7JKLMNOPBRZTUVWXYSAbcdefghijk1mnopqrstuvwxyz"[i];
49 SkGlyphID id(defaultFont.unicharToGlyph(c));
50 const SkGlyph* glyph = pathMaker.glyph(id);
51 if (glyph->path()) {
52 glyphPaths[i] = *glyph->path();
53 }
54 }
55
56 for (int i = 0; i < kNumPaths; ++i) {
57 const SkPath& p = glyphPaths[i % 52];
58 fGlyphs[i].init(fRand, p);
59 }
60 this->reset();
61 }
uint16_t SkGlyphID
Definition: SkTypes.h:179
Glyph fGlyphs[kNumPaths]
virtual void reset()
Definition: SkFont.h:35
SkGlyphID unicharToGlyph(SkUnichar uni) const
Definition: SkFont.cpp:173
const SkPath * path() const
Definition: SkGlyph.cpp:284
static SkStrikeSpec MakeWithNoDevice(const SkFont &font, const SkPaint *paint=nullptr)
SkFont DefaultFont()
SkScalar w
SkScalar h
void init(SkRandom &rand, const SkPath &path)
const uintptr_t id

◆ onChar()

bool PathTextSlide::onChar ( SkUnichar  unichar)
overridevirtual

Reimplemented from Slide.

Definition at line 435 of file PathTextSlide.cpp.

435 {
436 switch (unichar) {
437 case 'X':
438 fDoClip = !fDoClip;
439 return true;
440 case 'S':
441 fGlyphAnimator = std::make_unique<GlyphAnimator>(fGlyphs);
442 fGlyphAnimator->reset(&fRand, fSize.width(), fSize.height());
443 return true;
444 case 'M':
445 fGlyphAnimator = std::make_unique<MovingGlyphAnimator>(fGlyphs);
446 fGlyphAnimator->reset(&fRand, fSize.width(), fSize.height());
447 return true;
448 case 'W':
449 fGlyphAnimator = std::make_unique<WavyGlyphAnimator>(fGlyphs);
450 fGlyphAnimator->reset(&fRand, fSize.width(), fSize.height());
451 return true;
452 }
453 return false;
454}

◆ reset()

virtual void PathTextSlide::reset ( )
inlinevirtual

Definition at line 32 of file PathTextSlide.cpp.

32 {
33 for (Glyph& glyph : fGlyphs) {
34 glyph.reset(fRand, fSize.width(), fSize.height());
35 }
36 fGlyphAnimator->reset(&fRand, fSize.width(), fSize.height());
37 }

◆ resize()

void PathTextSlide::resize ( SkScalar  w,
SkScalar  h 
)
inlinefinalvirtual

Reimplemented from Slide.

Definition at line 63 of file PathTextSlide.cpp.

63 {
64 fSize = {w, h};
65 this->reset();
66 }

Member Data Documentation

◆ fClipPath

SkPath PathTextSlide::fClipPath = ToolUtils::make_star(SkRect{0, 0, 1, 1}, 11, 3)
protected

Definition at line 127 of file PathTextSlide.cpp.

◆ fDoClip

bool PathTextSlide::fDoClip = false
protected

Definition at line 128 of file PathTextSlide.cpp.

◆ fGlyphAnimator

std::unique_ptr<GlyphAnimator> PathTextSlide::fGlyphAnimator = std::make_unique<GlyphAnimator>(fGlyphs)
protected

Definition at line 129 of file PathTextSlide.cpp.

◆ fGlyphs

Glyph PathTextSlide::fGlyphs[kNumPaths]
protected

Definition at line 125 of file PathTextSlide.cpp.

◆ fRand

SkRandom PathTextSlide::fRand {25}
protected

Definition at line 126 of file PathTextSlide.cpp.


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