1 2 /* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 #include "gm.h" 9 10 namespace skiagm { 11 12 class FillTypeGM : public GM { 13 SkPath fPath; 14 public: 15 FillTypeGM() { 16 this->setBGColor(0xFFDDDDDD); 17 } 18 19 void makePath() { 20 if (fPath.isEmpty()) { 21 const SkScalar radius = SkIntToScalar(45); 22 fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); 23 fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); 24 } 25 } 26 27 protected: 28 virtual SkString onShortName() { 29 return SkString("filltypes"); 30 } 31 32 virtual SkISize onISize() { 33 return make_isize(835, 840); 34 } 35 36 void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft, 37 SkScalar scale, const SkPaint& paint) { 38 39 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) }; 40 41 canvas->save(); 42 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 43 canvas->clipRect(r); 44 canvas->drawColor(SK_ColorWHITE); 45 fPath.setFillType(ft); 46 canvas->translate(r.centerX(), r.centerY()); 47 canvas->scale(scale, scale); 48 canvas->translate(-r.centerX(), -r.centerY()); 49 canvas->drawPath(fPath, paint); 50 canvas->restore(); 51 } 52 53 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) { 54 showPath(canvas, 0, 0, SkPath::kWinding_FillType, 55 scale, paint); 56 showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType, 57 scale, paint); 58 showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType, 59 scale, paint); 60 showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType, 61 scale, paint); 62 } 63 64 virtual void onDraw(SkCanvas* canvas) { 65 this->makePath(); 66 67 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 68 69 SkPaint paint; 70 const SkScalar scale = SkIntToScalar(5)/4; 71 72 paint.setAntiAlias(false); 73 74 showFour(canvas, SK_Scalar1, paint); 75 canvas->translate(SkIntToScalar(450), 0); 76 showFour(canvas, scale, paint); 77 78 paint.setAntiAlias(true); 79 80 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450)); 81 showFour(canvas, SK_Scalar1, paint); 82 canvas->translate(SkIntToScalar(450), 0); 83 showFour(canvas, scale, paint); 84 } 85 86 private: 87 typedef GM INHERITED; 88 }; 89 90 ////////////////////////////////////////////////////////////////////////////// 91 92 static GM* MyFactory(void*) { return new FillTypeGM; } 93 static GMRegistry reg(MyFactory); 94 95 } 96