reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
| 9 | #include "include/core/SkCanvas.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkPaint.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/core/SkPath.h" |
Ben Wagner | 7fde8e1 | 2019-05-01 17:28:53 -0400 | [diff] [blame] | 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkScalar.h" |
| 15 | #include "include/core/SkSize.h" |
| 16 | #include "include/core/SkString.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "tools/ToolUtils.h" |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 18 | |
| 19 | static SkRect inset(const SkRect& r) { |
| 20 | SkRect rect = r; |
| 21 | rect.inset(r.width() / 8, r.height() / 8); |
| 22 | return rect; |
| 23 | } |
| 24 | |
| 25 | class PathInteriorGM : public skiagm::GM { |
| 26 | public: |
| 27 | PathInteriorGM() { |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 28 | this->setBGColor(0xFFDDDDDD); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 32 | SkISize onISize() override { |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 33 | return SkISize::Make(770, 770); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 34 | } |
| 35 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 36 | SkString onShortName() override { |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 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 | |
Mike Klein | ea3f014 | 2019-03-20 11:12:10 -0500 | [diff] [blame] | 51 | paint.setColor(hasInterior ? ToolUtils::color_to_565(0xFF8888FF) : SK_ColorGRAY); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 52 | canvas->drawPath(path, paint); |
| 53 | paint.setStyle(SkPaint::kStroke_Style); |
| 54 | paint.setColor(SK_ColorRED); |
| 55 | canvas->drawPath(path, paint); |
skia.committer@gmail.com | 73b140a | 2012-12-05 02:01:21 +0000 | [diff] [blame] | 56 | |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 57 | if (hasInterior) { |
| 58 | paint.setStyle(SkPaint::kFill_Style); |
| 59 | paint.setColor(0x8800FF00); |
| 60 | canvas->drawRect(rect, paint); |
| 61 | } |
| 62 | } |
| 63 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 64 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 65 | canvas->translate(8.5f, 8.5f); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 66 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 67 | const SkRect rect = { 0, 0, 80, 80 }; |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 68 | const SkScalar RAD = rect.width()/8; |
| 69 | |
| 70 | int i = 0; |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 71 | 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; |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 78 | path.setFillType(doEvenOdd ? SkPathFillType::kEvenOdd : SkPathFillType::kWinding); |
Mike Reed | 30bc527 | 2019-11-22 18:34:02 +0000 | [diff] [blame] | 79 | SkPathDirection outerDir = outerCW ? SkPathDirection::kCW : SkPathDirection::kCCW; |
| 80 | SkPathDirection innerDir = innerCW ? SkPathDirection::kCW : SkPathDirection::kCCW; |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 81 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 82 | 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.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 94 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 95 | 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.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 99 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 100 | this->show(canvas, path); |
| 101 | } |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | private: |
| 110 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 111 | using INHERITED = GM; |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | ////////////////////////////////////////////////////////////////////////////// |
| 115 | |
scroggo | 96f16e8 | 2015-12-10 13:31:59 -0800 | [diff] [blame] | 116 | DEF_GM( return new PathInteriorGM; ) |