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 | */ |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 7 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 8 | #include "Sample.h" |
Mike Reed | 75ae421 | 2018-01-23 11:24:08 -0500 | [diff] [blame] | 9 | #include "SkBitmap.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 10 | #include "SkCanvas.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | #include "SkPath.h" |
| 13 | #include "SkRegion.h" |
| 14 | #include "SkShader.h" |
Hal Canary | ea60b95 | 2018-08-21 11:45:46 -0400 | [diff] [blame] | 15 | #include "SkUTF.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | |
bungeman | b7069e9 | 2015-07-21 14:14:30 -0700 | [diff] [blame] | 17 | #include <math.h> |
| 18 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 19 | static void test_strokerect(SkCanvas* canvas) { |
| 20 | int width = 100; |
| 21 | int height = 100; |
| 22 | |
| 23 | SkBitmap bitmap; |
commit-bot@chromium.org | a8c1831 | 2014-02-17 02:55:57 +0000 | [diff] [blame] | 24 | bitmap.allocPixels(SkImageInfo::MakeA8(width*2, height*2)); |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 25 | bitmap.eraseColor(SK_ColorTRANSPARENT); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 26 | |
| 27 | SkScalar dx = 20; |
| 28 | SkScalar dy = 20; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 29 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 30 | SkPath path; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 31 | path.addRect(0.0f, 0.0f, |
| 32 | SkIntToScalar(width), SkIntToScalar(height), |
robertphillips@google.com | 4debcac | 2012-05-14 16:33:36 +0000 | [diff] [blame] | 33 | SkPath::kCW_Direction); |
| 34 | SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 35 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 36 | SkCanvas c(bitmap); |
| 37 | c.translate(dx, dy); |
| 38 | |
| 39 | SkPaint paint; |
| 40 | paint.setStyle(SkPaint::kStroke_Style); |
| 41 | paint.setStrokeWidth(1); |
| 42 | |
| 43 | // use the rect |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 44 | c.clear(SK_ColorTRANSPARENT); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 45 | c.drawRect(r, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 46 | canvas->drawBitmap(bitmap, 0, 0, nullptr); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 47 | |
| 48 | // use the path |
junov@google.com | dbfac8a | 2012-12-06 21:47:40 +0000 | [diff] [blame] | 49 | c.clear(SK_ColorTRANSPARENT); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 50 | c.drawPath(path, paint); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 51 | canvas->drawBitmap(bitmap, SkIntToScalar(2*width), 0, nullptr); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static void drawFadingText(SkCanvas* canvas, |
| 55 | const char* text, size_t len, SkScalar x, SkScalar y, |
| 56 | const SkPaint& paint) { |
| 57 | // Need a bounds for the text |
| 58 | SkRect bounds; |
Mike Reed | b5784ac | 2018-11-12 09:35:15 -0500 | [diff] [blame] | 59 | SkFontMetrics fm; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 60 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 61 | paint.getFontMetrics(&fm); |
| 62 | bounds.set(x, y + fm.fTop, x + paint.measureText(text, len), y + fm.fBottom); |
| 63 | |
| 64 | // may need to outset bounds a little, to account for hinting and/or |
| 65 | // antialiasing |
| 66 | bounds.inset(-SkIntToScalar(2), -SkIntToScalar(2)); |
| 67 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 68 | canvas->saveLayer(&bounds, nullptr); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 69 | canvas->drawText(text, len, x, y, paint); |
| 70 | |
| 71 | const SkPoint pts[] = { |
| 72 | { bounds.fLeft, y }, |
| 73 | { bounds.fRight, y } |
| 74 | }; |
| 75 | const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; |
| 76 | |
| 77 | // pos[1] value is where we start to fade, relative to the width |
| 78 | // of our pts[] array. |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 79 | const SkScalar pos[] = { 0, 0.9f, SK_Scalar1 }; |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 80 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 81 | SkPaint p; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 82 | p.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 3, SkShader::kClamp_TileMode)); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 83 | p.setBlendMode(SkBlendMode::kDstIn); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 84 | canvas->drawRect(bounds, p); |
| 85 | |
| 86 | canvas->restore(); |
| 87 | } |
| 88 | |
| 89 | static void test_text(SkCanvas* canvas) { |
| 90 | SkPaint paint; |
| 91 | paint.setAntiAlias(true); |
| 92 | paint.setTextSize(20); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 93 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 94 | const char* str = "Hamburgefons"; |
| 95 | size_t len = strlen(str); |
| 96 | SkScalar x = 20; |
| 97 | SkScalar y = 20; |
| 98 | |
| 99 | canvas->drawText(str, len, x, y, paint); |
| 100 | |
| 101 | y += 20; |
| 102 | |
| 103 | const SkPoint pts[] = { { x, y }, { x + paint.measureText(str, len), y } }; |
| 104 | const SkColor colors[] = { SK_ColorBLACK, SK_ColorBLACK, 0 }; |
| 105 | const SkScalar pos[] = { 0, 0.9f, 1 }; |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 106 | paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 107 | SK_ARRAY_COUNT(colors), |
reed | 8a21c9f | 2016-03-08 18:50:00 -0800 | [diff] [blame] | 108 | SkShader::kClamp_TileMode)); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 109 | canvas->drawText(str, len, x, y, paint); |
| 110 | |
| 111 | y += 20; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 112 | paint.setShader(nullptr); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 113 | drawFadingText(canvas, str, len, x, y, paint); |
| 114 | } |
| 115 | |
reed@android.com | f76bacf | 2009-05-13 14:00:33 +0000 | [diff] [blame] | 116 | static void scale_rect(SkIRect* dst, const SkIRect& src, float scale) { |
| 117 | dst->fLeft = (int)::roundf(src.fLeft * scale); |
| 118 | dst->fTop = (int)::roundf(src.fTop * scale); |
| 119 | dst->fRight = (int)::roundf(src.fRight * scale); |
| 120 | dst->fBottom = (int)::roundf(src.fBottom * scale); |
| 121 | } |
| 122 | |
| 123 | static void scale_rgn(SkRegion* dst, const SkRegion& src, float scale) { |
| 124 | SkRegion tmp; |
| 125 | SkRegion::Iterator iter(src); |
| 126 | |
| 127 | for (; !iter.done(); iter.next()) { |
| 128 | SkIRect r; |
| 129 | scale_rect(&r, iter.rect(), scale); |
| 130 | tmp.op(r, SkRegion::kUnion_Op); |
| 131 | } |
| 132 | dst->swap(tmp); |
| 133 | } |
| 134 | |
| 135 | static void paint_rgn(SkCanvas* canvas, const SkRegion& rgn, |
| 136 | const SkPaint& paint) { |
| 137 | SkRegion scaled; |
| 138 | scale_rgn(&scaled, rgn, 0.5f); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 139 | |
reed@android.com | f76bacf | 2009-05-13 14:00:33 +0000 | [diff] [blame] | 140 | SkRegion::Iterator iter(rgn); |
| 141 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 142 | for (; !iter.done(); iter.next()) |
| 143 | { |
| 144 | SkRect r; |
| 145 | r.set(iter.rect()); |
| 146 | canvas->drawRect(r, paint); |
| 147 | } |
| 148 | } |
| 149 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 150 | class RegionView : public Sample { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 152 | RegionView() { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 153 | fBase.set(100, 100, 150, 150); |
| 154 | fRect = fBase; |
| 155 | fRect.inset(5, 5); |
| 156 | fRect.offset(25, 25); |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 157 | this->setBGColor(0xFFDDDDDD); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 158 | } |
| 159 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 160 | void build_base_rgn(SkRegion* rgn) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 161 | rgn->setRect(fBase); |
| 162 | SkIRect r = fBase; |
| 163 | r.offset(75, 20); |
| 164 | rgn->op(r, SkRegion::kUnion_Op); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | void build_rgn(SkRegion* rgn, SkRegion::Op op) { |
| 168 | build_base_rgn(rgn); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 169 | rgn->op(fRect, op); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | protected: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 174 | bool onQuery(Sample::Event* evt) override { |
| 175 | if (Sample::TitleQ(*evt)) { |
| 176 | Sample::TitleR(evt, "Regions"); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 177 | return true; |
| 178 | } |
| 179 | return this->INHERITED::onQuery(evt); |
| 180 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 181 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 182 | static void drawstr(SkCanvas* canvas, const char text[], const SkPoint& loc, |
| 183 | bool hilite) { |
| 184 | SkPaint paint; |
| 185 | paint.setAntiAlias(true); |
| 186 | paint.setTextSize(SkIntToScalar(20)); |
| 187 | paint.setColor(hilite ? SK_ColorRED : 0x40FF0000); |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 188 | canvas->drawString(text, loc.fX, loc.fY, paint); |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | void drawPredicates(SkCanvas* canvas, const SkPoint pts[]) { |
| 192 | SkRegion rgn; |
| 193 | build_base_rgn(&rgn); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 194 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 195 | drawstr(canvas, "Intersects", pts[0], rgn.intersects(fRect)); |
| 196 | drawstr(canvas, "Contains", pts[1], rgn.contains(fRect)); |
| 197 | } |
| 198 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 199 | void drawOrig(SkCanvas* canvas, bool bg) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | SkRect r; |
| 201 | SkPaint paint; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 202 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 203 | paint.setStyle(SkPaint::kStroke_Style); |
| 204 | if (bg) |
| 205 | paint.setColor(0xFFBBBBBB); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 206 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 207 | SkRegion rgn; |
| 208 | build_base_rgn(&rgn); |
| 209 | paint_rgn(canvas, rgn, paint); |
| 210 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 211 | r.set(fRect); |
| 212 | canvas->drawRect(r, paint); |
| 213 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 214 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 215 | void drawRgnOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 216 | SkRegion rgn; |
| 217 | |
| 218 | this->build_rgn(&rgn, op); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 219 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | { |
| 221 | SkRegion tmp, tmp2(rgn); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 222 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 223 | tmp = tmp2; |
| 224 | tmp.translate(5, -3); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 225 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 226 | { |
| 227 | char buffer[1000]; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 228 | SkDEBUGCODE(size_t size = ) tmp.writeToMemory(nullptr); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 229 | SkASSERT(size <= sizeof(buffer)); |
humper@google.com | 0e51577 | 2013-01-07 19:54:40 +0000 | [diff] [blame] | 230 | SkDEBUGCODE(size_t size2 = ) tmp.writeToMemory(buffer); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 231 | SkASSERT(size == size2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 232 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 233 | SkRegion tmp3; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 234 | SkDEBUGCODE(size2 = ) tmp3.readFromMemory(buffer, 1000); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 235 | SkASSERT(size == size2); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 236 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 237 | SkASSERT(tmp3 == tmp); |
| 238 | } |
| 239 | |
| 240 | rgn.translate(20, 30, &tmp); |
| 241 | SkASSERT(rgn.isEmpty() || tmp != rgn); |
| 242 | tmp.translate(-20, -30); |
| 243 | SkASSERT(tmp == rgn); |
| 244 | } |
| 245 | |
| 246 | this->drawOrig(canvas, true); |
| 247 | |
| 248 | SkPaint paint; |
| 249 | paint.setColor((color & ~(0xFF << 24)) | (0x44 << 24)); |
| 250 | paint_rgn(canvas, rgn, paint); |
| 251 | |
| 252 | paint.setStyle(SkPaint::kStroke_Style); |
| 253 | paint.setColor(color); |
| 254 | paint_rgn(canvas, rgn, paint); |
| 255 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 256 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 257 | void drawPathOped(SkCanvas* canvas, SkRegion::Op op, SkColor color) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 258 | SkRegion rgn; |
| 259 | SkPath path; |
| 260 | |
| 261 | this->build_rgn(&rgn, op); |
| 262 | rgn.getBoundaryPath(&path); |
| 263 | |
| 264 | this->drawOrig(canvas, true); |
| 265 | |
| 266 | SkPaint paint; |
| 267 | |
| 268 | paint.setStyle(SkPaint::kFill_Style); |
| 269 | paint.setColor((color & ~(0xFF << 24)) | (0x44 << 24)); |
| 270 | canvas->drawPath(path, paint); |
| 271 | paint.setColor(color); |
| 272 | paint.setStyle(SkPaint::kStroke_Style); |
| 273 | canvas->drawPath(path, paint); |
| 274 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 275 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 276 | void onDrawContent(SkCanvas* canvas) override { |
caryclark@google.com | 02939ce | 2012-06-06 12:09:51 +0000 | [diff] [blame] | 277 | if (false) { // avoid bit rot, suppress warning |
| 278 | test_strokerect(canvas); |
| 279 | return; |
| 280 | } |
| 281 | if (false) { // avoid bit rot, suppress warning |
| 282 | test_text(canvas); |
| 283 | return; |
| 284 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 285 | |
reed@google.com | 4b5894c | 2012-05-02 18:03:32 +0000 | [diff] [blame] | 286 | const SkPoint origins[] = { |
| 287 | { 30*SK_Scalar1, 50*SK_Scalar1 }, |
| 288 | { 150*SK_Scalar1, 50*SK_Scalar1 }, |
| 289 | }; |
| 290 | this->drawPredicates(canvas, origins); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 291 | |
| 292 | static const struct { |
| 293 | SkColor fColor; |
| 294 | const char* fName; |
| 295 | SkRegion::Op fOp; |
| 296 | } gOps[] = { |
| 297 | { SK_ColorBLACK, "Difference", SkRegion::kDifference_Op }, |
| 298 | { SK_ColorRED, "Intersect", SkRegion::kIntersect_Op }, |
| 299 | { 0xFF008800, "Union", SkRegion::kUnion_Op }, |
| 300 | { SK_ColorBLUE, "XOR", SkRegion::kXOR_Op } |
| 301 | }; |
| 302 | |
| 303 | SkPaint textPaint; |
| 304 | textPaint.setAntiAlias(true); |
| 305 | textPaint.setTextSize(SK_Scalar1*24); |
| 306 | |
| 307 | this->drawOrig(canvas, false); |
| 308 | canvas->save(); |
| 309 | canvas->translate(SkIntToScalar(200), 0); |
| 310 | this->drawRgnOped(canvas, SkRegion::kUnion_Op, SK_ColorBLACK); |
| 311 | canvas->restore(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 312 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 313 | canvas->translate(0, SkIntToScalar(200)); |
| 314 | |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 315 | for (size_t op = 0; op < SK_ARRAY_COUNT(gOps); op++) { |
Cary Clark | 2a475ea | 2017-04-28 15:35:12 -0400 | [diff] [blame] | 316 | canvas->drawString(gOps[op].fName, SkIntToScalar(75), SkIntToScalar(50), textPaint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 317 | |
| 318 | this->drawRgnOped(canvas, gOps[op].fOp, gOps[op].fColor); |
| 319 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 320 | canvas->save(); |
| 321 | canvas->translate(0, SkIntToScalar(200)); |
| 322 | this->drawPathOped(canvas, gOps[op].fOp, gOps[op].fColor); |
| 323 | canvas->restore(); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 324 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 325 | canvas->translate(SkIntToScalar(200), 0); |
| 326 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 327 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 328 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 329 | virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 330 | unsigned modi) override { |
reed@google.com | e1ca705 | 2013-12-17 19:22:07 +0000 | [diff] [blame] | 331 | return fRect.contains(SkScalarRoundToInt(x), |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 332 | SkScalarRoundToInt(y)) ? new Click(this) : nullptr; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 333 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 334 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 335 | bool onClick(Click* click) override { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 336 | fRect.offset(click->fICurr.fX - click->fIPrev.fX, |
| 337 | click->fICurr.fY - click->fIPrev.fY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 338 | return true; |
| 339 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 340 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 341 | private: |
| 342 | SkIRect fBase, fRect; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 343 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 344 | typedef Sample INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | ////////////////////////////////////////////////////////////////////////////// |
| 348 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 349 | DEF_SAMPLE( return new RegionView(); ) |