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

Classes

class  DoNothingClick
 
class  DragPolyClick
 
class  DragRectClick
 
class  MyClick
 
class  VertClick
 

Public Member Functions

 EdgeClipSlide ()
 
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 SkScalar snap (SkScalar x)
 
static SkPoint snap (const SkPoint &pt)
 
static void snap (SkPoint dst[], const SkPoint src[], int count)
 
static bool hit_test (const SkPoint &pt, SkScalar x, SkScalar y)
 

Protected Member Functions

ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey) override
 
bool onClick (Click *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 145 of file PathClipSlide.cpp.

Constructor & Destructor Documentation

◆ EdgeClipSlide()

EdgeClipSlide::EdgeClipSlide ( )
inline

Definition at line 154 of file PathClipSlide.cpp.

154 : fClip(SkRect::MakeLTRB(150, 150, 550, 450)) {
155 fPoly[0].set(300, 40);
156 fPoly[1].set(550, 250);
157 fPoly[2].set(40, 450);
158
159 fEdgeColor[0] = 0xFFFF0000;
160 fEdgeColor[1] = 0xFF00FF00;
161 fEdgeColor[2] = 0xFF0000FF;
162 fName = "EdgeClip";
163 }
SkString fName
Definition: Slide.h:54
void set(float x, float y)
Definition: SkPoint_impl.h:200
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

Member Function Documentation

◆ draw()

void EdgeClipSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 177 of file PathClipSlide.cpp.

177 {
178 SkPath path;
179 path.addPoly(fPoly, N, true);
180
181 // Draw the full triangle, stroked and filled
182 SkPaint p;
183 p.setAntiAlias(true);
184 p.setColor(0xFFE0E0E0);
185 canvas->drawPath(path, p);
186 p.setStyle(SkPaint::kStroke_Style);
187 p.setStrokeWidth(2);
188 for (int i = 0; i < N; ++i) {
189 const int j = (i + 1) % N;
190 p.setColor(fEdgeColor[i]);
191 p.setAlpha(0x88);
192 canvas->drawLine(fPoly[i], fPoly[j], p);
193 }
194 p.setStyle(SkPaint::kFill_Style);
195
196 // Draw the clip itself
197 p.setColor(0xFF8888CC);
198 canvas->drawRect(fClip, p);
199
200 // Draw the filled triangle through the clip
201 p.setColor(0xFF88CC88);
202 canvas->save();
203 canvas->clipRect(fClip);
204 canvas->drawPath(path, p);
205 canvas->restore();
206
207 p.setStyle(SkPaint::kStroke_Style);
208 p.setStrokeWidth(6);
209
210 // Draw each of the "Edges" that survived the clipping
211 // We use a layer, so we can PLUS the different edge-colors, showing where two edges
212 // canceled each other out.
213 canvas->saveLayer(nullptr, nullptr);
214 p.setBlendMode(SkBlendMode::kPlus);
215 for (int i = 0; i < N; ++i) {
216 const int j = (i + 1) % N;
217 p.setColor(fEdgeColor[i]);
218 draw_clipped_line(canvas, fClip, fPoly[i], fPoly[j], p);
219 }
220 canvas->restore();
221 }
static void draw_clipped_line(SkCanvas *canvas, const SkRect &bounds, SkPoint p0, SkPoint p1, const SkPaint &paint)
@ kPlus
r = min(s + d, 1)
#define N
Definition: beziers.cpp:19
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
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

◆ hit_test()

static bool EdgeClipSlide::hit_test ( const SkPoint pt,
SkScalar  x,
SkScalar  y 
)
inlinestatic

Definition at line 268 of file PathClipSlide.cpp.

268 {
269 const SkScalar rad = 8;
270 const SkScalar dx = pt.x() - x;
271 const SkScalar dy = pt.y() - y;
272 return dx*dx + dy*dy <= rad*rad;
273 }
float SkScalar
Definition: extension.cpp:12
double y
double x
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ onClick()

bool EdgeClipSlide::onClick ( Click )
inlineoverrideprotectedvirtual

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

Implements ClickHandlerSlide.

Definition at line 295 of file PathClipSlide.cpp.

295 {
296 ((MyClick*)click)->handleMove();
297 return true;
298 }

◆ onFindClickHandler()

Click * EdgeClipSlide::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 276 of file PathClipSlide.cpp.

276 {
277 for (int i = 0; i < N; ++i) {
278 if (hit_test(fPoly[i], x, y)) {
279 return new VertClick(&fPoly[i]);
280 }
281 }
282
283 SkPath path;
284 path.addPoly(fPoly, N, true);
285 if (path.contains(x, y)) {
286 return new DragPolyClick(fPoly, N);
287 }
288
289 if (fClip.intersects(SkRect::MakeLTRB(x - 1, y - 1, x + 1, y + 1))) {
290 return new DragRectClick(&fClip);
291 }
292 return new DoNothingClick();
293 }
static bool hit_test(const SkPoint &pt, SkScalar x, SkScalar y)
bool intersects(const SkRect &r) const
Definition: SkRect.h:1121

◆ snap() [1/3]

static SkPoint EdgeClipSlide::snap ( const SkPoint pt)
inlinestatic

Definition at line 168 of file PathClipSlide.cpp.

168 {
169 return SkPoint::Make(snap(pt.x()), snap(pt.y()));
170 }
static SkScalar snap(SkScalar x)
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ snap() [2/3]

static void EdgeClipSlide::snap ( SkPoint  dst[],
const SkPoint  src[],
int  count 
)
inlinestatic

Definition at line 171 of file PathClipSlide.cpp.

171 {
172 for (int i = 0; i < count; ++i) {
173 dst[i] = snap(src[i]);
174 }
175 }
int count
Definition: FontMgrTest.cpp:50
dst
Definition: cp.py:12

◆ snap() [3/3]

static SkScalar EdgeClipSlide::snap ( SkScalar  x)
inlinestatic

Definition at line 165 of file PathClipSlide.cpp.

165 {
166 return SkScalarRoundToScalar(x * 0.5f) * 2;
167 }
#define SkScalarRoundToScalar(x)
Definition: SkScalar.h:32

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