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 | virtual uint32_t onGetFlags() const SK_OVERRIDE { |
| 24 | return kSkipTiled_Flag; |
| 25 | } |
| 26 | |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 27 | virtual SkString onShortName() { |
| 28 | return SkString("dashcubics"); |
| 29 | } |
| 30 | |
| 31 | virtual SkISize onISize() { |
| 32 | return SkISize::Make(640, 480); |
| 33 | } |
| 34 | |
| 35 | virtual void onDraw(SkCanvas* canvas) { |
| 36 | SkPath path; |
| 37 | const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212" |
| 38 | "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231" |
| 39 | "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250" |
| 40 | "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269" |
| 41 | "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288" |
| 42 | "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269" |
| 43 | "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250" |
| 44 | "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231" |
| 45 | "C 283,231 344,195 338,98"; |
| 46 | |
| 47 | SkParsePath::FromSVGString(d, &path); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 48 | |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 49 | SkScalar intervals[] = { 5, 10 }; |
commit-bot@chromium.org | 0a2bf90 | 2014-02-20 20:40:19 +0000 | [diff] [blame] | 50 | SkPathEffect* pe = SkDashPathEffect::Create(intervals, 2, 0); |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 51 | |
| 52 | SkPaint paint; |
| 53 | paint.setAntiAlias(true); |
| 54 | paint.setStyle(SkPaint::kStroke_Style); |
| 55 | |
| 56 | paint.setStrokeWidth(42); |
| 57 | canvas->drawPath(path, paint); |
| 58 | |
| 59 | paint.setColor(SK_ColorRED); |
| 60 | paint.setStrokeWidth(21); |
| 61 | paint.setPathEffect(pe)->unref(); |
| 62 | canvas->drawPath(path, paint); |
| 63 | |
| 64 | paint.setColor(SK_ColorGREEN); |
| 65 | paint.setPathEffect(NULL); |
| 66 | paint.setStrokeWidth(0); |
| 67 | canvas->drawPath(path, paint); |
| 68 | } |
| 69 | |
| 70 | private: |
| 71 | typedef GM INHERITED; |
| 72 | }; |
| 73 | |
| 74 | ////////////////////////////////////////////////////////////////////////////// |
| 75 | |
| 76 | static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; } |
| 77 | static skiagm::GMRegistry reg(MyFactory); |