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

Public Member Functions

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

Public Attributes

SkPoint fPts [kN]
 

Protected Member Functions

ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi) override
 
bool onClick (ClickHandlerSlide::Click *) override
 
virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 353 of file SimpleStrokerSlide.cpp.

Constructor & Destructor Documentation

◆ SimpleStrokerSlide()

SimpleStrokerSlide::SimpleStrokerSlide ( )
inline

Definition at line 363 of file SimpleStrokerSlide.cpp.

363 : fShowSkiaStroke(true), fShowHidden(true), fShowSkeleton(true) {
364 fPts[0] = {500, 200};
365 fPts[1] = {300, 200};
366 fPts[2] = {100, 100};
367
368 fPtsPaint.setAntiAlias(true);
369 fPtsPaint.setStrokeWidth(10);
371
372 fStrokePaint.setAntiAlias(true);
373 fStrokePaint.setStyle(SkPaint::kStroke_Style);
374 fStrokePaint.setColor(0x80FF0000);
375
376 fMirrorStrokePaint.setAntiAlias(true);
377 fMirrorStrokePaint.setStyle(SkPaint::kStroke_Style);
378 fMirrorStrokePaint.setColor(0x80FFFF00);
379
380 fNewFillPaint.setAntiAlias(true);
381 fNewFillPaint.setColor(0x8000FF00);
382
383 fHiddenPaint.setAntiAlias(true);
384 fHiddenPaint.setStyle(SkPaint::kStroke_Style);
385 fHiddenPaint.setColor(0xFF0000FF);
386
387 fSkeletonPaint.setAntiAlias(true);
388 fSkeletonPaint.setStyle(SkPaint::kStroke_Style);
389 fSkeletonPaint.setColor(SK_ColorRED);
390 fName = "SimpleStroker";
391 }
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setStrokeCap(Cap cap)
Definition: SkPaint.cpp:179
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void SimpleStrokerSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 416 of file SimpleStrokerSlide.cpp.

416 {
417 canvas->drawColor(0xFFEEEEEE);
418
419 SkPath path;
420 this->makePath(&path);
421
422 fStrokePaint.setStrokeWidth(fWidth);
423
424 // The correct result
425 if (fShowSkiaStroke) {
426 canvas->drawPath(path, fStrokePaint);
427 }
428
429 // Simple stroker result
430 SkPathStroker2 stroker;
431 SkPath fillPath = stroker.getFillPath(path, fStrokePaint);
432 canvas->drawPath(fillPath, fNewFillPaint);
433
434 if (fShowHidden) {
435 canvas->drawPath(fillPath, fHiddenPaint);
436 }
437 if (fShowSkeleton) {
438 canvas->drawPath(path, fSkeletonPaint);
439 }
440 canvas->drawPoints(SkCanvas::kPoints_PointMode, kN, fPts, fPtsPaint);
441
442 // Draw a mirror but using Skia's stroker.
443 canvas->translate(0, 400);
444 fMirrorStrokePaint.setStrokeWidth(fWidth);
445 canvas->drawPath(path, fMirrorStrokePaint);
446 if (fShowHidden) {
447 SkPath hidden;
448 skpathutils::FillPathWithPaint(path, fStrokePaint, &hidden);
449 canvas->drawPath(hidden, fHiddenPaint);
450 }
451 if (fShowSkeleton) {
452 canvas->drawPath(path, fSkeletonPaint);
453 }
454 }
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
Definition: SkPath.h:59
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23

◆ onChar()

bool SimpleStrokerSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 393 of file SimpleStrokerSlide.cpp.

393 {
394 switch (uni) {
395 case '1':
396 this->toggle(fShowSkeleton);
397 return true;
398 case '2':
399 this->toggle(fShowSkiaStroke);
400 return true;
401 case '3':
402 this->toggle(fShowHidden);
403 return true;
404 case '-':
405 fWidth -= 5;
406 return true;
407 case '=':
408 fWidth += 5;
409 return true;
410 default:
411 break;
412 }
413 return false;
414 }

◆ onClick()

bool SimpleStrokerSlide::onClick ( ClickHandlerSlide::Click )
inlineoverrideprotectedvirtual

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

Implements ClickHandlerSlide.

Definition at line 471 of file SimpleStrokerSlide.cpp.

471{ return false; }

◆ onFindClickHandler()

Click * SimpleStrokerSlide::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
inlineoverrideprotectedvirtual

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 457 of file SimpleStrokerSlide.cpp.

457 {
458 const SkScalar tol = 4;
459 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
460 for (int i = 0; i < kN; ++i) {
461 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) {
462 return new Click([this, i](Click* c) {
463 fPts[i] = c->fCurr;
464 return true;
465 });
466 }
467 }
468 return nullptr;
469 }
float SkScalar
Definition: extension.cpp:12
double y
double x
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
bool intersects(const SkRect &r) const
Definition: SkRect.h:1121

Member Data Documentation

◆ fPts

SkPoint SimpleStrokerSlide::fPts[kN]

Definition at line 361 of file SimpleStrokerSlide.cpp.


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