blob: f93e68250ddf7bb891ea3fd29d1c420b7d283970 [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"
bungemand3ebb482015-08-05 13:57:49 -07009#include "SkBlurMaskFilter.h"
reed@google.comb1c88272012-12-04 22:52:28 +000010#include "SkCanvas.h"
11#include "SkGraphics.h"
reedfb8c1fc2015-08-04 18:44:56 -070012#include "SkLayerDrawLooper.h"
bungemand3ebb482015-08-05 13:57:49 -070013#include "SkPath.h"
14#include "SkRandom.h"
reed@google.comb1c88272012-12-04 22:52:28 +000015
16static SkRect inset(const SkRect& r) {
17 SkRect rect = r;
18 rect.inset(r.width() / 8, r.height() / 8);
19 return rect;
20}
21
22class PathInteriorGM : public skiagm::GM {
23public:
24 PathInteriorGM() {
caryclark65cdba62015-06-15 06:51:08 -070025 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
reed@google.comb1c88272012-12-04 22:52:28 +000026 }
27
28protected:
mtklein36352bf2015-03-25 18:17:31 -070029 SkISize onISize() override {
reed@google.com3b8f4722012-12-05 05:34:51 +000030 return SkISize::Make(770, 770);
reed@google.comb1c88272012-12-04 22:52:28 +000031 }
32
mtklein36352bf2015-03-25 18:17:31 -070033 SkString onShortName() override {
reed@google.comb1c88272012-12-04 22:52:28 +000034 return SkString("pathinterior");
35 }
36
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
caryclarkf597c422015-07-28 10:37:53 -070048 paint.setColor(sk_tool_utils::color_to_565(hasInterior ? 0xFF8888FF : SK_ColorGRAY));
reed@google.comb1c88272012-12-04 22:52:28 +000049 canvas->drawPath(path, paint);
50 paint.setStyle(SkPaint::kStroke_Style);
51 paint.setColor(SK_ColorRED);
52 canvas->drawPath(path, paint);
skia.committer@gmail.com73b140a2012-12-05 02:01:21 +000053
reed@google.comb1c88272012-12-04 22:52:28 +000054 if (hasInterior) {
55 paint.setStyle(SkPaint::kFill_Style);
56 paint.setColor(0x8800FF00);
57 canvas->drawRect(rect, paint);
58 }
59 }
60
mtklein36352bf2015-03-25 18:17:31 -070061 void onDraw(SkCanvas* canvas) override {
reed@google.com3b8f4722012-12-05 05:34:51 +000062 canvas->translate(8.5f, 8.5f);
reed@google.comb1c88272012-12-04 22:52:28 +000063
reed@google.com3b8f4722012-12-05 05:34:51 +000064 const SkRect rect = { 0, 0, 80, 80 };
reed@google.comb1c88272012-12-04 22:52:28 +000065 const SkScalar RAD = rect.width()/8;
66
67 int i = 0;
reed@google.com3b8f4722012-12-05 05:34:51 +000068 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;
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000078
reed@google.com3b8f4722012-12-05 05:34:51 +000079 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 }
reed@google.comb1c88272012-12-04 22:52:28 +000091
reed@google.com3b8f4722012-12-05 05:34:51 +000092 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
93 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
94 i++;
95 path.offset(dx, dy);
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000096
reed@google.com3b8f4722012-12-05 05:34:51 +000097 this->show(canvas, path);
98 }
reed@google.comb1c88272012-12-04 22:52:28 +000099 }
100 }
101 }
102 }
103 }
104 }
105
106private:
107
108 typedef GM INHERITED;
109};
110
111//////////////////////////////////////////////////////////////////////////////
112
scroggo96f16e82015-12-10 13:31:59 -0800113DEF_GM( return new PathInteriorGM; )