| 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 'curves.dart'; | 5 import 'curves.dart'; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 import 'dart:sky' as sky; | 8 import 'dart:sky' as sky; |
| 9 import 'mechanics.dart'; | 9 import 'mechanics.dart'; |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 Stream<double> get onTick => _stream; | 61 Stream<double> get onTick => _stream; |
| 62 final double initialDelay; | 62 final double initialDelay; |
| 63 final double duration; | 63 final double duration; |
| 64 final double begin; | 64 final double begin; |
| 65 final double end; | 65 final double end; |
| 66 final Curve curve; | 66 final Curve curve; |
| 67 | 67 |
| 68 FrameGenerator _generator; | 68 FrameGenerator _generator; |
| 69 Stream<double> _stream; | 69 Stream<double> _stream; |
| 70 bool _done = false; | 70 bool _done = false; |
| 71 double _lastTime; |
| 71 | 72 |
| 72 AnimationGenerator({ | 73 AnimationGenerator({ |
| 73 this.initialDelay: 0.0, | 74 this.initialDelay: 0.0, |
| 74 this.duration, | 75 this.duration, |
| 75 this.begin: 0.0, | 76 this.begin: 0.0, |
| 76 this.end: 1.0, | 77 this.end: 1.0, |
| 77 this.curve: linear, | 78 this.curve: linear, |
| 78 Function onDone | 79 Function onDone |
| 79 }) { | 80 }) { |
| 80 assert(curve != null); | 81 assert(curve != null); |
| 81 assert(duration != null && duration > 0.0); | 82 assert(duration != null && duration > 0.0); |
| 82 _generator = new FrameGenerator(onDone: onDone); | 83 _generator = new FrameGenerator(onDone: onDone); |
| 83 | 84 |
| 84 double startTime = 0.0; | 85 double startTime = 0.0; |
| 85 _stream = _generator.onTick.map((timeStamp) { | 86 _stream = _generator.onTick.map((timeStamp) { |
| 86 if (startTime == 0.0) | 87 if (startTime == 0.0) |
| 87 startTime = timeStamp; | 88 startTime = timeStamp; |
| 88 | 89 |
| 89 double t = (timeStamp - (startTime + initialDelay)) / duration; | 90 double t = (timeStamp - (startTime + initialDelay)) / duration; |
| 90 return math.max(0.0, math.min(t, 1.0)); | 91 _lastTime = math.max(0.0, math.min(t, 1.0)); |
| 92 return _lastTime; |
| 91 }) | 93 }) |
| 92 .takeWhile(_checkForCompletion) | 94 .takeWhile(_checkForCompletion) |
| 93 .where((t) => t >= 0.0) | 95 .where((t) => t >= 0.0) |
| 94 .map(_transform); | 96 .map(_transform); |
| 95 } | 97 } |
| 96 | 98 |
| 99 double get remainingTime { |
| 100 if (_lastTime == null) |
| 101 return duration; |
| 102 return duration - _lastTime; |
| 103 } |
| 104 |
| 97 void cancel() { | 105 void cancel() { |
| 98 _generator.cancel(); | 106 _generator.cancel(); |
| 99 } | 107 } |
| 100 | 108 |
| 101 double _transform(double t) { | 109 double _transform(double t) { |
| 102 if (_done) | 110 if (_done) |
| 103 return end; | 111 return end; |
| 104 return begin + (end - begin) * curve.transform(t); | 112 return begin + (end - begin) * curve.transform(t); |
| 105 } | 113 } |
| 106 | 114 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 double _update(double timeStamp) { | 152 double _update(double timeStamp) { |
| 145 double previousTime = _previousTime; | 153 double previousTime = _previousTime; |
| 146 _previousTime = timeStamp; | 154 _previousTime = timeStamp; |
| 147 if (previousTime == 0.0) | 155 if (previousTime == 0.0) |
| 148 return timeStamp; | 156 return timeStamp; |
| 149 double deltaT = timeStamp - previousTime; | 157 double deltaT = timeStamp - previousTime; |
| 150 system.update(deltaT); | 158 system.update(deltaT); |
| 151 return timeStamp; | 159 return timeStamp; |
| 152 } | 160 } |
| 153 } | 161 } |
| OLD | NEW |