epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | #include "SkGraphics.h" |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 13 | #include "SkPath.h" |
| 14 | #include "SkRegion.h" |
| 15 | #include "SkShader.h" |
| 16 | #include "SkUtils.h" |
| 17 | #include "SkXfermode.h" |
| 18 | #include "SkColorPriv.h" |
| 19 | #include "SkColorFilter.h" |
| 20 | #include "SkParsePath.h" |
| 21 | #include "SkTime.h" |
| 22 | #include "SkTypeface.h" |
| 23 | |
| 24 | #include "SkGeometry.h" |
| 25 | |
| 26 | class ConcavePathView : public SampleView { |
| 27 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 28 | ConcavePathView() {} |
| 29 | |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 30 | protected: |
| 31 | // overrides from SkEventSink |
| 32 | virtual bool onQuery(SkEvent* evt) { |
| 33 | if (SampleCode::TitleQ(*evt)) { |
| 34 | SampleCode::TitleR(evt, "ConcavePaths"); |
| 35 | return true; |
| 36 | } |
| 37 | return this->INHERITED::onQuery(evt); |
| 38 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 39 | |
| 40 | virtual void onDrawContent(SkCanvas* canvas) { |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 41 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 42 | |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 43 | paint.setAntiAlias(true); |
| 44 | paint.setStyle(SkPaint::kFill_Style); |
| 45 | |
| 46 | // Concave test |
| 47 | if (1) { |
| 48 | SkPath path; |
| 49 | canvas->translate(0, 0); |
| 50 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 51 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 52 | path.lineTo(SkIntToScalar(30), SkIntToScalar(30)); |
| 53 | path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); |
| 54 | canvas->drawPath(path, paint); |
| 55 | } |
| 56 | // Reverse concave test |
| 57 | if (1) { |
| 58 | SkPath path; |
| 59 | canvas->save(); |
| 60 | canvas->translate(100, 0); |
| 61 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 62 | path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); |
| 63 | path.lineTo(SkIntToScalar(30), SkIntToScalar(30)); |
| 64 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 65 | canvas->drawPath(path, paint); |
| 66 | canvas->restore(); |
| 67 | } |
| 68 | // Bowtie (intersection) |
| 69 | if (1) { |
| 70 | SkPath path; |
| 71 | canvas->save(); |
| 72 | canvas->translate(200, 0); |
| 73 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 74 | path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); |
| 75 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 76 | path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); |
| 77 | canvas->drawPath(path, paint); |
| 78 | canvas->restore(); |
| 79 | } |
| 80 | // "fake" bowtie (concave, but no intersection) |
| 81 | if (1) { |
| 82 | SkPath path; |
| 83 | canvas->save(); |
| 84 | canvas->translate(300, 0); |
| 85 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 86 | path.lineTo(SkIntToScalar(50), SkIntToScalar(40)); |
| 87 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 88 | path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); |
| 89 | path.lineTo(SkIntToScalar(50), SkIntToScalar(60)); |
| 90 | path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); |
| 91 | canvas->drawPath(path, paint); |
| 92 | canvas->restore(); |
| 93 | } |
| 94 | // Fish test (intersection/concave) |
| 95 | if (1) { |
| 96 | SkPath path; |
| 97 | canvas->save(); |
| 98 | canvas->translate(0, 100); |
| 99 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 100 | path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); |
| 101 | path.lineTo(SkIntToScalar(70), SkIntToScalar(50)); |
| 102 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 103 | path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); |
| 104 | path.lineTo(SkIntToScalar(0), SkIntToScalar(50)); |
| 105 | canvas->drawPath(path, paint); |
| 106 | canvas->restore(); |
| 107 | } |
| 108 | // Collinear test |
| 109 | if (1) { |
| 110 | SkPath path; |
| 111 | canvas->save(); |
| 112 | canvas->translate(100, 100); |
| 113 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 114 | path.lineTo(SkIntToScalar(50), SkIntToScalar(20)); |
| 115 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 116 | path.lineTo(SkIntToScalar(50), SkIntToScalar(80)); |
| 117 | canvas->drawPath(path, paint); |
| 118 | canvas->restore(); |
| 119 | } |
| 120 | // Hole test |
| 121 | if (1) { |
| 122 | SkPath path; |
| 123 | canvas->save(); |
| 124 | canvas->translate(200, 100); |
| 125 | path.moveTo(SkIntToScalar(20), SkIntToScalar(20)); |
| 126 | path.lineTo(SkIntToScalar(80), SkIntToScalar(20)); |
| 127 | path.lineTo(SkIntToScalar(80), SkIntToScalar(80)); |
| 128 | path.lineTo(SkIntToScalar(20), SkIntToScalar(80)); |
| 129 | path.moveTo(SkIntToScalar(30), SkIntToScalar(30)); |
| 130 | path.lineTo(SkIntToScalar(30), SkIntToScalar(70)); |
| 131 | path.lineTo(SkIntToScalar(70), SkIntToScalar(70)); |
| 132 | path.lineTo(SkIntToScalar(70), SkIntToScalar(30)); |
| 133 | canvas->drawPath(path, paint); |
| 134 | canvas->restore(); |
| 135 | } |
| 136 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 137 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 138 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, |
| 139 | unsigned modi) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 140 | this->inval(nullptr); |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 141 | return this->INHERITED::onFindClickHandler(x, y, modi); |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 142 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 143 | |
senorblanco@chromium.org | 129b8e3 | 2011-06-15 17:52:09 +0000 | [diff] [blame] | 144 | private: |
| 145 | typedef SampleView INHERITED; |
| 146 | }; |
| 147 | |
| 148 | ////////////////////////////////////////////////////////////////////////////// |
| 149 | |
| 150 | static SkView* MyFactory() { return new ConcavePathView; } |
| 151 | static SkViewRegister reg(MyFactory); |