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 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:math' as Math; | 6 import 'dart:math' as Math; |
7 part 'tape.dart'; | 7 part 'tape.dart'; |
8 part 'settings.dart'; | 8 part 'settings.dart'; |
9 part 'calcui.dart'; | 9 part 'calcui.dart'; |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 document.on.keyUp.add((e) { | 72 document.on.keyUp.add((e) { |
73 processKeyEvent(e); | 73 processKeyEvent(e); |
74 }); | 74 }); |
75 | 75 |
76 document.on.click.add((MouseEvent e) { | 76 document.on.click.add((MouseEvent e) { |
77 bool wasOpened = mySettings.isOpen; | 77 bool wasOpened = mySettings.isOpen; |
78 | 78 |
79 // If settings dialog is open close it. | 79 // If settings dialog is open close it. |
80 mySettings.close(e); | 80 mySettings.close(e); |
81 | 81 |
82 renderPad(document.body.elements.last); | 82 renderPad(document.body.children.last); |
83 if (wasOpened) { | 83 if (wasOpened) { |
84 removePadEvents(); | 84 removePadEvents(); |
85 addPadEvents(); | 85 addPadEvents(); |
86 } | 86 } |
87 }); | 87 }); |
88 } | 88 } |
89 | 89 |
90 void addPadEvents() { | 90 void addPadEvents() { |
91 // Hook-up number key events: | 91 // Hook-up number key events: |
92 padUI.keyZero.on.click.add((MouseEvent e) { doCalc(48); }); | 92 padUI.keyZero.on.click.add((MouseEvent e) { doCalc(48); }); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 removePadEvents(); | 145 removePadEvents(); |
146 } | 146 } |
147 padUI = new ButtonPadUI(); | 147 padUI = new ButtonPadUI(); |
148 update = true; | 148 update = true; |
149 } | 149 } |
150 | 150 |
151 if (update) { | 151 if (update) { |
152 // Update calculator pad. | 152 // Update calculator pad. |
153 | 153 |
154 // Remove previous pad UI | 154 // Remove previous pad UI |
155 if (parentElement.elements.length > 1) { | 155 if (parentElement.children.length > 1) { |
156 parentElement.elements.last.remove(); | 156 parentElement.children.last.remove(); |
157 } | 157 } |
158 | 158 |
159 // Add new pad UI. | 159 // Add new pad UI. |
160 parentElement.elements.add(padUI.root); | 160 parentElement.children.add(padUI.root); |
161 } | 161 } |
162 } | 162 } |
163 | 163 |
164 /** | 164 /** |
165 * Controls the logic of how to respond to keypresses and then update the | 165 * Controls the logic of how to respond to keypresses and then update the |
166 * UI accordingly. | 166 * UI accordingly. |
167 */ | 167 */ |
168 void processKeyEvent(KeyboardEvent e) { | 168 void processKeyEvent(KeyboardEvent e) { |
169 int code = e.keyCode; | 169 int code = e.keyCode; |
170 bool shift = e.shiftKey; | 170 bool shift = e.shiftKey; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 window.setTimeout(() => resetKey(key, classToAdd), 80); | 360 window.setTimeout(() => resetKey(key, classToAdd), 80); |
361 } | 361 } |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 void main() { | 365 void main() { |
366 final Element element = new Element.tag('div'); | 366 final Element element = new Element.tag('div'); |
367 | 367 |
368 // Create our Tape UI. | 368 // Create our Tape UI. |
369 tapeUI = new TapeUI(); | 369 tapeUI = new TapeUI(); |
370 element.elements.add(tapeUI.root); | 370 element.children.add(tapeUI.root); |
371 | 371 |
372 // Create our tape controller. | 372 // Create our tape controller. |
373 tape = new Tape(); | 373 tape = new Tape(); |
374 | 374 |
375 renderPad(element); | 375 renderPad(element); |
376 | 376 |
377 // Render the UI. | 377 // Render the UI. |
378 document.body.elements.add(element); | 378 document.body.children.add(element); |
379 | 379 |
380 currentRegister = ""; | 380 currentRegister = ""; |
381 total = 0.0; | 381 total = 0.0; |
382 | 382 |
383 setupEvents(); | 383 setupEvents(); |
384 } | 384 } |
OLD | NEW |