blob: 72f530b6dbeed84c30286bf258bbec5f68530eda [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
9#include "include/core/SkCanvas.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040010#include "include/core/SkColor.h"
11#include "include/core/SkPaint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkPath.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -040013#include "include/core/SkRect.h"
14#include "include/core/SkScalar.h"
15#include "include/core/SkSize.h"
16#include "include/core/SkString.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "tools/ToolUtils.h"
reed@google.comb1c88272012-12-04 22:52:28 +000018
19static SkRect inset(const SkRect& r) {
20 SkRect rect = r;
21 rect.inset(r.width() / 8, r.height() / 8);
22 return rect;
23}
24
25class PathInteriorGM : public skiagm::GM {
26public:
27 PathInteriorGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040028 this->setBGColor(0xFFDDDDDD);
reed@google.comb1c88272012-12-04 22:52:28 +000029 }
30
31protected:
Leandro Lovisolo8f023882023-08-15 21:13:52 +000032 SkISize getISize() override { return SkISize::Make(770, 770); }
reed@google.comb1c88272012-12-04 22:52:28 +000033
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000034 SkString getName() const override { return SkString("pathinterior"); }
reed@google.comb1c88272012-12-04 22:52:28 +000035
36 void show(SkCanvas* canvas, const SkPath& path) {
37 SkPaint paint;
38 paint.setAntiAlias(true);
39
40 SkRect rect;
41#if 0
42 bool hasInterior = path.hasRectangularInterior(&rect);
43#else
44 bool hasInterior = false;
45#endif
46
Mike Kleinea3f0142019-03-20 11:12:10 -050047 paint.setColor(hasInterior ? ToolUtils::color_to_565(0xFF8888FF) : SK_ColorGRAY);
reed@google.comb1c88272012-12-04 22:52:28 +000048 canvas->drawPath(path, paint);
49 paint.setStyle(SkPaint::kStroke_Style);
50 paint.setColor(SK_ColorRED);
51 canvas->drawPath(path, paint);
skia.committer@gmail.com73b140a2012-12-05 02:01:21 +000052
reed@google.comb1c88272012-12-04 22:52:28 +000053 if (hasInterior) {
54 paint.setStyle(SkPaint::kFill_Style);
55 paint.setColor(0x8800FF00);
56 canvas->drawRect(rect, paint);
57 }
58 }
59
mtklein36352bf2015-03-25 18:17:31 -070060 void onDraw(SkCanvas* canvas) override {
reed@google.com3b8f4722012-12-05 05:34:51 +000061 canvas->translate(8.5f, 8.5f);
reed@google.comb1c88272012-12-04 22:52:28 +000062
reed@google.com3b8f4722012-12-05 05:34:51 +000063 const SkRect rect = { 0, 0, 80, 80 };
reed@google.comb1c88272012-12-04 22:52:28 +000064 const SkScalar RAD = rect.width()/8;
65
66 int i = 0;
reed@google.com3b8f4722012-12-05 05:34:51 +000067 for (int insetFirst = 0; insetFirst <= 1; ++insetFirst) {
68 for (int doEvenOdd = 0; doEvenOdd <= 1; ++doEvenOdd) {
69 for (int outerRR = 0; outerRR <= 1; ++outerRR) {
70 for (int innerRR = 0; innerRR <= 1; ++innerRR) {
71 for (int outerCW = 0; outerCW <= 1; ++outerCW) {
72 for (int innerCW = 0; innerCW <= 1; ++innerCW) {
73 SkPath path;
Mike Reed7d34dc72019-11-26 12:17:17 -050074 path.setFillType(doEvenOdd ? SkPathFillType::kEvenOdd : SkPathFillType::kWinding);
Mike Reed30bc5272019-11-22 18:34:02 +000075 SkPathDirection outerDir = outerCW ? SkPathDirection::kCW : SkPathDirection::kCCW;
76 SkPathDirection innerDir = innerCW ? SkPathDirection::kCW : SkPathDirection::kCCW;
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000077
reed@google.com3b8f4722012-12-05 05:34:51 +000078 SkRect r = insetFirst ? inset(rect) : rect;
79 if (outerRR) {
80 path.addRoundRect(r, RAD, RAD, outerDir);
81 } else {
82 path.addRect(r, outerDir);
83 }
84 r = insetFirst ? rect : inset(rect);
85 if (innerRR) {
86 path.addRoundRect(r, RAD, RAD, innerDir);
87 } else {
88 path.addRect(r, innerDir);
89 }
reed@google.comb1c88272012-12-04 22:52:28 +000090
reed@google.com3b8f4722012-12-05 05:34:51 +000091 SkScalar dx = (i / 8) * rect.width() * 6 / 5;
92 SkScalar dy = (i % 8) * rect.height() * 6 / 5;
93 i++;
94 path.offset(dx, dy);
skia.committer@gmail.com0264fb42012-12-06 02:01:25 +000095
reed@google.com3b8f4722012-12-05 05:34:51 +000096 this->show(canvas, path);
97 }
reed@google.comb1c88272012-12-04 22:52:28 +000098 }
99 }
100 }
101 }
102 }
103 }
104
105private:
106
John Stiles7571f9e2020-09-02 22:42:33 -0400107 using INHERITED = GM;
reed@google.comb1c88272012-12-04 22:52:28 +0000108};
109
110//////////////////////////////////////////////////////////////////////////////
111
scroggo96f16e82015-12-10 13:31:59 -0800112DEF_GM( return new PathInteriorGM; )