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.h"
9 #include "SkPath.h"
10
11 namespace skiagm {
12
13 class FillTypeGM : public GM {
14 SkPath fPath;
15 public:
FillTypeGM()16 FillTypeGM() {
17 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
18 }
19
makePath()20 void makePath() {
21 if (fPath.isEmpty()) {
22 const SkScalar radius = SkIntToScalar(45);
23 fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
24 fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
25 }
26 }
27
28 protected:
29
onShortName()30 SkString onShortName() override {
31 return SkString("filltypes");
32 }
33
onISize()34 SkISize onISize() override {
35 return SkISize::Make(835, 840);
36 }
37
showPath(SkCanvas * canvas,int x,int y,SkPath::FillType ft,SkScalar scale,const SkPaint & paint)38 void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
39 SkScalar scale, const SkPaint& paint) {
40 const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
41
42 canvas->save();
43 canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
44 canvas->clipRect(r);
45 canvas->drawColor(SK_ColorWHITE);
46 fPath.setFillType(ft);
47 canvas->translate(r.centerX(), r.centerY());
48 canvas->scale(scale, scale);
49 canvas->translate(-r.centerX(), -r.centerY());
50 canvas->drawPath(fPath, paint);
51 canvas->restore();
52 }
53
showFour(SkCanvas * canvas,SkScalar scale,const SkPaint & paint)54 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
55 showPath(canvas, 0, 0, SkPath::kWinding_FillType,
56 scale, paint);
57 showPath(canvas, 200, 0, SkPath::kEvenOdd_FillType,
58 scale, paint);
59 showPath(canvas, 00, 200, SkPath::kInverseWinding_FillType,
60 scale, paint);
61 showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
62 scale, paint);
63 }
64
onDraw(SkCanvas * canvas)65 void onDraw(SkCanvas* canvas) override {
66 this->makePath();
67
68 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
69
70 SkPaint paint;
71 const SkScalar scale = SkIntToScalar(5)/4;
72
73 paint.setAntiAlias(false);
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 GM INHERITED;
89 };
90
91 //////////////////////////////////////////////////////////////////////////////
92
MyFactory(void *)93 static GM* MyFactory(void*) { return new FillTypeGM; }
94 static GMRegistry reg(MyFactory);
95
96 }
97