annotate nodejs/examples/mce/mainmenu.js @ 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.
author wycc
date Tue, 09 Nov 2010 07:41:52 +0800
parents 30cd14b11bc7
children e45ad25a1462
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
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
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
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
20 }
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
21 MainMenu.prototype.init=function()
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
22 {
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
23 app.loadSVG("main.svg");
912
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
24
930
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
25 var i;
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
26 var self = this;
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
27 this.items=[];
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
28 for(i=0;i<4;i++) {
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
29 this.items.push(app.get("cat"+i));
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
30 }
912
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
31 this.app = app;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
32
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
33 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
34 this.lines = [];
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
35 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
36 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
37 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
38 }
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
39 this.line=0;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
40 this.item = 0;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
41
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
42 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
43 app.refresh();
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
44
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
45 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
46 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
47 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
48 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
49 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
50 }
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 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
53 {
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
54 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
55 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
56 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
57 this.item = 0;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
58 return;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
59 }
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 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
62
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
63 old.bbox.update();
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
64 target.bbox.update();
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 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
67 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
68 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
69 animate.run([an], 0, 0.3);
930
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
70 var sx = target.center.x - this.lightbar.center.x;
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
71 var an = new animate.shift(this.app, this.lightbar, sx, 0);
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
72 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
73 }
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 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
76 {
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
77 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
78 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
79 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
80 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
81 return;
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 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
85
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
86 old.bbox.update();
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
87 target.bbox.update();
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
88
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
89 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
90 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
91 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
92 animate.run([an], 0, 0.3);
930
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
93 var sx = target.center.x - this.lightbar.center.x;
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
94 var an = new animate.shift(this.app, this.lightbar, sx, 0);
30cd14b11bc7 USe the graphics from the Max.
wycc
parents: 915
diff changeset
95 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
96 }
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 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
99 {
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
100 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
101 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
102 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
103 this.line = 0;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
104 return;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
105 }
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
106 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
107 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
108 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
109 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
110 }
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 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
114 {
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
115 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
116 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
117 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
118 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
119 return;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
120 }
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
121 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
122 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
123 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
124 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
125 }
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 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
128 {
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
129 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
130 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
131 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
132 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
133 var self = this;
80000948fcde Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents: 912
diff changeset
134 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
135 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
136 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
137 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
138 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
139 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
140 else x = -500;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
141 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
142 else y = -500;
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
143 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
144 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
145 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
146 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
147 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
148 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
149 }
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
915
80000948fcde Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents: 912
diff changeset
152 MainMenu.prototype.changePage=function() {
80000948fcde Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents: 912
diff changeset
153 this.app.loadSVG("browser.svg");
80000948fcde Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents: 912
diff changeset
154 }
80000948fcde Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents: 912
diff changeset
155
912
a934ad0c8968 Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff changeset
156 exports.MainMenu=MainMenu;