OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
10 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
12 #include "SkRandom.h" | 13 #include "SkRandom.h" |
13 | 14 |
14 SkScalar get_anim_sin(SkMSec time, SkScalar amplitude, SkScalar periodInSec, SkS
calar phaseInSec) { | 15 SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkS
calar phaseInSec) { |
15 if (!periodInSec) { | 16 if (!periodInSec) { |
16 return 0; | 17 return 0; |
17 } | 18 } |
18 double t = (double)time / 1000.0 + phaseInSec; | 19 double t = secs + phaseInSec; |
19 t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec; | 20 t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec; |
20 amplitude = SK_ScalarHalf * amplitude; | 21 amplitude = SK_ScalarHalf * amplitude; |
21 return amplitude * SkDoubleToScalar(sin(t)) + amplitude; | 22 return amplitude * SkDoubleToScalar(sin(t)) + amplitude; |
22 } | 23 } |
23 | 24 |
24 class AnimBlurView : public SampleView { | 25 class AnimBlurView : public SampleView { |
25 public: | 26 public: |
26 AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {} | 27 AnimBlurView() : fBlurSigma(0), fCircleRadius(100) {} |
27 | 28 |
28 protected: | 29 protected: |
(...skipping 22 matching lines...) Expand all Loading... |
51 SkBlurMaskFilter::kHighQuality_BlurFlag); | 52 SkBlurMaskFilter::kHighQuality_BlurFlag); |
52 SkPaint paint; | 53 SkPaint paint; |
53 SkSafeUnref(paint.setMaskFilter(mf)); | 54 SkSafeUnref(paint.setMaskFilter(mf)); |
54 paint.setColor(random.nextU() | 0xff000000); | 55 paint.setColor(random.nextU() | 0xff000000); |
55 canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1, | 56 canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1, |
56 200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1, | 57 200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1, |
57 fCircleRadius, paint); | 58 fCircleRadius, paint); |
58 } | 59 } |
59 } | 60 } |
60 | 61 |
61 bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE { | 62 bool onAnimate(const SkAnimTimer& timer) SK_OVERRIDE { |
62 fBlurSigma = get_anim_sin(curr, 100, 4, 5); | 63 fBlurSigma = get_anim_sin(timer.secs(), 100, 4, 5); |
63 fCircleRadius = 3 + get_anim_sin(curr, 150, 25, 3); | 64 fCircleRadius = 3 + get_anim_sin(timer.secs(), 150, 25, 3); |
64 return true; | 65 return true; |
65 } | 66 } |
66 | 67 |
67 private: | 68 private: |
68 SkScalar fBlurSigma, fCircleRadius; | 69 SkScalar fBlurSigma, fCircleRadius; |
69 | 70 |
70 typedef SampleView INHERITED; | 71 typedef SampleView INHERITED; |
71 }; | 72 }; |
72 | 73 |
73 ////////////////////////////////////////////////////////////////////////////// | 74 ////////////////////////////////////////////////////////////////////////////// |
74 | 75 |
75 static SkView* MyFactory() { return new AnimBlurView; } | 76 static SkView* MyFactory() { return new AnimBlurView; } |
76 static SkViewRegister reg(MyFactory); | 77 static SkViewRegister reg(MyFactory); |
OLD | NEW |