Mercurial > MadButterfly
annotate nodejs/examples/mce/mainmenu.js @ 1395:a768d74e5f49
Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object.
Ad center object when the bbox-x is not available.
author | wycc |
---|---|
date | Sat, 02 Apr 2011 05:36:36 +0800 |
parents | eb3719020866 |
children | afa062941f39 |
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 { | |
24 app.loadSVG("main.svg"); | |
1033 | 25 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
|
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; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
43 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
44 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
|
45 app.refresh(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
46 |
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_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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 } |
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 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
|
55 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 this.item = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
60 return; |
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 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
63 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
|
64 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
65 old.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
66 target.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
67 |
1047 | 68 var an = new animate.scale(this.app, old, 1/1.1, 1/1.5); |
912
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.1); |
1047 | 70 an = new animate.scale(this.app, target, 1.1, 1.5); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
71 animate.run([an], 0, 0.3); |
930 | 72 var sx = target.center.x - this.lightbar.center.x; |
73 var an = new animate.shift(this.app, this.lightbar, sx, 0); | |
74 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
|
75 } |
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 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
|
78 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
79 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
|
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 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
|
82 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
|
83 return; |
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 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
86 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
|
87 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
88 old.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
89 target.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
90 |
1047 | 91 var an = new animate.scale(this.app, old, 1/1.1, 1/1.5); |
912
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.1); |
1047 | 93 an = new animate.scale(this.app, target, 1.1, 1.5); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
94 animate.run([an], 0, 0.3); |
930 | 95 var sx = target.center.x - this.lightbar.center.x; |
96 var an = new animate.shift(this.app, this.lightbar, sx, 0); | |
97 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
|
98 } |
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 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
|
101 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 this.line = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
106 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
107 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 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
|
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 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
115 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
|
116 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
117 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
|
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 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
|
120 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
|
121 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
122 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 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
|
127 } |
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 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
|
130 { |
1065 | 131 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
|
132 var target = this.items[this.item]; |
1065 | 133 var an = new animate.scale(this.app, target, 1/1.1, 1/1.5); |
134 animate.run([an], 0, 0.3,function() { | |
135 var sx = 259 - target.center.x; | |
136 var sy = 355 - target.center.y; | |
137 var an1 = new animate.shift(self.app,target,sx,sy); | |
138 animate.run([an1],0,1,function() {self.changePage(self.item);}); | |
139 }); | |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
140 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
|
141 if (i == this.item) continue; |
1047 | 142 if (i > this.item) { |
143 sx = 1920*2 - this.items[i].center.x; | |
144 sy = 0; | |
145 } else { | |
146 sx = -this.items[i].center.x*2; | |
147 sy = 0; | |
148 } | |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
149 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
|
150 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
|
151 alpha = new animate.alpha(this.app,this.items[i], 0); |
1047 | 152 animate.run([an], 0, 2); |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
153 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
154 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
155 |
1065 | 156 MainMenu.prototype.onNextPage=function() { |
1033 | 157 this.app.changeScene(2); |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
158 } |
1065 | 159 MainMenu.prototype.changePage=function(item) { |
160 this.epg.getList(item,self.onNextPage()); | |
161 } | |
915
80000948fcde
Add callback function to load browser.svg at the end of the ani9mation.
wycc
parents:
912
diff
changeset
|
162 |
912
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
163 exports.MainMenu=MainMenu; |