2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "sk_tool_utils.h"
17 class QuadPathGM : public GM {
23 SkString onShortName() override {
24 return SkString("quadpath");
27 SkISize onISize() override { return SkISize::Make(1240, 390); }
29 void drawPath(SkPath& path,SkCanvas* canvas,SkColor color,
30 const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join,
31 SkPaint::Style style, SkPath::FillType fill,
32 SkScalar strokeWidth) {
33 path.setFillType(fill);
35 paint.setStrokeCap(cap);
36 paint.setStrokeWidth(strokeWidth);
37 paint.setStrokeJoin(join);
38 paint.setColor(color);
39 paint.setStyle(style);
41 canvas->clipRect(clip);
42 canvas->drawPath(path, paint);
46 void onDraw(SkCanvas* canvas) override {
48 SkPath::FillType fFill;
51 constexpr FillAndName gFills[] = {
52 {SkPath::kWinding_FillType, "Winding"},
53 {SkPath::kEvenOdd_FillType, "Even / Odd"},
54 {SkPath::kInverseWinding_FillType, "Inverse Winding"},
55 {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"},
58 SkPaint::Style fStyle;
61 constexpr StyleAndName gStyles[] = {
62 {SkPaint::kFill_Style, "Fill"},
63 {SkPaint::kStroke_Style, "Stroke"},
64 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"},
71 constexpr CapAndName gCaps[] = {
72 {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"},
73 {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"},
74 {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"}
81 path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1);
82 path.fPath.quadTo(50*SK_Scalar1, 20*SK_Scalar1,
83 75*SK_Scalar1, 10*SK_Scalar1);
84 path.fName = "moveTo-quad";
87 titlePaint.setColor(SK_ColorBLACK);
88 titlePaint.setAntiAlias(true);
89 sk_tool_utils::set_portable_typeface(&titlePaint);
90 titlePaint.setTextSize(15 * SK_Scalar1);
91 const char title[] = "Quad Drawn Into Rectangle Clips With "
92 "Indicated Style, Fill and Linecaps, with stroke width 10";
93 canvas->drawString(title,
99 SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1);
101 canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1);
103 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) {
105 canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0);
108 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) {
110 canvas->translate(0, rect.height() + 40 * SK_Scalar1);
113 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) {
115 canvas->translate(rect.width() + 40 * SK_Scalar1, 0);
118 SkColor color = sk_tool_utils::color_to_565(0xff007000);
119 this->drawPath(path.fPath, canvas, color, rect,
120 gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle,
121 gFills[fill].fFill, SK_Scalar1*10);
124 rectPaint.setColor(SK_ColorBLACK);
125 rectPaint.setStyle(SkPaint::kStroke_Style);
126 rectPaint.setStrokeWidth(-1);
127 rectPaint.setAntiAlias(true);
128 canvas->drawRect(rect, rectPaint);
131 labelPaint.setColor(color);
132 labelPaint.setAntiAlias(true);
133 sk_tool_utils::set_portable_typeface(&labelPaint);
134 labelPaint.setTextSize(10 * SK_Scalar1);
135 canvas->drawString(gStyles[style].fName,
136 0, rect.height() + 12 * SK_Scalar1,
138 canvas->drawString(gFills[fill].fName,
139 0, rect.height() + 24 * SK_Scalar1,
141 canvas->drawString(gCaps[cap].fName,
142 0, rect.height() + 36 * SK_Scalar1,
154 typedef GM INHERITED;
157 class QuadClosePathGM : public GM {
163 SkString onShortName() override {
164 return SkString("quadclosepath");
167 SkISize onISize() override { return SkISize::Make(1240, 390); }
169 void drawPath(SkPath& path,SkCanvas* canvas,SkColor color,
170 const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join,
171 SkPaint::Style style, SkPath::FillType fill,
172 SkScalar strokeWidth) {
173 path.setFillType(fill);
175 paint.setStrokeCap(cap);
176 paint.setStrokeWidth(strokeWidth);
177 paint.setStrokeJoin(join);
178 paint.setColor(color);
179 paint.setStyle(style);
181 canvas->clipRect(clip);
182 canvas->drawPath(path, paint);
186 void onDraw(SkCanvas* canvas) override {
188 SkPath::FillType fFill;
191 constexpr FillAndName gFills[] = {
192 {SkPath::kWinding_FillType, "Winding"},
193 {SkPath::kEvenOdd_FillType, "Even / Odd"},
194 {SkPath::kInverseWinding_FillType, "Inverse Winding"},
195 {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"},
197 struct StyleAndName {
198 SkPaint::Style fStyle;
201 constexpr StyleAndName gStyles[] = {
202 {SkPaint::kFill_Style, "Fill"},
203 {SkPaint::kStroke_Style, "Stroke"},
204 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"},
211 constexpr CapAndName gCaps[] = {
212 {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"},
213 {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"},
214 {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"}
221 path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1);
222 path.fPath.quadTo(50*SK_Scalar1, 20*SK_Scalar1,
223 75*SK_Scalar1, 10*SK_Scalar1);
225 path.fName = "moveTo-quad-close";
228 titlePaint.setColor(SK_ColorBLACK);
229 titlePaint.setAntiAlias(true);
230 sk_tool_utils::set_portable_typeface(&titlePaint);
231 titlePaint.setTextSize(15 * SK_Scalar1);
232 const char title[] = "Quad Closed Drawn Into Rectangle Clips With "
233 "Indicated Style, Fill and Linecaps, with stroke width 10";
234 canvas->drawString(title,
240 SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1);
242 canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1);
244 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) {
246 canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0);
249 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) {
251 canvas->translate(0, rect.height() + 40 * SK_Scalar1);
254 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) {
256 canvas->translate(rect.width() + 40 * SK_Scalar1, 0);
259 SkColor color = sk_tool_utils::color_to_565(0xff007000);
260 this->drawPath(path.fPath, canvas, color, rect,
261 gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle,
262 gFills[fill].fFill, SK_Scalar1*10);
265 rectPaint.setColor(SK_ColorBLACK);
266 rectPaint.setStyle(SkPaint::kStroke_Style);
267 rectPaint.setStrokeWidth(-1);
268 rectPaint.setAntiAlias(true);
269 canvas->drawRect(rect, rectPaint);
272 labelPaint.setColor(color);
273 labelPaint.setAntiAlias(true);
274 sk_tool_utils::set_portable_typeface(&labelPaint);
275 labelPaint.setTextSize(10 * SK_Scalar1);
276 canvas->drawString(gStyles[style].fName,
277 0, rect.height() + 12 * SK_Scalar1,
279 canvas->drawString(gFills[fill].fName,
280 0, rect.height() + 24 * SK_Scalar1,
282 canvas->drawString(gCaps[cap].fName,
283 0, rect.height() + 36 * SK_Scalar1,
295 typedef GM INHERITED;
298 //////////////////////////////////////////////////////////////////////////////
300 static GM* QuadPathFactory(void*) { return new QuadPathGM; }
301 static GMRegistry regQuadPath(QuadPathFactory);
303 static GM* QuadClosePathFactory(void*) { return new QuadClosePathGM; }
304 static GMRegistry regQuadClosePath(QuadClosePathFactory);