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

Public Member Functions

 CubicCurve2Slide ()
 
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
 

Static Public Member Functions

static void Dot (SkCanvas *canvas, SkPoint p, SkScalar radius, SkColor c)
 

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 546 of file PathSlide.cpp.

Constructor & Destructor Documentation

◆ CubicCurve2Slide()

CubicCurve2Slide::CubicCurve2Slide ( )
inline

Definition at line 559 of file PathSlide.cpp.

559 {
560 fPts[0] = { 90, 300 };
561 fPts[1] = { 30, 60 };
562 fPts[2] = { 250, 30 };
563 fPts[3] = { 350, 200 };
564
565 fQuad[0] = fPts[0] + SkVector{ 300, 0};
566 fQuad[1] = fPts[1] + SkVector{ 300, 0};
567 fQuad[2] = fPts[2] + SkVector{ 300, 0};
568
569 fName = "CubicCurve2";
570 }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ Dot()

static void CubicCurve2Slide::Dot ( SkCanvas canvas,
SkPoint  p,
SkScalar  radius,
SkColor  c 
)
inlinestatic

Definition at line 585 of file PathSlide.cpp.

585 {
587 paint.setAntiAlias(true);
588 paint.setColor(c);
589 canvas->drawCircle(p.fX, p.fY, radius, paint);
590 }
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
const Paint & paint
Definition: color_source.cc:38

◆ draw()

void CubicCurve2Slide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 592 of file PathSlide.cpp.

592 {
594 paint.setAntiAlias(true);
595
596 {
598 SkPath path;
599 path.moveTo(fPts[0]);
600 path.cubicTo(fPts[1], fPts[2], fPts[3]);
601 path.moveTo(fQuad[0]);
602 path.quadTo(fQuad[1], fQuad[2]);
603 canvas->drawPath(path, paint);
604 }
605
606 if (fShowSub) {
607 paint.setColor(SK_ColorRED);
608 paint.setStrokeWidth(1.7f);
609 this->showFrame(canvas, fPts, 3, paint);
610 this->showFrame(canvas, fQuad, 2, paint);
611
612 paint.setColor(SK_ColorBLACK);
613 paint.setStyle(SkPaint::kFill_Style);
615 canvas->drawString(SkStringPrintf("t = %g", fT), 20, 20, font, paint);
616 }
617
618 if (fShowFlatness) {
619 this->showFlattness(canvas);
620 }
621
622 if (fShowInnerQuads) {
623 this->showInnerQuads(canvas);
624 }
625
626 paint.setColor(SK_ColorGRAY);
627 paint.setStroke(true);
628 canvas->drawPath(SkPathBuilder().addPolygon(fPts, 4, false).detach(), paint);
629 canvas->drawPath(SkPathBuilder().addPolygon(fQuad, 3, false).detach(), paint);
630
631 for (SkPoint p : fPts) {
632 Dot(canvas, p, 7, SK_ColorBLACK);
633 }
634
635 if ((false)) {
636 SkScalar ts[2];
637 int n = SkFindCubicInflections(fPts, ts);
638 for (int i = 0; i < n; ++i) {
639 SkPoint p;
640 SkEvalCubicAt(fPts, ts[i], &p, nullptr, nullptr);
641 canvas->drawCircle(p.fX, p.fY, 3, paint);
642 }
643 }
644
645 }
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void SkEvalCubicAt(const SkPoint src[4], SkScalar t, SkPoint *loc, SkVector *tangent, SkVector *curvature)
Definition: SkGeometry.cpp:418
int SkFindCubicInflections(const SkPoint src[4], SkScalar tValues[2])
Definition: SkGeometry.cpp:741
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static void Dot(SkCanvas *canvas, SkPoint p, SkScalar radius, SkColor c)
Definition: PathSlide.cpp:585
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
Definition: SkPath.h:59
float SkScalar
Definition: extension.cpp:12
sk_sp< SkTypeface > DefaultTypeface()
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
font
Font Metadata and Metrics.

◆ onChar()

bool CubicCurve2Slide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 572 of file PathSlide.cpp.

572 {
573 switch (uni) {
574 case 's': fShowSub = !fShowSub; break;
575 case 'f': fShowFlatness = !fShowFlatness; break;
576 case '-': fT -= 1.0f / 32; break;
577 case '=': fT += 1.0f / 32; break;
578 case 'q': fShowInnerQuads = !fShowInnerQuads; break;
579 default: return false;
580 }
581 fT = std::min(1.0f, std::max(0.0f, fT));
582 return true;
583 }
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ onClick()

bool CubicCurve2Slide::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 662 of file PathSlide.cpp.

662{ return false; }

◆ onFindClickHandler()

Click * CubicCurve2Slide::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 648 of file PathSlide.cpp.

648 {
649 const SkScalar tol = 8;
650 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
651 for (int i = 0; i < N; ++i) {
652 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) {
653 return new Click([this, i](Click* c) {
654 fPts[i] = c->fCurr;
655 return true;
656 });
657 }
658 }
659 return nullptr;
660 }
double y
double x
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

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