2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
11 #include "SkDashPathEffect.h"
13 static SkPath generate_square(SkScalar cx, SkScalar cy, SkScalar w) {
14 SkRect rect = SkRect::MakeXYWH(cx - w / 2, cy - w / 2, w, w);
20 static SkPath generate_rect_line(SkScalar cx, SkScalar cy, SkScalar l) {
21 SkRect rect = SkRect::MakeXYWH(cx - l / 2, cy, l, 0);
27 static SkPath generate_circle(SkScalar cx, SkScalar cy, SkScalar d) {
29 path.addCircle(cx, cy, d/2, SkPath::kCW_Direction);
33 static SkPath generate_line(SkScalar cx, SkScalar cy, SkScalar l) {
35 path.moveTo(cx - l / 2, cy);
36 path.lineTo(cx + l / 2, cy);
42 Style(SkPaint::Style paintStyle, sk_sp<SkPathEffect> pe = sk_sp<SkPathEffect>())
43 : fPaintStyle(paintStyle)
44 , fPathEffect(std::move(pe)) {}
45 SkPaint::Style fPaintStyle;
46 sk_sp<SkPathEffect> fPathEffect;
49 sk_sp<SkPathEffect> make_dash() {
50 constexpr SkScalar kIntervals[] = { 4.f, 3.f };
51 return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), 0);
55 {SkPaint::kStroke_Style},
56 {SkPaint::kStrokeAndFill_Style},
57 {SkPaint::kFill_Style},
58 {SkPaint::kStroke_Style, make_dash()},
61 SkScalar pathSizes[] = {
66 SkScalar strokeWidths[] = {
70 SkPath ((*paths[])(SkScalar, SkScalar, SkScalar)) = {
77 const SkScalar slideWidth = 90, slideHeight = 90;
78 const SkScalar slideBoundary = 5;
82 DEF_SIMPLE_GM(inverse_paths, canvas, 800, 1200) {
83 SkScalar cx = slideWidth / 2 + slideBoundary;
84 SkScalar cy = slideHeight / 2 + slideBoundary;
85 SkScalar dx = slideWidth + 2 * slideBoundary;
86 SkScalar dy = slideHeight + 2 * slideBoundary;
88 SkRect clipRect = SkRect::MakeLTRB(slideBoundary, slideBoundary,
89 slideBoundary + slideWidth,
90 slideBoundary + slideHeight);
92 clipPaint.setStyle(SkPaint::kStroke_Style);
93 clipPaint.setStrokeWidth(SkIntToScalar(2));
96 outlinePaint.setColor(0x40000000);
97 outlinePaint.setStyle(SkPaint::kStroke_Style);
98 outlinePaint.setStrokeWidth(SkIntToScalar(0));
100 for (size_t styleIndex = 0; styleIndex < SK_ARRAY_COUNT(styles);
102 for (size_t sizeIndex = 0; sizeIndex < SK_ARRAY_COUNT(pathSizes);
104 SkScalar size = pathSizes[sizeIndex];
108 for (size_t widthIndex = 0;
109 widthIndex < SK_ARRAY_COUNT(strokeWidths);
112 paint.setColor(0xff007000);
113 paint.setStrokeWidth(strokeWidths[widthIndex]);
114 paint.setStyle(styles[styleIndex].fPaintStyle);
115 paint.setPathEffect(styles[styleIndex].fPathEffect);
117 for (size_t pathIndex = 0;
118 pathIndex < SK_ARRAY_COUNT(paths);
120 canvas->drawRect(clipRect, clipPaint);
123 canvas->clipRect(clipRect);
125 SkPath path = paths[pathIndex](cx, cy, size);
126 path.setFillType(SkPath::kInverseWinding_FillType);
127 canvas->drawPath(path, paint);
129 path.setFillType(SkPath::kWinding_FillType);
130 canvas->drawPath(path, outlinePaint);
133 canvas->translate(dx, 0);
137 canvas->translate(0, dy);