Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Attributes | List of all members
PathTextSlide::MovingGlyphAnimator Class Reference
Inheritance diagram for PathTextSlide::MovingGlyphAnimator:
PathTextSlide::GlyphAnimator PathTextSlide::WavyGlyphAnimator

Classes

struct  Velocity
 

Public Member Functions

 MovingGlyphAnimator (Glyph *glyphs)
 
 ~MovingGlyphAnimator () override
 
void reset (SkRandom *rand, int screenWidth, int screenHeight) override
 
bool animate (double nanos, int screenWidth, int screenHeight) final
 
virtual void runAnimationTask (double t, double dt, int w, int h)
 
virtual void swapAnimationBuffers ()
 
void draw (SkCanvas *canvas) override
 
- Public Member Functions inherited from PathTextSlide::GlyphAnimator
 GlyphAnimator (Glyph *glyphs)
 
virtual void reset (SkRandom *, int screenWidth, int screenHeight)
 
virtual bool animate (double nanos, int screenWidth, int screenHeight)
 
virtual void draw (SkCanvas *canvas)
 
virtual ~GlyphAnimator ()
 

Protected Attributes

Velocity fVelocities [kNumPaths]
 
std::unique_ptr< SkMatrix[]> fFrontMatrices
 
std::unique_ptr< SkMatrix[]> fBackMatrices
 
SkTaskGroup fBackgroundAnimationTask
 
double fLastTick
 
- Protected Attributes inherited from PathTextSlide::GlyphAnimator
Glyph *const fGlyphs
 

Detailed Description

Definition at line 153 of file PathTextSlide.cpp.

Constructor & Destructor Documentation

◆ MovingGlyphAnimator()

PathTextSlide::MovingGlyphAnimator::MovingGlyphAnimator ( Glyph glyphs)
inline

Definition at line 155 of file PathTextSlide.cpp.

157 , fFrontMatrices(new SkMatrix[kNumPaths])
158 , fBackMatrices(new SkMatrix[kNumPaths]) {
159 }
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
std::unique_ptr< SkMatrix[]> fFrontMatrices
std::unique_ptr< SkMatrix[]> fBackMatrices

◆ ~MovingGlyphAnimator()

PathTextSlide::MovingGlyphAnimator::~MovingGlyphAnimator ( )
inlineoverride

Definition at line 161 of file PathTextSlide.cpp.

Member Function Documentation

◆ animate()

bool PathTextSlide::MovingGlyphAnimator::animate ( double  nanos,
int  screenWidth,
int  screenHeight 
)
inlinefinalvirtual

Reimplemented from PathTextSlide::GlyphAnimator.

Definition at line 185 of file PathTextSlide.cpp.

185 {
187 this->swapAnimationBuffers();
188
189 const double tsec = 1e-9 * nanos;
190 const double dt = fLastTick ? (1e-9 * nanos - fLastTick) : 0;
192 dt, screenWidth, screenHeight));
193 fLastTick = 1e-9 * nanos;
194 return true;
195 }
virtual void runAnimationTask(double t, double dt, int w, int h)
void add(std::function< void(void)> fn)
Definition: SkTaskGroup.cpp:16

◆ draw()

void PathTextSlide::MovingGlyphAnimator::draw ( SkCanvas canvas)
inlineoverridevirtual

Reimplemented from PathTextSlide::GlyphAnimator.

Reimplemented in PathTextSlide::WavyGlyphAnimator.

Definition at line 237 of file PathTextSlide.cpp.

237 {
238 for (int i = 0; i < kNumPaths; ++i) {
239 SkAutoCanvasRestore acr(canvas, true);
240 canvas->concat(fFrontMatrices[i]);
241 canvas->drawPath(fGlyphs[i].fPath, fGlyphs[i].fPaint);
242 }
243 }
SkPath fPath
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318

◆ reset()

void PathTextSlide::MovingGlyphAnimator::reset ( SkRandom rand,
int  screenWidth,
int  screenHeight 
)
inlineoverridevirtual

Reimplemented from PathTextSlide::GlyphAnimator.

Reimplemented in PathTextSlide::WavyGlyphAnimator.

Definition at line 165 of file PathTextSlide.cpp.

165 {
166 const SkScalar screensize = static_cast<SkScalar>(std::max(screenWidth, screenHeight));
167
168 for (auto& v : fVelocities) {
169 for (SkScalar* d : {&v.fDx, &v.fDy}) {
170 SkScalar t = pow(rand->nextF(), 3);
171 *d = ((1 - t) / 60 + t / 10) * (rand->nextBool() ? screensize : -screensize);
172 }
173
174 SkScalar t = pow(rand->nextF(), 25);
175 v.fDSpin = ((1 - t) * 360 / 7.5 + t * 360 / 1.5) * (rand->nextBool() ? 1 : -1);
176 }
177
178 // Get valid front data.
180 this->runAnimationTask(0, 0, screenWidth, screenHeight);
181 std::copy_n(fBackMatrices.get(), kNumPaths, fFrontMatrices.get());
182 fLastTick = 0;
183 }
float nextF()
Definition: SkRandom.h:55
bool nextBool()
Definition: SkRandom.h:117
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
float SkScalar
Definition: extension.cpp:12
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ runAnimationTask()

virtual void PathTextSlide::MovingGlyphAnimator::runAnimationTask ( double  t,
double  dt,
int  w,
int  h 
)
inlinevirtual

Called on a background thread. Here we can only modify fBackMatrices.

Reimplemented in PathTextSlide::WavyGlyphAnimator.

Definition at line 200 of file PathTextSlide.cpp.

200 {
201 for (int idx = 0; idx < kNumPaths; ++idx) {
202 Velocity* v = &fVelocities[idx];
203 Glyph* glyph = &fGlyphs[idx];
204 SkMatrix* backMatrix = &fBackMatrices[idx];
205
206 glyph->fPosition.fX += v->fDx * dt;
207 if (glyph->fPosition.x() < 0) {
208 glyph->fPosition.fX -= 2 * glyph->fPosition.x();
209 v->fDx = -v->fDx;
210 } else if (glyph->fPosition.x() > w) {
211 glyph->fPosition.fX -= 2 * (glyph->fPosition.x() - w);
212 v->fDx = -v->fDx;
213 }
214
215 glyph->fPosition.fY += v->fDy * dt;
216 if (glyph->fPosition.y() < 0) {
217 glyph->fPosition.fY -= 2 * glyph->fPosition.y();
218 v->fDy = -v->fDy;
219 } else if (glyph->fPosition.y() > h) {
220 glyph->fPosition.fY -= 2 * (glyph->fPosition.y() - h);
221 v->fDy = -v->fDy;
222 }
223
224 glyph->fSpin += v->fDSpin * dt;
225
226 backMatrix->setTranslate(glyph->fPosition.x(), glyph->fPosition.y());
227 backMatrix->preScale(glyph->fZoom, glyph->fZoom);
228 backMatrix->preRotate(glyph->fSpin);
229 backMatrix->preTranslate(-glyph->fMidpt.x(), -glyph->fMidpt.y());
230 }
231 }
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:254
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:263
SkMatrix & preRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:462
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:315
SkScalar w
SkScalar h

◆ swapAnimationBuffers()

virtual void PathTextSlide::MovingGlyphAnimator::swapAnimationBuffers ( )
inlinevirtual

Reimplemented in PathTextSlide::WavyGlyphAnimator.

Definition at line 233 of file PathTextSlide.cpp.

233 {
235 }
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341

Member Data Documentation

◆ fBackgroundAnimationTask

SkTaskGroup PathTextSlide::MovingGlyphAnimator::fBackgroundAnimationTask
protected

Definition at line 254 of file PathTextSlide.cpp.

◆ fBackMatrices

std::unique_ptr<SkMatrix[]> PathTextSlide::MovingGlyphAnimator::fBackMatrices
protected

Definition at line 253 of file PathTextSlide.cpp.

◆ fFrontMatrices

std::unique_ptr<SkMatrix[]> PathTextSlide::MovingGlyphAnimator::fFrontMatrices
protected

Definition at line 252 of file PathTextSlide.cpp.

◆ fLastTick

double PathTextSlide::MovingGlyphAnimator::fLastTick
protected

Definition at line 255 of file PathTextSlide.cpp.

◆ fVelocities

Velocity PathTextSlide::MovingGlyphAnimator::fVelocities[kNumPaths]
protected

Definition at line 251 of file PathTextSlide.cpp.


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