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 8 #include "gm/gm.h" 9 #include "include/core/SkCanvas.h" 10 #include "include/core/SkColor.h" 11 #include "include/core/SkPaint.h" 12 #include "include/core/SkPathBuilder.h" 13 #include "include/core/SkRect.h" 14 #include "include/core/SkScalar.h" 15 #include "include/core/SkSize.h" 16 #include "include/core/SkString.h" 17 18 namespace skiagm { 19 20 class FillTypeGM : public GM { 21 SkPath fPath; 22 public: FillTypeGM()23 FillTypeGM() { 24 this->setBGColor(0xFFDDDDDD); 25 } 26 makePath()27 void makePath() { 28 if (fPath.isEmpty()) { 29 const SkScalar radius = SkIntToScalar(45); 30 fPath = SkPathBuilder().addCircle(SkIntToScalar(50), SkIntToScalar(50), radius) 31 .addCircle(SkIntToScalar(100), SkIntToScalar(100), radius) 32 .detach(); 33 } 34 } 35 36 protected: 37 onShortName()38 SkString onShortName() override { 39 return SkString("filltypes"); 40 } 41 onISize()42 SkISize onISize() override { 43 return SkISize::Make(835, 840); 44 } 45 showPath(SkCanvas * canvas,int x,int y,SkPathFillType ft,SkScalar scale,const SkPaint & paint)46 void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft, 47 SkScalar scale, const SkPaint& paint) { 48 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) }; 49 50 canvas->save(); 51 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 52 canvas->clipRect(r); 53 canvas->drawColor(SK_ColorWHITE); 54 fPath.setFillType(ft); 55 canvas->translate(r.centerX(), r.centerY()); 56 canvas->scale(scale, scale); 57 canvas->translate(-r.centerX(), -r.centerY()); 58 canvas->drawPath(fPath, paint); 59 canvas->restore(); 60 } 61 showFour(SkCanvas * canvas,SkScalar scale,const SkPaint & paint)62 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) { 63 showPath(canvas, 0, 0, SkPathFillType::kWinding, 64 scale, paint); 65 showPath(canvas, 200, 0, SkPathFillType::kEvenOdd, 66 scale, paint); 67 showPath(canvas, 00, 200, SkPathFillType::kInverseWinding, 68 scale, paint); 69 showPath(canvas, 200, 200, SkPathFillType::kInverseEvenOdd, 70 scale, paint); 71 } 72 onDraw(SkCanvas * canvas)73 void onDraw(SkCanvas* canvas) override { 74 this->makePath(); 75 76 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 77 78 SkPaint paint; 79 const SkScalar scale = SkIntToScalar(5)/4; 80 81 paint.setAntiAlias(false); 82 83 showFour(canvas, SK_Scalar1, paint); 84 canvas->translate(SkIntToScalar(450), 0); 85 showFour(canvas, scale, paint); 86 87 paint.setAntiAlias(true); 88 89 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450)); 90 showFour(canvas, SK_Scalar1, paint); 91 canvas->translate(SkIntToScalar(450), 0); 92 showFour(canvas, scale, paint); 93 } 94 95 private: 96 using INHERITED = GM; 97 }; 98 99 ////////////////////////////////////////////////////////////////////////////// 100 101 DEF_GM( return new FillTypeGM; ) 102 103 } // namespace skiagm 104