OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SampleCode.h" | 8 #include "SampleCode.h" |
9 #include "SkAnimTimer.h" | 9 #include "SkAnimTimer.h" |
10 #include "SkView.h" | 10 #include "SkView.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480), | 54 fR = SkRect::MakeXYWH(rand.nextRangeF(0, 640), rand.nextRangeF(0, 480), |
55 rand.nextRangeF(20, 200), rand.nextRangeF(20, 200)
); | 55 rand.nextRangeF(20, 200), rand.nextRangeF(20, 200)
); |
56 fColor = rand_opaque_color(rand.nextU()); | 56 fColor = rand_opaque_color(rand.nextU()); |
57 fInterp = NULL; | 57 fInterp = NULL; |
58 fTime = 0; | 58 fTime = 0; |
59 } | 59 } |
60 | 60 |
61 void spawnAnimation(SkMSec now) { | 61 void spawnAnimation(SkMSec now) { |
62 this->setTime(now); | 62 this->setTime(now); |
63 | 63 |
64 SkDELETE(fInterp); | 64 delete fInterp; |
65 fInterp = SkNEW_ARGS(SkInterpolator, (5, 3)); | 65 fInterp = new SkInterpolator(5, 3); |
66 SkScalar values[5]; | 66 SkScalar values[5]; |
67 color_to_floats(fColor, values); values[4] = 0; | 67 color_to_floats(fColor, values); values[4] = 0; |
68 fInterp->setKeyFrame(0, now, values); | 68 fInterp->setKeyFrame(0, now, values); |
69 values[0] = 0; values[4] = 180; | 69 values[0] = 0; values[4] = 180; |
70 fInterp->setKeyFrame(1, now + 1000, values); | 70 fInterp->setKeyFrame(1, now + 1000, values); |
71 color_to_floats(rand_opaque_color(fColor), values); values[4] = 360; | 71 color_to_floats(rand_opaque_color(fColor), values); values[4] = 360; |
72 fInterp->setKeyFrame(2, now + 2000, values); | 72 fInterp->setKeyFrame(2, now + 2000, values); |
73 | 73 |
74 fInterp->setMirror(true); | 74 fInterp->setMirror(true); |
75 fInterp->setRepeatCount(3); | 75 fInterp->setRepeatCount(3); |
(...skipping 18 matching lines...) Expand all Loading... |
94 SkInterpolator::Result res = fInterp->timeToValues(fTime, values); | 94 SkInterpolator::Result res = fInterp->timeToValues(fTime, values); |
95 fColor = floats_to_color(values); | 95 fColor = floats_to_color(values); |
96 | 96 |
97 canvas->save(); | 97 canvas->save(); |
98 canvas->translate(fR.centerX(), fR.centerY()); | 98 canvas->translate(fR.centerX(), fR.centerY()); |
99 canvas->rotate(values[4]); | 99 canvas->rotate(values[4]); |
100 canvas->translate(-fR.centerX(), -fR.centerY()); | 100 canvas->translate(-fR.centerX(), -fR.centerY()); |
101 | 101 |
102 switch (res) { | 102 switch (res) { |
103 case SkInterpolator::kFreezeEnd_Result: | 103 case SkInterpolator::kFreezeEnd_Result: |
104 SkDELETE(fInterp); | 104 delete fInterp; |
105 fInterp = NULL; | 105 fInterp = NULL; |
106 break; | 106 break; |
107 default: | 107 default: |
108 break; | 108 break; |
109 } | 109 } |
110 } | 110 } |
111 paint.setColor(fColor); | 111 paint.setColor(fColor); |
112 canvas->drawRect(fR, paint); | 112 canvas->drawRect(fR, paint); |
113 } | 113 } |
114 | 114 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 } | 177 } |
178 | 178 |
179 private: | 179 private: |
180 typedef SampleView INHERITED; | 180 typedef SampleView INHERITED; |
181 }; | 181 }; |
182 | 182 |
183 ////////////////////////////////////////////////////////////////////////////// | 183 ////////////////////////////////////////////////////////////////////////////// |
184 | 184 |
185 static SkView* MyFactory() { return new HTView; } | 185 static SkView* MyFactory() { return new HTView; } |
186 static SkViewRegister reg(MyFactory); | 186 static SkViewRegister reg(MyFactory); |
OLD | NEW |