blob: 6438dcfb7d4849f3922a4725c804e32ce1bd6d60 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
reed339cdbf2015-02-05 22:02:37 -08009#include "SkAnimTimer.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkView.h"
11#include "SkCanvas.h"
12#include "SkGradientShader.h"
13#include "SkGraphics.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000014#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015#include "SkRegion.h"
16#include "SkShader.h"
17#include "SkUtils.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000018#include "SkColorPriv.h"
19#include "SkColorFilter.h"
reed@android.comd0d0e652009-10-13 13:31:27 +000020#include "SkParsePath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000021#include "SkTime.h"
22#include "SkTypeface.h"
23
reed@android.coma9640282009-08-28 20:06:54 +000024#include "SkGeometry.h"
25
bungeman60e0fee2015-08-26 05:15:46 -070026#include <stdlib.h>
27
reed@android.coma9640282009-08-28 20:06:54 +000028// http://code.google.com/p/skia/issues/detail?id=32
29static void test_cubic() {
30 SkPoint src[4] = {
reed@google.com261b8e22011-04-14 17:53:24 +000031 { 556.25000f, 523.03003f },
32 { 556.23999f, 522.96002f },
33 { 556.21997f, 522.89001f },
34 { 556.21997f, 522.82001f }
reed@android.coma9640282009-08-28 20:06:54 +000035 };
36 SkPoint dst[11];
37 dst[10].set(42, -42); // one past the end, that we don't clobber these
38 SkScalar tval[] = { 0.33333334f, 0.99999994f };
39
40 SkChopCubicAt(src, dst, tval, 2);
41
42#if 0
43 for (int i = 0; i < 11; i++) {
44 SkDebugf("--- %d [%g %g]\n", i, dst[i].fX, dst[i].fY);
45 }
46#endif
47}
48
reed@android.comd0d0e652009-10-13 13:31:27 +000049static void test_cubic2() {
50 const char* str = "M2242 -590088L-377758 9.94099e+07L-377758 9.94099e+07L2242 -590088Z";
51 SkPath path;
52 SkParsePath::FromSVGString(str, &path);
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
reed@android.comd0d0e652009-10-13 13:31:27 +000054 {
reed@android.comd0d0e652009-10-13 13:31:27 +000055 SkRect r = path.getBounds();
56 SkIRect ir;
57 r.round(&ir);
bungeman@google.comfab44db2013-10-11 18:50:45 +000058 SkDebugf("[%g %g %g %g] [%x %x %x %x]\n",
59 SkScalarToDouble(r.fLeft), SkScalarToDouble(r.fTop),
60 SkScalarToDouble(r.fRight), SkScalarToDouble(r.fBottom),
61 ir.fLeft, ir.fTop, ir.fRight, ir.fBottom);
reed@android.comd0d0e652009-10-13 13:31:27 +000062 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000063
reed@android.comd0d0e652009-10-13 13:31:27 +000064 SkBitmap bitmap;
commit-bot@chromium.orga8c18312014-02-17 02:55:57 +000065 bitmap.allocN32Pixels(300, 200);
reed@android.comd0d0e652009-10-13 13:31:27 +000066
67 SkCanvas canvas(bitmap);
68 SkPaint paint;
69 paint.setAntiAlias(true);
70 canvas.drawPath(path, paint);
71}
72
reed@google.com0faac1e2011-05-11 05:58:58 +000073class PathView : public SampleView {
reed339cdbf2015-02-05 22:02:37 -080074 SkScalar fPrevSecs;
reed@android.com8a1c16f2008-12-17 15:59:43 +000075public:
reed339cdbf2015-02-05 22:02:37 -080076 SkScalar fDStroke, fStroke, fMinStroke, fMaxStroke;
reed@android.com8a1c16f2008-12-17 15:59:43 +000077 SkPath fPath[6];
78 bool fShowHairline;
reed@google.comc9fa63c2012-03-12 21:14:09 +000079 bool fOnce;
rmistry@google.comae933ce2012-08-23 18:19:56 +000080
81 PathView() {
reed339cdbf2015-02-05 22:02:37 -080082 fPrevSecs = 0;
reed@google.comc9fa63c2012-03-12 21:14:09 +000083 fOnce = false;
84 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000085
reed@google.comc9fa63c2012-03-12 21:14:09 +000086 void init() {
87 if (fOnce) {
88 return;
89 }
90 fOnce = true;
91
reed@android.coma9640282009-08-28 20:06:54 +000092 test_cubic();
reed@android.comd0d0e652009-10-13 13:31:27 +000093 test_cubic2();
reed@android.coma9640282009-08-28 20:06:54 +000094
reed@android.com8a1c16f2008-12-17 15:59:43 +000095 fShowHairline = false;
rmistry@google.comae933ce2012-08-23 18:19:56 +000096
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 fDStroke = 1;
98 fStroke = 10;
99 fMinStroke = 10;
100 fMaxStroke = 180;
101
reed339cdbf2015-02-05 22:02:37 -0800102 const SkScalar V = 85;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000103
reed339cdbf2015-02-05 22:02:37 -0800104 fPath[0].moveTo(40, 70);
105 fPath[0].lineTo(70, 70 + SK_ScalarHalf);
106 fPath[0].lineTo(110, 70);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000107
reed339cdbf2015-02-05 22:02:37 -0800108 fPath[1].moveTo(40, 70);
109 fPath[1].lineTo(70, 70 - SK_ScalarHalf);
110 fPath[1].lineTo(110, 70);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000111
reed339cdbf2015-02-05 22:02:37 -0800112 fPath[2].moveTo(V, V);
113 fPath[2].lineTo(50, V);
114 fPath[2].lineTo(50, 50);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000115
reed339cdbf2015-02-05 22:02:37 -0800116 fPath[3].moveTo(50, 50);
117 fPath[3].lineTo(50, V);
118 fPath[3].lineTo(V, V);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000119
reed339cdbf2015-02-05 22:02:37 -0800120 fPath[4].moveTo(50, 50);
121 fPath[4].lineTo(50, V);
122 fPath[4].lineTo(52, 50);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000123
reed339cdbf2015-02-05 22:02:37 -0800124 fPath[5].moveTo(52, 50);
125 fPath[5].lineTo(50, V);
126 fPath[5].lineTo(50, 50);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000127
reed@google.com0faac1e2011-05-11 05:58:58 +0000128 this->setBGColor(0xFFDDDDDD);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000129 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000130
reed@android.com8a1c16f2008-12-17 15:59:43 +0000131protected:
132 // overrides from SkEventSink
mtkleinf0599002015-07-13 06:18:39 -0700133 bool onQuery(SkEvent* evt) override {
reed@google.com0faac1e2011-05-11 05:58:58 +0000134 if (SampleCode::TitleQ(*evt)) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000135 SampleCode::TitleR(evt, "Paths");
136 return true;
137 }
138 return this->INHERITED::onQuery(evt);
139 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000140
reed@google.com0faac1e2011-05-11 05:58:58 +0000141 void drawPath(SkCanvas* canvas, const SkPath& path, SkPaint::Join j) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000142 SkPaint paint;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000143
reed@android.com8a1c16f2008-12-17 15:59:43 +0000144 paint.setAntiAlias(true);
145 paint.setStyle(SkPaint::kStroke_Style);
146 paint.setStrokeJoin(j);
reed339cdbf2015-02-05 22:02:37 -0800147 paint.setStrokeWidth(fStroke);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000148
reed@google.com0faac1e2011-05-11 05:58:58 +0000149 if (fShowHairline) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000150 SkPath fill;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000151
152 paint.getFillPath(path, &fill);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000153 paint.setStrokeWidth(0);
154 canvas->drawPath(fill, paint);
reed@google.com0faac1e2011-05-11 05:58:58 +0000155 } else {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000156 canvas->drawPath(path, paint);
reed@google.com0faac1e2011-05-11 05:58:58 +0000157 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000158
reed@android.com8a1c16f2008-12-17 15:59:43 +0000159 paint.setColor(SK_ColorRED);
160 paint.setStrokeWidth(0);
161 canvas->drawPath(path, paint);
162 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000163
mtkleinf0599002015-07-13 06:18:39 -0700164 void onDrawContent(SkCanvas* canvas) override {
reed@google.comc9fa63c2012-03-12 21:14:09 +0000165 this->init();
reed339cdbf2015-02-05 22:02:37 -0800166 canvas->translate(50, 50);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000167
168 static const SkPaint::Join gJoins[] = {
169 SkPaint::kBevel_Join,
170 SkPaint::kMiter_Join,
171 SkPaint::kRound_Join
172 };
173
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +0000174 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoins); i++) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000175 canvas->save();
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +0000176 for (size_t j = 0; j < SK_ARRAY_COUNT(fPath); j++) {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000177 this->drawPath(canvas, fPath[j], gJoins[i]);
reed339cdbf2015-02-05 22:02:37 -0800178 canvas->translate(200, 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000179 }
180 canvas->restore();
rmistry@google.comae933ce2012-08-23 18:19:56 +0000181
reed339cdbf2015-02-05 22:02:37 -0800182 canvas->translate(0, 200);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000183 }
reed339cdbf2015-02-05 22:02:37 -0800184 }
mtkleinf0599002015-07-13 06:18:39 -0700185
mtklein36352bf2015-03-25 18:17:31 -0700186 bool onAnimate(const SkAnimTimer& timer) override {
reed339cdbf2015-02-05 22:02:37 -0800187 SkScalar currSecs = timer.scaled(100);
188 SkScalar delta = currSecs - fPrevSecs;
189 fPrevSecs = currSecs;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000190
reed339cdbf2015-02-05 22:02:37 -0800191 fStroke += fDStroke * delta;
192 if (fStroke > fMaxStroke || fStroke < fMinStroke) {
193 fDStroke = -fDStroke;
194 }
195 return true;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000196 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000197
mtklein36352bf2015-03-25 18:17:31 -0700198 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
reed@android.com8a1c16f2008-12-17 15:59:43 +0000199 fShowHairline = !fShowHairline;
halcanary96fcdcc2015-08-27 07:41:13 -0700200 this->inval(nullptr);
reed@google.com4d5c26d2013-01-08 16:17:50 +0000201 return this->INHERITED::onFindClickHandler(x, y, modi);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000202 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000203
reed@android.com8a1c16f2008-12-17 15:59:43 +0000204private:
reed@google.com0faac1e2011-05-11 05:58:58 +0000205 typedef SampleView INHERITED;
reed@android.com8a1c16f2008-12-17 15:59:43 +0000206};
reeda7a8b102014-12-16 08:07:43 -0800207DEF_SAMPLE( return new PathView; )
reed@android.com8a1c16f2008-12-17 15:59:43 +0000208
209//////////////////////////////////////////////////////////////////////////////
210
reed8b575242014-12-17 01:47:32 -0800211#include "SkArcToPathEffect.h"
reeda7a8b102014-12-16 08:07:43 -0800212#include "SkCornerPathEffect.h"
213#include "SkRandom.h"
214
215class ArcToView : public SampleView {
reed8b575242014-12-17 01:47:32 -0800216 bool fDoFrame, fDoArcTo, fDoCorner, fDoConic;
217 SkPaint fPtsPaint, fArcToPaint, fSkeletonPaint, fCornerPaint;
reeda7a8b102014-12-16 08:07:43 -0800218public:
219 enum {
220 N = 4
221 };
222 SkPoint fPts[N];
reeda7a8b102014-12-16 08:07:43 -0800223
reed8b575242014-12-17 01:47:32 -0800224 ArcToView()
225 : fDoFrame(false), fDoArcTo(false), fDoCorner(false), fDoConic(false)
226 {
reeda7a8b102014-12-16 08:07:43 -0800227 SkRandom rand;
228 for (int i = 0; i < N; ++i) {
229 fPts[i].fX = 20 + rand.nextUScalar1() * 640;
230 fPts[i].fY = 20 + rand.nextUScalar1() * 480;
231 }
mtkleinf0599002015-07-13 06:18:39 -0700232
reed8b575242014-12-17 01:47:32 -0800233 const SkScalar rad = 50;
reeda7a8b102014-12-16 08:07:43 -0800234
235 fPtsPaint.setAntiAlias(true);
236 fPtsPaint.setStrokeWidth(15);
237 fPtsPaint.setStrokeCap(SkPaint::kRound_Cap);
238
reed8b575242014-12-17 01:47:32 -0800239 fArcToPaint.setAntiAlias(true);
240 fArcToPaint.setStyle(SkPaint::kStroke_Style);
241 fArcToPaint.setStrokeWidth(9);
242 fArcToPaint.setColor(0x800000FF);
reeda4393342016-03-18 11:22:57 -0700243 fArcToPaint.setPathEffect(SkArcToPathEffect::Make(rad));
reeda7a8b102014-12-16 08:07:43 -0800244
245 fCornerPaint.setAntiAlias(true);
246 fCornerPaint.setStyle(SkPaint::kStroke_Style);
247 fCornerPaint.setStrokeWidth(13);
248 fCornerPaint.setColor(SK_ColorGREEN);
reeda4393342016-03-18 11:22:57 -0700249 fCornerPaint.setPathEffect(SkCornerPathEffect::Make(rad*2));
reeda7a8b102014-12-16 08:07:43 -0800250
251 fSkeletonPaint.setAntiAlias(true);
252 fSkeletonPaint.setStyle(SkPaint::kStroke_Style);
253 fSkeletonPaint.setColor(SK_ColorRED);
254 }
255
reed8b575242014-12-17 01:47:32 -0800256 void toggle(bool& value) {
257 value = !value;
halcanary96fcdcc2015-08-27 07:41:13 -0700258 this->inval(nullptr);
reed8b575242014-12-17 01:47:32 -0800259 }
260
reeda7a8b102014-12-16 08:07:43 -0800261protected:
262 // overrides from SkEventSink
mtklein36352bf2015-03-25 18:17:31 -0700263 bool onQuery(SkEvent* evt) override {
reeda7a8b102014-12-16 08:07:43 -0800264 if (SampleCode::TitleQ(*evt)) {
265 SampleCode::TitleR(evt, "ArcTo");
266 return true;
267 }
reed8b575242014-12-17 01:47:32 -0800268 SkUnichar uni;
269 if (SampleCode::CharQ(*evt, &uni)) {
270 switch (uni) {
271 case '1': this->toggle(fDoFrame); return true;
272 case '2': this->toggle(fDoArcTo); return true;
273 case '3': this->toggle(fDoCorner); return true;
274 case '4': this->toggle(fDoConic); return true;
275 default: break;
276 }
277 }
reeda7a8b102014-12-16 08:07:43 -0800278 return this->INHERITED::onQuery(evt);
279 }
mtkleinf0599002015-07-13 06:18:39 -0700280
reed8b575242014-12-17 01:47:32 -0800281 void makePath(SkPath* path) {
282 path->moveTo(fPts[0]);
283 for (int i = 1; i < N; ++i) {
284 path->lineTo(fPts[i]);
285 }
286 if (!fDoFrame) {
287 path->close();
288 }
289 }
reeda7a8b102014-12-16 08:07:43 -0800290
mtklein36352bf2015-03-25 18:17:31 -0700291 void onDrawContent(SkCanvas* canvas) override {
reeda7a8b102014-12-16 08:07:43 -0800292 canvas->drawPoints(SkCanvas::kPoints_PointMode, N, fPts, fPtsPaint);
293
294 SkPath path;
reed8b575242014-12-17 01:47:32 -0800295 this->makePath(&path);
reeda7a8b102014-12-16 08:07:43 -0800296
reed8b575242014-12-17 01:47:32 -0800297 if (fDoCorner) {
298 canvas->drawPath(path, fCornerPaint);
reeda7a8b102014-12-16 08:07:43 -0800299 }
reed8b575242014-12-17 01:47:32 -0800300 if (fDoArcTo) {
301 canvas->drawPath(path, fArcToPaint);
reeda7a8b102014-12-16 08:07:43 -0800302 }
reeda7a8b102014-12-16 08:07:43 -0800303
reed8b575242014-12-17 01:47:32 -0800304 canvas->drawPath(path, fSkeletonPaint);
reeda7a8b102014-12-16 08:07:43 -0800305 }
306
mtklein36352bf2015-03-25 18:17:31 -0700307 bool onClick(Click* click) override {
reeda7a8b102014-12-16 08:07:43 -0800308 int32_t index;
309 if (click->fMeta.findS32("index", &index)) {
310 SkASSERT((unsigned)index < N);
311 fPts[index] = click->fCurr;
halcanary96fcdcc2015-08-27 07:41:13 -0700312 this->inval(nullptr);
reeda7a8b102014-12-16 08:07:43 -0800313 return true;
314 }
315 return false;
316 }
317
mtklein36352bf2015-03-25 18:17:31 -0700318 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
reeda7a8b102014-12-16 08:07:43 -0800319 const SkScalar tol = 4;
320 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
321 for (int i = 0; i < N; ++i) {
322 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) {
323 Click* click = new Click(this);
324 click->fMeta.setS32("index", i);
325 return click;
326 }
327 }
328 return this->INHERITED::onFindClickHandler(x, y, modi);
329 }
330
331private:
332 typedef SampleView INHERITED;
333};
334DEF_SAMPLE( return new ArcToView; )
Mike Reeda964a292016-11-02 22:09:25 -0400335
336/////////////
337
338class FatStroke : public SampleView {
339 bool fClosed, fShowStroke, fShowHidden, fShowSkeleton;
340 int fJoinType, fCapType;
Mike Reed1fba7022016-12-15 10:23:42 -0500341 float fWidth = 30;
Mike Reeda964a292016-11-02 22:09:25 -0400342 SkPaint fPtsPaint, fHiddenPaint, fSkeletonPaint, fStrokePaint;
343public:
344 enum {
345 N = 4
346 };
347 SkPoint fPts[N];
348
349 FatStroke() : fClosed(false), fShowStroke(true), fShowHidden(false), fShowSkeleton(true),
350 fJoinType(0), fCapType(0)
351 {
352 SkRandom rand;
353 for (int i = 0; i < N; ++i) {
354 fPts[i].fX = 20 + rand.nextUScalar1() * 640;
355 fPts[i].fY = 20 + rand.nextUScalar1() * 480;
356 }
357
358 fPtsPaint.setAntiAlias(true);
359 fPtsPaint.setStrokeWidth(10);
360 fPtsPaint.setStrokeCap(SkPaint::kRound_Cap);
361
362 fHiddenPaint.setAntiAlias(true);
363 fHiddenPaint.setStyle(SkPaint::kStroke_Style);
364 fHiddenPaint.setColor(0xFF0000FF);
365
366 fStrokePaint.setAntiAlias(true);
367 fStrokePaint.setStyle(SkPaint::kStroke_Style);
368 fStrokePaint.setStrokeWidth(50);
369 fStrokePaint.setColor(0x8000FF00);
370
371 fSkeletonPaint.setAntiAlias(true);
372 fSkeletonPaint.setStyle(SkPaint::kStroke_Style);
373 fSkeletonPaint.setColor(SK_ColorRED);
374 }
375
376 void toggle(bool& value) {
377 value = !value;
378 this->inval(nullptr);
379 }
380
381 void toggle3(int& value) {
382 value = (value + 1) % 3;
383 this->inval(nullptr);
384 }
385
386protected:
387 // overrides from SkEventSink
388 bool onQuery(SkEvent* evt) override {
389 if (SampleCode::TitleQ(*evt)) {
390 SampleCode::TitleR(evt, "FatStroke");
391 return true;
392 }
393 SkUnichar uni;
394 if (SampleCode::CharQ(*evt, &uni)) {
395 switch (uni) {
396 case '1': this->toggle(fShowSkeleton); return true;
397 case '2': this->toggle(fShowStroke); return true;
398 case '3': this->toggle(fShowHidden); return true;
399 case '4': this->toggle3(fJoinType); return true;
400 case '5': this->toggle3(fCapType); return true;
401 case '6': this->toggle(fClosed); return true;
Mike Reed1fba7022016-12-15 10:23:42 -0500402 case '-': fWidth -= 5; this->inval(nullptr); return true;
403 case '=': fWidth += 5; this->inval(nullptr); return true;
Mike Reeda964a292016-11-02 22:09:25 -0400404 default: break;
405 }
406 }
407 return this->INHERITED::onQuery(evt);
408 }
409
410 void makePath(SkPath* path) {
411 path->moveTo(fPts[0]);
412 for (int i = 1; i < N; ++i) {
413 path->lineTo(fPts[i]);
414 }
415 if (fClosed) {
416 path->close();
417 }
418 }
419
420 void onDrawContent(SkCanvas* canvas) override {
421 canvas->drawColor(0xFFEEEEEE);
422
423 SkPath path;
424 this->makePath(&path);
425
Mike Reed1fba7022016-12-15 10:23:42 -0500426 fStrokePaint.setStrokeWidth(fWidth);
Mike Reeda964a292016-11-02 22:09:25 -0400427 fStrokePaint.setStrokeJoin((SkPaint::Join)fJoinType);
428 fStrokePaint.setStrokeCap((SkPaint::Cap)fCapType);
429
430 if (fShowStroke) {
431 canvas->drawPath(path, fStrokePaint);
432 }
433 if (fShowHidden) {
434 SkPath hidden;
435 fStrokePaint.getFillPath(path, &hidden);
436 canvas->drawPath(hidden, fHiddenPaint);
437 }
438 if (fShowSkeleton) {
439 canvas->drawPath(path, fSkeletonPaint);
440 }
441 canvas->drawPoints(SkCanvas::kPoints_PointMode, N, fPts, fPtsPaint);
442 }
443
444 bool onClick(Click* click) override {
445 int32_t index;
446 if (click->fMeta.findS32("index", &index)) {
447 SkASSERT((unsigned)index < N);
448 fPts[index] = click->fCurr;
449 this->inval(nullptr);
450 return true;
451 }
452 return false;
453 }
454
455 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
456 const SkScalar tol = 4;
457 const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
458 for (int i = 0; i < N; ++i) {
459 if (r.intersects(SkRect::MakeXYWH(fPts[i].fX, fPts[i].fY, 1, 1))) {
460 Click* click = new Click(this);
461 click->fMeta.setS32("index", i);
462 return click;
463 }
464 }
465 return this->INHERITED::onFindClickHandler(x, y, modi);
466 }
467
468private:
469 typedef SampleView INHERITED;
470};
471DEF_SAMPLE( return new FatStroke; )