• 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 #include "include/core/SkCanvas.h"
8 #include "include/core/SkPath.h"
9 #include "include/core/SkRegion.h"
10 #include "include/core/SkShader.h"
11 #include "include/effects/SkCornerPathEffect.h"
12 #include "include/effects/SkGradientShader.h"
13 #include "samplecode/Sample.h"
14 #include "src/utils/SkUTF.h"
15 
16 class FillTypeView : public Sample {
17     SkPath fPath;
18 public:
FillTypeView()19     FillTypeView() {
20         const SkScalar radius = SkIntToScalar(45);
21         fPath.addCircle(SkIntToScalar(50), SkIntToScalar(50), radius);
22         fPath.addCircle(SkIntToScalar(100), SkIntToScalar(100), radius);
23 
24         this->setBGColor(0xFFDDDDDD);
25     }
26 
27 protected:
name()28     SkString name() override{ return SkString("FillType"); }
29 
showPath(SkCanvas * canvas,int x,int y,SkPathFillType ft,SkScalar scale,const SkPaint & paint)30     void showPath(SkCanvas* canvas, int x, int y, SkPathFillType ft,
31                   SkScalar scale, const SkPaint& paint) {
32 
33         const SkRect r = { 0, 0, SkIntToScalar(150), SkIntToScalar(150) };
34 
35         canvas->save();
36         canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
37         canvas->clipRect(r);
38         canvas->drawColor(SK_ColorWHITE);
39         fPath.setFillType(ft);
40         canvas->translate(r.centerX(), r.centerY());
41         canvas->scale(scale, scale);
42         canvas->translate(-r.centerX(), -r.centerY());
43         canvas->drawPath(fPath, paint);
44         canvas->restore();
45     }
46 
showFour(SkCanvas * canvas,SkScalar scale,const SkPaint & paint)47     void showFour(SkCanvas* canvas, SkScalar scale, const SkPaint& paint) {
48         showPath(canvas,   0,   0, SkPathFillType::kWinding,
49                  scale, paint);
50         showPath(canvas, 200,   0, SkPathFillType::kEvenOdd,
51                  scale, paint);
52         showPath(canvas,  00, 200, SkPathFillType::kInverseWinding,
53                  scale, paint);
54         showPath(canvas, 200, 200, SkPathFillType::kInverseEvenOdd,
55                  scale, paint);
56     }
57 
onDrawContent(SkCanvas * canvas)58     void onDrawContent(SkCanvas* canvas) override {
59         canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
60 
61         SkPaint paint;
62         const SkScalar scale = SkIntToScalar(5)/4;
63 
64         paint.setAntiAlias(false);
65         paint.setColor(0x8000FF00);
66 
67         showFour(canvas, SK_Scalar1, paint);
68         canvas->translate(SkIntToScalar(450), 0);
69         showFour(canvas, scale, paint);
70 
71         paint.setAntiAlias(true);
72 
73         canvas->translate(SkIntToScalar(-450), SkIntToScalar(450));
74         showFour(canvas, SK_Scalar1, paint);
75         canvas->translate(SkIntToScalar(450), 0);
76         showFour(canvas, scale, paint);
77     }
78 
79 private:
80     using INHERITED = Sample;
81 };
82 
83 //////////////////////////////////////////////////////////////////////////////
84 
85 DEF_SAMPLE( return new FillTypeView(); )
86