• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkPath.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:
FillTypeGM()23     FillTypeGM() {
24         this->setBGColor(0xFFDDDDDD);
25     }
26 
makePath()27     void makePath() {
28         if (fPath.isEmpty()) {
29             const SkScalar radius = SkIntToScalar(45);
30             fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
31             fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
32         }
33     }
34 
35 protected:
36 
onShortName()37     SkString onShortName() override {
38         return SkString("filltypes");
39     }
40 
onISize()41     SkISize onISize() override {
42         return SkISize::Make(835, 840);
43     }
44 
showPath(SkCanvas * canvas,int x,int y,SkPath::FillType ft,SkScalar scale,const SkPaint & paint)45     void showPath(SkCanvas* canvas, int x, int y, SkPath::FillType ft,
46                   SkScalar scale, const SkPaint& paint) {
47         const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
48 
49         canvas->save();
50         canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
51         canvas->clipRect(r);
52         canvas->drawColor(SK_ColorWHITE);
53         fPath.setFillType(ft);
54         canvas->translate(r.centerX(), r.centerY());
55         canvas->scale(scale, scale);
56         canvas->translate(-r.centerX(), -r.centerY());
57         canvas->drawPath(fPath, paint);
58         canvas->restore();
59     }
60 
showFour(SkCanvas * canvas,SkScalar scale,const SkPaint & paint)61     void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
62         showPath(canvas,   0,   0, SkPath::kWinding_FillType,
63                  scale, paint);
64         showPath(canvas, 200,   0, SkPath::kEvenOdd_FillType,
65                  scale, paint);
66         showPath(canvas,  00, 200, SkPath::kInverseWinding_FillType,
67                  scale, paint);
68         showPath(canvas, 200, 200, SkPath::kInverseEvenOdd_FillType,
69                  scale, paint);
70     }
71 
onDraw(SkCanvas * canvas)72     void onDraw(SkCanvas* canvas) override {
73         this->makePath();
74 
75         canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
76 
77         SkPaint paint;
78         const SkScalar scale = SkIntToScalar(5)/4;
79 
80         paint.setAntiAlias(false);
81 
82         showFour(canvas, SK_Scalar1, paint);
83         canvas->translate(SkIntToScalar(450), 0);
84         showFour(canvas, scale, paint);
85 
86         paint.setAntiAlias(true);
87 
88         canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
89         showFour(canvas, SK_Scalar1, paint);
90         canvas->translate(SkIntToScalar(450), 0);
91         showFour(canvas, scale, paint);
92     }
93 
94 private:
95     typedef GM INHERITED;
96 };
97 
98 //////////////////////////////////////////////////////////////////////////////
99 
100 DEF_GM( return new FillTypeGM; )
101 
102 }
103