caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPath.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 13 | #include "include/core/SkPathEffect.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkTypes.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 16 | #include "include/effects/SkDashPathEffect.h" |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 17 | |
| 18 | DEF_SIMPLE_GM(bug530095, canvas, 900, 1200) { |
Mike Reed | 92f6eb1 | 2020-08-25 11:48:41 -0400 | [diff] [blame] | 19 | SkPath path1 = SkPath::Circle(200, 200, 124), |
| 20 | path2 = SkPath::Circle(2, 2, 1.24f); |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 21 | |
| 22 | SkPaint paint; |
| 23 | paint.setAntiAlias(true); |
| 24 | paint.setStyle(SkPaint::kStroke_Style); |
| 25 | paint.setStrokeWidth(26); |
| 26 | SkScalar intervals[] = {700, 700 }; |
| 27 | int intervalCount = (int) SK_ARRAY_COUNT(intervals); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 28 | paint.setPathEffect(SkDashPathEffect::Make(intervals, intervalCount, -40)); |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 29 | canvas->drawPath(path1, paint); |
| 30 | |
| 31 | paint.setStrokeWidth(0.26f); |
| 32 | SkScalar smIntervals[] = {7, 7 }; |
| 33 | int smIntervalCount = (int) SK_ARRAY_COUNT(smIntervals); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 34 | paint.setPathEffect(SkDashPathEffect::Make(smIntervals, smIntervalCount, -0.40f)); |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 35 | canvas->save(); |
| 36 | canvas->scale(100, 100); |
| 37 | canvas->translate(4, 0); |
| 38 | canvas->drawPath(path2, paint); |
| 39 | canvas->restore(); |
| 40 | |
| 41 | paint.setStrokeWidth(26); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 42 | paint.setPathEffect(SkDashPathEffect::Make(intervals, intervalCount, 0)); |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 43 | canvas->save(); |
| 44 | canvas->translate(0, 400); |
| 45 | canvas->drawPath(path1, paint); |
| 46 | canvas->restore(); |
| 47 | |
| 48 | paint.setStrokeWidth(0.26f); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 49 | paint.setPathEffect(SkDashPathEffect::Make(smIntervals, smIntervalCount, 0)); |
caryclark | 1a7eb26 | 2016-01-21 07:07:02 -0800 | [diff] [blame] | 50 | canvas->scale(100, 100); |
| 51 | canvas->translate(4, 4); |
| 52 | canvas->drawPath(path2, paint); |
| 53 | } |
caryclark | d3cfd94 | 2016-03-17 05:33:28 -0700 | [diff] [blame] | 54 | |
| 55 | DEF_SIMPLE_GM(bug591993, canvas, 40, 140) { |
| 56 | SkPaint p; |
| 57 | p.setColor(SK_ColorRED); |
| 58 | p.setAntiAlias(true); |
| 59 | p.setStyle(SkPaint::kStroke_Style); |
| 60 | p.setStrokeCap(SkPaint::kRound_Cap); |
| 61 | p.setStrokeWidth(10); |
reed | a439334 | 2016-03-18 11:22:57 -0700 | [diff] [blame] | 62 | const SkScalar intervals[] = { 100, 100 }; |
| 63 | p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 100)); |
caryclark | d3cfd94 | 2016-03-17 05:33:28 -0700 | [diff] [blame] | 64 | canvas->drawLine(20, 20, 120, 20, p); |
| 65 | } |