2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkDashPathEffect.h"
17 class ContourStartGM : public GM {
20 const SkScalar kMaxDashLen = 100;
21 const SkScalar kDashGrowth = 1.2f;
23 SkSTArray<100, SkScalar> intervals;
24 for (SkScalar len = 1; len < kMaxDashLen; len *= kDashGrowth) {
25 intervals.push_back(len);
26 intervals.push_back(len);
29 fDashPaint.setAntiAlias(true);
30 fDashPaint.setStyle(SkPaint::kStroke_Style);
31 fDashPaint.setStrokeWidth(6);
32 fDashPaint.setColor(0xff008000);
33 fDashPaint.setPathEffect(SkDashPathEffect::Make(intervals.begin(), intervals.count(), 0));
35 fPointsPaint.setColor(0xff800000);
36 fPointsPaint.setStrokeWidth(3);
38 fRect = SkRect::MakeLTRB(10, 10, 100, 70);
42 SkString onShortName() override {
43 return SkString("contour_start");
46 SkISize onISize() override { return SkISize::Make(kImageWidth, kImageHeight); }
48 void onDraw(SkCanvas* canvas) override {
50 drawDirs(canvas, [](const SkRect& rect, SkPath::Direction dir, unsigned startIndex) {
52 path.addRect(rect, dir, startIndex);
56 drawDirs(canvas, [](const SkRect& rect, SkPath::Direction dir, unsigned startIndex) {
58 path.addOval(rect, dir, startIndex);
62 drawDirs(canvas, [](const SkRect& rect, SkPath::Direction dir, unsigned startIndex) {
64 const SkVector radii[4] = { {15, 15}, {15, 15}, {15, 15}, {15, 15}};
65 rrect.setRectRadii(rect, radii);
68 path.addRRect(rrect, dir, startIndex);
72 drawDirs(canvas, [](const SkRect& rect, SkPath::Direction dir, unsigned startIndex) {
77 path.addRRect(rrect, dir, startIndex);
81 drawDirs(canvas, [](const SkRect& rect, SkPath::Direction dir, unsigned startIndex) {
86 path.addRRect(rrect, dir, startIndex);
93 static constexpr int kImageWidth = 1200;
94 static constexpr int kImageHeight = 600;
96 SkPaint fDashPaint, fPointsPaint;
99 void drawDirs(SkCanvas* canvas,
100 SkPath (*makePath)(const SkRect&, SkPath::Direction, unsigned)) const {
101 drawOneColumn(canvas, SkPath::kCW_Direction, makePath);
102 canvas->translate(kImageWidth / 10, 0);
103 drawOneColumn(canvas, SkPath::kCCW_Direction, makePath);
104 canvas->translate(kImageWidth / 10, 0);
107 void drawOneColumn(SkCanvas* canvas, SkPath::Direction dir,
108 SkPath (*makePath)(const SkRect&, SkPath::Direction, unsigned)) const {
109 SkAutoCanvasRestore acr(canvas, true);
111 for (unsigned i = 0; i < 8; ++i) {
112 const SkPath path = makePath(fRect, dir, i);
113 canvas->drawPath(path, fDashPaint);
115 const int n = path.countPoints();
116 SkAutoTArray<SkPoint> points(n);
117 path.getPoints(points.get(), n);
118 canvas->drawPoints(SkCanvas::kPoints_PointMode, n, points.get(), fPointsPaint);
120 canvas->translate(0, kImageHeight / 8);
124 typedef GM INHERITED;
127 DEF_GM( return new ContourStartGM(); )
129 } // namespace skiagm