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