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

Public Member Functions

 AnimatedTextSlide ()
 
bool onChar (SkUnichar uni) override
 
void draw (SkCanvas *canvas) override
 
bool animate (double nanos) 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
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 45 of file AnimatedTextSlide.cpp.

Constructor & Destructor Documentation

◆ AnimatedTextSlide()

AnimatedTextSlide::AnimatedTextSlide ( )
inline

Definition at line 52 of file AnimatedTextSlide.cpp.

52{ fName = "AnimatedText"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ animate()

bool AnimatedTextSlide::animate ( double  nanos)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 103 of file AnimatedTextSlide.cpp.

103 {
104 // TODO: use nanos
105 // We add noise to the scale and rotation animations to
106 // keep the font atlas from falling into a steady state
107 fRotation += (1.0f + gRand.nextRangeF(-0.1f, 0.1f));
108 fScale += (fScaleInc + gRand.nextRangeF(-0.025f, 0.025f));
109 if (fScale >= 2.0f) {
110 fScaleInc = -0.1f;
111 } else if (fScale <= 1.0f) {
112 fScaleInc = 0.1f;
113 }
114 return true;
115 }
SkRandom gRand
float nextRangeF(float min, float max)
Definition: SkRandom.h:64

◆ draw()

void AnimatedTextSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 66 of file AnimatedTextSlide.cpp.

66 {
67 SkFont font(ToolUtils::TestFontMgr()->makeFromFile("/skimages/samplefont.ttf"));
68
70 paint.setAntiAlias(true);
71
72 canvas->save();
73
74#if defined(SK_GANESH)
75 auto direct = GrAsDirectContext(canvas->recordingContext());
76 if (direct) {
78 sk_sp<SkImage> image = direct->priv().testingOnly_getFontAtlasImage(MaskFormat::kA8);
79 const SkRect rect = SkRect::MakeXYWH(512.0f, 10.0f, 512.0f, 512.0f);
82 }
83#endif
84 canvas->translate(180, 180);
85 canvas->rotate(fRotation);
86 canvas->scale(fScale, fScale);
87 canvas->translate(-180, -180);
88
89 const char* text = "Hamburgefons";
90 size_t length = strlen(text);
91
93 for (int i = 12; i <= 26; i++) {
94 font.setSize(SkIntToScalar(i*fSizeScale));
95 y += font.getSpacing();
96 DrawTheText(canvas, text, length, SkIntToScalar(110), y, font, paint);
97 }
98 canvas->restore();
99
100 font.setSize(16);
101 }
static void DrawTheText(SkCanvas *canvas, const char text[], size_t length, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
Definition: SkFont.h:35
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
size_t length
std::u16string text
double y
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SkSamplingOptions sampling
Definition: SkRecords.h:337
sk_sp< SkFontMgr > TestFontMgr()
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ onChar()

bool AnimatedTextSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 54 of file AnimatedTextSlide.cpp.

54 {
55 if ('2' == uni) {
56 if (fSizeScale == 2) {
57 fSizeScale = 1;
58 } else {
59 fSizeScale = 2;
60 }
61 return true;
62 }
63 return false;
64 }

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