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