annotate nodejs/mbapp.js @ 762:6133319d3fb4

Add udpate command
author wycc
date Sat, 28 Aug 2010 23:11:02 +0800
parents 1719484ed15d
children 37a1bd3e3ce1
rev   line source
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
1 var mbfly = require("mbfly");
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
2 var svg = require("./svg");
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
3 var sys = require("sys");
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
4 var mb_rt = new mbfly.mb_rt(":0.0", 720,480);
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
5 var ldr = mbfly.img_ldr_new(".");
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
6 var background = mb_rt.rect_new(0, 0, 720, 480, 0, 0);
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
7 var paint = mb_rt.paint_color_new(1, 1, 1, 1);
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
8 paint.fill(background);
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
9 mb_rt.root.add_shape(background);
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
10
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
11 app=function() {
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
12 var self = this;
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
13 this.mb_rt = mb_rt;
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
14 this.mb_rt.kbevents.add_event_observer(exports.EVT_KB_PRESS, function(evt) { self.KeyPress(evt);});
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
15 this.keymap={};
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
16 this.onKeyPress = null;
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
17 }
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
18 app.prototype.loadSVG=function(fname) {
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
19 svg.loadSVG(this.mb_rt,this.mb_rt.root,fname);
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
20 }
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
21
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
22 app.prototype.KeyPress = function(evt) {
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
23 if (this.onKeyPress) this.onKeyPress(evt.sym);
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
24 if (evt.sym in this.keymap) this.keymap[evt.sym]();
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
25 }
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
26
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
27 app.prototype.loop=function() {
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
28 this.mb_rt.redraw_all();
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
29 this.mb_rt.flush();
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
30 }
762
6133319d3fb4 Add udpate command
wycc
parents: 731
diff changeset
31 app.prototype.update=function() {
6133319d3fb4 Add udpate command
wycc
parents: 731
diff changeset
32 this.mb_rt.redraw_all();
6133319d3fb4 Add udpate command
wycc
parents: 731
diff changeset
33 this.mb_rt.flush();
6133319d3fb4 Add udpate command
wycc
parents: 731
diff changeset
34 }
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
35 app.prototype.get=function(name) {
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
36 return this.mb_rt.mbnames[name];
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
37 }
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
38 app.prototype.addKeyboardListener=function(type,f) {
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
39 return this.mb_rt.kbevents.add_event_observer(type,f);
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
40 }
724
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
41 app.prototype.refresh=function() {
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
42 this.mb_rt.redraw_all();
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
43 this.mb_rt.flush();
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
44 }
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
45 app.prototype.dump=function() {
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
46 sys.puts(this.onKeyPress);
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
47 }
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
48
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
49 app.prototype.addKeyListener=function(key,f) {
731
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
50 if (typeof(key) == 'number')
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
51 this.keymap[key] = f;
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
52 else {
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
53 for(k in key) {
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
54 this.keymap[k] = f;
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
55 }
1719484ed15d Make the argument key can be an array to register multiple keys.
wycc
parents: 730
diff changeset
56 }
730
e77ae2d23245 Add addKeyListener to handle key input.
wycc
parents: 729
diff changeset
57 }
716
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
58
72abb4154936 Add mbapp module
wycc
parents:
diff changeset
59 exports.app=app;
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
60
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
61 // Put all key definition here
729
299ed9319dc6 Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents: 724
diff changeset
62 exports.KEY_UP = 0xff52;
299ed9319dc6 Use key symbols instead of keycodes.
Thinker K.F. Li <thinker@branda.to>
parents: 724
diff changeset
63 exports.KEY_DOWN = 0xff54;
724
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
64 exports.EVT_ANY=0;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
65 exports.EVT_MOUSE_OVER=1;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
66 exports.EVT_MOUSE_OUT=2;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
67 exports.EVT_MOUSE_MOVE=3;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
68 exports.EVT_MOUSE_BUT_PRESS4;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
69 exports.EVT_MOUSE_BUT_RELEASE=5
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
70 exports.EVT_KB_PRESS=6;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
71 exports.EVT_KB_RELEASE=7;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
72 exports.EVT_PROGM_COMPLETE=8;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
73 exports.EVT_RDMAN_REDRAW=9;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
74 exports.EVT_MONITOR_ADD=10;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
75 exports.EVT_MONITOR_REMOVE=11;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
76 exports.EVT_MONITOR_FREE=12;
503f3d18248e Add symbolic name of event types.
wycc
parents: 721
diff changeset
77 exports.EVT_MOUSE_MOVE_RAW=13;