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

Public Member Functions

 HalfPlaneSlide2 ()
 
void load (SkScalar w, SkScalar h) override
 
void draw (SkCanvas *canvas) override
 
ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi) override
 
bool onClick (Click *click) 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
 

Additional Inherited Members

virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 
- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 360 of file ClipSlide.cpp.

Constructor & Destructor Documentation

◆ HalfPlaneSlide2()

HalfPlaneSlide2::HalfPlaneSlide2 ( )
inline

Definition at line 365 of file ClipSlide.cpp.

365{ fName = "halfplane2"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void HalfPlaneSlide2::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 373 of file ClipSlide.cpp.

373 {
374 SkMatrix mx;
375 {
376 SkRect r = fPath.getBounds();
377 SkPoint src[4];
378 r.toQuad(src);
379 mx.setPolyToPoly(src, fPts, 4);
380 }
381
383 canvas->drawPath(fPath, paint);
384
385 canvas->save();
386 canvas->concat(mx);
387 paint.setColor(0x40FF0000);
388 canvas->drawPath(fPath, paint);
389 canvas->restore();
390
391 // draw the frame
392 paint.setStrokeWidth(10);
393 paint.setColor(SK_ColorGREEN);
395
396 // draw the half-planes
397 SkHalfPlane planes[4];
398 compute_half_planes(mx, 400, 400, planes);
399 for (auto& p : planes) {
400 draw_halfplane(canvas, p, SK_ColorRED);
401 }
402 }
static void draw_halfplane(SkCanvas *canvas, SkPoint p0, SkPoint p1, SkColor c)
Definition: ClipSlide.cpp:275
static void compute_half_planes(const SkMatrix &mx, SkScalar width, SkScalar height, SkHalfPlane planes[4])
Definition: ClipSlide.cpp:348
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
Definition: SkMatrix.cpp:1385
const SkRect & getBounds() const
Definition: SkPath.cpp:430
const Paint & paint
Definition: color_source.cc:38
void toQuad(SkPoint quad[4]) const
Definition: SkRect.cpp:50

◆ load()

void HalfPlaneSlide2::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 367 of file ClipSlide.cpp.

367 {
368 fPath = make_path();
369 SkRect r = fPath.getBounds();
370 r.toQuad(fPts);
371 }
static SkPath make_path()
Definition: ClipSlide.cpp:285

◆ onClick()

bool HalfPlaneSlide2::onClick ( Click )
inlineoverridevirtual

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

Implements ClickHandlerSlide.

Definition at line 417 of file ClipSlide.cpp.

417 {
418 int32_t index;
419 SkAssertResult(click->fMeta.findS32("index", &index));
420 SkASSERT(index >= 0 && index < 4);
421 fPts[index] = click->fCurr;
422 return true;
423 }
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ onFindClickHandler()

Click * HalfPlaneSlide2::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 404 of file ClipSlide.cpp.

404 {
405 SkScalar r = 8;
406 SkRect rect = SkRect::MakeXYWH(x - r, y - r, 2*r, 2*r);
407 for (int i = 0; i < 4; ++i) {
408 if (rect.contains(fPts[i].fX, fPts[i].fY)) {
409 Click* c = new Click;
410 c->fMeta.setS32("index", i);
411 return c;
412 }
413 }
414 return nullptr;
415 }
float SkScalar
Definition: extension.cpp:12
double y
double x
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

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