OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
11 #include "SkParsePath.h" | 11 #include "SkParsePath.h" |
12 #include "SkDashPathEffect.h" | 12 #include "SkDashPathEffect.h" |
13 | 13 |
14 /* | 14 /* |
15 * Inspired by http://code.google.com/p/chromium/issues/detail?id=112145 | 15 * Inspired by http://code.google.com/p/chromium/issues/detail?id=112145 |
16 */ | 16 */ |
17 static void flower(SkCanvas* canvas, const SkPath& path, | 17 static void flower(SkCanvas* canvas, const SkPath& path, SkScalar intervals[2], |
18 SkScalar intervals[2], SkPaint::Join join) { | 18 SkPaint::Join join) { |
19 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0); | 19 SkPaint paint; |
| 20 paint.setAntiAlias(true); |
| 21 paint.setStyle(SkPaint::kStroke_Style); |
| 22 paint.setStrokeJoin(join); |
| 23 paint.setStrokeWidth(42); |
| 24 canvas->drawPath(path, paint); |
20 | 25 |
21 SkPaint paint; | 26 paint.setColor(SK_ColorRED); |
22 paint.setAntiAlias(true); | 27 paint.setStrokeWidth(21); |
23 paint.setStyle(SkPaint::kStroke_Style); | 28 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0)); |
24 paint.setStrokeJoin(join); | 29 canvas->drawPath(path, paint); |
25 paint.setStrokeWidth(42); | |
26 canvas->drawPath(path, paint); | |
27 | 30 |
28 paint.setColor(SK_ColorRED); | 31 paint.setColor(SK_ColorGREEN); |
29 paint.setStrokeWidth(21); | 32 paint.setPathEffect(nullptr); |
30 paint.setPathEffect(pe)->unref(); | 33 paint.setStrokeWidth(0); |
31 canvas->drawPath(path, paint); | 34 canvas->drawPath(path, paint); |
32 | |
33 paint.setColor(SK_ColorGREEN); | |
34 paint.setPathEffect(nullptr); | |
35 paint.setStrokeWidth(0); | |
36 canvas->drawPath(path, paint); | |
37 } | 35 } |
38 | 36 |
39 DEF_SIMPLE_GM(dashcubics, canvas, 860, 700) { | 37 DEF_SIMPLE_GM(dashcubics, canvas, 860, 700) { |
40 SkPath path; | 38 SkPath path; |
41 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 25
0,212" | 39 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 25
0,212" |
42 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 21
7,231" | 40 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 21
7,231" |
43 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 7
5,250" | 41 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 7
5,250" |
44 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 2
17,269" | 42 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 2
17,269" |
45 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 2
50,288" | 43 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 2
50,288" |
46 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 2
83,269" | 44 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 2
83,269" |
47 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 4
25,250" | 45 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 4
25,250" |
48 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 2
83,231" | 46 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 2
83,231" |
49 "C 283,231 344,195 338,98"; | 47 "C 283,231 344,195 338,98"; |
50 | 48 |
51 SkParsePath::FromSVGString(d, &path); | 49 SkParsePath::FromSVGString(d, &path); |
52 canvas->translate(-35.f, -55.f); | 50 canvas->translate(-35.f, -55.f); |
53 for (int x = 0; x < 2; ++x) { | 51 for (int x = 0; x < 2; ++x) { |
54 for (int y = 0; y < 2; ++y) { | 52 for (int y = 0; y < 2; ++y) { |
55 canvas->save(); | 53 canvas->save(); |
56 canvas->translate(x * 430.f, y * 355.f); | 54 canvas->translate(x * 430.f, y * 355.f); |
57 SkScalar intervals[] = { 5 + (x ? 0 : 0.0001f + 0.0001f), 10 }; | 55 SkScalar intervals[] = { 5 + (x ? 0 : 0.0001f + 0.0001f), 10 }; |
58 flower(canvas, path, intervals, y ? SkPaint::kDefault_Join : SkP
aint::kRound_Join); | 56 flower(canvas, path, intervals, y ? SkPaint::kDefault_Join : SkP
aint::kRound_Join); |
59 canvas->restore(); | 57 canvas->restore(); |
60 } | 58 } |
61 } | 59 } |
62 } | 60 } |
OLD | NEW |