| 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 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import '../base/scheduler.dart' as scheduler; | 7 import '../base/scheduler.dart' as scheduler; |
| 8 | 8 |
| 9 class Ticker { | 9 class Ticker { |
| 10 Ticker(Function onTick) : _onTick = onTick; | 10 Ticker(Function onTick) : _onTick = onTick; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 void set value(double newValue) { | 73 void set value(double newValue) { |
| 74 assert(newValue != null && newValue >= 0.0 && newValue <= 1.0); | 74 assert(newValue != null && newValue >= 0.0 && newValue <= 1.0); |
| 75 assert(!_ticker.isTicking); | 75 assert(!_ticker.isTicking); |
| 76 _value = newValue; | 76 _value = newValue; |
| 77 _onTick(_value); | 77 _onTick(_value); |
| 78 } | 78 } |
| 79 | 79 |
| 80 double _duration; | 80 double _duration; |
| 81 double _begin; | 81 double _begin; |
| 82 double _end; | 82 double _end; |
| 83 double _delay; |
| 83 | 84 |
| 84 double _startTime; | 85 double _startTime; |
| 85 | 86 |
| 86 Future start({ | 87 Future start({ |
| 87 double duration, | 88 double duration, |
| 88 double begin: 0.0, | 89 double begin: 0.0, |
| 89 double end: 1.0 | 90 double end: 1.0, |
| 91 double delay: 0.0 |
| 90 }) { | 92 }) { |
| 91 assert(duration != null && duration > 0.0); | 93 assert(duration != null && duration > 0.0); |
| 92 assert(begin != null && begin >= 0.0 && begin <= 1.0); | 94 assert(begin != null && begin >= 0.0 && begin <= 1.0); |
| 93 assert(end != null && end >= 0.0 && end <= 1.0); | 95 assert(end != null && end >= 0.0 && end <= 1.0); |
| 96 assert(delay != null && delay >= 0.0); |
| 94 | 97 |
| 95 assert(!_ticker.isTicking); | 98 assert(!_ticker.isTicking); |
| 96 | 99 |
| 97 _duration = duration; | 100 _duration = duration; |
| 98 _begin = begin; | 101 _begin = begin; |
| 99 _end = end; | 102 _end = end; |
| 103 _delay = delay; |
| 100 | 104 |
| 101 _startTime = null; | 105 _startTime = null; |
| 102 _value = begin; | 106 _value = begin; |
| 103 | 107 |
| 104 return _ticker.start(); | 108 return _ticker.start(); |
| 105 } | 109 } |
| 106 | 110 |
| 107 Future animateTo(double target, { double duration }) { | 111 Future animateTo(double target, { double duration, double delay }) { |
| 108 return start(duration: duration, begin: _value, end: target); | 112 return start(duration: duration, begin: _value, end: target, delay: delay); |
| 109 } | 113 } |
| 110 | 114 |
| 111 void stop() { | 115 void stop() { |
| 112 _duration = null; | 116 _duration = null; |
| 113 _begin = null; | 117 _begin = null; |
| 114 _end = null; | 118 _end = null; |
| 119 _delay = null; |
| 115 _startTime = null; | 120 _startTime = null; |
| 116 _ticker.stop(); | 121 _ticker.stop(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 bool get isAnimating => _ticker.isTicking; | 124 bool get isAnimating => _ticker.isTicking; |
| 120 | 125 |
| 121 void _tick(double timeStamp) { | 126 void _tick(double timeStamp) { |
| 122 if (_startTime == null) | 127 if (_startTime == null) |
| 123 _startTime = timeStamp; | 128 _startTime = timeStamp; |
| 124 | 129 |
| 125 final double t = ((timeStamp - _startTime) / _duration).clamp(0.0, 1.0); | 130 final double t = ((timeStamp - (_startTime + _delay)) / _duration).clamp(0.0
, 1.0); |
| 126 final bool isLastTick = t >= 1.0; | 131 final bool isLastTick = t >= 1.0; |
| 127 | 132 |
| 128 _value = isLastTick ? _end : _begin + (_end - _begin) * t; | 133 _value = isLastTick ? _end : _begin + (_end - _begin) * t; |
| 129 _onTick(_value); | 134 _onTick(_value); |
| 130 | 135 |
| 131 if (isLastTick) | 136 if (isLastTick) |
| 132 stop(); | 137 stop(); |
| 133 } | 138 } |
| 134 } | 139 } |
| OLD | NEW |