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

Side by Side Diff: sky/sdk/lib/framework/animation/generators.dart

Issue 1145973009: Add a simple inksplash example (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: nits Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/framework/app.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../scheduler.dart' as scheduler;
5 import 'curves.dart'; 6 import 'curves.dart';
6 import 'dart:async'; 7 import 'dart:async';
7 import 'dart:math' as math; 8 import 'dart:math' as math;
8 import 'dart:sky' as sky;
9 import 'mechanics.dart'; 9 import 'mechanics.dart';
10 10
11 abstract class Generator { 11 abstract class Generator {
12 Stream<double> get onTick; 12 Stream<double> get onTick;
13 void cancel(); 13 void cancel();
14 } 14 }
15 15
16 class FrameGenerator extends Generator { 16 class FrameGenerator extends Generator {
17 Function onDone; 17 Function onDone;
18 StreamController _controller; 18 StreamController _controller;
19 19
20 Stream<double> get onTick => _controller.stream; 20 Stream<double> get onTick => _controller.stream;
21 21
22 int _animationId = 0; 22 int _animationId = 0;
23 bool _cancelled = false; 23 bool _cancelled = false;
24 24
25 FrameGenerator({this.onDone}) { 25 FrameGenerator({this.onDone}) {
26 _controller = new StreamController( 26 _controller = new StreamController(
27 sync: true, 27 sync: true,
28 onListen: _scheduleTick, 28 onListen: _scheduleTick,
29 onCancel: cancel); 29 onCancel: cancel);
30 } 30 }
31 31
32 void cancel() { 32 void cancel() {
33 if (_cancelled) { 33 if (_cancelled) {
34 return; 34 return;
35 } 35 }
36 if (_animationId != 0) { 36 if (_animationId != 0) {
37 sky.window.cancelAnimationFrame(_animationId); 37 scheduler.cancelAnimationFrame(_animationId);
38 } 38 }
39 _animationId = 0; 39 _animationId = 0;
40 _cancelled = true; 40 _cancelled = true;
41 if (onDone != null) { 41 if (onDone != null) {
42 onDone(); 42 onDone();
43 } 43 }
44 } 44 }
45 45
46 void _scheduleTick() { 46 void _scheduleTick() {
47 assert(_animationId == 0); 47 assert(_animationId == 0);
48 _animationId = sky.window.requestAnimationFrame(_tick); 48 _animationId = scheduler.requestAnimationFrame(_tick);
49 } 49 }
50 50
51 void _tick(double timeStamp) { 51 void _tick(double timeStamp) {
52 _animationId = 0; 52 _animationId = 0;
53 _controller.add(timeStamp); 53 _controller.add(timeStamp);
54 if (!_cancelled) { 54 if (!_cancelled) {
55 _scheduleTick(); 55 _scheduleTick();
56 } 56 }
57 } 57 }
58 } 58 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 double _update(double timeStamp) { 152 double _update(double timeStamp) {
153 double previousTime = _previousTime; 153 double previousTime = _previousTime;
154 _previousTime = timeStamp; 154 _previousTime = timeStamp;
155 if (previousTime == 0.0) 155 if (previousTime == 0.0)
156 return timeStamp; 156 return timeStamp;
157 double deltaT = timeStamp - previousTime; 157 double deltaT = timeStamp - previousTime;
158 system.update(deltaT); 158 system.update(deltaT);
159 return timeStamp; 159 return timeStamp;
160 } 160 }
161 } 161 }
OLDNEW
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | sky/sdk/lib/framework/app.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698