blob: 41c1a69a8e0b8e5d38917f87bb8e6785a4cf5f19 [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"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
bungemand3ebb482015-08-05 13:57:49 -070010#include "SkBlurMaskFilter.h"
reed@google.comb1c88272012-12-04 22:52:28 +000011#include "SkCanvas.h"
12#include "SkGraphics.h"
reedfb8c1fc2015-08-04 18:44:56 -070013#include "SkLayerDrawLooper.h"
bungemand3ebb482015-08-05 13:57:49 -070014#include "SkPath.h"
15#include "SkRandom.h"
reed@google.comb1c88272012-12-04 22:52:28 +000016
17static SkRect inset(const SkRect& r) {
18 SkRect rect = r;
19 rect.inset(r.width() / 8, r.height() / 8);
20 return rect;
21}
22
23class PathInteriorGM : public skiagm::GM {
24public:
25 PathInteriorGM() {
caryclark65cdba62015-06-15 06:51:08 -070026 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
reed@google.comb1c88272012-12-04 22:52:28 +000027 }
28
29protected:
mtklein36352bf2015-03-25 18:17:31 -070030 SkISize onISize() override {
reed@google.com3b8f4722012-12-05 05:34:51 +000031 return SkISize::Make(770, 770);
reed@google.comb1c88272012-12-04 22:52:28 +000032 }
33
mtklein36352bf2015-03-25 18:17:31 -070034 SkString onShortName() override {
reed@google.comb1c88272012-12-04 22:52:28 +000035 return SkString("pathinterior");
36 }
37
38 void show(SkCanvas* canvas, const SkPath& path) {
39 SkPaint paint;
40 paint.setAntiAlias(true);
41
42 SkRect rect;
43#if 0
44 bool hasInterior = path.hasRectangularInterior(&rect);
45#else
46 bool hasInterior = false;
47#endif
48
caryclarkf597c422015-07-28 10:37:53 -070049 paint.setColor(sk_tool_utils::color_to_565(hasInterior ? 0xFF8888FF : SK_ColorGRAY));
reed@google.comb1c88272012-12-04 22:52:28 +000050 canvas->drawPath(path, paint);
51 paint.setStyle(SkPaint::kStroke_Style);
52 paint.setColor(SK_ColorRED);
53 canvas->drawPath(path, paint);
skia.committer@gmail.com73b140a2012-12-05 02:01:21 +000054
reed@google.comb1c88272012-12-04 22:52:28 +000055 if (hasInterior) {
56 paint.setStyle(SkPaint::kFill_Style);
57 paint.setColor(0x8800FF00);
58 canvas->drawRect(rect, paint);
59 }
60 }
61
mtklein36352bf2015-03-25 18:17:31 -070062 void onDraw(SkCanvas* canvas) override {
reed@google.com3b8f4722012-12-05 05:34:51 +000063 canvas->translate(8.5f, 8.5f);
reed@google.comb1c88272012-12-04 22:52:28 +000064
reed@google.com3b8f4722012-12-05 05:34:51 +000065 const SkRect rect = { 0, 0, 80, 80 };
reed@google.comb1c88272012-12-04 22:52:28 +000066 const SkScalar RAD = rect.width()/8;
67
68 int i = 0;
reed@google.com3b8f4722012-12-05 05:34:51 +000069 for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
70 for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
71 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
72 for (int innerRR = 0; innerRR <= 1; ++innerRR) {
73 for (int outerCW = 0; outerCW <= 1; ++outerCW) {
74 for (int innerCW = 0; innerCW <= 1; ++innerCW) {
75 SkPath path;
76 path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType);
77 SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
78 SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction;
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000079
reed@google.com3b8f4722012-12-05 05:34:51 +000080 SkRect r = insetFirst ? inset(rect) : rect;
81 if (outerRR) {
82 path.addRoundRect(r, RAD, RAD, outerDir);
83 } else {
84 path.addRect(r, outerDir);
85 }
86 r = insetFirst ? rect : inset(rect);
87 if (innerRR) {
88 path.addRoundRect(r, RAD, RAD, innerDir);
89 } else {
90 path.addRect(r, innerDir);
91 }
reed@google.comb1c88272012-12-04 22:52:28 +000092
reed@google.com3b8f4722012-12-05 05:34:51 +000093 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
94 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
95 i++;
96 path.offset(dx, dy);
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000097
reed@google.com3b8f4722012-12-05 05:34:51 +000098 this->show(canvas, path);
99 }
reed@google.comb1c88272012-12-04 22:52:28 +0000100 }
101 }
102 }
103 }
104 }
105 }
106
107private:
108
109 typedef GM INHERITED;
110};
111
112//////////////////////////////////////////////////////////////////////////////
113
scroggo96f16e82015-12-10 13:31:59 -0800114DEF_GM( return new PathInteriorGM; )