OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library clock; | 5 library clock; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'dart:math'; | 8 import 'dart:math'; |
9 | 9 |
10 part 'balls.dart'; | 10 part 'balls.dart'; |
(...skipping 29 matching lines...) Expand all Loading... |
40 int displayedHour = 0; | 40 int displayedHour = 0; |
41 int displayedMinute = 0; | 41 int displayedMinute = 0; |
42 int displayedSecond = 0; | 42 int displayedSecond = 0; |
43 Balls balls = new Balls(); | 43 Balls balls = new Balls(); |
44 | 44 |
45 CountDownClock() { | 45 CountDownClock() { |
46 var parent = query("#canvas-content"); | 46 var parent = query("#canvas-content"); |
47 | 47 |
48 createNumbers(parent, parent.clientWidth, parent.clientHeight); | 48 createNumbers(parent, parent.clientWidth, parent.clientHeight); |
49 | 49 |
50 updateTime(new Date.now()); | 50 updateTime(new DateTime.now()); |
51 | 51 |
52 window.requestAnimationFrame(tick); | 52 window.requestAnimationFrame(tick); |
53 } | 53 } |
54 | 54 |
55 void tick(num time) { | 55 void tick(num time) { |
56 updateTime(new Date.now()); | 56 updateTime(new DateTime.now()); |
57 balls.tick(time); | 57 balls.tick(time); |
58 window.requestAnimationFrame(tick); | 58 window.requestAnimationFrame(tick); |
59 } | 59 } |
60 | 60 |
61 void updateTime(Date now) { | 61 void updateTime(DateTime now) { |
62 if (now.hour != displayedHour) { | 62 if (now.hour != displayedHour) { |
63 setDigits(pad2(now.hour), hours); | 63 setDigits(pad2(now.hour), hours); |
64 displayedHour = now.hour; | 64 displayedHour = now.hour; |
65 } | 65 } |
66 | 66 |
67 if (now.minute != displayedMinute) { | 67 if (now.minute != displayedMinute) { |
68 setDigits(pad2(now.minute), minutes); | 68 setDigits(pad2(now.minute), minutes); |
69 displayedMinute = now.minute; | 69 displayedMinute = now.minute; |
70 } | 70 } |
71 | 71 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 void setElementPosition(Element elem, double x, double y) { | 156 void setElementPosition(Element elem, double x, double y) { |
157 elem.style.transform = 'translate(${x}px, ${y}px)'; | 157 elem.style.transform = 'translate(${x}px, ${y}px)'; |
158 } | 158 } |
159 | 159 |
160 void setElementSize(Element elem, double l, double t, double r, double b) { | 160 void setElementSize(Element elem, double l, double t, double r, double b) { |
161 setElementPosition(elem, l, t); | 161 setElementPosition(elem, l, t); |
162 elem.style.right = "${r}px"; | 162 elem.style.right = "${r}px"; |
163 elem.style.bottom = "${b}px"; | 163 elem.style.bottom = "${b}px"; |
164 } | 164 } |
OLD | NEW |