• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 "SkBlurMaskFilter.h"
10 #include "SkCanvas.h"
11 #include "SkGraphics.h"
12 #include "SkLayerDrawLooper.h"
13 #include "SkPath.h"
14 #include "SkRandom.h"
15 
inset(const SkRect & r)16 static SkRect inset(const SkRect& r) {
17     SkRect rect = r;
18     rect.inset(r.width() / 8, r.height() / 8);
19     return rect;
20 }
21 
22 class PathInteriorGM : public skiagm::GM {
23 public:
PathInteriorGM()24     PathInteriorGM() {
25         this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
26     }
27 
28 protected:
onISize()29     SkISize onISize() override {
30         return SkISize::Make(770, 770);
31     }
32 
onShortName()33     SkString onShortName() override {
34         return SkString("pathinterior");
35     }
36 
show(SkCanvas * canvas,const SkPath & path)37     void show(SkCanvas* canvas, const SkPath& path) {
38         SkPaint paint;
39         paint.setAntiAlias(true);
40 
41         SkRect rect;
42 #if 0
43         bool hasInterior = path.hasRectangularInterior(&rect);
44 #else
45         bool hasInterior = false;
46 #endif
47 
48         paint.setColor(sk_tool_utils::color_to_565(hasInterior ? 0xFF8888FF : SK_ColorGRAY));
49         canvas->drawPath(path, paint);
50         paint.setStyle(SkPaint::kStroke_Style);
51         paint.setColor(SK_ColorRED);
52         canvas->drawPath(path, paint);
53 
54         if (hasInterior) {
55             paint.setStyle(SkPaint::kFill_Style);
56             paint.setColor(0x8800FF00);
57             canvas->drawRect(rect, paint);
58         }
59     }
60 
onDraw(SkCanvas * canvas)61     void onDraw(SkCanvas* canvas) override {
62         canvas->translate(8.5f, 8.5f);
63 
64         const SkRect rect = { 0, 0, 80, 80 };
65         const SkScalar RAD = rect.width()/8;
66 
67         int i = 0;
68         for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
69             for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
70                 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
71                     for (int innerRR = 0; innerRR <= 1; ++innerRR) {
72                         for (int outerCW = 0; outerCW <= 1; ++outerCW) {
73                             for (int innerCW = 0; innerCW <= 1; ++innerCW) {
74                                 SkPath path;
75                                 path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
76                                 SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
77                                 SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
78 
79                                 SkRect r = insetFirst ? inset(rect) : rect;
80                                 if (outerRR) {
81                                     path.addRoundRect(r, RAD, RAD, outerDir);
82                                 } else {
83                                     path.addRect(r, outerDir);
84                                 }
85                                 r = insetFirst ? rect : inset(rect);
86                                 if (innerRR) {
87                                     path.addRoundRect(r, RAD, RAD, innerDir);
88                                 } else {
89                                     path.addRect(r, innerDir);
90                                 }
91 
92                                 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
93                                 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
94                                 i++;
95                                 path.offset(dx, dy);
96 
97                                 this->show(canvas, path);
98                             }
99                         }
100                     }
101                 }
102             }
103         }
104     }
105 
106 private:
107 
108     typedef GM INHERITED;
109 };
110 
111 //////////////////////////////////////////////////////////////////////////////
112 
113 DEF_GM( return new PathInteriorGM; )
114