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

Classes

class  MyClick
 

Public Member Functions

 QuadStrokerSlide ()
 
bool onChar (SkUnichar uni) override
 
void load (SkScalar w, SkScalar h) override
 
void resize (SkScalar w, SkScalar h) 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 bool animate (double nanos)
 
virtual void unload ()
 
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 (Click *click) override
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 112 of file QuadStrokerSlide.cpp.

Constructor & Destructor Documentation

◆ QuadStrokerSlide()

QuadStrokerSlide::QuadStrokerSlide ( )
inline

Definition at line 156 of file QuadStrokerSlide.cpp.

156 {
157 fPts[0].set(50, 200); // cubic
158 fPts[1].set(50, 100);
159 fPts[2].set(150, 50);
160 fPts[3].set(300, 50);
161
162 fPts[4].set(350, 200); // conic
163 fPts[5].set(350, 100);
164 fPts[6].set(450, 50);
165
166 fPts[7].set(150, 300); // quad
167 fPts[8].set(150, 200);
168 fPts[9].set(250, 150);
169
170 fPts[10].set(250, 200); // arc
171 fPts[11].set(250, 300);
172 fPts[12].set(150, 350);
173
174 fPts[13].set(200, 200); // rrect
175 fPts[14].set(400, 400);
176
177 fPts[15].set(250, 250); // oval
178 fPts[16].set(450, 450);
179
180 fText = "a";
181 fTextSize = 12;
182 fWidth = 50;
183 fDWidth = 0.25f;
184 fWeight = 1;
185 fRadius = 150;
186
187 fCubicButton.fLabel = 'C';
188 fCubicButton.fEnabled = false;
189 fConicButton.fLabel = 'K';
190 fConicButton.fEnabled = false;
191 fQuadButton.fLabel = 'Q';
192 fQuadButton.fEnabled = false;
193 fArcButton.fLabel = 'A';
194 fArcButton.fEnabled = true;
195 fRRectButton.fLabel = 'R';
196 fRRectButton.fEnabled = false;
197 fCircleButton.fLabel = 'O';
198 fCircleButton.fEnabled = true;
199 fCircleButton.fFill = true;
200 fTextButton.fLabel = 'T';
201 fTextButton.fEnabled = false;
202 fAnimate = false;
203 setAsNeeded();
204 fName = "QuadStroker";
205 }
SkString fName
Definition Slide.h:54
void set(float x, float y)

Member Function Documentation

◆ draw()

void QuadStrokerSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 232 of file QuadStrokerSlide.cpp.

232 {
233 canvas->clear(SK_ColorLTGRAY);
234
235 SkPath path;
236 SkScalar width = fWidth;
237
238 if (fCubicButton.fEnabled) {
239 path.moveTo(fPts[0]);
240 path.cubicTo(fPts[1], fPts[2], fPts[3]);
241 setForSingles();
242 draw_stroke(canvas, path, width, 950, false);
243 }
244
245 if (fConicButton.fEnabled) {
246 path.reset();
247 path.moveTo(fPts[4]);
248 path.conicTo(fPts[5], fPts[6], fWeight);
249 setForSingles();
250 draw_stroke(canvas, path, width, 950, false);
251 }
252
253 if (fQuadButton.fEnabled) {
254 path.reset();
255 path.moveTo(fPts[7]);
256 path.quadTo(fPts[8], fPts[9]);
257 setForSingles();
258 draw_stroke(canvas, path, width, 950, false);
259 }
260
261 if (fArcButton.fEnabled) {
262 path.reset();
263 path.moveTo(fPts[10]);
264 path.arcTo(fPts[11], fPts[12], fRadius);
265 setForGeometry();
266 draw_stroke(canvas, path, width, 950, false);
267 SkPath pathPts;
268 pathPts.moveTo(fPts[10]);
269 pathPts.lineTo(fPts[11]);
270 pathPts.lineTo(fPts[12]);
271 draw_points(canvas, pathPts, SK_ColorDKGRAY, true);
272 }
273
274 if (fRRectButton.fEnabled) {
275 SkScalar rad = 32;
276 SkRect r;
277 r.setBounds(&fPts[13], 2);
278 path.reset();
279 SkRRect rr;
280 rr.setRectXY(r, rad, rad);
281 path.addRRect(rr);
282 setForGeometry();
283 draw_stroke(canvas, path, width, 950, false);
284
285 path.reset();
286 SkRRect rr2;
287 rr.inset(width/2, width/2, &rr2);
288 path.addRRect(rr2, SkPathDirection::kCCW);
289 rr.inset(-width/2, -width/2, &rr2);
290 path.addRRect(rr2, SkPathDirection::kCW);
292 paint.setAntiAlias(true);
293 paint.setColor(0x40FF8844);
294 canvas->drawPath(path, paint);
295 }
296
297 if (fCircleButton.fEnabled) {
298 path.reset();
299 SkRect r;
300 r.setBounds(&fPts[15], 2);
301 path.addOval(r);
302 setForGeometry();
303 if (fCircleButton.fFill) {
304 if (fArcButton.fEnabled) {
306 if (arcCenter(&center)) {
307 r.setLTRB(center.fX - fRadius, center.fY - fRadius,
308 center.fX + fRadius, center.fY + fRadius);
309 }
310 }
311 draw_fill(canvas, r, width);
312 } else {
313 draw_stroke(canvas, path, width, 950, false);
314 }
315 }
316
317 if (fTextButton.fEnabled) {
318 path.reset();
320 font.setSize(fTextSize);
322 0, fTextSize, font, &path);
323 setForText();
324 draw_stroke(canvas, path, width * fWidthScale / fTextSize, fTextSize, true);
325 }
326
327 if (fAnimate) {
328 fWidth += fDWidth;
329 if (fDWidth > 0 && fWidth > kWidthMax) {
330 fDWidth = -fDWidth;
331 } else if (fDWidth < 0 && fWidth < kWidthMin) {
332 fDWidth = -fDWidth;
333 }
334 }
335 setAsNeeded();
336 if (fConicButton.fEnabled) {
337 draw_control(canvas, fWeightControl, fWeight, 0, 5, "weight");
338 }
339 if (fArcButton.fEnabled) {
340 draw_control(canvas, fRadiusControl, fRadius, 0, 500, "radius");
341 }
342#ifdef SK_DEBUG
343 draw_control(canvas, fErrorControl, gDebugStrokerError, kStrokerErrorMin, kStrokerErrorMax,
344 "error");
345#endif
346 draw_control(canvas, fWidthControl, fWidth * fWidthScale, kWidthMin * fWidthScale,
347 kWidthMax * fWidthScale, "width");
348 draw_button(canvas, fQuadButton);
349 draw_button(canvas, fCubicButton);
350 draw_button(canvas, fConicButton);
351 draw_button(canvas, fArcButton);
352 draw_button(canvas, fRRectButton);
353 draw_button(canvas, fCircleButton);
354 draw_button(canvas, fTextButton);
355 }
#define kWidthMax
#define kWidthMin
constexpr SkColor SK_ColorLTGRAY
Definition SkColor.h:118
constexpr SkColor SK_ColorDKGRAY
Definition SkColor.h:108
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static SkScalar center(float pos0, float pos1)
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawPath(const SkPath &path, const SkPaint &paint)
SkPath & moveTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:678
SkPath & lineTo(SkScalar x, SkScalar y)
Definition SkPath.cpp:718
void inset(SkScalar dx, SkScalar dy, SkRRect *dst) const
Definition SkRRect.cpp:562
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.cpp:52
size_t size() const
Definition SkString.h:131
const char * c_str() const
Definition SkString.h:133
static void GetPath(const void *text, size_t length, SkTextEncoding, SkScalar x, SkScalar y, const SkFont &, SkPath *)
const Paint & paint
float SkScalar
Definition extension.cpp:12
SkFont DefaultFont()
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.
int32_t width
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865
void setBounds(const SkPoint pts[], int count)
Definition SkRect.h:881

◆ load()

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

Reimplemented from Slide.

Definition at line 228 of file QuadStrokerSlide.cpp.

228{ this->layout(w, h); }
SkScalar w
SkScalar h

◆ onChar()

bool QuadStrokerSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 207 of file QuadStrokerSlide.cpp.

207 {
208 if (fTextButton.fEnabled) {
209 switch (uni) {
210 case ' ':
211 fText = "";
212 break;
213 case '-':
214 fTextSize = std::max(1.0f, fTextSize - 1);
215 break;
216 case '+':
217 case '=':
218 fTextSize += 1;
219 break;
220 default:
221 fText.appendUnichar(uni);
222 }
223 return true;
224 }
225 return false;
226 }
void appendUnichar(SkUnichar uni)
Definition SkString.h:207

◆ onClick()

bool QuadStrokerSlide::onClick ( Click )
inlineoverrideprotectedvirtual

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

Implements ClickHandlerSlide.

Definition at line 417 of file QuadStrokerSlide.cpp.

417 {
418 int index = ((MyClick*)click)->fIndex;
419 if (index < (int) std::size(fPts)) {
420 fPts[index].offset(click->fCurr.fX - click->fPrev.fX,
421 click->fCurr.fY - click->fPrev.fY);
422 } else if (index == (int) std::size(fPts) + 1) {
423 fWeight = MapScreenYtoValue(click->fCurr.fY, fWeightControl, 0, 5);
424 } else if (index == (int) std::size(fPts) + 2) {
425 fRadius = MapScreenYtoValue(click->fCurr.fY, fRadiusControl, 0, 500);
426 }
427#ifdef SK_DEBUG
428 else if (index == (int) std::size(fPts) + 3) {
429 gDebugStrokerError = std::max(FLT_EPSILON, MapScreenYtoValue(click->fCurr.fY,
430 fErrorControl, kStrokerErrorMin, kStrokerErrorMax));
431 gDebugStrokerErrorSet = true;
432 }
433#endif
434 else if (index == (int) std::size(fPts) + 4) {
435 fWidth = std::max(FLT_EPSILON, MapScreenYtoValue(click->fCurr.fY, fWidthControl,
437 fAnimate = fWidth <= kWidthMin;
438 }
439 return true;
440 }
void offset(float dx, float dy)

◆ onFindClickHandler()

Click * QuadStrokerSlide::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 363 of file QuadStrokerSlide.cpp.

363 {
364 for (size_t i = 0; i < std::size(fPts); ++i) {
365 if (hittest(fPts[i], x, y)) {
366 return new MyClick((int)i);
367 }
368 }
369 const SkRect& rectPt = SkRect::MakeXYWH(x, y, 1, 1);
370 if (fWeightControl.contains(rectPt)) {
371 return new MyClick((int) std::size(fPts) + 1);
372 }
373 if (fRadiusControl.contains(rectPt)) {
374 return new MyClick((int) std::size(fPts) + 2);
375 }
376#ifdef SK_DEBUG
377 if (fErrorControl.contains(rectPt)) {
378 return new MyClick((int) std::size(fPts) + 3);
379 }
380#endif
381 if (fWidthControl.contains(rectPt)) {
382 return new MyClick((int) std::size(fPts) + 4);
383 }
384 if (fCubicButton.fBounds.contains(rectPt)) {
385 fCubicButton.fEnabled ^= true;
386 return new MyClick((int) std::size(fPts) + 5);
387 }
388 if (fConicButton.fBounds.contains(rectPt)) {
389 fConicButton.fEnabled ^= true;
390 return new MyClick((int) std::size(fPts) + 6);
391 }
392 if (fQuadButton.fBounds.contains(rectPt)) {
393 fQuadButton.fEnabled ^= true;
394 return new MyClick((int) std::size(fPts) + 7);
395 }
396 if (fArcButton.fBounds.contains(rectPt)) {
397 fArcButton.fEnabled ^= true;
398 return new MyClick((int) std::size(fPts) + 8);
399 }
400 if (fRRectButton.fBounds.contains(rectPt)) {
401 fRRectButton.fEnabled ^= true;
402 return new MyClick((int) std::size(fPts) + 9);
403 }
404 if (fCircleButton.fBounds.contains(rectPt)) {
405 bool wasEnabled = fCircleButton.fEnabled;
406 fCircleButton.fEnabled = !fCircleButton.fFill;
407 fCircleButton.fFill = wasEnabled && !fCircleButton.fFill;
408 return new MyClick((int) std::size(fPts) + 10);
409 }
410 if (fTextButton.fBounds.contains(rectPt)) {
411 fTextButton.fEnabled ^= true;
412 return new MyClick((int) std::size(fPts) + 11);
413 }
414 return nullptr;
415 }
static bool hittest(const SkPoint &target, SkScalar x, SkScalar y)
double y
double x
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
bool contains(SkScalar x, SkScalar y) const
Definition extension.cpp:19

◆ resize()

void QuadStrokerSlide::resize ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 230 of file QuadStrokerSlide.cpp.

230{ this->layout(w, h); }

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