Debian Codegraph @

gm/filltypes.cpp

raw
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/gm.h"
9 #include "include/core/SkCanvas.h"
10 #include "include/core/SkColor.h"
11 #include "include/core/SkPaint.h"
12 #include "include/core/SkPathBuilder.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkSize.h"
16 #include "include/core/SkString.h"
17
18 namespace skiagm {
19
20 class FillTypeGM : public GM {
21 SkPath fPath;
22 public:
23 FillTypeGM() {
24 this->setBGColor(0xFFDDDDDD);
25 }
26
27 void makePath() {
28 if (fPath.isEmpty()) {
29 const SkScalar radius = SkIntToScalar(45);
30 fPath = SkPathBuilder().addCircle(SkIntToScalar(50), SkIntToScalar(50), radius)
31 .addCircle(SkIntToScalar(100), SkIntToScalar(100), radius)
32 .detach();
33 }
34 }
35
36 protected:
37 SkString getName() const override { return SkString("filltypes"); }
38
39 SkISize getISize() override { return SkISize::Make(835, 840); }
40
41 void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft,
42 SkScalar scale, const SkPaint& paint) {
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
57 void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
58 showPath(canvas, 0, 0, SkPathFillType::kWinding,
59 scale, paint);
60 showPath(canvas, 200, 0, SkPathFillType::kEvenOdd,
61 scale, paint);
62 showPath(canvas, 00, 200, SkPathFillType::kInverseWinding,
63 scale, paint);
64 showPath(canvas, 200, 200, SkPathFillType::kInverseEvenOdd,
65 scale, paint);
66 }
67
68 void onDraw(SkCanvas* canvas) override {
69 this->makePath();
70
71 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
72
73 SkPaint paint;
74 const SkScalar scale = SkIntToScalar(5)/4;
75
76 paint.setAntiAlias(false);
77
78 showFour(canvas, SK_Scalar1, paint);
79 canvas->translate(SkIntToScalar(450), 0);
80 showFour(canvas, scale, paint);
81
82 paint.setAntiAlias(true);
83
84 canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
85 showFour(canvas, SK_Scalar1, paint);
86 canvas->translate(SkIntToScalar(450), 0);
87 showFour(canvas, scale, paint);
88 }
89
90 private:
91 using INHERITED = GM;
92 };
93
94 //////////////////////////////////////////////////////////////////////////////
95
96 DEF_GM( return new FillTypeGM; )
97
98 } // namespace skiagm