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 "sk_tool_utils.h"
10 #include "SkPath.h"
11
12 namespace skiagm {
13
14 class FillTypeGM : public GM {
15 SkPath fPath;
16 public:
FillTypeGM()17 FillTypeGM() {
18 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
19 }
20
makePath()21 void makePath() {
22 if (fPath.isEmpty()) {
23 const SkScalar radius = SkIntToScalar(45);
24 fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
25 fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
26 }
27 }
28
29 protected:
30
onShortName()31 SkString onShortName() override {
32 return SkString("filltypes");
33 }
34
onISize()35 SkISize onISize() override {
36 return SkISize::Make(835, 840);
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 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
showFour(SkCanvas * canvas,SkScalar scale,const SkPaint & paint)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
onDraw(SkCanvas * canvas)66 void onDraw(SkCanvas* canvas) override {
67 this->makePath();
68
69 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
70
71 SkPaint paint;
72 const SkScalar scale = SkIntToScalar(5)/4;
73
74 paint.setAntiAlias(false);
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 GM INHERITED;
90 };
91
92 //////////////////////////////////////////////////////////////////////////////
93
MyFactory(void *)94 static GM* MyFactory(void*) { return new FillTypeGM; }
95 static GMRegistry reg(MyFactory);
96
97 }
98