blob: e58792877d1052886cc35de8d6a1ee3715503214 [file] [log] [blame]
reed@google.comb1c88272012-12-04 22:52:28 +00001/*
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 "SkCanvas.h"
10#include "SkGraphics.h"
11#include "SkRandom.h"
12#include "SkLayerDrawLooper.h"
13#include "SkBlurMaskFilter.h"
14
15static SkRect inset(const SkRect& r) {
16 SkRect rect = r;
17 rect.inset(r.width() / 8, r.height() / 8);
18 return rect;
19}
20
21class PathInteriorGM : public skiagm::GM {
22public:
23 PathInteriorGM() {
24 this->setBGColor(0xFFDDDDDD);
25 }
26
27protected:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000028 virtual uint32_t onGetFlags() const SK_OVERRIDE {
29 return kSkipTiled_Flag;
30 }
31
reed@google.comb1c88272012-12-04 22:52:28 +000032 virtual SkISize onISize() {
reed@google.com3b8f4722012-12-05 05:34:51 +000033 return SkISize::Make(770, 770);
reed@google.comb1c88272012-12-04 22:52:28 +000034 }
35
36 virtual SkString onShortName() SK_OVERRIDE {
37 return SkString("pathinterior");
38 }
39
40 void show(SkCanvas* canvas, const SkPath& path) {
41 SkPaint paint;
42 paint.setAntiAlias(true);
43
44 SkRect rect;
45#if 0
46 bool hasInterior = path.hasRectangularInterior(&rect);
47#else
48 bool hasInterior = false;
49#endif
50
51 paint.setColor(hasInterior ? 0xFF8888FF : SK_ColorGRAY);
52 canvas->drawPath(path, paint);
53 paint.setStyle(SkPaint::kStroke_Style);
54 paint.setColor(SK_ColorRED);
55 canvas->drawPath(path, paint);
skia.committer@gmail.com73b140a2012-12-05 02:01:21 +000056
reed@google.comb1c88272012-12-04 22:52:28 +000057 if (hasInterior) {
58 paint.setStyle(SkPaint::kFill_Style);
59 paint.setColor(0x8800FF00);
60 canvas->drawRect(rect, paint);
61 }
62 }
63
64 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
reed@google.com3b8f4722012-12-05 05:34:51 +000065 canvas->translate(8.5f, 8.5f);
reed@google.comb1c88272012-12-04 22:52:28 +000066
reed@google.com3b8f4722012-12-05 05:34:51 +000067 const SkRect rect = { 0, 0, 80, 80 };
reed@google.comb1c88272012-12-04 22:52:28 +000068 const SkScalar RAD = rect.width()/8;
69
70 int i = 0;
reed@google.com3b8f4722012-12-05 05:34:51 +000071 for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
72 for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
73 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
74 for (int innerRR = 0; innerRR <= 1; ++innerRR) {
75 for (int outerCW = 0; outerCW <= 1; ++outerCW) {
76 for (int innerCW = 0; innerCW <= 1; ++innerCW) {
77 SkPath path;
78 path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
79 SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
80 SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000081
reed@google.com3b8f4722012-12-05 05:34:51 +000082 SkRect r = insetFirst ? inset(rect) : rect;
83 if (outerRR) {
84 path.addRoundRect(r, RAD, RAD, outerDir);
85 } else {
86 path.addRect(r, outerDir);
87 }
88 r = insetFirst ? rect : inset(rect);
89 if (innerRR) {
90 path.addRoundRect(r, RAD, RAD, innerDir);
91 } else {
92 path.addRect(r, innerDir);
93 }
reed@google.comb1c88272012-12-04 22:52:28 +000094
reed@google.com3b8f4722012-12-05 05:34:51 +000095 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
96 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
97 i++;
98 path.offset(dx, dy);
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000099
reed@google.com3b8f4722012-12-05 05:34:51 +0000100 this->show(canvas, path);
101 }
reed@google.comb1c88272012-12-04 22:52:28 +0000102 }
103 }
104 }
105 }
106 }
107 }
108
109private:
110
111 typedef GM INHERITED;
112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116static skiagm::GM* MyFactory(void*) { return new PathInteriorGM; }
117static skiagm::GMRegistry reg(MyFactory);