Mercurial > MadButterfly
annotate nodejs/examples/mce/mainmenu.js @ 912:a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
author | wycc |
---|---|
date | Tue, 19 Oct 2010 04:07:47 +0800 |
parents | |
children | 80000948fcde |
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"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
8 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
9 function MainMenu(app) |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
10 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
11 var self = this; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
12 app.loadSVG("desktop.svg"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
13 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
14 this.video = app.get("video"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
15 this.audio = app.get("audio"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
16 this.picture = app.get("picture"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
17 this.setting = app.get("setting"); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
18 this.app = app; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
19 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
20 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
|
21 this.lines = []; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
22 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
|
23 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
|
24 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
|
25 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
26 this.line=0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
27 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
28 this.items=[this.video, this.audio, this.picture, this.setting]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
29 this.item = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
30 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
31 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
|
32 app.refresh(); |
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 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 } |
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 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
|
42 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 this.item = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
47 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
48 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
49 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
50 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
|
51 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
52 old.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
53 target.bbox.update(); |
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 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
|
56 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
|
57 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
|
58 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
|
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 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
|
62 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 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
|
67 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
68 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
69 |
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]; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
71 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
72 old.bbox.update(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
73 target.bbox.update(); |
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 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
|
76 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
|
77 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
|
78 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
|
79 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
80 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
81 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
|
82 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 this.line = 0; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
87 return; |
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 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
|
90 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
|
91 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
|
92 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
|
93 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
94 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
95 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
96 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
|
97 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
98 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
|
99 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
|
100 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
|
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 return; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
103 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 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
|
108 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
109 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
110 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
|
111 { |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
112 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
|
113 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
|
114 var sy = 220 - target.center.y; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
115 var an = new animate.shift(this.app,target,sx,sy,1); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
116 an.start(); |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 else x = -500; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
123 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
|
124 else y = -500; |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
132 } |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
133 |
a934ad0c8968
Add the sample app framework. The scene framework will be added latter for multi scene applications.
wycc
parents:
diff
changeset
|
134 exports.MainMenu=MainMenu; |