reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
| 8 | #include "gm.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkPath.h" |
| 11 | #include "SkParsePath.h" |
| 12 | #include "SkDashPathEffect.h" |
| 13 | |
| 14 | /* |
| 15 | * Inspired by http://code.google.com/p/chromium/issues/detail?id=112145 |
| 16 | */ |
| 17 | |
| 18 | class DashCubicsGM : public skiagm::GM { |
| 19 | public: |
| 20 | DashCubicsGM() {} |
| 21 | |
| 22 | protected: |
commit-bot@chromium.org | a90c680 | 2014-04-30 13:20:45 +0000 | [diff] [blame] | 23 | |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 24 | virtual SkString onShortName() { |
| 25 | return SkString("dashcubics"); |
| 26 | } |
| 27 | |
| 28 | virtual SkISize onISize() { |
caryclark | 6df8e34 | 2015-02-23 12:47:03 -0800 | [diff] [blame] | 29 | return SkISize::Make(860, 700); |
| 30 | } |
| 31 | |
| 32 | void flower(SkCanvas* canvas, const SkPath& path, SkScalar intervals[2], SkPaint::Join join) { |
| 33 | SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0); |
| 34 | |
| 35 | SkPaint paint; |
| 36 | paint.setAntiAlias(true); |
| 37 | paint.setStyle(SkPaint::kStroke_Style); |
| 38 | paint.setStrokeJoin(join); |
| 39 | paint.setStrokeWidth(42); |
| 40 | canvas->drawPath(path, paint); |
| 41 | |
| 42 | paint.setColor(SK_ColorRED); |
| 43 | paint.setStrokeWidth(21); |
| 44 | paint.setPathEffect(pe)->unref(); |
| 45 | canvas->drawPath(path, paint); |
| 46 | |
| 47 | paint.setColor(SK_ColorGREEN); |
| 48 | paint.setPathEffect(NULL); |
| 49 | paint.setStrokeWidth(0); |
| 50 | canvas->drawPath(path, paint); |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 51 | } |
| 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 250,212" |
| 56 | "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231" |
| 57 | "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250" |
| 58 | "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269" |
| 59 | "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288" |
| 60 | "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269" |
| 61 | "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250" |
| 62 | "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231" |
| 63 | "C 283,231 344,195 338,98"; |
| 64 | |
| 65 | SkParsePath::FromSVGString(d, &path); |
caryclark | 6df8e34 | 2015-02-23 12:47:03 -0800 | [diff] [blame] | 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 : SkPaint::kRound_Join); |
| 73 | canvas->restore(); |
| 74 | } |
| 75 | } |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | private: |
| 79 | typedef GM INHERITED; |
| 80 | }; |
| 81 | |
| 82 | ////////////////////////////////////////////////////////////////////////////// |
| 83 | |
| 84 | static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; } |
| 85 | static skiagm::GMRegistry reg(MyFactory); |