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 | |
| 8 | #include "gm.h" |
Mike Klein | 33d2055 | 2017-03-22 13:47:51 -0400 | [diff] [blame] | 9 | #include "sk_tool_utils.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 10 | #include "SkBlurMaskFilter.h" |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| 12 | #include "SkGraphics.h" |
reed | fb8c1fc | 2015-08-04 18:44:56 -0700 | [diff] [blame] | 13 | #include "SkLayerDrawLooper.h" |
bungeman | d3ebb48 | 2015-08-05 13:57:49 -0700 | [diff] [blame] | 14 | #include "SkPath.h" |
| 15 | #include "SkRandom.h" |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 16 | |
| 17 | static SkRect inset(const SkRect& r) { |
| 18 | SkRect rect = r; |
| 19 | rect.inset(r.width() / 8, r.height() / 8); |
| 20 | return rect; |
| 21 | } |
| 22 | |
| 23 | class PathInteriorGM : public skiagm::GM { |
| 24 | public: |
| 25 | PathInteriorGM() { |
caryclark | 65cdba6 | 2015-06-15 06:51:08 -0700 | [diff] [blame] | 26 | this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 30 | SkISize onISize() override { |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 31 | return SkISize::Make(770, 770); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 34 | SkString onShortName() override { |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 35 | 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 | |
caryclark | f597c42 | 2015-07-28 10:37:53 -0700 | [diff] [blame] | 49 | paint.setColor(sk_tool_utils::color_to_565(hasInterior ? 0xFF8888FF : SK_ColorGRAY)); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 50 | canvas->drawPath(path, paint); |
| 51 | paint.setStyle(SkPaint::kStroke_Style); |
| 52 | paint.setColor(SK_ColorRED); |
| 53 | canvas->drawPath(path, paint); |
skia.committer@gmail.com | 73b140a | 2012-12-05 02:01:21 +0000 | [diff] [blame] | 54 | |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 55 | if (hasInterior) { |
| 56 | paint.setStyle(SkPaint::kFill_Style); |
| 57 | paint.setColor(0x8800FF00); |
| 58 | canvas->drawRect(rect, paint); |
| 59 | } |
| 60 | } |
| 61 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 62 | void onDraw(SkCanvas* canvas) override { |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 63 | canvas->translate(8.5f, 8.5f); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 64 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 65 | const SkRect rect = { 0, 0, 80, 80 }; |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 66 | const SkScalar RAD = rect.width()/8; |
| 67 | |
| 68 | int i = 0; |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 69 | 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.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 79 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 80 | 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.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 92 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 93 | 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.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 97 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 98 | this->show(canvas, path); |
| 99 | } |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | private: |
| 108 | |
| 109 | typedef GM INHERITED; |
| 110 | }; |
| 111 | |
| 112 | ////////////////////////////////////////////////////////////////////////////// |
| 113 | |
scroggo | 96f16e8 | 2015-12-10 13:31:59 -0800 | [diff] [blame] | 114 | DEF_GM( return new PathInteriorGM; ) |