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" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkGraphics.h" |
| 11 | #include "SkRandom.h" |
| 12 | #include "SkLayerDrawLooper.h" |
| 13 | #include "SkBlurMaskFilter.h" |
| 14 | |
| 15 | static SkRect inset(const SkRect& r) { |
| 16 | SkRect rect = r; |
| 17 | rect.inset(r.width() / 8, r.height() / 8); |
| 18 | return rect; |
| 19 | } |
| 20 | |
| 21 | class PathInteriorGM : public skiagm::GM { |
| 22 | public: |
| 23 | PathInteriorGM() { |
| 24 | this->setBGColor(0xFFDDDDDD); |
| 25 | } |
| 26 | |
| 27 | protected: |
| 28 | virtual SkISize onISize() { |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 29 | return SkISize::Make(770, 770); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | virtual SkString onShortName() SK_OVERRIDE { |
| 33 | return SkString("pathinterior"); |
| 34 | } |
| 35 | |
| 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 | |
| 47 | paint.setColor(hasInterior ? 0xFF8888FF : SK_ColorGRAY); |
| 48 | canvas->drawPath(path, paint); |
| 49 | paint.setStyle(SkPaint::kStroke_Style); |
| 50 | paint.setColor(SK_ColorRED); |
| 51 | canvas->drawPath(path, paint); |
skia.committer@gmail.com | 73b140a | 2012-12-05 02:01:21 +0000 | [diff] [blame] | 52 | |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 53 | if (hasInterior) { |
| 54 | paint.setStyle(SkPaint::kFill_Style); |
| 55 | paint.setColor(0x8800FF00); |
| 56 | canvas->drawRect(rect, paint); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 61 | canvas->translate(8.5f, 8.5f); |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 62 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 63 | const SkRect rect = { 0, 0, 80, 80 }; |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 64 | const SkScalar RAD = rect.width()/8; |
| 65 | |
| 66 | int i = 0; |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 67 | 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; |
| 74 | path.setFillType(doEvenOdd ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType); |
| 75 | SkPath::Direction outerDir = outerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction; |
| 76 | SkPath::Direction innerDir = innerCW ? SkPath::kCW_Direction : SkPath::kCCW_Direction; |
skia.committer@gmail.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 77 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 78 | 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.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 90 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 91 | 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.com | 0264fb4 | 2012-12-06 02:01:25 +0000 | [diff] [blame] | 95 | |
reed@google.com | 3b8f472 | 2012-12-05 05:34:51 +0000 | [diff] [blame] | 96 | this->show(canvas, path); |
| 97 | } |
reed@google.com | b1c8827 | 2012-12-04 22:52:28 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | |
| 107 | typedef GM INHERITED; |
| 108 | }; |
| 109 | |
| 110 | ////////////////////////////////////////////////////////////////////////////// |
| 111 | |
| 112 | static skiagm::GM* MyFactory(void*) { return new PathInteriorGM; } |
| 113 | static skiagm::GMRegistry reg(MyFactory); |