Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Types | Protected Attributes | List of all members
CubeBaseSlide Class Referenceabstract
Inheritance diagram for CubeBaseSlide:
ThreeDSlide ClickHandlerSlide Slide SkRefCnt SkRefCntBase Bump3DSlide SkottieCubeSlide

Public Member Functions

 CubeBaseSlide (Flags flags)
 
bool onChar (SkUnichar uni) override
 
virtual void drawFace (SkCanvas *, SkColor, int face, bool front, const SkM44 &localToWorld)=0
 
void draw (SkCanvas *canvas) override
 
ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi) override
 
bool onClick (Click *click) override
 
bool animate (double nanos) override
 
- Public Member Functions inherited from ThreeDSlide
void concatCamera (SkCanvas *canvas, const SkRect &area, SkScalar zscale)
 
- Public Member Functions inherited from ClickHandlerSlide
bool onMouse (SkScalar x, SkScalar y, skui::InputState clickState, skui::ModifierKey modifierKeys) final
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
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 Types

enum  Flags { kCanRunOnCPU = 1 << 0 , kShowLightDome = 1 << 1 }
 

Protected Attributes

LightOnSphere fLight = {{200 + DX, 200 + DY}, 800, 12}
 
VSphere fSphere
 
Flags fFlags
 
- Protected Attributes inherited from ThreeDSlide
float fNear = 0.05f
 
float fFar = 4
 
float fAngle = SK_ScalarPI / 12
 
SkV3 fEye { 0, 0, 1.0f/std::tan(fAngle/2) - 1 }
 
SkV3 fCOA { 0, 0, 0 }
 
SkV3 fUp { 0, 1, 0 }
 
- Protected Attributes inherited from Slide
SkString fName
 

Additional Inherited Members

Detailed Description

Definition at line 234 of file 3DSlide.cpp.

Member Enumeration Documentation

◆ Flags

enum CubeBaseSlide::Flags
protected
Enumerator
kCanRunOnCPU 
kShowLightDome 

Definition at line 245 of file 3DSlide.cpp.

245 {
246 kCanRunOnCPU = 1 << 0,
247 kShowLightDome = 1 << 1,
248 };

Constructor & Destructor Documentation

◆ CubeBaseSlide()

CubeBaseSlide::CubeBaseSlide ( Flags  flags)
inline

Definition at line 256 of file 3DSlide.cpp.

257 : fSphere({200 + DX, 200 + DY}, 400)
258 , fFlags(flags)
259 {}
VSphere fSphere
Definition 3DSlide.cpp:252
FlutterSemanticsFlag flags

Member Function Documentation

◆ animate()

bool CubeBaseSlide::animate ( double  nanos)
inlineoverridevirtual

Reimplemented from Slide.

Reimplemented in SkottieCubeSlide.

Definition at line 353 of file 3DSlide.cpp.

353 {
354 return fRotateAnimator.isAnimating();
355 }
bool isAnimating() const
Definition 3DSlide.cpp:231

◆ draw()

void CubeBaseSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 271 of file 3DSlide.cpp.

271 {
272 if (!canvas->recordingContext() && !(fFlags & kCanRunOnCPU)) {
273 return;
274 }
275
276 canvas->save();
277 canvas->translate(DX, DY);
278
279 this->concatCamera(canvas, {0, 0, 400, 400}, 200);
280
281 SkM44 m = fRotateAnimator.rotation() * fRotation;
282 for (bool front : {false, true}) {
283 int index = 0;
284 for (auto f : faces) {
285 SkAutoCanvasRestore acr(canvas, true);
286
287 SkM44 trans = SkM44::Translate(200, 200, 0); // center of the rotation
288
289 canvas->concat(trans);
290
291 // "World" space - content is centered at the origin, in device scale (+-200)
292 SkM44 localToWorld = m * f.asM44(200) * inv(trans);
293
294 canvas->concat(localToWorld);
295 this->drawFace(canvas, f.fColor, index++, front, localToWorld);
296 }
297 }
298
299 canvas->restore(); // camera & center the content in the window
300
301 if (fFlags & kShowLightDome){
302 fLight.draw(canvas);
303
305 paint.setAntiAlias(true);
307 paint.setColor(0x40FF0000);
313 }
314 }
const Face faces[]
Definition 3DSlide.cpp:137
static SkM44 inv(const SkM44 &m)
Definition 3DSlide.cpp:71
virtual void drawFace(SkCanvas *, SkColor, int face, bool front, const SkM44 &localToWorld)=0
LightOnSphere fLight
Definition 3DSlide.cpp:250
SkM44 rotation()
Definition 3DSlide.cpp:197
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
virtual GrRecordingContext * recordingContext() const
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
int save()
Definition SkCanvas.cpp:451
void concat(const SkMatrix &matrix)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition SkM44.h:150
static SkM44 Translate(SkScalar x, SkScalar y, SkScalar z=0)
Definition SkM44.h:225
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
void concatCamera(SkCanvas *canvas, const SkRect &area, SkScalar zscale)
Definition 3DSlide.cpp:96
const Paint & paint
void draw(SkCanvas *canvas) const
Definition 3DSlide.cpp:159
float x
Definition SkM44.h:20
float y
Definition SkM44.h:20
SkScalar fRadius
Definition 3DSlide.cpp:21
SkV2 fCenter
Definition 3DSlide.cpp:20

◆ drawFace()

virtual void CubeBaseSlide::drawFace ( SkCanvas ,
SkColor  ,
int  face,
bool  front,
const SkM44 localToWorld 
)
pure virtual

Implemented in SkottieCubeSlide, and Bump3DSlide.

◆ onChar()

bool CubeBaseSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 261 of file 3DSlide.cpp.

261 {
262 switch (uni) {
263 case 'Z': fLight.fDistance += 10; return true;
264 case 'z': fLight.fDistance -= 10; return true;
265 }
266 return this->ThreeDSlide::onChar(uni);
267 }
virtual bool onChar(SkUnichar c)
Definition Slide.h:44
SkScalar fDistance
Definition 3DSlide.cpp:152

◆ onClick()

bool CubeBaseSlide::onClick ( Click )
inlineoverridevirtual

Override to track clicks. Return true as long as you want to track the pen/mouse.

Implements ClickHandlerSlide.

Definition at line 333 of file 3DSlide.cpp.

333 {
334 if (click->fMeta.hasS32("type", 0)) {
335 fLight.fLoc = fSphere.pinLoc({click->fCurr.fX, click->fCurr.fY});
336 return true;
337 }
338 if (click->fMeta.hasS32("type", 1)) {
339 if (click->fState == skui::InputState::kUp) {
340 fRotation = fRotateAnimator.rotation() * fRotation;
341 fRotateAnimator.start();
342 } else {
343 auto [axis, angle] = fSphere.computeRotationInfo(
344 {click->fOrig.fX, click->fOrig.fY},
345 {click->fCurr.fX, click->fCurr.fY});
346 fRotateAnimator.update(axis, angle);
347 }
348 return true;
349 }
350 return true;
351 }
void update(SkV3 axis, SkScalar angle)
Definition 3DSlide.cpp:185
RotateInfo computeRotationInfo(SkV2 a, SkV2 b) const
Definition 3DSlide.cpp:53
SkV2 pinLoc(SkV2 p) const
Definition 3DSlide.cpp:29

◆ onFindClickHandler()

Click * CubeBaseSlide::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
inlineoverridevirtual

Return a Click object to handle the click. onClick will be called repeatedly with the latest mouse state tracked on the Click object until it returns false.

Implements ClickHandlerSlide.

Definition at line 316 of file 3DSlide.cpp.

316 {
317 SkV2 p = fLight.fLoc - SkV2{x, y};
318 if (p.length() <= fLight.fRadius) {
319 Click* c = new Click();
320 c->fMeta.setS32("type", 0);
321 return c;
322 }
323 if (fSphere.contains({x, y})) {
324 Click* c = new Click();
325 c->fMeta.setS32("type", 1);
326
327 fRotation = fRotateAnimator.rotation() * fRotation;
328 fRotateAnimator.reset();
329 return c;
330 }
331 return nullptr;
332 }
double y
double x
SkScalar fRadius
Definition 3DSlide.cpp:153
Definition SkM44.h:19
bool contains(SkV2 v) const
Definition 3DSlide.cpp:25

Member Data Documentation

◆ fFlags

Flags CubeBaseSlide::fFlags
protected

Definition at line 253 of file 3DSlide.cpp.

◆ fLight

LightOnSphere CubeBaseSlide::fLight = {{200 + DX, 200 + DY}, 800, 12}
protected

Definition at line 250 of file 3DSlide.cpp.

250{{200 + DX, 200 + DY}, 800, 12};

◆ fSphere

VSphere CubeBaseSlide::fSphere
protected

Definition at line 252 of file 3DSlide.cpp.


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