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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 SkMSec fTime; | 50 SkMSec fTime; |
51 | 51 |
52 public: | 52 public: |
53 HTDrawable(SkRandom& rand) { | 53 HTDrawable(SkRandom& rand) { |
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 = nullptr; | 57 fInterp = nullptr; |
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 delete fInterp; | 64 delete fInterp; |
65 fInterp = new 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); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 SkRect onGetBounds() override { return fR; } | 115 SkRect onGetBounds() override { return fR; } |
116 }; | 116 }; |
117 | 117 |
118 class HTView : public SampleView { | 118 class HTView : public SampleView { |
119 public: | 119 public: |
120 enum { | 120 enum { |
121 N = 50, | 121 N = 50, |
122 W = 640, | 122 W = 640, |
123 H = 480, | 123 H = 480, |
124 }; | 124 }; |
125 | 125 |
126 struct Rec { | 126 struct Rec { |
127 HTDrawable* fDrawable; | 127 HTDrawable* fDrawable; |
128 }; | 128 }; |
129 Rec fArray[N]; | 129 Rec fArray[N]; |
130 sk_sp<SkDrawable> fRoot; | 130 sk_sp<SkDrawable> fRoot; |
131 SkMSec fTime; | 131 SkMSec fTime; |
132 | 132 |
133 HTView() { | 133 HTView() { |
134 SkRandom rand; | 134 SkRandom rand; |
135 | 135 |
136 SkPictureRecorder recorder; | 136 SkPictureRecorder recorder; |
137 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(W, H)); | 137 SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(W, H)); |
138 for (int i = 0; i < N; ++i) { | 138 for (int i = 0; i < N; ++i) { |
139 fArray[i].fDrawable = new HTDrawable(rand); | 139 fArray[i].fDrawable = new HTDrawable(rand); |
140 canvas->drawDrawable(fArray[i].fDrawable); | 140 canvas->drawDrawable(fArray[i].fDrawable); |
141 fArray[i].fDrawable->unref(); | 141 fArray[i].fDrawable->unref(); |
142 } | 142 } |
(...skipping 34 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 |