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