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