annotate nodejs/testdesktop.js @ 878:818e5bed913d abs_n_rel_center

Handle stroke-width and gradientTransform
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 25 Sep 2010 16:17:49 +0800
parents 881efcd8a18f
children 3136db0ac01b
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");
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;
801
f84ccf1f59ae Add icons for the menu demo
wycc
parents: 776
diff changeset
30 an = new animate.scale(app,items[item],1,1.5,0.1);
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
31 an.start();
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
32 app.refresh();
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
33 app.addKeyListener(mbapp.KEY_LEFT, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
34 var old = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
35 item = item - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
36 if (item == -1) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
37 item = 0;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
38 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
39 }
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
40
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
41 var target = items[item];
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
42
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
43 old.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
44 target.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
45
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
46 var an = new animate.scale(app, old, 1, 1, 0.1);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
47 an.start();
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
48 an = new animate.scale(app, target, 1, 1.5, 0.3);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
49 an.start();
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
50 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
51
820
7875e8026e86 Change the key from up/down to left/right
wycc
parents: 801
diff changeset
52 app.addKeyListener(mbapp.KEY_RIGHT, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
53 var old = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
54 item = item + 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
55 if (item == items.length) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
56 item = item - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
57 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
58 }
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
59
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
60 var target = items[item];
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
61
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
62 old.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
63 target.bbox.update();
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
64
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
65 var an = new animate.scale(app, old, 1, 1, 0.1);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
66 an.start();
862
3ce9daa9558b Scale an object according bbox.orig
Thinker K.F. Li <thinker@codemud.net>
parents: 858
diff changeset
67 an = new animate.scale(app, target, 1, 1.5, 0.3);
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
68 an.start();
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
69 });
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
70
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
71 app.addKeyListener(mbapp.KEY_UP, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
72 var old = lines[line];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
73 line = line - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
74 if (line == -1) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
75 line = 0;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
76 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
77 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
78 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
79 var sy = target.center.y - lightbar.center.y;
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
80 sys.puts(sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
81 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
82 an.start();
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
83 });
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
84 app.addKeyListener(mbapp.KEY_DOWN, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
85 var old = lines[line];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
86 line = line + 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
87 if (line == lines.length) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
88 line = line - 1;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
89 return;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
90 }
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
91 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
92 var sy = target.center.y - lightbar.center.y;
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
93 sys.puts("line="+line);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
94 sys.puts("sy="+sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
95 sys.puts("target.y="+target.center.y);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
96 sys.puts("lightbar.y="+lightbar.center.y);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
97 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
98 an.start();
847
dfe28355bded Fix the location of the text elements.
wycc
parents: 845
diff changeset
99 });
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
100
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
101 app.addKeyListener(mbapp.KEY_ENTER, function() {
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
102 var target = items[item];
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
103 var sx = 500 - target.center.x;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
104 var sy = 220 - target.center.y;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
105 sys.puts("target "+sx+','+sy);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
106 var an = new animate.linear(app,target,sx,sy,1);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
107 an.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
108 for(i=0;i<items.length;i++) {
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
109 if (i == item) continue;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
110 var x = Math.random();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
111 var y = Math.random();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
112 if (x > 0.5) x = 900;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
113 else x = -500;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
114 if (y > 0.5) y = 900;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
115 else y = -500;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
116 sx = x - items[i].center.x;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
117 sy = y - items[i].center.y;
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
118 an = new animate.linear(app,items[i], sx,sy,2);
845
2101a355acba Use the new animate.linear
wycc
parents: 822
diff changeset
119 an.start();
855
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
120 alpha = new animate.alpha(app,items[i],0, 1);
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
121 alpha.start();
c385493e04b6 Re-indent
Thinker K.F. Li <thinker@codemud.net>
parents: 847
diff changeset
122 }
752
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
123 });
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
124
ffbf9910213c Add testdesktop,js example.
wycc
parents:
diff changeset
125 app.loop();