Mercurial > MadButterfly
annotate nodejs/examples/mce/mainmenu.js @ 1422:6fa411fd9549
Commit merged result
author | wycc |
---|---|
date | Wed, 06 Apr 2011 21:35:21 +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++) { |
930 | 31 this.items.push(app.get("cat"+i)); |
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.lightbar = app.get("lightbar"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
36 this.lines = []; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
37 for(i = 0; i < 5; i++) { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
38 var line = app.get("line" + (i + 1)); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
39 this.lines.push(line); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
40 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
41 this.line=0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
42 this.item = 0; |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
43 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
|
44 |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
45 app.addKeyListener(mbapp.KEY_LEFT, function() { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
46 self.item = self.item - 1; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
47 if (self.item == -1) { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
48 self.item = 0; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
49 return; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
50 } |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
51 self.app.runToScene(self.itemToScene[self.item]); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
52 }); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
53 app.addKeyListener(mbapp.KEY_RIGHT, function() { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
54 self.item = self.item + 1; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
55 if (self.item == self.items.length) { |
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 return; |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
58 } |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
59 self.app.runToScene(self.itemToScene[self.item]); |
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 app.addKeyListener(mbapp.KEY_ENTER, function() { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
62 self.key_enter(); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
63 }); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
64 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
65 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
66 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
67 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
|
68 { |
1065 | 69 var self = this; |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
70 var target = this.items[this.item]; |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
71 var an = new animate.scale(this.app, target, 1, 1/1.5); |
1065 | 72 animate.run([an], 0, 0.3,function() { |
73 var sx = 259 - target.center.x; | |
74 var sy = 355 - target.center.y; | |
75 var an1 = new animate.shift(self.app,target,sx,sy); | |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
76 animate.run([an1],0,1,function() { |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
77 self.changePage(self.item); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
78 }); |
1065 | 79 }); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
80 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
|
81 if (i == this.item) continue; |
1047 | 82 if (i > this.item) { |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
83 sx = 1920 - this.items[i].center.x; |
1047 | 84 sy = 0; |
85 } else { | |
86 sx = -this.items[i].center.x*2; | |
87 sy = 0; | |
88 } | |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
89 //alpha = new animate.alpha(this.app,this.items[i], 0); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
90 an = new animate.shift(this.app,this.items[i], sx,sy); |
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
91 animate.run([an], 0, 1); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
92 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
93 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
94 |
1065 | 95 MainMenu.prototype.onNextPage=function() { |
1422 | 96 this.app.changeScene(97); |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
97 } |
1065 | 98 MainMenu.prototype.changePage=function(item) { |
1410
afa062941f39
Use closure to replace the function to simplify the code.
wycc
parents:
1065
diff
changeset
|
99 this.app.epg.getList(item,this.onNextPage); |
1065 | 100 } |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
101 |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
102 exports.MainMenu=MainMenu; |