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 | 17 |
18 class DashCubicsGM : public skiagm::GM { | 18 class DashCubicsGM : public skiagm::GM { |
19 public: | 19 public: |
20 DashCubicsGM() {} | 20 DashCubicsGM() {} |
21 | 21 |
22 protected: | 22 protected: |
23 | 23 |
24 virtual SkString onShortName() { | 24 virtual SkString onShortName() { |
25 return SkString("dashcubics"); | 25 return SkString("dashcubics"); |
26 } | 26 } |
27 | 27 |
28 virtual SkISize onISize() { | 28 virtual SkISize onISize() { |
29 return SkISize::Make(640, 480); | 29 return SkISize::Make(860, 700); |
30 } | 30 } |
31 | 31 |
32 virtual void onDraw(SkCanvas* canvas) { | 32 void flower(SkCanvas* canvas, const SkPath& path, SkScalar intervals[2], SkP
aint::Join join) { |
33 SkPath path; | |
34 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 25
0,212" | |
35 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 21
7,231" | |
36 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 7
5,250" | |
37 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 2
17,269" | |
38 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 2
50,288" | |
39 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 2
83,269" | |
40 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 4
25,250" | |
41 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 2
83,231" | |
42 "C 283,231 344,195 338,98"; | |
43 | |
44 SkParsePath::FromSVGString(d, &path); | |
45 | |
46 SkScalar intervals[] = { 5, 10 }; | |
47 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0); | 33 SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0); |
48 | 34 |
49 SkPaint paint; | 35 SkPaint paint; |
50 paint.setAntiAlias(true); | 36 paint.setAntiAlias(true); |
51 paint.setStyle(SkPaint::kStroke_Style); | 37 paint.setStyle(SkPaint::kStroke_Style); |
52 | 38 paint.setStrokeJoin(join); |
53 paint.setStrokeWidth(42); | 39 paint.setStrokeWidth(42); |
54 canvas->drawPath(path, paint); | 40 canvas->drawPath(path, paint); |
55 | 41 |
56 paint.setColor(SK_ColorRED); | 42 paint.setColor(SK_ColorRED); |
57 paint.setStrokeWidth(21); | 43 paint.setStrokeWidth(21); |
58 paint.setPathEffect(pe)->unref(); | 44 paint.setPathEffect(pe)->unref(); |
59 canvas->drawPath(path, paint); | 45 canvas->drawPath(path, paint); |
60 | 46 |
61 paint.setColor(SK_ColorGREEN); | 47 paint.setColor(SK_ColorGREEN); |
62 paint.setPathEffect(NULL); | 48 paint.setPathEffect(NULL); |
63 paint.setStrokeWidth(0); | 49 paint.setStrokeWidth(0); |
64 canvas->drawPath(path, paint); | 50 canvas->drawPath(path, paint); |
65 } | 51 } |
66 | 52 |
| 53 virtual void onDraw(SkCanvas* canvas) { |
| 54 SkPath path; |
| 55 const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 25
0,212" |
| 56 "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 21
7,231" |
| 57 "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 7
5,250" |
| 58 "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 2
17,269" |
| 59 "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 2
50,288" |
| 60 "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 2
83,269" |
| 61 "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 4
25,250" |
| 62 "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 2
83,231" |
| 63 "C 283,231 344,195 338,98"; |
| 64 |
| 65 SkParsePath::FromSVGString(d, &path); |
| 66 canvas->translate(-35.f, -55.f); |
| 67 for (int x = 0; x < 2; ++x) { |
| 68 for (int y = 0; y < 2; ++y) { |
| 69 canvas->save(); |
| 70 canvas->translate(x * 430.f, y * 355.f); |
| 71 SkScalar intervals[] = { 5 + (x ? 0 : 0.0001f + 0.0001f), 10 }; |
| 72 flower(canvas, path, intervals, y ? SkPaint::kDefault_Join : SkP
aint::kRound_Join); |
| 73 canvas->restore(); |
| 74 } |
| 75 } |
| 76 } |
| 77 |
67 private: | 78 private: |
68 typedef GM INHERITED; | 79 typedef GM INHERITED; |
69 }; | 80 }; |
70 | 81 |
71 ////////////////////////////////////////////////////////////////////////////// | 82 ////////////////////////////////////////////////////////////////////////////// |
72 | 83 |
73 static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; } | 84 static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; } |
74 static skiagm::GMRegistry reg(MyFactory); | 85 static skiagm::GMRegistry reg(MyFactory); |
OLD | NEW |