annotate nodejs/examples/desktop/testdesktop.js @ 1183:e8446e138427

Move update_scenes_of_dom() to MBScene_dom
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 31 Dec 2010 12:37:30 +0800
parents a74b4d986a91
children
rev   line source
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 820
diff changeset
2 // vim: sw=4:ts=8:sts=4
939
a74b4d986a91 Move examples for nodejs into nodejs/examples/ sub-directories.
Thinker K.F. Li <thinker@codemud.net>
parents: 895
diff changeset
3 var svg = require("svg");
a74b4d986a91 Move examples for nodejs into nodejs/examples/ sub-directories.
Thinker K.F. Li <thinker@codemud.net>
parents: 895
diff changeset
4 var mbapp = require("mbapp");
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
5 var sys=require("sys");
939
a74b4d986a91 Move examples for nodejs into nodejs/examples/ sub-directories.
Thinker K.F. Li <thinker@codemud.net>
parents: 895
diff changeset
6 var animate=require("animate");
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
7 var fs = require("fs");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
8
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
9 app = new mbapp.app();
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
10 app.loadSVG("desktop.svg");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
11
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
12 video = app.get("video");
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
13 //var an = new animate.alpha(app,video,0,1);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
14 //an.start();
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
15 audio = app.get("audio");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
16 picture = app.get("picture");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
17 setting = app.get("setting");
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
18
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
19 lightbar = app.get("lightbar");
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
20 lines = [];
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
21 for(i = 0; i < 5; i++) {
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
22 line = app.get("line" + (i + 1));
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
23 lines.push(line);
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
24 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
25 line=0;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
26
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
27 items=[video, audio, picture, setting];
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
28
776
77b561bb7929 Implement new algorithm to calculate the origin of the SVG elemnts so that we can implement object resize without changing the position of the object.
wycc
parents: 758
diff changeset
29 item = 0;
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
30
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
31 animate.run([new animate.scale(app,items[item], 1, 1.5)], 0, 0.1);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
32 app.refresh();
894
460b2629be30 Commit the change again
wycc
parents: 893
diff changeset
33
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
34 app.addKeyListener(mbapp.KEY_LEFT, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
35 var old = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
36 item = item - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
37 if (item == -1) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
38 item = 0;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
39 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
40 }
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
41
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
42 var target = items[item];
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
43
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
44 old.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
45 target.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
46
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
47 var an = new animate.scale(app, old, 1, 1);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
48 animate.run([an], 0, 0.1);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
49 an = new animate.scale(app, target, 1, 1.5);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
50 animate.run([an], 0, 0.3);
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
51 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
52
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
53 app.addKeyListener(mbapp.KEY_RIGHT, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
54 var old = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
55 item = item + 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
56 if (item == items.length) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
57 item = item - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
58 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
59 }
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
60
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
61 var target = items[item];
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
62
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
63 old.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
64 target.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
65
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
66 var an = new animate.scale(app, old, 1, 1);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
67 animate.run([an], 0, 0.1);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
68 an = new animate.scale(app, target, 1, 1.5);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
69 animate.run([an], 0, 0.3);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
70 });
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
71
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
72 app.addKeyListener(mbapp.KEY_UP, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
73 var old = lines[line];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
74 line = line - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
75 if (line == -1) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
76 line = 0;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
77 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
78 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
79 var target = lines[line];
858
ed49dc0a26f1 Move lightbar to correct position when it being up
Thinker K.F. Li <thinker@codemud.net>
parents: 857
diff changeset
80 var sy = target.center.y - lightbar.center.y;
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
81 sys.puts(sy);
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
82 var an = new animate.shift(app, lightbar, 0, sy);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
83 animate.run([an], 0, 0.3);
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
84 });
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
85 app.addKeyListener(mbapp.KEY_DOWN, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
86 var old = lines[line];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
87 line = line + 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
88 if (line == lines.length) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
89 line = line - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
90 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
91 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
92 var target = lines[line];
856
88f4916a0691 Compute y position according center of lightbar and text
Thinker K.F. Li <thinker@codemud.net>
parents: 855
diff changeset
93 var sy = target.center.y - lightbar.center.y;
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
94 sys.puts("line="+line);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
95 sys.puts("sy="+sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
96 sys.puts("target.y="+target.center.y);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
97 sys.puts("lightbar.y="+lightbar.center.y);
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
98 var an = new animate.shift(app, lightbar, 0, sy);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
99 animate.run([an], 0, 0.3);
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
100 });
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
101
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
102 app.addKeyListener(mbapp.KEY_ENTER, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
103 var target = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
104 var sx = 500 - target.center.x;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
105 var sy = 220 - target.center.y;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
106 sys.puts("target "+sx+','+sy);
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
107 var an = new animate.shift(app,target,sx,sy,1);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
108 an.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
109 for(i=0;i<items.length;i++) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
110 if (i == item) continue;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
111 var x = Math.random();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
112 var y = Math.random();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
113 if (x > 0.5) x = 900;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
114 else x = -500;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
115 if (y > 0.5) y = 900;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
116 else y = -500;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
117 sx = x - items[i].center.x;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
118 sy = y - items[i].center.y;
895
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
119 an = new animate.shift(app,items[i], sx, sy);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
120 animate.run([an], 0, 2);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
121 alpha = new animate.alpha(app,items[i], 0);
3136db0ac01b Merged from default branch
Thinker K.F. Li <thinker@branda.to>
parents: 873 894
diff changeset
122 animate.run([an], 0, 1);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
123 }
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
124 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
125
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
126 app.loop();