Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(980)

Unified Diff: sky/framework/animation/generator.dart

Issue 1001373002: Organize sky/framework/animation (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/animation/controller.dart ('k') | sky/framework/animation/generators.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/animation/generator.dart
diff --git a/sky/framework/animation/generator.dart b/sky/framework/animation/generator.dart
deleted file mode 100644
index 7530f04a4ad3ae4af94d2219d400f9cec38cc9e5..0000000000000000000000000000000000000000
--- a/sky/framework/animation/generator.dart
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import 'curves.dart';
-import 'dart:async';
-import 'dart:math' as math;
-import 'dart:sky' as sky;
-
-class FrameGenerator {
- Function onDone;
- StreamController _controller;
-
- Stream<double> get onTick => _controller.stream;
-
- int _animationId = 0;
- bool _cancelled = false;
-
- FrameGenerator({this.onDone}) {
- _controller = new StreamController(
- sync: true,
- onListen: _scheduleTick,
- onCancel: cancel);
- }
-
- void cancel() {
- if (_cancelled) {
- return;
- }
- if (_animationId != 0) {
- sky.window.cancelAnimationFrame(_animationId);
- }
- _animationId = 0;
- _cancelled = true;
- if (onDone != null) {
- onDone();
- }
- }
-
- void _scheduleTick() {
- assert(_animationId == 0);
- _animationId = sky.window.requestAnimationFrame(_tick);
- }
-
- void _tick(double timeStamp) {
- _animationId = 0;
- _controller.add(timeStamp);
- if (!_cancelled) {
- _scheduleTick();
- }
- }
-}
-
-class AnimationGenerator {
- Stream<double> get onTick => _stream;
- final double initialDelay;
- final double duration;
- final double begin;
- final double end;
- final Curve curve;
-
- FrameGenerator _generator;
- Stream<double> _stream;
- bool _done = false;
-
- AnimationGenerator({
- this.initialDelay: 0.0,
- this.duration,
- this.begin: 0.0,
- this.end: 1.0,
- this.curve: linear,
- Function onDone
- }) {
- assert(duration != null && duration > 0.0);
- _generator = new FrameGenerator(onDone: onDone);
-
- double startTime = 0.0;
- _stream = _generator.onTick.map((timeStamp) {
- if (startTime == 0.0)
- startTime = timeStamp;
-
- double t = (timeStamp - (startTime + initialDelay)) / duration;
- return math.max(0.0, math.min(t, 1.0));
- })
- .takeWhile(_checkForCompletion)
- .where((t) => t >= 0.0)
- .map(_transform);
- }
-
- void cancel() {
- _generator.cancel();
- }
-
- double _transform(double t) {
- if (_done)
- return end;
- return begin + (end - begin) * curve.transform(t);
- }
-
- // This is required because Dart Streams don't have takeUntil (inclusive).
- bool _checkForCompletion(double t) {
- if (_done)
- return false;
-
- _done = t >= 1;
- return true;
- }
-}
-
-class Animation {
- Stream<double> get onValueChanged => _controller.stream;
-
- double get value => _value;
-
- void set value(double value) {
- stop();
- _setValue(value);
- }
-
- bool get isAnimating => _animation != null;
-
- StreamController _controller = new StreamController(sync: true);
-
- AnimationGenerator _animation;
-
- double _value;
-
- void _setValue(double value) {
- _value = value;
- _controller.add(_value);
- }
-
- void stop() {
- if (_animation != null) {
- _animation.cancel();
- _animation = null;
- }
- }
-
- void animateTo(double newValue, double duration,
- { Curve curve: linear, double initialDelay: 0.0 }) {
- stop();
-
- _animation = new AnimationGenerator(
- duration: duration,
- begin: _value,
- end: newValue,
- curve: curve,
- initialDelay: initialDelay);
-
- _animation.onTick.listen(_setValue, onDone: () {
- _animation = null;
- });
- }
-}
« no previous file with comments | « sky/framework/animation/controller.dart ('k') | sky/framework/animation/generators.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698