Chromium Code Reviews| Index: sky/framework/animation/controller.sky |
| diff --git a/sky/framework/animation/controller.sky b/sky/framework/animation/controller.sky |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..752a3f4070462399f5d3f8d209ec05346cdd30e3 |
| --- /dev/null |
| +++ b/sky/framework/animation/controller.sky |
| @@ -0,0 +1,46 @@ |
| +<!-- |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +--> |
| +<import src="timer.sky" as="Timer" /> |
| +<script> |
| +module.exports = class Controller { |
|
esprehn
2015/01/29 19:03:57
AnimationController ? It'll print nicer in the con
abarth-chromium
2015/01/29 19:16:45
Sure!
|
| + constructor(delegate) { |
| + this.delegate_ = delegate; |
| + this.timer_ = new Timer(this); |
| + this.begin_ = 0; |
| + this.end_ = 0; |
| + this.curve_ = null; |
| + this.isAnimating = false; |
| + Object.preventExtensions(this); |
| + } |
| + |
| + start(options) { |
| + this.begin_ = options.begin; |
| + this.end_ = options.end; |
| + this.curve_ = options.curve; |
| + this.isAnimating = true; |
| + this.timer_.start(options.duration); |
| + } |
| + |
| + stop() { |
| + this.isAnimating = false; |
| + this.timer_.stop(); |
| + } |
| + |
| + positionForTime_(t) { |
| + // Explicitly finish animations at |this.end_| in case the curve isn't an |
| + // exact numerical transform. |
| + if (t == 1) |
| + return this.end_; |
| + var curvedTime = this.curve_.transform(t); |
| + var begin = this.begin_; |
| + return begin + (this.end_ - begin) * curvedTime; |
| + } |
| + |
| + updateAnimation(t) { |
| + this.delegate_.updateAnimation(this.positionForTime_(t)); |
| + } |
| +}; |
| +</script> |