OLD | NEW |
1 part of widgets; | 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'curves.dart'; |
| 6 import 'dart:async'; |
| 7 import 'dart:math' as math; |
| 8 import 'dart:sky' as sky; |
2 | 9 |
3 class FrameGenerator { | 10 class FrameGenerator { |
4 | |
5 Function onDone; | 11 Function onDone; |
6 StreamController _controller; | 12 StreamController _controller; |
7 | 13 |
8 Stream<double> get onTick => _controller.stream; | 14 Stream<double> get onTick => _controller.stream; |
9 | 15 |
10 int _animationId = 0; | 16 int _animationId = 0; |
11 bool _cancelled = false; | 17 bool _cancelled = false; |
12 | 18 |
13 FrameGenerator({this.onDone}) { | 19 FrameGenerator({this.onDone}) { |
14 _controller = new StreamController( | 20 _controller = new StreamController( |
(...skipping 24 matching lines...) Expand all Loading... |
39 void _tick(double timeStamp) { | 45 void _tick(double timeStamp) { |
40 _animationId = 0; | 46 _animationId = 0; |
41 _controller.add(timeStamp); | 47 _controller.add(timeStamp); |
42 if (!_cancelled) { | 48 if (!_cancelled) { |
43 _scheduleTick(); | 49 _scheduleTick(); |
44 } | 50 } |
45 } | 51 } |
46 } | 52 } |
47 | 53 |
48 class AnimationGenerator extends FrameGenerator { | 54 class AnimationGenerator extends FrameGenerator { |
49 | |
50 Stream<double> get onTick => _stream; | 55 Stream<double> get onTick => _stream; |
51 final double duration; | 56 final double duration; |
52 final double begin; | 57 final double begin; |
53 final double end; | 58 final double end; |
54 final Curve curve; | 59 final Curve curve; |
55 Stream<double> _stream; | 60 Stream<double> _stream; |
56 bool _done = false; | 61 bool _done = false; |
57 | 62 |
58 AnimationGenerator(this.duration, { | 63 AnimationGenerator(this.duration, { |
59 this.begin: 0.0, | 64 this.begin: 0.0, |
(...skipping 14 matching lines...) Expand all Loading... |
74 .map((t) => begin + (end - begin) * curve.transform(t)); | 79 .map((t) => begin + (end - begin) * curve.transform(t)); |
75 } | 80 } |
76 | 81 |
77 bool _checkForCompletion(double t) { | 82 bool _checkForCompletion(double t) { |
78 if (_done) | 83 if (_done) |
79 return false; | 84 return false; |
80 _done = t >= 1; | 85 _done = t >= 1; |
81 return true; | 86 return true; |
82 } | 87 } |
83 } | 88 } |
OLD | NEW |