| 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 | 9 |
| 10 class FrameGenerator { | 10 class FrameGenerator { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 final Curve curve; | 59 final Curve curve; |
| 60 Stream<double> _stream; | 60 Stream<double> _stream; |
| 61 bool _done = false; | 61 bool _done = false; |
| 62 | 62 |
| 63 AnimationGenerator(this.duration, { | 63 AnimationGenerator(this.duration, { |
| 64 this.begin: 0.0, | 64 this.begin: 0.0, |
| 65 this.end: 1.0, | 65 this.end: 1.0, |
| 66 this.curve: linear, | 66 this.curve: linear, |
| 67 Function onDone | 67 Function onDone |
| 68 }):super(onDone: onDone) { | 68 }):super(onDone: onDone) { |
| 69 assert(duration > 0); |
| 69 double startTime = 0.0; | 70 double startTime = 0.0; |
| 70 _stream = super.onTick.map((timeStamp) { | 71 _stream = super.onTick.map((timeStamp) { |
| 71 if (startTime == 0.0) | 72 if (startTime == 0.0) |
| 72 startTime = timeStamp; | 73 startTime = timeStamp; |
| 73 return math.min((timeStamp - startTime) / duration, 1.0); | 74 return math.min((timeStamp - startTime) / duration, 1.0); |
| 74 }) | 75 }) |
| 75 .takeWhile(_checkForCompletion) | 76 .takeWhile(_checkForCompletion) |
| 76 .map((t) => begin + (end - begin) * curve.transform(t)); | 77 .map((t) => begin + (end - begin) * curve.transform(t)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 bool _checkForCompletion(double t) { | 80 bool _checkForCompletion(double t) { |
| 80 if (_done) | 81 if (_done) |
| 81 return false; | 82 return false; |
| 82 _done = t >= 1; | 83 _done = t >= 1; |
| 83 return true; | 84 return true; |
| 84 } | 85 } |
| 85 } | 86 } |
| OLD | NEW |