OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
| 9 #include "SkAnimTimer.h" |
9 #include "SkView.h" | 10 #include "SkView.h" |
10 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
11 #include "SkGradientShader.h" | 12 #include "SkGradientShader.h" |
12 #include "SkGraphics.h" | 13 #include "SkGraphics.h" |
13 #include "SkImageDecoder.h" | 14 #include "SkImageDecoder.h" |
14 #include "SkPath.h" | 15 #include "SkPath.h" |
15 #include "SkRandom.h" | 16 #include "SkRandom.h" |
16 #include "SkRegion.h" | 17 #include "SkRegion.h" |
17 #include "SkShader.h" | 18 #include "SkShader.h" |
18 #include "SkUtils.h" | 19 #include "SkUtils.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 canvas->translate(SkIntToScalar(180), 0); | 215 canvas->translate(SkIntToScalar(180), 0); |
215 patch->draw(canvas, paint, nu, nv, false, true); | 216 patch->draw(canvas, paint, nu, nv, false, true); |
216 canvas->translate(SkIntToScalar(180), 0); | 217 canvas->translate(SkIntToScalar(180), 0); |
217 patch->draw(canvas, paint, nu, nv, true, true); | 218 patch->draw(canvas, paint, nu, nv, true, true); |
218 } | 219 } |
219 | 220 |
220 const SkScalar DX = 20; | 221 const SkScalar DX = 20; |
221 const SkScalar DY = 0; | 222 const SkScalar DY = 0; |
222 | 223 |
223 class PatchView : public SampleView { | 224 class PatchView : public SampleView { |
| 225 SkScalar fAngle; |
224 SkShader* fShader0; | 226 SkShader* fShader0; |
225 SkShader* fShader1; | 227 SkShader* fShader1; |
226 SkIPoint fSize0, fSize1; | 228 SkIPoint fSize0, fSize1; |
227 SkPoint fPts[12]; | 229 SkPoint fPts[12]; |
228 | 230 |
229 public: | 231 public: |
230 PatchView() { | 232 PatchView() : fAngle(0) { |
231 fShader0 = make_shader0(&fSize0); | 233 fShader0 = make_shader0(&fSize0); |
232 fSize1 = fSize0; | 234 fSize1 = fSize0; |
233 if (fSize0.fX == 0 || fSize0.fY == 0) { | 235 if (fSize0.fX == 0 || fSize0.fY == 0) { |
234 fSize1.set(2, 2); | 236 fSize1.set(2, 2); |
235 } | 237 } |
236 fShader1 = make_shader1(fSize1); | 238 fShader1 = make_shader1(fSize1); |
237 | 239 |
238 const SkScalar S = SkIntToScalar(50); | 240 const SkScalar S = SkIntToScalar(50); |
239 const SkScalar T = SkIntToScalar(40); | 241 const SkScalar T = SkIntToScalar(40); |
240 fPts[0].set(S*0, T); | 242 fPts[0].set(S*0, T); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 303 |
302 paint.setAntiAlias(false); | 304 paint.setAntiAlias(false); |
303 paint.setShader(fShader1); | 305 paint.setShader(fShader1); |
304 if (true) { | 306 if (true) { |
305 SkMatrix m; | 307 SkMatrix m; |
306 m.setSkew(1, 0); | 308 m.setSkew(1, 0); |
307 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m
); | 309 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m
); |
308 paint.setShader(s)->unref(); | 310 paint.setShader(s)->unref(); |
309 } | 311 } |
310 if (true) { | 312 if (true) { |
311 static int gAngle; | |
312 SkMatrix m; | 313 SkMatrix m; |
313 m.setRotate(SkIntToScalar(gAngle++)); | 314 m.setRotate(fAngle); |
314 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m
); | 315 SkShader* s = SkShader::CreateLocalMatrixShader(paint.getShader(), m
); |
315 paint.setShader(s)->unref(); | 316 paint.setShader(s)->unref(); |
316 } | 317 } |
317 patch.setBounds(fSize1.fX, fSize1.fY); | 318 patch.setBounds(fSize1.fX, fSize1.fY); |
318 drawpatches(canvas, paint, nu, nv, &patch); | 319 drawpatches(canvas, paint, nu, nv, &patch); |
| 320 } |
319 | 321 |
320 this->inval(NULL); | 322 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { |
| 323 fAngle = timer.scaled(60, 360); |
| 324 return true; |
321 } | 325 } |
322 | 326 |
323 class PtClick : public Click { | 327 class PtClick : public Click { |
324 public: | 328 public: |
325 int fIndex; | 329 int fIndex; |
326 PtClick(SkView* view, int index) : Click(view), fIndex(index) {} | 330 PtClick(SkView* view, int index) : Click(view), fIndex(index) {} |
327 }; | 331 }; |
328 | 332 |
329 static bool hittest(const SkPoint& pt, SkScalar x, SkScalar y) { | 333 static bool hittest(const SkPoint& pt, SkScalar x, SkScalar y) { |
330 return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5); | 334 return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5); |
(...skipping 18 matching lines...) Expand all Loading... |
349 } | 353 } |
350 | 354 |
351 private: | 355 private: |
352 typedef SampleView INHERITED; | 356 typedef SampleView INHERITED; |
353 }; | 357 }; |
354 | 358 |
355 ////////////////////////////////////////////////////////////////////////////// | 359 ////////////////////////////////////////////////////////////////////////////// |
356 | 360 |
357 static SkView* MyFactory() { return new PatchView; } | 361 static SkView* MyFactory() { return new PatchView; } |
358 static SkViewRegister reg(MyFactory); | 362 static SkViewRegister reg(MyFactory); |
OLD | NEW |