| 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 'package:sky/animation/timeline.dart'; | 5 import 'package:sky/animation/timeline.dart'; |
| 6 import 'package:sky/animation/curves.dart'; | 6 import 'package:sky/animation/curves.dart'; |
| 7 | 7 |
| 8 abstract class AnimatedVariable { | 8 abstract class AnimatedVariable { |
| 9 void setFraction(double t); | 9 void setFraction(double t); |
| 10 String toString(); | 10 String toString(); |
| 11 } | 11 } |
| 12 | 12 |
| 13 class Interval { |
| 14 final double start; |
| 15 final double end; |
| 16 |
| 17 double adjustTime(double t) { |
| 18 return ((t - start) / (end - start)).clamp(0.0, 1.0); |
| 19 } |
| 20 |
| 21 Interval(this.start, this.end) { |
| 22 assert(start >= 0.0); |
| 23 assert(start <= 1.0); |
| 24 assert(end >= 0.0); |
| 25 assert(end <= 1.0); |
| 26 } |
| 27 } |
| 28 |
| 13 class AnimatedType<T extends dynamic> extends AnimatedVariable { | 29 class AnimatedType<T extends dynamic> extends AnimatedVariable { |
| 14 AnimatedType(this.begin, { this.end, this.curve: linear }) { | 30 AnimatedType(this.begin, { this.end, this.interval, this.curve: linear }) { |
| 15 value = begin; | 31 value = begin; |
| 16 } | 32 } |
| 17 | 33 |
| 18 T value; | 34 T value; |
| 19 T begin; | 35 T begin; |
| 20 T end; | 36 T end; |
| 37 Interval interval; |
| 21 Curve curve; | 38 Curve curve; |
| 22 | 39 |
| 23 void setFraction(double t) { | 40 void setFraction(double t) { |
| 24 if (end != null) { | 41 if (end != null) { |
| 25 if (t == 1.0) { | 42 double adjustedTime = interval == null ? t : interval.adjustTime(t); |
| 43 if (adjustedTime == 1.0) { |
| 26 value = end; | 44 value = end; |
| 27 } else { | 45 } else { |
| 28 // TODO(mpcomplete): Reverse the timeline and curve. | 46 // TODO(mpcomplete): Reverse the timeline and curve. |
| 29 value = begin + (end - begin) * curve.transform(t); | 47 value = begin + (end - begin) * curve.transform(adjustedTime); |
| 30 } | 48 } |
| 31 } | 49 } |
| 32 } | 50 } |
| 33 | 51 |
| 34 String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)'; | 52 String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)'; |
| 35 } | 53 } |
| 36 | 54 |
| 37 class AnimatedList extends AnimatedVariable { | 55 class AnimatedList extends AnimatedVariable { |
| 38 List<AnimatedVariable> variables; | 56 List<AnimatedVariable> variables; |
| 39 AnimatedList(this.variables); | 57 AnimatedList(this.variables); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 timeline.stop(); | 137 timeline.stop(); |
| 120 if (remainingDistance != 0.0) | 138 if (remainingDistance != 0.0) |
| 121 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); | 139 timeline.animateTo(target, duration: remainingDistance * duration.inMillis
econds); |
| 122 } | 140 } |
| 123 | 141 |
| 124 void _tick(double t) { | 142 void _tick(double t) { |
| 125 variable.setFraction(t); | 143 variable.setFraction(t); |
| 126 _notifyListeners(); | 144 _notifyListeners(); |
| 127 } | 145 } |
| 128 } | 146 } |
| OLD | NEW |