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