epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SampleCode.h" |
| 9 | #include "SkView.h" |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkGradientShader.h" |
| 12 | #include "SkGraphics.h" |
| 13 | #include "SkImageDecoder.h" |
| 14 | #include "SkPath.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | #include "SkRandom.h" |
| 16 | #include "SkRegion.h" |
| 17 | #include "SkShader.h" |
| 18 | #include "SkUtils.h" |
| 19 | #include "SkXfermode.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 20 | #include "SkColorPriv.h" |
| 21 | #include "SkColorFilter.h" |
| 22 | #include "SkTime.h" |
| 23 | #include "SkTypeface.h" |
| 24 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | #include "SkOSFile.h" |
| 26 | #include "SkStream.h" |
| 27 | |
| 28 | #include "SkGeometry.h" // private include :( |
| 29 | |
| 30 | static void drawtriangle(SkCanvas* canvas, const SkPaint& paint, |
| 31 | const SkPoint pts[3]) { |
| 32 | SkPath path; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 33 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 34 | path.moveTo(pts[0]); |
| 35 | path.lineTo(pts[1]); |
| 36 | path.lineTo(pts[2]); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 37 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | canvas->drawPath(path, paint); |
| 39 | } |
| 40 | |
| 41 | static SkShader* make_shader0(SkIPoint* size) { |
| 42 | SkBitmap bm; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 43 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | // SkImageDecoder::DecodeFile("/skimages/progressivejpg.jpg", &bm); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 45 | SkImageDecoder::DecodeFile("/skimages/logo.png", &bm); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | size->set(bm.width(), bm.height()); |
| 47 | return SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, |
| 48 | SkShader::kClamp_TileMode); |
| 49 | } |
| 50 | |
| 51 | static SkShader* make_shader1(const SkIPoint& size) { |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 52 | SkPoint pts[] = { { 0, 0, }, |
| 53 | { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } }; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED }; |
| 55 | return SkGradientShader::CreateLinear(pts, colors, NULL, |
| 56 | SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode, NULL); |
| 57 | } |
| 58 | |
| 59 | /////////////////////////////////////////////////////////////////////////////// |
| 60 | |
| 61 | class Patch { |
| 62 | public: |
reed@android.com | 4516f47 | 2009-06-29 16:25:36 +0000 | [diff] [blame] | 63 | Patch() { sk_bzero(fPts, sizeof(fPts)); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | ~Patch() {} |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 65 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | void setPatch(const SkPoint pts[12]) { |
| 67 | memcpy(fPts, pts, 12 * sizeof(SkPoint)); |
| 68 | fPts[12] = pts[0]; // the last shall be first |
| 69 | } |
| 70 | void setBounds(int w, int h) { fW = w; fH = h; } |
| 71 | |
| 72 | void draw(SkCanvas*, const SkPaint&, int segsU, int segsV, |
| 73 | bool doTextures, bool doColors); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 74 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | private: |
| 76 | SkPoint fPts[13]; |
| 77 | int fW, fH; |
| 78 | }; |
| 79 | |
| 80 | static void eval_patch_edge(const SkPoint cubic[], SkPoint samples[], int segs) { |
| 81 | SkScalar t = 0; |
| 82 | SkScalar dt = SK_Scalar1 / segs; |
| 83 | |
| 84 | samples[0] = cubic[0]; |
| 85 | for (int i = 1; i < segs; i++) { |
| 86 | t += dt; |
| 87 | SkEvalCubicAt(cubic, t, &samples[i], NULL, NULL); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | static void eval_sheet(const SkPoint edge[], int nu, int nv, int iu, int iv, |
| 92 | SkPoint* pt) { |
| 93 | const int TL = 0; |
| 94 | const int TR = nu; |
| 95 | const int BR = TR + nv; |
| 96 | const int BL = BR + nu; |
| 97 | |
| 98 | SkScalar u = SkIntToScalar(iu) / nu; |
| 99 | SkScalar v = SkIntToScalar(iv) / nv; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 100 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 101 | SkScalar uv = SkScalarMul(u, v); |
| 102 | SkScalar Uv = SkScalarMul(SK_Scalar1 - u, v); |
| 103 | SkScalar uV = SkScalarMul(u, SK_Scalar1 - v); |
| 104 | SkScalar UV = SkScalarMul(SK_Scalar1 - u, SK_Scalar1 - v); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 105 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 106 | SkScalar x0 = SkScalarMul(UV, edge[TL].fX) + SkScalarMul(uV, edge[TR].fX) + |
| 107 | SkScalarMul(Uv, edge[BL].fX) + SkScalarMul(uv, edge[BR].fX); |
| 108 | SkScalar y0 = SkScalarMul(UV, edge[TL].fY) + SkScalarMul(uV, edge[TR].fY) + |
| 109 | SkScalarMul(Uv, edge[BL].fY) + SkScalarMul(uv, edge[BR].fY); |
| 110 | |
| 111 | SkScalar x = SkScalarMul(SK_Scalar1 - v, edge[TL+iu].fX) + |
| 112 | SkScalarMul(u, edge[TR+iv].fX) + |
| 113 | SkScalarMul(v, edge[BR+nu-iu].fX) + |
| 114 | SkScalarMul(SK_Scalar1 - u, edge[BL+nv-iv].fX) - x0; |
| 115 | SkScalar y = SkScalarMul(SK_Scalar1 - v, edge[TL+iu].fY) + |
| 116 | SkScalarMul(u, edge[TR+iv].fY) + |
| 117 | SkScalarMul(v, edge[BR+nu-iu].fY) + |
| 118 | SkScalarMul(SK_Scalar1 - u, edge[BL+nv-iv].fY) - y0; |
| 119 | pt->set(x, y); |
| 120 | } |
| 121 | |
| 122 | static int ScalarTo255(SkScalar v) { |
| 123 | int scale = SkScalarToFixed(v) >> 8; |
| 124 | if (scale < 0) { |
| 125 | scale = 0; |
| 126 | } else if (scale > 255) { |
| 127 | scale = 255; |
| 128 | } |
| 129 | return scale; |
| 130 | } |
| 131 | |
| 132 | static SkColor make_color(SkScalar s, SkScalar t) { |
| 133 | int cs = ScalarTo255(s); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 134 | int ct = ScalarTo255(t); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 135 | return SkColorSetARGB(0xFF, cs, 0, 0) + SkColorSetARGB(0, 0, ct, 0); |
| 136 | } |
| 137 | |
| 138 | void Patch::draw(SkCanvas* canvas, const SkPaint& paint, int nu, int nv, |
| 139 | bool doTextures, bool doColors) { |
| 140 | if (nu < 1 || nv < 1) { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | int i, npts = (nu + nv) * 2; |
| 145 | SkAutoSTMalloc<16, SkPoint> storage(npts + 1); |
| 146 | SkPoint* edge0 = storage.get(); |
| 147 | SkPoint* edge1 = edge0 + nu; |
| 148 | SkPoint* edge2 = edge1 + nv; |
| 149 | SkPoint* edge3 = edge2 + nu; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 150 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 151 | // evaluate the edge points |
| 152 | eval_patch_edge(fPts + 0, edge0, nu); |
| 153 | eval_patch_edge(fPts + 3, edge1, nv); |
| 154 | eval_patch_edge(fPts + 6, edge2, nu); |
| 155 | eval_patch_edge(fPts + 9, edge3, nv); |
| 156 | edge3[nv] = edge0[0]; // the last shall be first |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 157 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 158 | for (i = 0; i < npts; i++) { |
| 159 | // canvas->drawLine(edge0[i].fX, edge0[i].fY, edge0[i+1].fX, edge0[i+1].fY, paint); |
| 160 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 161 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 162 | int row, vertCount = (nu + 1) * (nv + 1); |
| 163 | SkAutoTMalloc<SkPoint> vertStorage(vertCount); |
| 164 | SkPoint* verts = vertStorage.get(); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 165 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 166 | // first row |
| 167 | memcpy(verts, edge0, (nu + 1) * sizeof(SkPoint)); |
| 168 | // rows |
| 169 | SkPoint* r = verts; |
| 170 | for (row = 1; row < nv; row++) { |
| 171 | r += nu + 1; |
| 172 | r[0] = edge3[nv - row]; |
| 173 | for (int col = 1; col < nu; col++) { |
| 174 | eval_sheet(edge0, nu, nv, col, row, &r[col]); |
| 175 | } |
| 176 | r[nu] = edge1[row]; |
| 177 | } |
| 178 | // last row |
| 179 | SkPoint* last = verts + nv * (nu + 1); |
| 180 | for (i = 0; i <= nu; i++) { |
| 181 | last[i] = edge2[nu - i]; |
| 182 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 183 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 184 | // canvas->drawPoints(verts, vertCount, paint); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 185 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | int stripCount = (nu + 1) * 2; |
| 187 | SkAutoTMalloc<SkPoint> stripStorage(stripCount * 2); |
| 188 | SkAutoTMalloc<SkColor> colorStorage(stripCount); |
| 189 | SkPoint* strip = stripStorage.get(); |
| 190 | SkPoint* tex = strip + stripCount; |
| 191 | SkColor* colors = colorStorage.get(); |
| 192 | SkScalar t = 0; |
| 193 | const SkScalar ds = SK_Scalar1 * fW / nu; |
| 194 | const SkScalar dt = SK_Scalar1 * fH / nv; |
| 195 | r = verts; |
| 196 | for (row = 0; row < nv; row++) { |
| 197 | SkPoint* upper = r; |
| 198 | SkPoint* lower = r + nu + 1; |
| 199 | r = lower; |
| 200 | SkScalar s = 0; |
| 201 | for (i = 0; i <= nu; i++) { |
| 202 | strip[i*2 + 0] = *upper++; |
| 203 | strip[i*2 + 1] = *lower++; |
| 204 | tex[i*2 + 0].set(s, t); |
| 205 | tex[i*2 + 1].set(s, t + dt); |
| 206 | colors[i*2 + 0] = make_color(s/fW, t/fH); |
| 207 | colors[i*2 + 1] = make_color(s/fW, (t + dt)/fH); |
| 208 | s += ds; |
| 209 | } |
| 210 | t += dt; |
| 211 | canvas->drawVertices(SkCanvas::kTriangleStrip_VertexMode, stripCount, |
| 212 | strip, doTextures ? tex : NULL, |
| 213 | doColors ? colors : NULL, NULL, |
| 214 | NULL, 0, paint); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv, |
| 219 | Patch* patch) { |
| 220 | |
| 221 | SkAutoCanvasRestore ar(canvas, true); |
| 222 | |
| 223 | patch->draw(canvas, paint, 10, 10, false, false); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 224 | canvas->translate(SkIntToScalar(180), 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 225 | patch->draw(canvas, paint, 10, 10, true, false); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 226 | canvas->translate(SkIntToScalar(180), 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 227 | patch->draw(canvas, paint, 10, 10, false, true); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 228 | canvas->translate(SkIntToScalar(180), 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 229 | patch->draw(canvas, paint, 10, 10, true, true); |
| 230 | } |
| 231 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 232 | class PatchView : public SampleView { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 233 | SkShader* fShader0; |
| 234 | SkShader* fShader1; |
| 235 | SkIPoint fSize0, fSize1; |
| 236 | SkPoint fPts[12]; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 237 | |
| 238 | public: |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | PatchView() { |
| 240 | fShader0 = make_shader0(&fSize0); |
| 241 | fSize1 = fSize0; |
| 242 | if (fSize0.fX == 0 || fSize0.fY == 0) { |
| 243 | fSize1.set(2, 2); |
| 244 | } |
| 245 | fShader1 = make_shader1(fSize1); |
| 246 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 247 | const SkScalar S = SkIntToScalar(50); |
| 248 | const SkScalar T = SkIntToScalar(40); |
| 249 | fPts[0].set(S*0, T); |
| 250 | fPts[1].set(S*1, T); |
| 251 | fPts[2].set(S*2, T); |
| 252 | fPts[3].set(S*3, T); |
| 253 | fPts[4].set(S*3, T*2); |
| 254 | fPts[5].set(S*3, T*3); |
| 255 | fPts[6].set(S*3, T*4); |
| 256 | fPts[7].set(S*2, T*4); |
| 257 | fPts[8].set(S*1, T*4); |
| 258 | fPts[9].set(S*0, T*4); |
| 259 | fPts[10].set(S*0, T*3); |
| 260 | fPts[11].set(S*0, T*2); |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 261 | |
| 262 | this->setBGColor(SK_ColorGRAY); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 263 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 264 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 265 | virtual ~PatchView() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 266 | SkSafeUnref(fShader0); |
| 267 | SkSafeUnref(fShader1); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 268 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 269 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 270 | protected: |
| 271 | // overrides from SkEventSink |
| 272 | virtual bool onQuery(SkEvent* evt) { |
| 273 | if (SampleCode::TitleQ(*evt)) |
| 274 | { |
| 275 | SkString str("Patch"); |
| 276 | SampleCode::TitleR(evt, str.c_str()); |
| 277 | return true; |
| 278 | } |
| 279 | return this->INHERITED::onQuery(evt); |
| 280 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 281 | |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 282 | virtual void onDrawContent(SkCanvas* canvas) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 283 | SkPaint paint; |
| 284 | paint.setDither(true); |
| 285 | paint.setFilterBitmap(true); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 286 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 287 | canvas->translate(SkIntToScalar(20), 0); |
| 288 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 289 | Patch patch; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 290 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 291 | paint.setShader(fShader0); |
| 292 | if (fSize0.fX == 0) { |
| 293 | fSize0.fX = 1; |
| 294 | } |
| 295 | if (fSize0.fY == 0) { |
| 296 | fSize0.fY = 1; |
| 297 | } |
| 298 | patch.setBounds(fSize0.fX, fSize0.fY); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 299 | |
| 300 | patch.setPatch(fPts); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 301 | drawpatches(canvas, paint, 10, 10, &patch); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 302 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 303 | paint.setShader(NULL); |
| 304 | paint.setAntiAlias(true); |
| 305 | paint.setStrokeWidth(SkIntToScalar(5)); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 306 | canvas->drawPoints(SkCanvas::kPoints_PointMode, SK_ARRAY_COUNT(fPts), fPts, paint); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 307 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 308 | canvas->translate(0, SkIntToScalar(300)); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 309 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 310 | paint.setAntiAlias(false); |
| 311 | paint.setShader(fShader1); |
| 312 | patch.setBounds(fSize1.fX, fSize1.fY); |
| 313 | drawpatches(canvas, paint, 10, 10, &patch); |
| 314 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 315 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 316 | class PtClick : public Click { |
| 317 | public: |
| 318 | int fIndex; |
| 319 | PtClick(SkView* view, int index) : Click(view), fIndex(index) {} |
| 320 | }; |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 321 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 322 | static bool hittest(const SkPoint& pt, SkScalar x, SkScalar y) { |
| 323 | return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5); |
| 324 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 325 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 326 | virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y) { |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 327 | for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); i++) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 328 | if (hittest(fPts[i], x, y)) { |
| 329 | return new PtClick(this, i); |
| 330 | } |
| 331 | } |
| 332 | return this->INHERITED::onFindClickHandler(x, y); |
| 333 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 334 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 335 | virtual bool onClick(Click* click) { |
| 336 | fPts[((PtClick*)click)->fIndex].set(click->fCurr.fX, click->fCurr.fY); |
| 337 | this->inval(NULL); |
| 338 | return true; |
| 339 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 340 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 341 | private: |
mike@reedtribe.org | 5fd9243 | 2011-05-05 01:59:48 +0000 | [diff] [blame] | 342 | typedef SampleView INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | ////////////////////////////////////////////////////////////////////////////// |
| 346 | |
| 347 | static SkView* MyFactory() { return new PatchView; } |
| 348 | static SkViewRegister reg(MyFactory); |
| 349 | |