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 "SampleCode.h" 8 #include "SkView.h" 9 #include "SkCanvas.h" 10 #include "SkCornerPathEffect.h" 11 #include "SkGradientShader.h" 12 #include "SkPath.h" 13 #include "SkRegion.h" 14 #include "SkShader.h" 15 #include "SkUtils.h" 16 17 class FillTypeView : public SampleView { 18 SkPath fPath; 19 public: 20 FillTypeView() { 21 const SkScalar radius = SkIntToScalar(45); 22 fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius); 23 fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius); 24 25 this->setBGColor(0xFFDDDDDD); 26 } 27 28 protected: 29 // overrides from SkEventSink 30 virtual bool onQuery(SkEvent* evt) { 31 if (SampleCode::TitleQ(*evt)) { 32 SampleCode::TitleR(evt, "FillType"); 33 return true; 34 } 35 return this->INHERITED::onQuery(evt); 36 } 37 38 void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft, 39 SkScalar scale, const SkPaint& paint) { 40 41 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) }; 42 43 canvas->save(); 44 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); 45 canvas->clipRect(r); 46 canvas->drawColor(SK_ColorWHITE); 47 fPath.setFillType(ft); 48 canvas->translate(r.centerX(), r.centerY()); 49 canvas->scale(scale, scale); 50 canvas->translate(-r.centerX(), -r.centerY()); 51 canvas->drawPath(fPath, paint); 52 canvas->restore(); 53 } 54 55 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) { 56 showPath(canvas, 0, 0, SkPath::kWinding_FillType, 57 scale, paint); 58 showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType, 59 scale, paint); 60 showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType, 61 scale, paint); 62 showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType, 63 scale, paint); 64 } 65 66 virtual void onDrawContent(SkCanvas* canvas) { 67 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 68 69 SkPaint paint; 70 const SkScalar scale = SkIntToScalar(5)/4; 71 72 paint.setAntiAlias(false); 73 paint.setColor(0x8000FF00); 74 75 showFour(canvas, SK_Scalar1, paint); 76 canvas->translate(SkIntToScalar(450), 0); 77 showFour(canvas, scale, paint); 78 79 paint.setAntiAlias(true); 80 81 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450)); 82 showFour(canvas, SK_Scalar1, paint); 83 canvas->translate(SkIntToScalar(450), 0); 84 showFour(canvas, scale, paint); 85 } 86 87 private: 88 typedef SampleView INHERITED; 89 }; 90 91 ////////////////////////////////////////////////////////////////////////////// 92 93 static SkView* MyFactory() { return new FillTypeView; } 94 static SkViewRegister reg(MyFactory); 95