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

Public Member Functions

 AnimatedRects ()
 
- 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 Member Functions

void load (SkScalar, SkScalar) override
 
void draw (SkCanvas *canvas) override
 
bool animate (double nanos) override
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 24 of file AnimatedRectsSlide.cpp.

Constructor & Destructor Documentation

◆ AnimatedRects()

AnimatedRects::AnimatedRects ( )
inline

Definition at line 26 of file AnimatedRectsSlide.cpp.

26 {
27 fName = "animated-rects";
28 }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ animate()

bool AnimatedRects::animate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from Slide.

Definition at line 59 of file AnimatedRectsSlide.cpp.

59 {
60 float seconds = 1e-9 * nanos;
61 if (0.0f != fLastTime) {
62 float scale = (seconds - fLastTime) * 60;
63
64 for (int i = 0; i < kNumRects; ++i) {
65 AnimatedRect& r = fRect[i];
66 r.x -= r.speed * scale;
67 if (r.x + r.size < 0) {
68 r.x = kWidth + r.size;
69 }
70 }
71 }
72
73 fLastTime = seconds;
74 return true;
75 }
static constexpr int kNumRects
const Scalar scale

◆ draw()

void AnimatedRects::draw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Implements Slide.

Definition at line 48 of file AnimatedRectsSlide.cpp.

48 {
49 SkAutoCanvasRestore acr(canvas, /*doSave=*/true);
50 canvas->clipRect({0, 0, (float)kWidth, (float)kHeight});
51
52 for (int i = 0; i < kNumRects; ++i) {
53 const AnimatedRect& r = fRect[i];
54 canvas->drawRect(SkRect{r.x, r.y, r.x + r.size, r.y + r.size}, fStrokePaint);
55 canvas->drawRect(SkRect{r.x, r.y, r.x + r.size, r.y + r.size}, fFillPaint);
56 }
57 }
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
constexpr float x() const
Definition: SkRect.h:720

◆ load()

void AnimatedRects::load ( SkScalar  ,
SkScalar   
)
inlineoverrideprotectedvirtual

Reimplemented from Slide.

Definition at line 31 of file AnimatedRectsSlide.cpp.

31 {
32 for (int i = 0; i < kNumRects; ++i) {
33 fRect[i].x = fRand.nextF() * kWidth;
34 fRect[i].y = fRand.nextF() * kHeight;
35 fRect[i].size = 10.0 + fRand.nextF() * 40.0;
36 fRect[i].speed = 1.0 + fRand.nextF();
37 }
38
39 fStrokePaint.setAntiAlias(true);
40 fStrokePaint.setColor(SK_ColorBLACK);
41 fStrokePaint.setStyle(SkPaint::kStroke_Style);
42 fStrokePaint.setStrokeWidth(2.0);
43 fFillPaint.setAntiAlias(true);
45 fFillPaint.setColor(SK_ColorWHITE);
46 }
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
float nextF()
Definition: SkRandom.h:55

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