annotate nodejs/testdesktop.js @ 849:d1c98eb474e1

Change the code to fit the change of the center of the transformation point.
author wycc
date Mon, 20 Sep 2010 21:49:23 +0800
parents dfe28355bded
children 881efcd8a18f 23dffb564ace
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 820
diff changeset
1 // vim: sw=4:ts=8:sts=4
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
2 var svg = require("./svg");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
3 var mbapp = require("./mbapp");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
4 var sys=require("sys");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
5 var animate=require("./animate");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
6 var fs = require("fs");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
7
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
8 app = new mbapp.app();
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
9 app.loadSVG("desktop.svg");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
10
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
11 video = app.get("video");
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
12 //var an = new animate.alpha(app,video,0,1);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
13 //an.start();
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
14 audio = app.get("audio");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
15 picture = app.get("picture");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
16 setting = app.get("setting");
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
17
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
18 lightbar = app.get("lightbar");
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
19 lines=[app.get("line1"),app.get("line2"),app.get("line3"), app.get("line4"),app.get("line5")];
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
20 for(i=0;i<lines.length;i++) {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
21 sys.puts("["+i+"]="+lines[i].y);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
22 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
23 line=0;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
24
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
25 items=[video,audio,picture,setting];
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
26 item = 0;
801
f84ccf1f59ae Add icons for the menu demo
wycc
parents: 776
diff changeset
27 an = new animate.scale(app,items[item],1,1.5,0.1);
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
28 an.start();
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
29 app.refresh();
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
30 app.addKeyListener(mbapp.KEY_LEFT, function() {
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
31 var old = items[item];
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
32 item = item - 1;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
33 if (item == -1) {
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
34 item = 0;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
35 return;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
36 }
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
37 var target = items[item];
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 752
diff changeset
38 var an = new animate.scale(app,old,1,1,0.1);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
39 an.start();
801
f84ccf1f59ae Add icons for the menu demo
wycc
parents: 776
diff changeset
40 an = new animate.scale(app,target,1,1.5,0.3);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
41 an.start();
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
42 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
43
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
44 app.addKeyListener(mbapp.KEY_RIGHT, function() {
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
45 var old = items[item];
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
46 item = item + 1;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
47 if (item == items.length) {
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
48 item = item - 1;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
49 return;
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
50 }
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
51 var target = items[item];
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 752
diff changeset
52 var an = new animate.scale(app,old,1,1,0.1);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
53 an.start();
801
f84ccf1f59ae Add icons for the menu demo
wycc
parents: 776
diff changeset
54 an = new animate.scale(app,target,1,1.5,0.3);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
55 an.start();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
56 });
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
57
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
58 app.addKeyListener(mbapp.KEY_UP, function() {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
59 var old = lines[line];
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
60 line = line - 1;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
61 if (line == -1) {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
62 line = 0;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
63 return;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
64 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
65 var target = lines[line];
849
d1c98eb474e1 Change the code to fit the change of the center of the transformation point.
wycc
parents: 847
diff changeset
66 var sy = target.y-lightbar.y;
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
67 sys.puts(sy);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
68 var an = new animate.linear(app,lightbar,0,sy,0.3);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
69 an.start();
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
70 });
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
71 app.addKeyListener(mbapp.KEY_DOWN, function() {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
72 var old = lines[line];
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
73 line = line + 1;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
74 if (line == lines.length) {
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
75 line = line - 1;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
76 return;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
77 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
78 var target = lines[line];
849
d1c98eb474e1 Change the code to fit the change of the center of the transformation point.
wycc
parents: 847
diff changeset
79 var sy = target.y-lightbar.y;
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
80 sys.puts("line="+line);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
81 sys.puts("sy="+sy);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
82 sys.puts("target.y="+target.y);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
83 sys.puts("lightbar.y="+lightbar.y);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
84 var an = new animate.linear(app,lightbar,0,sy,0.3);
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
85 an.start();
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
86 });
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
87
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
88 app.addKeyListener(mbapp.KEY_ENTER, function() {
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
89 var target = items[item];
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
90 var sx = 500-target.x;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
91 var sy = 220-target.y;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
92 sys.puts("target "+sx+','+sy);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
93 var an = new animate.linear(app,target,sx,sy,1);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
94 an.start();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
95 for(i=0;i<items.length;i++) {
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
96 if (i == item) continue;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
97 var x = Math.random();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
98 var y = Math.random();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
99 if (x > 0.5) x = 900;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
100 else x = -500;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
101 if (y > 0.5) y = 900;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
102 else y = -500;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
103 sx = x-items[i].x;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
104 sy = y-items[i].y;
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
105 an = new animate.linear(app,items[i], sx,sy,2);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
106 an.start();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
107 alpha = new animate.alpha(app,items[i],0, 1);
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
108 alpha.start();
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
109 }
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
110 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
111
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
112 app.loop();