Debian Codegraph @

gm/pathcontourstart.cpp

raw
1 /*
2 * Copyright 2015 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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkPaint.h"
11 #include "include/core/SkPath.h"
12 #include "include/core/SkPathEffect.h"
13 #include "include/core/SkPoint.h"
14 #include "include/core/SkRRect.h"
15 #include "include/core/SkRect.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkSize.h"
18 #include "include/core/SkString.h"
19 #include "include/effects/SkDashPathEffect.h"
20 #include "include/private/base/SkTArray.h"
21 #include "include/private/base/SkTemplates.h"
22
23 using namespace skia_private;
24
25 namespace skiagm {
26
27 class ContourStartGM : public GM {
28 protected:
29 void onOnceBeforeDraw() override {
30 const SkScalar kMaxDashLen = 100;
31 const SkScalar kDashGrowth = 1.2f;
32
33 STArray<100, SkScalar> intervals;
34 for (SkScalar len = 1; len < kMaxDashLen; len *= kDashGrowth) {
35 intervals.push_back(len);
36 intervals.push_back(len);
37 }
38
39 fDashPaint.setAntiAlias(true);
40 fDashPaint.setStyle(SkPaint::kStroke_Style);
41 fDashPaint.setStrokeWidth(6);
42 fDashPaint.setColor(0xff008000);
43 fDashPaint.setPathEffect(SkDashPathEffect::Make(intervals, 0));
44
45 fPointsPaint.setColor(0xff800000);
46 fPointsPaint.setStrokeWidth(3);
47
48 fRect = SkRect::MakeLTRB(10, 10, 100, 70);
49 }
50
51 SkString getName() const override { return SkString("contour_start"); }
52
53 SkISize getISize() override { return SkISize::Make(kImageWidth, kImageHeight); }
54
55 void onDraw(SkCanvas* canvas) override {
56
57 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
58 return SkPath::Rect(rect, dir, startIndex);
59 });
60
61 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
62 return SkPath::Oval(rect, dir, startIndex);
63 });
64
65 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
66 SkRRect rrect;
67 const SkVector radii[4] = { {15, 15}, {15, 15}, {15, 15}, {15, 15}};
68 rrect.setRectRadii(rect, radii);
69 return SkPath::RRect(rrect, dir, startIndex);
70 });
71
72 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
73 SkRRect rrect;
74 rrect.setRect(rect);
75 return SkPath::RRect(rrect, dir, startIndex);
76 });
77
78 drawDirs(canvas, [](const SkRect& rect, SkPathDirection dir, unsigned startIndex) {
79 SkRRect rrect;
80 rrect.setOval(rect);
81 return SkPath::RRect(rrect, dir, startIndex);
82 });
83
84 }
85
86 private:
87 inline static constexpr int kImageWidth = 1200;
88 inline static constexpr int kImageHeight = 600;
89
90 SkPaint fDashPaint, fPointsPaint;
91 SkRect fRect;
92
93 void drawDirs(SkCanvas* canvas,
94 SkPath (*makePath)(const SkRect&, SkPathDirection, unsigned)) const {
95 drawOneColumn(canvas, SkPathDirection::kCW, makePath);
96 canvas->translate(kImageWidth / 10, 0);
97 drawOneColumn(canvas, SkPathDirection::kCCW, makePath);
98 canvas->translate(kImageWidth / 10, 0);
99 }
100
101 void drawOneColumn(SkCanvas* canvas, SkPathDirection dir,
102 SkPath (*makePath)(const SkRect&, SkPathDirection, unsigned)) const {
103 SkAutoCanvasRestore acr(canvas, true);
104
105 for (unsigned i = 0; i < 8; ++i) {
106 const SkPath path = makePath(fRect, dir, i);
107 canvas->drawPath(path, fDashPaint);
108 canvas->drawPoints(SkCanvas::kPoints_PointMode, path.points(), fPointsPaint);
109
110 canvas->translate(0, kImageHeight / 8);
111 }
112 }
113
114 using INHERITED = GM;
115 };
116
117 DEF_GM( return new ContourStartGM(); )
118
119 } // namespace skiagm