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 | */ |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 17 | static void flower(SkCanvas* canvas, const SkPath& path, SkScalar intervals[2], |
| 18 | SkPaint::Join join) { |
| 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); |
caryclark | 6df8e34 | 2015-02-23 12:47:03 -0800 | [diff] [blame] | 25 | |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 26 | paint.setColor(SK_ColorRED); |
| 27 | paint.setStrokeWidth(21); |
| 28 | paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 0)); |
| 29 | canvas->drawPath(path, paint); |
caryclark | 6df8e34 | 2015-02-23 12:47:03 -0800 | [diff] [blame] | 30 | |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 31 | paint.setColor(SK_ColorGREEN); |
| 32 | paint.setPathEffect(nullptr); |
| 33 | paint.setStrokeWidth(0); |
| 34 | canvas->drawPath(path, paint); |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 35 | } |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 36 | |
reed | 6dc14aa | 2016-04-11 07:46:38 -0700 | [diff] [blame] | 37 | DEF_SIMPLE_GM(dashcubics, canvas, 865, 750) { |
reed@google.com | 8d850be | 2012-07-13 15:55:15 +0000 | [diff] [blame] | 38 | SkPath path; |
| 39 | const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212" |
| 40 | "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231" |
| 41 | "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250" |
| 42 | "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269" |
| 43 | "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288" |
| 44 | "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269" |
| 45 | "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250" |
| 46 | "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231" |
| 47 | "C 283,231 344,195 338,98"; |
| 48 | |
| 49 | SkParsePath::FromSVGString(d, &path); |
caryclark | 6df8e34 | 2015-02-23 12:47:03 -0800 | [diff] [blame] | 50 | canvas->translate(-35.f, -55.f); |
| 51 | for (int x = 0; x < 2; ++x) { |
| 52 | for (int y = 0; y < 2; ++y) { |
| 53 | canvas->save(); |
| 54 | canvas->translate(x * 430.f, y * 355.f); |
| 55 | SkScalar intervals[] = { 5 + (x ? 0 : 0.0001f + 0.0001f), 10 }; |
| 56 | flower(canvas, path, intervals, y ? SkPaint::kDefault_Join : SkPaint::kRound_Join); |
| 57 | canvas->restore(); |
| 58 | } |
| 59 | } |
halcanary | 2a24338 | 2015-09-09 08:16:41 -0700 | [diff] [blame] | 60 | } |
Mike Reed | 4123223 | 2018-03-07 17:02:47 -0500 | [diff] [blame^] | 61 | |
| 62 | #include "SkTrimPathEffect.h" |
| 63 | class TrimGM : public skiagm::GM { |
| 64 | public: |
| 65 | TrimGM() {} |
| 66 | |
| 67 | protected: |
| 68 | SkString onShortName() override { return SkString("trimpatheffect"); } |
| 69 | |
| 70 | SkISize onISize() override { return SkISize::Make(1240, 390); } |
| 71 | |
| 72 | void onDraw(SkCanvas* canvas) override { |
| 73 | SkPaint paint; |
| 74 | paint.setPathEffect(SkTrimPathEffect::Make(0.25 + fOffset, 0.75)); |
| 75 | paint.setStyle(SkPaint::kStroke_Style); |
| 76 | paint.setAntiAlias(true); |
| 77 | paint.setStrokeWidth(10); |
| 78 | |
| 79 | SkPath path; |
| 80 | path.moveTo(50, 300); |
| 81 | path.cubicTo(100, 50, 150, 550, 200, 300); |
| 82 | |
| 83 | paint.setColor(0xFF888888); |
| 84 | canvas->drawPath(path, paint); |
| 85 | paint.setPathEffect(nullptr); |
| 86 | paint.setStrokeWidth(0); |
| 87 | paint.setColor(0xFF000000); |
| 88 | canvas->drawPath(path, paint); |
| 89 | } |
| 90 | |
| 91 | bool onAnimate(const SkAnimTimer&) override { |
| 92 | // fOffset += 1; |
| 93 | return true; |
| 94 | } |
| 95 | private: |
| 96 | SkScalar fOffset = 0; |
| 97 | typedef skiagm::GM INHERITED; |
| 98 | }; |
| 99 | DEF_GM(return new TrimGM;) |
| 100 | |