| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | #include "gm.h" |
| 8 | #include "SkCanvas.h" |
| 9 | #include "SkPaint.h" |
| 10 | #include "SkRandom.h" |
| 11 | |
| 12 | namespace skiagm { |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 13 | class ZeroCubicPathGM : public GM { |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 14 | public: |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 15 | ZeroCubicPathGM() {} |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 16 | |
| 17 | protected: |
| 18 | SkString onShortName() { |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 19 | return SkString("zerocubicpath"); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 22 | SkISize onISize() { return make_isize(1240, 390); } |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 23 | |
| 24 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 25 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 26 | SkPaint::Style style, SkPath::FillType fill, |
| 27 | SkScalar strokeWidth) { |
| 28 | path.setFillType(fill); |
| 29 | SkPaint paint; |
| 30 | paint.setStrokeCap(cap); |
| 31 | paint.setStrokeWidth(strokeWidth); |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 32 | paint.setStrokeJoin(join); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 33 | paint.setColor(color); |
| 34 | paint.setStyle(style); |
| 35 | canvas->save(); |
| 36 | canvas->clipRect(clip); |
| 37 | canvas->drawPath(path, paint); |
| 38 | canvas->restore(); |
| 39 | } |
| 40 | |
| 41 | virtual void onDraw(SkCanvas* canvas) { |
| 42 | struct FillAndName { |
| 43 | SkPath::FillType fFill; |
| 44 | const char* fName; |
| 45 | }; |
| 46 | static const FillAndName gFills[] = { |
| 47 | {SkPath::kWinding_FillType, "Winding"}, |
| 48 | {SkPath::kEvenOdd_FillType, "Even / Odd"}, |
| 49 | {SkPath::kInverseWinding_FillType, "Inverse Winding"}, |
| 50 | {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, |
| 51 | }; |
| 52 | struct StyleAndName { |
| 53 | SkPaint::Style fStyle; |
| 54 | const char* fName; |
| 55 | }; |
| 56 | static const StyleAndName gStyles[] = { |
| 57 | {SkPaint::kFill_Style, "Fill"}, |
| 58 | {SkPaint::kStroke_Style, "Stroke"}, |
| 59 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 60 | }; |
| 61 | struct CapAndName { |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 62 | SkPaint::Cap fCap; |
| 63 | SkPaint::Join fJoin; |
| 64 | const char* fName; |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 65 | }; |
| 66 | static const CapAndName gCaps[] = { |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 67 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 68 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 69 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 70 | }; |
| 71 | struct PathAndName { |
| 72 | SkPath fPath; |
| 73 | const char* fName; |
| 74 | }; |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 75 | PathAndName path; |
| 76 | path.fPath.moveTo(50*SK_Scalar1, 15*SK_Scalar1); |
| 77 | path.fPath.cubicTo(50*SK_Scalar1, 15*SK_Scalar1, |
| 78 | 50*SK_Scalar1, 15*SK_Scalar1, |
| 79 | 50*SK_Scalar1, 15*SK_Scalar1); |
| 80 | path.fName = "moveTo-zerocubic"; |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 81 | |
| 82 | SkPaint titlePaint; |
| 83 | titlePaint.setColor(SK_ColorBLACK); |
| 84 | titlePaint.setAntiAlias(true); |
| 85 | titlePaint.setLCDRenderText(true); |
| 86 | titlePaint.setTextSize(15 * SK_Scalar1); |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 87 | const char title[] = "Zero-Length Cubic Drawn Into Rectangle Clips With " |
| 88 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 89 | canvas->drawText(title, strlen(title), |
| 90 | 20 * SK_Scalar1, |
| 91 | 20 * SK_Scalar1, |
| 92 | titlePaint); |
| 93 | |
| 94 | SkRandom rand; |
| 95 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 96 | canvas->save(); |
| 97 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 98 | canvas->save(); |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 99 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 100 | if (0 < cap) { |
| 101 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 102 | } |
| 103 | canvas->save(); |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 104 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 105 | if (0 < fill) { |
| 106 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 107 | } |
| 108 | canvas->save(); |
| 109 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 110 | if (0 < style) { |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 111 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 112 | } |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 113 | |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 114 | SkColor color = 0xff007000; |
| 115 | this->drawPath(path.fPath, canvas, color, rect, |
| 116 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 117 | gFills[fill].fFill, SK_Scalar1*10); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 118 | |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 119 | SkPaint rectPaint; |
| 120 | rectPaint.setColor(SK_ColorBLACK); |
| 121 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 122 | rectPaint.setStrokeWidth(-1); |
| 123 | rectPaint.setAntiAlias(true); |
| 124 | canvas->drawRect(rect, rectPaint); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 125 | |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 126 | SkPaint labelPaint; |
| 127 | labelPaint.setColor(color); |
| 128 | labelPaint.setAntiAlias(true); |
| 129 | labelPaint.setLCDRenderText(true); |
| 130 | labelPaint.setTextSize(10 * SK_Scalar1); |
| 131 | canvas->drawText(gStyles[style].fName, |
| 132 | strlen(gStyles[style].fName), |
| 133 | 0, rect.height() + 12 * SK_Scalar1, |
| 134 | labelPaint); |
| 135 | canvas->drawText(gFills[fill].fName, |
| 136 | strlen(gFills[fill].fName), |
| 137 | 0, rect.height() + 24 * SK_Scalar1, |
| 138 | labelPaint); |
| 139 | canvas->drawText(gCaps[cap].fName, |
| 140 | strlen(gCaps[cap].fName), |
| 141 | 0, rect.height() + 36 * SK_Scalar1, |
| 142 | labelPaint); |
| 143 | } |
| 144 | canvas->restore(); |
| 145 | } |
| 146 | canvas->restore(); |
| 147 | } |
| 148 | canvas->restore(); |
| 149 | canvas->restore(); |
| 150 | } |
| 151 | |
| 152 | private: |
| 153 | typedef GM INHERITED; |
| 154 | }; |
| 155 | |
| 156 | class ZeroCubicClosePathGM : public GM { |
| 157 | public: |
| 158 | ZeroCubicClosePathGM() {} |
| 159 | |
| 160 | protected: |
| 161 | SkString onShortName() { |
| 162 | return SkString("zerocubicclosepath"); |
| 163 | } |
| 164 | |
| 165 | SkISize onISize() { return make_isize(1240, 390); } |
| 166 | |
| 167 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 168 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
| 169 | SkPaint::Style style, SkPath::FillType fill, |
| 170 | SkScalar strokeWidth) { |
| 171 | path.setFillType(fill); |
| 172 | SkPaint paint; |
| 173 | paint.setStrokeCap(cap); |
| 174 | paint.setStrokeWidth(strokeWidth); |
| 175 | paint.setStrokeJoin(join); |
| 176 | paint.setColor(color); |
| 177 | paint.setStyle(style); |
| 178 | canvas->save(); |
| 179 | canvas->clipRect(clip); |
| 180 | canvas->drawPath(path, paint); |
| 181 | canvas->restore(); |
| 182 | } |
| 183 | |
| 184 | virtual void onDraw(SkCanvas* canvas) { |
| 185 | struct FillAndName { |
| 186 | SkPath::FillType fFill; |
| 187 | const char* fName; |
| 188 | }; |
| 189 | static const FillAndName gFills[] = { |
| 190 | {SkPath::kWinding_FillType, "Winding"}, |
| 191 | {SkPath::kEvenOdd_FillType, "Even / Odd"}, |
| 192 | {SkPath::kInverseWinding_FillType, "Inverse Winding"}, |
| 193 | {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, |
| 194 | }; |
| 195 | struct StyleAndName { |
| 196 | SkPaint::Style fStyle; |
| 197 | const char* fName; |
| 198 | }; |
| 199 | static const StyleAndName gStyles[] = { |
| 200 | {SkPaint::kFill_Style, "Fill"}, |
| 201 | {SkPaint::kStroke_Style, "Stroke"}, |
| 202 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 203 | }; |
| 204 | struct CapAndName { |
| 205 | SkPaint::Cap fCap; |
| 206 | SkPaint::Join fJoin; |
| 207 | const char* fName; |
| 208 | }; |
| 209 | static const CapAndName gCaps[] = { |
| 210 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 211 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 212 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 213 | }; |
| 214 | struct PathAndName { |
| 215 | SkPath fPath; |
| 216 | const char* fName; |
| 217 | }; |
| 218 | PathAndName path; |
| 219 | path.fPath.moveTo(50*SK_Scalar1, 15*SK_Scalar1); |
| 220 | path.fPath.cubicTo(50*SK_Scalar1, 15*SK_Scalar1, |
| 221 | 50*SK_Scalar1, 15*SK_Scalar1, |
| 222 | 50*SK_Scalar1, 15*SK_Scalar1); |
| 223 | path.fPath.close(); |
| 224 | path.fName = "moveTo-zerocubic-close"; |
| 225 | |
| 226 | SkPaint titlePaint; |
| 227 | titlePaint.setColor(SK_ColorBLACK); |
| 228 | titlePaint.setAntiAlias(true); |
| 229 | titlePaint.setLCDRenderText(true); |
| 230 | titlePaint.setTextSize(15 * SK_Scalar1); |
| 231 | const char title[] = "Zero-Length Cubic Closed Drawn Into Rectangle Clips With " |
| 232 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
| 233 | canvas->drawText(title, strlen(title), |
| 234 | 20 * SK_Scalar1, |
| 235 | 20 * SK_Scalar1, |
| 236 | titlePaint); |
| 237 | |
| 238 | SkRandom rand; |
| 239 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 240 | canvas->save(); |
| 241 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 242 | canvas->save(); |
| 243 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 244 | if (0 < cap) { |
| 245 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 246 | } |
| 247 | canvas->save(); |
| 248 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 249 | if (0 < fill) { |
| 250 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 251 | } |
| 252 | canvas->save(); |
| 253 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 254 | if (0 < style) { |
| 255 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 256 | } |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 257 | |
| 258 | SkColor color = 0xff007000; |
| 259 | this->drawPath(path.fPath, canvas, color, rect, |
| 260 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 261 | gFills[fill].fFill, SK_Scalar1*10); |
| 262 | |
| 263 | SkPaint rectPaint; |
| 264 | rectPaint.setColor(SK_ColorBLACK); |
| 265 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 266 | rectPaint.setStrokeWidth(-1); |
| 267 | rectPaint.setAntiAlias(true); |
| 268 | canvas->drawRect(rect, rectPaint); |
| 269 | |
| 270 | SkPaint labelPaint; |
| 271 | labelPaint.setColor(color); |
| 272 | labelPaint.setAntiAlias(true); |
| 273 | labelPaint.setLCDRenderText(true); |
| 274 | labelPaint.setTextSize(10 * SK_Scalar1); |
| 275 | canvas->drawText(gStyles[style].fName, |
| 276 | strlen(gStyles[style].fName), |
| 277 | 0, rect.height() + 12 * SK_Scalar1, |
| 278 | labelPaint); |
| 279 | canvas->drawText(gFills[fill].fName, |
| 280 | strlen(gFills[fill].fName), |
| 281 | 0, rect.height() + 24 * SK_Scalar1, |
| 282 | labelPaint); |
| 283 | canvas->drawText(gCaps[cap].fName, |
| 284 | strlen(gCaps[cap].fName), |
| 285 | 0, rect.height() + 36 * SK_Scalar1, |
| 286 | labelPaint); |
| 287 | } |
| 288 | canvas->restore(); |
| 289 | } |
| 290 | canvas->restore(); |
| 291 | } |
| 292 | canvas->restore(); |
| 293 | canvas->restore(); |
| 294 | } |
| 295 | |
| 296 | private: |
| 297 | typedef GM INHERITED; |
| 298 | }; |
| 299 | |
| 300 | class CubicPathGM : public GM { |
| 301 | public: |
| 302 | CubicPathGM() {} |
| 303 | |
| 304 | protected: |
| 305 | SkString onShortName() { |
| 306 | return SkString("cubicpath"); |
| 307 | } |
| 308 | |
| 309 | SkISize onISize() { return make_isize(1240, 390); } |
| 310 | |
| 311 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 312 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
| 313 | SkPaint::Style style, SkPath::FillType fill, |
| 314 | SkScalar strokeWidth) { |
| 315 | path.setFillType(fill); |
| 316 | SkPaint paint; |
| 317 | paint.setStrokeCap(cap); |
| 318 | paint.setStrokeWidth(strokeWidth); |
| 319 | paint.setStrokeJoin(join); |
| 320 | paint.setColor(color); |
| 321 | paint.setStyle(style); |
| 322 | canvas->save(); |
| 323 | canvas->clipRect(clip); |
| 324 | canvas->drawPath(path, paint); |
| 325 | canvas->restore(); |
| 326 | } |
| 327 | |
| 328 | virtual void onDraw(SkCanvas* canvas) { |
| 329 | struct FillAndName { |
| 330 | SkPath::FillType fFill; |
| 331 | const char* fName; |
| 332 | }; |
| 333 | static const FillAndName gFills[] = { |
| 334 | {SkPath::kWinding_FillType, "Winding"}, |
| 335 | {SkPath::kEvenOdd_FillType, "Even / Odd"}, |
| 336 | {SkPath::kInverseWinding_FillType, "Inverse Winding"}, |
| 337 | {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, |
| 338 | }; |
| 339 | struct StyleAndName { |
| 340 | SkPaint::Style fStyle; |
| 341 | const char* fName; |
| 342 | }; |
| 343 | static const StyleAndName gStyles[] = { |
| 344 | {SkPaint::kFill_Style, "Fill"}, |
| 345 | {SkPaint::kStroke_Style, "Stroke"}, |
| 346 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 347 | }; |
| 348 | struct CapAndName { |
| 349 | SkPaint::Cap fCap; |
| 350 | SkPaint::Join fJoin; |
| 351 | const char* fName; |
| 352 | }; |
| 353 | static const CapAndName gCaps[] = { |
| 354 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 355 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 356 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 357 | }; |
| 358 | struct PathAndName { |
| 359 | SkPath fPath; |
| 360 | const char* fName; |
| 361 | }; |
| 362 | PathAndName path; |
| 363 | path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1); |
| 364 | path.fPath.cubicTo(40*SK_Scalar1, 20*SK_Scalar1, |
| 365 | 60*SK_Scalar1, 20*SK_Scalar1, |
| 366 | 75*SK_Scalar1, 10*SK_Scalar1); |
| 367 | path.fName = "moveTo-cubic"; |
| 368 | |
| 369 | SkPaint titlePaint; |
| 370 | titlePaint.setColor(SK_ColorBLACK); |
| 371 | titlePaint.setAntiAlias(true); |
| 372 | titlePaint.setLCDRenderText(true); |
| 373 | titlePaint.setTextSize(15 * SK_Scalar1); |
| 374 | const char title[] = "Cubic Drawn Into Rectangle Clips With " |
| 375 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
| 376 | canvas->drawText(title, strlen(title), |
| 377 | 20 * SK_Scalar1, |
| 378 | 20 * SK_Scalar1, |
| 379 | titlePaint); |
| 380 | |
| 381 | SkRandom rand; |
| 382 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 383 | canvas->save(); |
| 384 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 385 | canvas->save(); |
| 386 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 387 | if (0 < cap) { |
| 388 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 389 | } |
| 390 | canvas->save(); |
| 391 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 392 | if (0 < fill) { |
| 393 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 394 | } |
| 395 | canvas->save(); |
| 396 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 397 | if (0 < style) { |
| 398 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| 399 | } |
| 400 | |
| 401 | SkColor color = 0xff007000; |
| 402 | this->drawPath(path.fPath, canvas, color, rect, |
| 403 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 404 | gFills[fill].fFill, SK_Scalar1*10); |
| 405 | |
| 406 | SkPaint rectPaint; |
| 407 | rectPaint.setColor(SK_ColorBLACK); |
| 408 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 409 | rectPaint.setStrokeWidth(-1); |
| 410 | rectPaint.setAntiAlias(true); |
| 411 | canvas->drawRect(rect, rectPaint); |
| 412 | |
| 413 | SkPaint labelPaint; |
| 414 | labelPaint.setColor(color); |
| 415 | labelPaint.setAntiAlias(true); |
| 416 | labelPaint.setLCDRenderText(true); |
| 417 | labelPaint.setTextSize(10 * SK_Scalar1); |
| 418 | canvas->drawText(gStyles[style].fName, |
| 419 | strlen(gStyles[style].fName), |
| 420 | 0, rect.height() + 12 * SK_Scalar1, |
| 421 | labelPaint); |
| 422 | canvas->drawText(gFills[fill].fName, |
| 423 | strlen(gFills[fill].fName), |
| 424 | 0, rect.height() + 24 * SK_Scalar1, |
| 425 | labelPaint); |
| 426 | canvas->drawText(gCaps[cap].fName, |
| 427 | strlen(gCaps[cap].fName), |
| 428 | 0, rect.height() + 36 * SK_Scalar1, |
| 429 | labelPaint); |
| 430 | } |
| 431 | canvas->restore(); |
| 432 | } |
| 433 | canvas->restore(); |
| 434 | } |
| 435 | canvas->restore(); |
| 436 | canvas->restore(); |
| 437 | } |
| 438 | |
| 439 | private: |
| 440 | typedef GM INHERITED; |
| 441 | }; |
| 442 | |
| 443 | class CubicClosePathGM : public GM { |
| 444 | public: |
| 445 | CubicClosePathGM() {} |
| 446 | |
| 447 | protected: |
| 448 | SkString onShortName() { |
| 449 | return SkString("cubicclosepath"); |
| 450 | } |
| 451 | |
| 452 | SkISize onISize() { return make_isize(1240, 390); } |
| 453 | |
| 454 | void drawPath(SkPath& path,SkCanvas* canvas,SkColor color, |
| 455 | const SkRect& clip,SkPaint::Cap cap, SkPaint::Join join, |
| 456 | SkPaint::Style style, SkPath::FillType fill, |
| 457 | SkScalar strokeWidth) { |
| 458 | path.setFillType(fill); |
| 459 | SkPaint paint; |
| 460 | paint.setStrokeCap(cap); |
| 461 | paint.setStrokeWidth(strokeWidth); |
| 462 | paint.setStrokeJoin(join); |
| 463 | paint.setColor(color); |
| 464 | paint.setStyle(style); |
| 465 | canvas->save(); |
| 466 | canvas->clipRect(clip); |
| 467 | canvas->drawPath(path, paint); |
| 468 | canvas->restore(); |
| 469 | } |
| 470 | |
| 471 | virtual void onDraw(SkCanvas* canvas) { |
| 472 | struct FillAndName { |
| 473 | SkPath::FillType fFill; |
| 474 | const char* fName; |
| 475 | }; |
| 476 | static const FillAndName gFills[] = { |
| 477 | {SkPath::kWinding_FillType, "Winding"}, |
| 478 | {SkPath::kEvenOdd_FillType, "Even / Odd"}, |
| 479 | {SkPath::kInverseWinding_FillType, "Inverse Winding"}, |
| 480 | {SkPath::kInverseEvenOdd_FillType, "Inverse Even / Odd"}, |
| 481 | }; |
| 482 | struct StyleAndName { |
| 483 | SkPaint::Style fStyle; |
| 484 | const char* fName; |
| 485 | }; |
| 486 | static const StyleAndName gStyles[] = { |
| 487 | {SkPaint::kFill_Style, "Fill"}, |
| 488 | {SkPaint::kStroke_Style, "Stroke"}, |
| 489 | {SkPaint::kStrokeAndFill_Style, "Stroke And Fill"}, |
| 490 | }; |
| 491 | struct CapAndName { |
| 492 | SkPaint::Cap fCap; |
| 493 | SkPaint::Join fJoin; |
| 494 | const char* fName; |
| 495 | }; |
| 496 | static const CapAndName gCaps[] = { |
| 497 | {SkPaint::kButt_Cap, SkPaint::kBevel_Join, "Butt"}, |
| 498 | {SkPaint::kRound_Cap, SkPaint::kRound_Join, "Round"}, |
| 499 | {SkPaint::kSquare_Cap, SkPaint::kBevel_Join, "Square"} |
| 500 | }; |
| 501 | struct PathAndName { |
| 502 | SkPath fPath; |
| 503 | const char* fName; |
| 504 | }; |
| 505 | PathAndName path; |
| 506 | path.fPath.moveTo(25*SK_Scalar1, 10*SK_Scalar1); |
| 507 | path.fPath.cubicTo(40*SK_Scalar1, 20*SK_Scalar1, |
| 508 | 60*SK_Scalar1, 20*SK_Scalar1, |
| 509 | 75*SK_Scalar1, 10*SK_Scalar1); |
| 510 | path.fPath.close(); |
| 511 | path.fName = "moveTo-cubic-close"; |
| 512 | |
| 513 | SkPaint titlePaint; |
| 514 | titlePaint.setColor(SK_ColorBLACK); |
| 515 | titlePaint.setAntiAlias(true); |
| 516 | titlePaint.setLCDRenderText(true); |
| 517 | titlePaint.setTextSize(15 * SK_Scalar1); |
| 518 | const char title[] = "Cubic Closed Drawn Into Rectangle Clips With " |
| 519 | "Indicated Style, Fill and Linecaps, with stroke width 10"; |
| 520 | canvas->drawText(title, strlen(title), |
| 521 | 20 * SK_Scalar1, |
| 522 | 20 * SK_Scalar1, |
| 523 | titlePaint); |
| 524 | |
| 525 | SkRandom rand; |
| 526 | SkRect rect = SkRect::MakeWH(100*SK_Scalar1, 30*SK_Scalar1); |
| 527 | canvas->save(); |
| 528 | canvas->translate(10 * SK_Scalar1, 30 * SK_Scalar1); |
| 529 | canvas->save(); |
| 530 | for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { |
| 531 | if (0 < cap) { |
| 532 | canvas->translate((rect.width() + 40 * SK_Scalar1) * SK_ARRAY_COUNT(gStyles), 0); |
| 533 | } |
| 534 | canvas->save(); |
| 535 | for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { |
| 536 | if (0 < fill) { |
| 537 | canvas->translate(0, rect.height() + 40 * SK_Scalar1); |
| 538 | } |
| 539 | canvas->save(); |
| 540 | for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { |
| 541 | if (0 < style) { |
| 542 | canvas->translate(rect.width() + 40 * SK_Scalar1, 0); |
| 543 | } |
| 544 | |
| 545 | SkColor color = 0xff007000; |
| 546 | this->drawPath(path.fPath, canvas, color, rect, |
| 547 | gCaps[cap].fCap, gCaps[cap].fJoin, gStyles[style].fStyle, |
| 548 | gFills[fill].fFill, SK_Scalar1*10); |
| 549 | |
| 550 | SkPaint rectPaint; |
| 551 | rectPaint.setColor(SK_ColorBLACK); |
| 552 | rectPaint.setStyle(SkPaint::kStroke_Style); |
| 553 | rectPaint.setStrokeWidth(-1); |
| 554 | rectPaint.setAntiAlias(true); |
| 555 | canvas->drawRect(rect, rectPaint); |
| 556 | |
| 557 | SkPaint labelPaint; |
| 558 | labelPaint.setColor(color); |
| 559 | labelPaint.setAntiAlias(true); |
| 560 | labelPaint.setLCDRenderText(true); |
| 561 | labelPaint.setTextSize(10 * SK_Scalar1); |
| 562 | canvas->drawText(gStyles[style].fName, |
| 563 | strlen(gStyles[style].fName), |
| 564 | 0, rect.height() + 12 * SK_Scalar1, |
| 565 | labelPaint); |
| 566 | canvas->drawText(gFills[fill].fName, |
| 567 | strlen(gFills[fill].fName), |
| 568 | 0, rect.height() + 24 * SK_Scalar1, |
| 569 | labelPaint); |
| 570 | canvas->drawText(gCaps[cap].fName, |
| 571 | strlen(gCaps[cap].fName), |
| 572 | 0, rect.height() + 36 * SK_Scalar1, |
| 573 | labelPaint); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 574 | } |
| 575 | canvas->restore(); |
| 576 | } |
| 577 | canvas->restore(); |
| 578 | } |
| 579 | canvas->restore(); |
| 580 | canvas->restore(); |
| 581 | } |
| 582 | |
| 583 | private: |
| 584 | typedef GM INHERITED; |
| 585 | }; |
| 586 | |
| 587 | ////////////////////////////////////////////////////////////////////////////// |
| 588 | |
| schenney@chromium.org | 45cbfdd | 2011-12-20 21:48:14 +0000 | [diff] [blame^] | 589 | static GM* ZeroCubicPathFactory(void*) { return new ZeroCubicPathGM; } |
| 590 | static GMRegistry regZeroCubicPath(ZeroCubicPathFactory); |
| 591 | |
| 592 | static GM* ZeroCubicClosePathFactory(void*) { return new ZeroCubicClosePathGM; } |
| 593 | static GMRegistry regZeroCubicClosePath(ZeroCubicClosePathFactory); |
| 594 | |
| 595 | static GM* CubicPathFactory(void*) { return new CubicPathGM; } |
| 596 | static GMRegistry regCubicPath(CubicPathFactory); |
| 597 | |
| 598 | static GM* CubicClosePathFactory(void*) { return new CubicClosePathGM; } |
| 599 | static GMRegistry regCubicClosePath(CubicClosePathFactory); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 600 | |
| 601 | } |