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