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.
14 class QuadPathGM : public GM {
19 virtual uint32_t onGetFlags() const SK_OVERRIDE {
20 return kSkipTiled_Flag;
23 SkString onShortName() {
24 return SkString("quadpath");
27 SkISize onISize() { 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 virtual void onDraw(SkCanvas* canvas) {
48 SkPath::FillType fFill;
51 static const 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 static const StyleAndName gStyles[] = {
62 {SkPaint::kFill_Style, "Fill"},
63 {SkPaint::kStroke_Style, "Stroke"},
64 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"},
71 static const 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.setLCDRenderText(true);
91 titlePaint.setTextSize(15 * SK_Scalar1);
92 const char title[] = "Quad Drawn Into Rectangle Clips With "
93 "Indicated Style, Fill and Linecaps, with stroke width 10";
94 canvas->drawText(title, strlen(title),
100 SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1);
102 canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1);
104 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) {
106 canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0);
109 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) {
111 canvas->translate(0, rect.height() + 40 * SK_Scalar1);
114 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) {
116 canvas->translate(rect.width() + 40 * SK_Scalar1, 0);
119 SkColor color = 0xff007000;
120 this->drawPath(path.fPath, canvas, color, rect,
121 gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle,
122 gFills[fill].fFill, SK_Scalar1*10);
125 rectPaint.setColor(SK_ColorBLACK);
126 rectPaint.setStyle(SkPaint::kStroke_Style);
127 rectPaint.setStrokeWidth(-1);
128 rectPaint.setAntiAlias(true);
129 canvas->drawRect(rect, rectPaint);
132 labelPaint.setColor(color);
133 labelPaint.setAntiAlias(true);
134 sk_tool_utils::set_portable_typeface(&labelPaint);
135 labelPaint.setLCDRenderText(true);
136 labelPaint.setTextSize(10 * SK_Scalar1);
137 canvas->drawText(gStyles[style].fName,
138 strlen(gStyles[style].fName),
139 0, rect.height() + 12 * SK_Scalar1,
141 canvas->drawText(gFills[fill].fName,
142 strlen(gFills[fill].fName),
143 0, rect.height() + 24 * SK_Scalar1,
145 canvas->drawText(gCaps[cap].fName,
146 strlen(gCaps[cap].fName),
147 0, rect.height() + 36 * SK_Scalar1,
159 typedef GM INHERITED;
162 class QuadClosePathGM : public GM {
167 virtual uint32_t onGetFlags() const SK_OVERRIDE {
168 return kSkipTiled_Flag;
171 SkString onShortName() {
172 return SkString("quadclosepath");
175 SkISize onISize() { return SkISize::Make(1240, 390); }
177 void drawPath(SkPath& path,SkCanvas* canvas,SkColor color,
178 const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join,
179 SkPaint::Style style, SkPath::FillType fill,
180 SkScalar strokeWidth) {
181 path.setFillType(fill);
183 paint.setStrokeCap(cap);
184 paint.setStrokeWidth(strokeWidth);
185 paint.setStrokeJoin(join);
186 paint.setColor(color);
187 paint.setStyle(style);
189 canvas->clipRect(clip);
190 canvas->drawPath(path, paint);
194 virtual void onDraw(SkCanvas* canvas) {
196 SkPath::FillType fFill;
199 static const FillAndName gFills[] = {
200 {SkPath::kWinding_FillType, "Winding"},
201 {SkPath::kEvenOdd_FillType, "Even / Odd"},
202 {SkPath::kInverseWinding_FillType, "Inverse Winding"},
203 {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"},
205 struct StyleAndName {
206 SkPaint::Style fStyle;
209 static const StyleAndName gStyles[] = {
210 {SkPaint::kFill_Style, "Fill"},
211 {SkPaint::kStroke_Style, "Stroke"},
212 {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"},
219 static const CapAndName gCaps[] = {
220 {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"},
221 {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"},
222 {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"}
229 path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1);
230 path.fPath.quadTo(50*SK_Scalar1, 20*SK_Scalar1,
231 75*SK_Scalar1, 10*SK_Scalar1);
233 path.fName = "moveTo-quad-close";
236 titlePaint.setColor(SK_ColorBLACK);
237 titlePaint.setAntiAlias(true);
238 sk_tool_utils::set_portable_typeface(&titlePaint);
239 titlePaint.setLCDRenderText(true);
240 titlePaint.setTextSize(15 * SK_Scalar1);
241 const char title[] = "Quad Closed Drawn Into Rectangle Clips With "
242 "Indicated Style, Fill and Linecaps, with stroke width 10";
243 canvas->drawText(title, strlen(title),
249 SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1);
251 canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1);
253 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) {
255 canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0);
258 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) {
260 canvas->translate(0, rect.height() + 40 * SK_Scalar1);
263 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) {
265 canvas->translate(rect.width() + 40 * SK_Scalar1, 0);
268 SkColor color = 0xff007000;
269 this->drawPath(path.fPath, canvas, color, rect,
270 gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle,
271 gFills[fill].fFill, SK_Scalar1*10);
274 rectPaint.setColor(SK_ColorBLACK);
275 rectPaint.setStyle(SkPaint::kStroke_Style);
276 rectPaint.setStrokeWidth(-1);
277 rectPaint.setAntiAlias(true);
278 canvas->drawRect(rect, rectPaint);
281 labelPaint.setColor(color);
282 labelPaint.setAntiAlias(true);
283 sk_tool_utils::set_portable_typeface(&labelPaint);
284 labelPaint.setLCDRenderText(true);
285 labelPaint.setTextSize(10 * SK_Scalar1);
286 canvas->drawText(gStyles[style].fName,
287 strlen(gStyles[style].fName),
288 0, rect.height() + 12 * SK_Scalar1,
290 canvas->drawText(gFills[fill].fName,
291 strlen(gFills[fill].fName),
292 0, rect.height() + 24 * SK_Scalar1,
294 canvas->drawText(gCaps[cap].fName,
295 strlen(gCaps[cap].fName),
296 0, rect.height() + 36 * SK_Scalar1,
308 typedef GM INHERITED;
311 //////////////////////////////////////////////////////////////////////////////
313 static GM* QuadPathFactory(void*) { return new QuadPathGM; }
314 static GMRegistry regQuadPath(QuadPathFactory);
316 static GM* QuadClosePathFactory(void*) { return new QuadClosePathGM; }
317 static GMRegistry regQuadClosePath(QuadClosePathFactory);