Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
CubicCurveSlide Class Reference
Inheritance diagram for CubicCurveSlide:
ClickHandlerSlide Slide SkRefCnt SkRefCntBase

Public Member Functions

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

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

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 442 of file PathSlide.cpp.

Constructor & Destructor Documentation

◆ CubicCurveSlide()

CubicCurveSlide::CubicCurveSlide ( )
inline

Definition at line 449 of file PathSlide.cpp.

449 {
450 SkRandom rand;
451 for (int i = 0; i < N; ++i) {
452 fPts[i].fX = 20 + rand.nextUScalar1() * 640;
453 fPts[i].fY = 20 + rand.nextUScalar1() * 480;
454 }
455 fName = "CubicCurve";
456 }
SkScalar nextUScalar1()
Definition SkRandom.h:101
SkString fName
Definition Slide.h:54
float fX
x-axis value
float fY
y-axis value

Member Function Documentation

◆ draw()

void CubicCurveSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 458 of file PathSlide.cpp.

458 {
460 paint.setAntiAlias(true);
461
462 {
463 SkPath path;
464 path.moveTo(fPts[0]);
465 path.cubicTo(fPts[1], fPts[2], fPts[3]);
467 canvas->drawPath(path, paint);
468 }
469
470 {
471 paint.setColor(SK_ColorRED);
472 SkScalar t[2];
473 int n = compute_parallel_to_base(fPts, t);
474 SkPoint loc;
475 SkVector tan;
476 for (int i = 0; i < n; ++i) {
477 SkEvalCubicAt(fPts, t[i], &loc, &tan, nullptr);
478 tan.setLength(30);
479 canvas->drawLine(loc - tan, loc + tan, paint);
480 }
481 paint.setStrokeWidth(0.5f);
482 canvas->drawLine(fPts[0], fPts[3], paint);
483
484 paint.setColor(SK_ColorBLUE);
485 paint.setStrokeWidth(6);
486 SkEvalCubicAt(fPts, 0.5f, &loc, nullptr, nullptr);
487 canvas->drawPoint(loc, paint);
488
489 paint.setColor(0xFF008800);
490 SkEvalCubicAt(fPts, 1.0f/3, &loc, nullptr, nullptr);
491 canvas->drawPoint(loc, paint);
492 SkEvalCubicAt(fPts, 2.0f/3, &loc, nullptr, nullptr);
493 canvas->drawPoint(loc, paint);
494
495 // n = SkFindCubicInflections(fPts, t);
496 // printf("inflections %d %g %g\n", n, t[0], t[1]);
497 }
498
499 {
500 paint.setStyle(SkPaint::kFill_Style);
501 paint.setColor(SK_ColorRED);
502 for (SkPoint p : fPts) {
503 canvas->drawCircle(p.fX, p.fY, 8, paint);
504 }
505 }
506 }
static int compute_parallel_to_base(const SkPoint pts[4], SkScalar t[2])
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void SkEvalCubicAt(const SkPoint src[4], SkScalar t, SkPoint *loc, SkVector *tangent, SkVector *curvature)
void drawPoint(SkScalar x, SkScalar y, const SkPaint &paint)
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
const Paint & paint
float SkScalar
Definition extension.cpp:12
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
bool setLength(float length)
Definition SkPoint.cpp:30

◆ onClick()

bool CubicCurveSlide::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 523 of file PathSlide.cpp.

523{ return false; }

◆ onFindClickHandler()

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

509 {
510 const SkScalar tol = 8;
511 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
512 for (int i = 0; i < N; ++i) {
513 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) {
514 return new Click([this, i](Click* c) {
515 fPts[i] = c->fCurr;
516 return true;
517 });
518 }
519 }
520 return nullptr;
521 }
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: