Mercurial > MadButterfly
annotate nodejs/examples/mce/mainmenu.js @ 1442:66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
author | wycc |
---|---|
date | Mon, 11 Apr 2011 13:09:48 +0800 |
parents | afa062941f39 |
children | 167873cd35c5 |
rev | line source |
---|---|
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
3 var svg = require("svg"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
4 var mbapp = require("mbapp"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
5 var sys=require("sys"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
6 var animate=require("animate"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
7 var fs = require("fs"); |
930 | 8 var EPG = require('./epg'); |
932
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
9 /** |
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
10 * We will fetch the EPG file from the server and fetch all images required for the main category from it. |
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
11 * If these files are cached, we will not fetch it again. Otherwise, we will fetch them. The EPG class is |
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
12 * responsible for the cache management. |
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
13 */ |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
14 function MainMenu(app) |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
15 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
16 var self = this; |
932
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
17 var epg = new EPG.EPG(); |
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
18 epg.registerInitDone(function() { self.init();}); |
1065 | 19 app.epg = epg; |
932
bd9b0142fc7e
Update the sample application. We can use the ./test5 to test it now. It will download the image from the VOD server and render it in the screen.
wycc
parents:
930
diff
changeset
|
20 //self.init(); |
930 | 21 } |
22 MainMenu.prototype.init=function() | |
23 { | |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
24 app.loadSVG("main1.svg"); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
25 app.changeScene(0); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
26 |
930 | 27 var i; |
28 var self = this; | |
29 this.items=[]; | |
933 | 30 for(i=0;i<8;i++) { |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
31 this.items.push(app.getComponent("cat"+i)); |
930 | 32 } |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
33 this.app = app; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
34 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
35 this.lines = []; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
36 this.line=0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
37 this.item = 0; |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
38 this.itemToScene=[0,15,31,47,63,79,95]; |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
39 |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
40 app.addKeyListener(mbapp.KEY_UP, function() { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
41 var target = self.items[self.item].toCoord(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
42 sys.puts(target); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
43 target.center.move(target.center.x, target.center.y-50); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
44 sys.puts(target.center.y); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
45 self.app.refresh(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
46 }); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
47 app.addKeyListener(mbapp.KEY_DOWN, function() { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
48 var target = self.items[self.item].toCoord(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
49 target.center.move(target.center.x, target.center.y+50); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
50 sys.puts("move "+target.center.owner.id); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
51 sys.puts(target.center.y); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
52 self.app.refresh(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
53 }); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
54 |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
55 app.addKeyListener(mbapp.KEY_LEFT, function() { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
56 self.item = self.item - 1; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
57 if (self.item == -1) { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
58 self.item = 0; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
59 return; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
60 } |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
61 self.app.runToScene(self.itemToScene[self.item]); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
62 }); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
63 app.addKeyListener(mbapp.KEY_RIGHT, function() { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
64 self.item = self.item + 1; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
65 if (self.item == self.items.length) { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
66 self.item = self.item - 1; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
67 return; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
68 } |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
69 self.app.runToScene(self.itemToScene[self.item]); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
70 }); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
71 app.addKeyListener(mbapp.KEY_ENTER, function() { |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
72 try { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
73 //self.app.runToScene(self.itemToScene[self.item]); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
74 self.key_enter(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
75 } catch(e) { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
76 sys.puts("aaa"+e.stack); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
77 for(k in e) { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
78 sys.puts(k+"="+e[k]); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
79 } |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
80 } |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
81 }); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
82 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
83 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
84 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
85 MainMenu.prototype.key_enter=function() |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
86 { |
1065 | 87 var self = this; |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
88 var target = this.items[this.item].toCoord(); |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
89 var an = new animate.scale(this.app, target, 1, 1/1.5); |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
90 |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
91 this.changePage(self.item); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
92 /* |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
93 animate.run(this.app,[an], 0, 0.3,function() { |
1065 | 94 var sx = 259 - target.center.x; |
95 var sy = 355 - target.center.y; | |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
96 sys.puts("target="+target.id); |
1065 | 97 var an1 = new animate.shift(self.app,target,sx,sy); |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
98 animate.run(self.app, [an1],0,1,function() { |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
99 self.changePage(self.item); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
100 }); |
1065 | 101 }); |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
102 */ |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
103 return; |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
104 var list=[]; |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
105 for(i=0;i<this.items.length;i++) { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
106 if (i == this.item) continue; |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
107 var obj = this.items[i].toCoord(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
108 sys.puts(obj); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
109 if (obj == undefined) continue; |
1047 | 110 if (i > this.item) { |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
111 sx = 1920 - this.items[i].toCoord().center.x; |
1047 | 112 sy = 0; |
113 } else { | |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
114 sx = -this.items[i].toCoord().center.x; |
1047 | 115 sy = 0; |
116 } | |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
117 //alpha = new animate.alpha(this.app,this.items[i], 0); |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
118 sys.puts("111"); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
119 an = new animate.shift(this.app,this.items[i].toCoord(), sx,sy); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
120 list.push(an); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
121 } |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
122 animate.run(this.app,list, 0, 1); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
123 sys.puts("enter"); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
124 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
125 |
1065 | 126 MainMenu.prototype.onNextPage=function() { |
1442
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
127 sys.puts("aaaaaaaaaaaaaaaaaaaaaa"); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
128 this.app.changeScene(97); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
129 var l = this.app.getComponent('line2'); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
130 var coord = l.toCoord(); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
131 if (coord == undefined) return; |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
132 sys.puts(coord.isdup); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
133 sys.puts(coord.id); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
134 sys.puts(coord.refid); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
135 try { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
136 l.set_text('aaaaaaqa'); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
137 } catch(e) { |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
138 sys.puts(e); |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
139 } |
66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
wycc
parents:
1410
diff
changeset
|
140 this.app.refresh(); |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
141 } |
1065 | 142 MainMenu.prototype.changePage=function(item) { |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
143 this.app.epg.getList(item,this.onNextPage); |
1065 | 144 } |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
145 |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
146 exports.MainMenu=MainMenu; |