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