annotate nodejs/testdesktop.js @ 858:ed49dc0a26f1 abs_n_rel_center

Move lightbar to correct position when it being up
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 20 Sep 2010 22:43:44 +0800
parents ea1e88c40548
children 3ce9daa9558b
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
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
3 var svg = require("./svg");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
4 var mbapp = require("./mbapp");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
5 var sys=require("sys");
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
6 var animate=require("./animate");
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");
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
20 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
21 for(i=0;i<lines.length;i++) {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
22 sys.puts("["+i+"]="+lines[i].center.x);
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
23 }
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
24 line=0;
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
25
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
26 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
27 item = 0;
801
f84ccf1f59ae Add icons for the menu demo
wycc
parents: 776
diff changeset
28 an = new animate.scale(app,items[item],1,1.5,0.1);
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
29 an.start();
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
30 app.refresh();
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
31 app.addKeyListener(mbapp.KEY_LEFT, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
32 var old = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
33 item = item - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
34 if (item == -1) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
35 item = 0;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
36 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
37 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
38 var target = items[item];
857
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
39 var an = new animate.scale(app,old,1,1/1.5,0.1);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
40 an.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
41 an = new animate.scale(app,target,1,1.5,0.3);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
42 an.start();
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
43 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
44
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
45 app.addKeyListener(mbapp.KEY_RIGHT, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
46 var old = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
47 item = item + 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
48 if (item == items.length) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
49 item = item - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
50 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
51 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
52 var target = items[item];
857
ea1e88c40548 Make scale work on center of an object
Thinker K.F. Li <thinker@codemud.net>
parents: 856
diff changeset
53 var an = new animate.scale(app,old,1,1/1.5,0.1);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
54 an.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
55 an = new animate.scale(app,target,1,1.5,0.3);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
56 an.start();
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
57 });
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
58
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
59 app.addKeyListener(mbapp.KEY_UP, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
60 var old = lines[line];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
61 line = line - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
62 if (line == -1) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
63 line = 0;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
64 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
65 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
66 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
67 var sy = target.center.y - lightbar.center.y;
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
68 sys.puts(sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
69 var an = new animate.linear(app,lightbar,0,sy,0.3);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
70 an.start();
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
71 });
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
72 app.addKeyListener(mbapp.KEY_DOWN, 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 == lines.length) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
76 line = line - 1;
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];
856
88f4916a0691 Compute y position according center of lightbar and text
Thinker K.F. Li <thinker@codemud.net>
parents: 855
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("line="+line);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
82 sys.puts("sy="+sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
83 sys.puts("target.y="+target.center.y);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
84 sys.puts("lightbar.y="+lightbar.center.y);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
85 var an = new animate.linear(app,lightbar,0,sy,0.3);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
86 an.start();
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
87 });
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
88
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
89 app.addKeyListener(mbapp.KEY_ENTER, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
90 var target = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
91 var sx = 500 - target.center.x;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
92 var sy = 220 - target.center.y;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
93 sys.puts("target "+sx+','+sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
94 var an = new animate.linear(app,target,sx,sy,1);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
95 an.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
96 for(i=0;i<items.length;i++) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
97 if (i == item) continue;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
98 var x = Math.random();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
99 var y = Math.random();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
100 if (x > 0.5) x = 900;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
101 else x = -500;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
102 if (y > 0.5) y = 900;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
103 else y = -500;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
104 sx = x - items[i].center.x;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
105 sy = y - items[i].center.y;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
106 an = new animate.linear(app,items[i], sx,sy,2);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
107 an.start();
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
108 alpha = new animate.alpha(app,items[i],0, 1);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
109 alpha.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
110 }
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
111 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
112
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
113 app.loop();