| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'timeline.dart'; | 5 import 'timeline.dart'; |
| 6 import 'curves.dart'; | 6 import 'curves.dart'; |
| 7 | 7 |
| 8 // TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't | 8 // TODO(mpcomplete): merge this stuff with AnimatedValue somehow. We shouldn't |
| 9 // have 2 different ways to animate values. | 9 // have 2 different ways to animate values. |
| 10 abstract class AnimatedVariable { | 10 abstract class AnimatedVariable { |
| 11 void setFraction(double t); | 11 void setFraction(double t); |
| 12 } | 12 } |
| 13 | 13 |
| 14 class AnimatedType<T extends dynamic> extends AnimatedVariable { | 14 class AnimatedType<T extends dynamic> extends AnimatedVariable { |
| 15 T value; | |
| 16 T begin, end; | |
| 17 final Curve curve; | |
| 18 | |
| 19 AnimatedType(this.begin, {this.end, this.curve: linear}) { | 15 AnimatedType(this.begin, {this.end, this.curve: linear}) { |
| 20 value = begin; | 16 value = begin; |
| 21 } | 17 } |
| 22 | 18 |
| 19 T value; |
| 20 T begin; |
| 21 T end; |
| 22 Curve curve; |
| 23 |
| 23 void setFraction(double t) { | 24 void setFraction(double t) { |
| 24 if (end != null) { | 25 if (end != null) { |
| 25 // TODO(mpcomplete): Reverse the timeline and curve. | 26 // TODO(mpcomplete): Reverse the timeline and curve. |
| 26 value = begin + (end - begin) * curve.transform(t); | 27 value = begin + (end - begin) * curve.transform(t); |
| 27 } | 28 } |
| 28 } | 29 } |
| 29 } | 30 } |
| 30 | 31 |
| 31 // This class manages a "performance" - a collection of values that change | 32 // This class manages a "performance" - a collection of values that change |
| 32 // based on a timeline. For example, a performance may handle an animation | 33 // based on a timeline. For example, a performance may handle an animation |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 timeline.stop(); | 104 timeline.stop(); |
| 104 if (remainingDistance != 0.0) | 105 if (remainingDistance != 0.0) |
| 105 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); | 106 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void _tick(double t) { | 109 void _tick(double t) { |
| 109 variable.setFraction(t); | 110 variable.setFraction(t); |
| 110 _notifyListeners(); | 111 _notifyListeners(); |
| 111 } | 112 } |
| 112 } | 113 } |
| OLD | NEW |