| 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 // Canvas API tests. Some of these are adapted from: | 5 // Canvas API tests. Some of these are adapted from: |
| 6 // | 6 // |
| 7 // http://www.html5canvastutorials.com/ | 7 // http://www.html5canvastutorials.com/ |
| 8 | 8 |
| 9 library openglui_canvas_tests; | 9 library openglui_canvas_tests; |
| 10 | 10 |
| 11 import 'gl.dart'; | 11 import 'gl.dart'; |
| 12 import 'dart:math' as Math; | 12 import 'dart:math' as Math; |
| 13 | 13 |
| 14 var ctx; | 14 var ctx; |
| 15 var width, height; | 15 var width, height; |
| 16 bool isDirty = true; | 16 bool isDirty = true; |
| 17 var canvas; | 17 var canvas; |
| 18 | 18 |
| 19 void resize(int w, int h) { | 19 void resize(int w, int h) { |
| 20 width = w; | 20 width = w; |
| 21 height = h; | 21 height = h; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void setup(canvasp, int w, int h) { | 24 void setup(canvasp, int w, int h) { |
| 25 if (canvasp == null) { | 25 if (canvasp == null) { |
| 26 log("Allocating canvas"); | 26 log("Allocating canvas"); |
| 27 canvas = new CanvasElement(width: w, height: h); | 27 canvas = new CanvasElement(width: w, height: h); |
| 28 document.body.nodes.add(canvas); |
| 28 } else { | 29 } else { |
| 29 log("Using parent canvas"); | 30 log("Using parent canvas"); |
| 30 canvas = canvasp; | 31 canvas = canvasp; |
| 31 // called from gl_driver.dart. | |
| 32 // This is a kludge; we need a clean way of handling events. | |
| 33 canvas.on.mouseDown.add((e) { | |
| 34 ++testnum; | |
| 35 }); | |
| 36 } | 32 } |
| 33 canvas.onMouseDown.listen((e) { |
| 34 ++testnum; |
| 35 isDirty = true; |
| 36 }); |
| 37 canvas.onKeyDown.listen((e) { |
| 38 ++testnum; |
| 39 isDirty = true; |
| 40 }); |
| 37 ctx = canvas.getContext("2d"); | 41 ctx = canvas.getContext("2d"); |
| 38 if (ctx == null) { | 42 if (ctx == null) { |
| 39 throw "Failed to get 2D context"; | 43 throw "Failed to get 2D context"; |
| 40 } | 44 } |
| 41 resize(w, h); | 45 resize(w, h); |
| 42 log("Done setup"); | 46 log("Done setup"); |
| 43 } | 47 } |
| 44 | 48 |
| 45 resetCanvas() { | 49 resetCanvas() { |
| 46 ctx.globalCompositeOperation = "source-over"; | 50 ctx.globalCompositeOperation = "source-over"; |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 testnum = 22; | 733 testnum = 22; |
| 730 } else { | 734 } else { |
| 731 testnum = 0; | 735 testnum = 0; |
| 732 } | 736 } |
| 733 update(); | 737 update(); |
| 734 break; | 738 break; |
| 735 } | 739 } |
| 736 isDirty = false; | 740 isDirty = false; |
| 737 } | 741 } |
| 738 | 742 |
| 739 /* | |
| 740 TODO(gram): below are the current entry points for input events for the | |
| 741 native code version. We need to integrate these somehow with the WebGL | |
| 742 version: | |
| 743 */ | |
| 744 onMotionDown(num when, num x, num y) { | |
| 745 ++testnum; | |
| 746 isDirty = true; | |
| 747 log("Marking dirty"); | |
| 748 } | |
| 749 onMotionUp(num when, num x, num y) {} | |
| 750 onMotionMove(num when, num x, num y) {} | |
| 751 onMotionCancel(num when, num x, num y) {} | |
| 752 onMotionOutside(num when, num x, num y) {} | |
| 753 onMotionPointerDown(num when, num x, num y) { | |
| 754 ++testnum; | |
| 755 isDirty = true; | |
| 756 log("Marking dirty"); | |
| 757 } | |
| 758 | |
| 759 onMotionPointerUp(num when, num x, num y) {} | |
| 760 | |
| 761 onKeyDown(num when, int flags, int keycode, int metastate, int repeat) { | |
| 762 if (keycode == 32) { | |
| 763 ++testnum; | |
| 764 isDirty = true; | |
| 765 log("Marking dirty"); | |
| 766 } | |
| 767 } | |
| 768 | |
| 769 onKeyUp(num when, int flags, int keycode, int metastate, int repeat) {} | |
| 770 | |
| 771 onKeyMultiple(num when, int flags, int keycode, int metastate, int repeat) { | |
| 772 } | |
| 773 | |
| 774 | |
| OLD | NEW |