allow GMs to animate
BUG=skia:
Review URL: https://codereview.chromium.org/888283002
diff --git a/samplecode/SampleHT.cpp b/samplecode/SampleHT.cpp
index c6e2b49..07605fe 100644
--- a/samplecode/SampleHT.cpp
+++ b/samplecode/SampleHT.cpp
@@ -46,6 +46,7 @@
SkRect fR;
SkColor fColor;
SkInterpolator* fInterp;
+ SkMSec fTime;
public:
HTDrawable(SkRandom& rand) {
@@ -53,18 +54,21 @@
rand.nextRangeF(20, 200), rand.nextRangeF(20, 200));
fColor = rand_opaque_color(rand.nextU());
fInterp = NULL;
+ fTime = 0;
}
- void spawnAnimation() {
+ void spawnAnimation(SkMSec now) {
+ this->setTime(now);
+
SkDELETE(fInterp);
fInterp = SkNEW_ARGS(SkInterpolator, (5, 3));
SkScalar values[5];
color_to_floats(fColor, values); values[4] = 0;
- fInterp->setKeyFrame(0, SampleCode::GetAnimTime(), values);
+ fInterp->setKeyFrame(0, now, values);
values[0] = 0; values[4] = 180;
- fInterp->setKeyFrame(1, SampleCode::GetAnimTime() + 1000, values);
+ fInterp->setKeyFrame(1, now + 1000, values);
color_to_floats(rand_opaque_color(fColor), values); values[4] = 360;
- fInterp->setKeyFrame(2, SampleCode::GetAnimTime() + 2000, values);
+ fInterp->setKeyFrame(2, now + 2000, values);
fInterp->setMirror(true);
fInterp->setRepeatCount(3);
@@ -76,6 +80,8 @@
return oval_contains(fR, x, y);
}
+ void setTime(SkMSec time) { fTime = time; }
+
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkAutoCanvasRestore acr(canvas, false);
@@ -84,7 +90,7 @@
if (fInterp) {
SkScalar values[5];
- SkInterpolator::Result res = fInterp->timeToValues(SampleCode::GetAnimTime(), values);
+ SkInterpolator::Result res = fInterp->timeToValues(fTime, values);
fColor = floats_to_color(values);
canvas->save();
@@ -104,7 +110,7 @@
paint.setColor(fColor);
canvas->drawRect(fR, paint);
}
-
+
SkRect onGetBounds() SK_OVERRIDE { return fR; }
};
@@ -121,6 +127,7 @@
};
Rec fArray[N];
SkAutoTUnref<SkCanvasDrawable> fRoot;
+ SkMSec fTime;
HTView() {
SkRandom rand;
@@ -146,14 +153,21 @@
void onDrawContent(SkCanvas* canvas) SK_OVERRIDE {
canvas->EXPERIMENTAL_drawDrawable(fRoot);
- this->inval(NULL);
+ }
+
+ bool onAnimatePulse(SkMSec curr, SkMSec prev) SK_OVERRIDE {
+ fTime = curr;
+ for (int i = 0; i < N; ++i) {
+ fArray[i].fDrawable->setTime(fTime);
+ }
+ return true;
}
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
// search backwards to find the top-most
for (int i = N - 1; i >= 0; --i) {
if (fArray[i].fDrawable->hitTest(x, y)) {
- fArray[i].fDrawable->spawnAnimation();
+ fArray[i].fDrawable->spawnAnimation(fTime);
break;
}
}