Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1022)

Unified Diff: samplecode/SampleHT.cpp

Issue 888283002: allow GMs to animate (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: switch all existing animations to use animatePulse Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleDegenerateTwoPtRadials.cpp ('k') | samplecode/SampleHairline.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleHT.cpp
diff --git a/samplecode/SampleHT.cpp b/samplecode/SampleHT.cpp
index c6e2b4971a4f8a529ae8078197d4719855c2513d..07605fe1ed65dd0cb8c1f18a3abf4dba9895fefc 100644
--- a/samplecode/SampleHT.cpp
+++ b/samplecode/SampleHT.cpp
@@ -46,6 +46,7 @@ class HTDrawable : public SkCanvasDrawable {
SkRect fR;
SkColor fColor;
SkInterpolator* fInterp;
+ SkMSec fTime;
public:
HTDrawable(SkRandom& rand) {
@@ -53,18 +54,21 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
paint.setColor(fColor);
canvas->drawRect(fR, paint);
}
-
+
SkRect onGetBounds() SK_OVERRIDE { return fR; }
};
@@ -121,6 +127,7 @@ public:
};
Rec fArray[N];
SkAutoTUnref<SkCanvasDrawable> fRoot;
+ SkMSec fTime;
HTView() {
SkRandom rand;
@@ -146,14 +153,21 @@ protected:
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;
}
}
« no previous file with comments | « samplecode/SampleDegenerateTwoPtRadials.cpp ('k') | samplecode/SampleHairline.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698