annotate nodejs/testsvg.js @ 724:503f3d18248e

Add symbolic name of event types.
author wycc
date Mon, 16 Aug 2010 07:32:56 +0800
parents f95d58a8edd1
children d479f319d7b7
rev   line source
714
f53e45d1fcd0 Translate the svg.js as a nodejs module.
wycc
parents:
diff changeset
1 var svg = require("./svg");
716
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
2 var mbapp = require("./mbapp");
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
3 var sys=require("sys");
714
f53e45d1fcd0 Translate the svg.js as a nodejs module.
wycc
parents:
diff changeset
4
716
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
5 app = new mbapp.app();
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
6 app.loadSVG("test.svg");
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
7 lightbar = app.get("item_lightbar")
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
8 item=1
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
9 lightbar[5] = app.get("item"+item)[5]
722
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
10
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
11 function animated(app,obj) {
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
12 var d=obj.animated_loc - obj[5];
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
13 var dd=d;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
14 if (dd<0) dd = -dd;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
15
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
16 if (dd > 5) {
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
17 if (d > 0) d = 5; else d = -5;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
18 }
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
19
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
20 obj[5] += d;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
21 sys.puts(d);
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
22 app.refresh()
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
23 if (dd > 1) {
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
24 setTimeout(function() { animated(app,obj);}, 20);
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
25 return;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
26 }
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
27 app.animated_end = 1;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
28 }
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
29 function animated_start(app,obj,target) {
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
30 if (obj.animated_end==0)
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
31 obj[5] = obj.animated_loc;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
32 obj.animated_loc = target[5];
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
33 obj.animated_end = 0;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
34 animated(app,obj);
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
35 }
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
36 lightbar.animated_loc = 1;
724
503f3d18248e Add symbolic name of event types.
wycc
parents: 722
diff changeset
37 app.addKeyboardListener(mbapp.EVT_KB_PRESS, function(evt) {
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
38 if (evt.keycode == mbapp.KEY_UP) {
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
39 item = item - 1;
722
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
40 if (item == 0) item = 1;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
41 else
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
42 animated_start(app,lightbar,app.get("item"+item));
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
43 } else if (evt.keycode == mbapp.KEY_DOWN) {
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
44 item = item + 1;
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
45 if (item == 10) {
722
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
46 item = 9;
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
47 } else
f95d58a8edd1 Add javascript-based animation test program. We should make it as module in the future.
wycc
parents: 721
diff changeset
48 animated_start(app,lightbar,app.get("item"+item));
721
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
49 }
01d02382dea7 Refactory the mbapp and testsvg to use keyboard events
wycc
parents: 716
diff changeset
50 });
716
72abb4154936 Add mbapp module
wycc
parents: 714
diff changeset
51 app.loop();