Mercurial > MadButterfly
annotate nodejs/examples/mce/mainmenu.js @ 1033:8c2862e40c28
Change the main.svg to be the multi scene format.
Use change Scene to switch from main to viewer page.
author | wycc |
---|---|
date | Mon, 22 Nov 2010 22:58:37 +0800 |
parents | e45ad25a1462 |
children | 4072a302b207 |
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();}); |
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
|
19 //self.init(); |
930 | 20 } |
21 MainMenu.prototype.init=function() | |
22 { | |
23 app.loadSVG("main.svg"); | |
1033 | 24 app.changeScene(1); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
25 |
930 | 26 var i; |
27 var self = this; | |
28 this.items=[]; | |
933 | 29 for(i=0;i<8;i++) { |
930 | 30 this.items.push(app.get("cat"+i)); |
31 } | |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
32 this.app = app; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
33 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
34 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
|
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 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
|
37 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
|
38 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
|
39 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
40 this.line=0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
41 this.item = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
42 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
43 animate.run([new animate.scale(app,this.items[this.item], 1, 1.5)], 0, 0.1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
44 app.refresh(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
45 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
46 app.addKeyListener(mbapp.KEY_LEFT, function() { self.key_left();}); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
47 app.addKeyListener(mbapp.KEY_RIGHT, function() { self.key_right();}); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
48 app.addKeyListener(mbapp.KEY_UP, function() {self.key_up();}); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
49 app.addKeyListener(mbapp.KEY_DOWN, function() {self.key_down();}); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
50 app.addKeyListener(mbapp.KEY_ENTER, function() {self.key_enter();}); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
51 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
52 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
53 MainMenu.prototype.key_left=function () |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
54 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
55 var old = this.items[this.item]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
56 this.item = this.item - 1; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
57 if (this.item == -1) { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
58 this.item = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
59 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
60 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
61 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
62 var target = this.items[this.item]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
63 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
64 old.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
65 target.bbox.update(); |
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 var an = new animate.scale(this.app, old, 1, 1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
68 animate.run([an], 0, 0.1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
69 an = new animate.scale(this.app, target, 1, 1.5); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
70 animate.run([an], 0, 0.3); |
930 | 71 var sx = target.center.x - this.lightbar.center.x; |
72 var an = new animate.shift(this.app, this.lightbar, sx, 0); | |
73 animate.run([an], 0, 0.3); | |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
74 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
75 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
76 MainMenu.prototype.key_right=function() |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
77 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
78 var old = this.items[this.item]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
79 this.item = this.item + 1; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
80 if (this.item == this.items.length) { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
81 this.item = this.item - 1; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
82 return; |
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 var target = this.items[this.item]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
86 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
87 old.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
88 target.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
89 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
90 var an = new animate.scale(this.app, old, 1, 1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
91 animate.run([an], 0, 0.1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
92 an = new animate.scale(this.app, target, 1, 1.5); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
93 animate.run([an], 0, 0.3); |
930 | 94 var sx = target.center.x - this.lightbar.center.x; |
95 var an = new animate.shift(this.app, this.lightbar, sx, 0); | |
96 animate.run([an], 0, 0.3); | |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
97 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
98 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
99 MainMenu.prototype.key_up=function() |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
100 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
101 var old = this.lines[this.line]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
102 this.line = this.line - 1; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
103 if (this.line == -1) { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
104 this.line = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
105 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
106 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
107 var target = this.lines[this.line]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
108 var sy = target.center.y - this.lightbar.center.y; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
109 var an = new animate.shift(this.app, this.lightbar, 0, sy); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
110 animate.run([an], 0, 0.3); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
111 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
112 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
113 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
114 MainMenu.prototype.key_down=function () |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
115 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
116 var old = this.lines[this.line]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
117 this.line = this.line + 1; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
118 if (this.line == this.lines.length) { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
119 this.line = this.line - 1; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
120 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
121 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
122 var target = this.lines[this.line]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
123 var sy = target.center.y - this.lightbar.center.y; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
124 var an = new animate.shift(this.app, this.lightbar, 0, sy); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
125 animate.run([an], 0, 0.3); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
126 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
127 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
128 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
|
129 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
130 var target = this.items[this.item]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
131 var sx = 500 - target.center.x; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
132 var sy = 220 - target.center.y; |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
133 var an = new animate.shift(this.app,target,sx,sy); |
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
134 var self = this; |
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
135 animate.run([an],0,1,function() {self.changePage();}); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
136 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
|
137 if (i == this.item) continue; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
138 var x = Math.random(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
139 var y = Math.random(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
140 if (x > 0.5) x = 900; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
141 else x = -500; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
142 if (y > 0.5) y = 900; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
143 else y = -500; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
144 sx = x - this.items[i].center.x; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
145 sy = y - this.items[i].center.y; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
146 an = new animate.shift(this.app,this.items[i], sx, sy); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
147 animate.run([an], 0, 2); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
148 alpha = new animate.alpha(this.app,this.items[i], 0); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
149 animate.run([an], 0, 1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
150 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
151 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
152 |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
153 MainMenu.prototype.changePage=function() { |
1033 | 154 this.app.changeScene(2); |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
155 } |
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
156 |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
157 exports.MainMenu=MainMenu; |