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

Classes

class  Click
 

Public Member Functions

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

Protected Member Functions

ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey) override
 
bool onClick (Click *) override
 
- Protected Member Functions inherited from ClickHandlerSlide
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 440 of file GraphitePrimitivesSlide.cpp.

Constructor & Destructor Documentation

◆ GraphitePrimitivesSlide()

GraphitePrimitivesSlide::GraphitePrimitivesSlide ( )
inline

Definition at line 445 of file GraphitePrimitivesSlide.cpp.

446 : fOrigin{300.f, 300.f}
447 , fXAxisPoint{300.f + kBaseScale, 300.f}
448 , fYAxisPoint{300.f, 300.f + kBaseScale}
449 , fStrokeWidth{10.f}
450 , fJoinMode(SkPaint::kMiter_Join)
451 , fMode(PrimitiveMode::kFillRect) {
452 fName = "GraphitePrimitives";
453 }
@ kMiter_Join
extends to miter limit
Definition: SkPaint.h:359
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void GraphitePrimitivesSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 455 of file GraphitePrimitivesSlide.cpp.

455 {
456 canvas->save();
457 SkM44 viewMatrix = canvas->getLocalToDevice();
458
459 canvas->concat(this->basisMatrix());
460
461 SkM44 totalMatrix = canvas->getLocalToDevice();
462
463 // Base shape + style
464 SkRRect rrect = this->primitiveShape();
465 canvas->drawRRect(rrect, paint(SK_ColorBLUE, this->strokeWidth(), fJoinMode));
466 canvas->restore();
467
468 canvas->save();
469 canvas->resetMatrix();
470 // Draw the full mesh directly in device space
471 this->drawVertices(canvas, totalMatrix);
472 // Draw the controls in device space so we get consistent circles for the click points.
473 SkV4 origin = viewMatrix.map(fOrigin.x, fOrigin.y, 0.f, 1.f);
474 SkV4 xAxis = viewMatrix.map(fXAxisPoint.x, fXAxisPoint.y, 0.f, 1.f);
475 SkV4 yAxis = viewMatrix.map(fYAxisPoint.x, fYAxisPoint.y, 0.f, 1.f);
476
477 // Axes
478 canvas->drawLine({origin.x/origin.w, origin.y/origin.w},
479 {xAxis.x/xAxis.w, xAxis.y/xAxis.w}, paint(SK_ColorRED, 0.f));
480 canvas->drawLine({origin.x/origin.w, origin.y/origin.w},
481 {yAxis.x/yAxis.w, yAxis.y/yAxis.w}, paint(SK_ColorGREEN, 0.f));
482
483 // Control points
484 canvas->drawCircle({origin.x/origin.w, origin.y/origin.w},
485 kControlPointRadius, paint(SK_ColorBLACK));
486 canvas->drawCircle({xAxis.x/xAxis.w, xAxis.y/xAxis.w},
487 kControlPointRadius, paint(SK_ColorRED));
488 canvas->drawCircle({yAxis.x/yAxis.w, yAxis.y/yAxis.w},
489 kControlPointRadius, paint(SK_ColorGREEN));
490 canvas->restore();
491 }
static SkPaint paint(SkColor color, float strokeWidth=-1.f, SkPaint::Join join=SkPaint::kMiter_Join)
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void restore()
Definition: SkCanvas.cpp:461
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
SkM44 getLocalToDevice() const
Definition: SkCanvas.cpp:1633
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
void resetMatrix()
Definition: SkCanvas.cpp:1355
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
Definition: SkM44.h:150
SkV4 map(float x, float y, float z, float w) const
Definition: SkM44.cpp:129
SkRRect rrect
Definition: SkRecords.h:232
float x
Definition: SkM44.h:20
float y
Definition: SkM44.h:20
Definition: SkM44.h:98
float w
Definition: SkM44.h:99
float y
Definition: SkM44.h:99
float x
Definition: SkM44.h:99

◆ onChar()

bool GraphitePrimitivesSlide::onChar ( SkUnichar  code)
overridevirtual

Reimplemented from Slide.

Definition at line 674 of file GraphitePrimitivesSlide.cpp.

674 {
675 switch(code) {
676 case '1':
677 fMode = PrimitiveMode::kFillRect;
678 return true;
679 case '2':
680 fMode = PrimitiveMode::kFillRRect;
681 return true;
682 case '3':
683 fMode = PrimitiveMode::kStrokeRect;
684 return true;
685 case '4':
686 fMode = PrimitiveMode::kStrokeRRect;
687 return true;
688 case '-':
689 fStrokeWidth = std::max(0.f, fStrokeWidth - 0.4f);
690 return true;
691 case '=':
692 fStrokeWidth = std::min(5 * kBaseScale, fStrokeWidth + 0.4f);
693 return true;
694 case 'q':
695 fJoinMode = SkPaint::kRound_Join;
696 return true;
697 case 'w':
698 fJoinMode = SkPaint::kBevel_Join;
699 return true;
700 case 'e':
701 fJoinMode = SkPaint::kMiter_Join;
702 return true;
703 case 'r':
704 fStrokeWidth = 10.f;
705 fOrigin = {300.f, 300.f};
706 fXAxisPoint = {300.f + kBaseScale, 300.f};
707 fYAxisPoint = {300.f, 300.f + kBaseScale};
708 return true;
709 case 'c':
710 fColorize = !fColorize;
711 return true;
712 }
713 return false;
714}
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
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 GraphitePrimitivesSlide::onClick ( Click )
overrideprotected

Definition at line 668 of file GraphitePrimitivesSlide.cpp.

668 {
669 Click* myClick = (Click*) click;
670 myClick->drag();
671 return true;
672}

◆ onFindClickHandler()

ClickHandlerSlide::Click * GraphitePrimitivesSlide::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
overrideprotectedvirtual

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 651 of file GraphitePrimitivesSlide.cpp.

652 {
653 auto selected = [x,y](const SkV2& p) {
654 return ((p - SkV2{x,y}).length() < kControlPointRadius);
655 };
656
657 if (selected(fOrigin)) {
658 return new Click(&fOrigin);
659 } else if (selected(fXAxisPoint)) {
660 return new Click(&fXAxisPoint);
661 } else if (selected(fYAxisPoint)) {
662 return new Click(&fYAxisPoint);
663 } else {
664 return nullptr;
665 }
666}
size_t length
double y
double x
Definition: SkM44.h:19

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