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

Public Member Functions

 DrawShipSlide (const char name[], DrawAtlasProc proc)
 
- 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 unload () 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 50 of file ShipSlide.cpp.

Constructor & Destructor Documentation

◆ DrawShipSlide()

DrawShipSlide::DrawShipSlide ( const char  name[],
DrawAtlasProc  proc 
)
inline

Definition at line 52 of file ShipSlide.cpp.

52 : fProc(proc) {
53 fName = name;
54 }
SkString fName
Definition: Slide.h:54
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

Member Function Documentation

◆ animate()

bool DrawShipSlide::animate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from Slide.

Definition at line 129 of file ShipSlide.cpp.

129 {
130 //TODO: use nanos
131 //SkScalar angle = SkDoubleToScalar(fmod(1e-9 * nanos * 360 / 24, 360));
132 //fAnimatingDrawable->setSweep(angle);
133 return true;
134 }

◆ draw()

void DrawShipSlide::draw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Implements Slide.

Definition at line 96 of file ShipSlide.cpp.

96 {
97 const float kCosDiff = 0.99984769515f;
98 const float kSinDiff = 0.01745240643f;
99
100 if (!fAtlas) {
101 return;
102 }
103
105 paint.setColor(SK_ColorWHITE);
106
107 SkScalar anchorX = fAtlas->width()*0.5f;
108 SkScalar anchorY = fAtlas->height()*0.5f;
109 for (int i = 0; i < kGrid*kGrid+1; ++i) {
110 SkScalar c = fXform[i].fSCos;
111 SkScalar s = fXform[i].fSSin;
112
113 SkScalar dx = c*anchorX - s*anchorY;
114 SkScalar dy = s*anchorX + c*anchorY;
115
116 fXform[i].fSCos = kCosDiff*c - kSinDiff*s;
117 fXform[i].fSSin = kSinDiff*c + kCosDiff*s;
118
119 dx -= fXform[i].fSCos*anchorX - fXform[i].fSSin*anchorY;
120 dy -= fXform[i].fSSin*anchorX + fXform[i].fSCos*anchorY;
121 fXform[i].fTx += dx;
122 fXform[i].fTy += dy;
123 }
124
125 fProc(canvas, fAtlas.get(), fXform, fTex, nullptr, kGrid*kGrid+1, nullptr,
127 }
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
struct MyStruct s
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
SkScalar fTy
Definition: SkRSXform.h:45
SkScalar fSCos
Definition: SkRSXform.h:42
SkScalar fTx
Definition: SkRSXform.h:44
SkScalar fSSin
Definition: SkRSXform.h:43

◆ load()

void DrawShipSlide::load ( SkScalar  ,
SkScalar   
)
inlineoverrideprotectedvirtual

Reimplemented from Slide.

Definition at line 57 of file ShipSlide.cpp.

57 {
58 fAtlas = ToolUtils::GetResourceAsImage("images/ship.png");
59 if (!fAtlas) {
60 SkDebugf("\nCould not decode file ship.png. Falling back to penguin mode.\n");
61 fAtlas = ToolUtils::GetResourceAsImage("images/baby_tux.png");
62 if (!fAtlas) {
63 SkDebugf("\nCould not decode file baby_tux.png. Did you forget"
64 " to set the resourcePath?\n");
65 return;
66 }
67 }
68
69 SkScalar anchorX = fAtlas->width()*0.5f;
70 SkScalar anchorY = fAtlas->height()*0.5f;
71 int currIndex = 0;
72 for (int x = 0; x < kGrid; x++) {
73 for (int y = 0; y < kGrid; y++) {
74 float xPos = (x / (kGrid - 1.0f)) * kWidth;
75 float yPos = (y / (kGrid - 1.0f)) * kWidth;
76
77 fTex[currIndex] = SkRect::MakeLTRB(0.0f, 0.0f,
78 SkIntToScalar(fAtlas->width()),
79 SkIntToScalar(fAtlas->height()));
80 fXform[currIndex] = SkRSXform::MakeFromRadians(0.1f, SK_ScalarPI*0.5f,
81 xPos, yPos, anchorX, anchorY);
82 currIndex++;
83 }
84 }
85 fTex[currIndex] = SkRect::MakeLTRB(0.0f, 0.0f,
86 SkIntToScalar(fAtlas->width()),
87 SkIntToScalar(fAtlas->height()));
88 fXform[currIndex] = SkRSXform::MakeFromRadians(0.5f, SK_ScalarPI*0.5f,
89 kWidth*0.5f, kHeight*0.5f, anchorX, anchorY);
90 }
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SK_ScalarPI
Definition: SkScalar.h:21
double y
double x
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
static SkRSXform MakeFromRadians(SkScalar scale, SkScalar radians, SkScalar tx, SkScalar ty, SkScalar ax, SkScalar ay)
Definition: SkRSXform.h:35
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ unload()

void DrawShipSlide::unload ( )
inlineoverrideprotectedvirtual

Reimplemented from Slide.

Definition at line 92 of file ShipSlide.cpp.

92 {
93 fAtlas = nullptr;
94 }

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