Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
911:7c4df3c1027f | 912:a934ad0c8968 |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
3 var svg = require("svg"); | |
4 var mbapp = require("mbapp"); | |
5 var sys=require("sys"); | |
6 var animate=require("animate"); | |
7 var fs = require("fs"); | |
8 | |
9 function MainMenu(app) | |
10 { | |
11 var self = this; | |
12 app.loadSVG("desktop.svg"); | |
13 | |
14 this.video = app.get("video"); | |
15 this.audio = app.get("audio"); | |
16 this.picture = app.get("picture"); | |
17 this.setting = app.get("setting"); | |
18 this.app = app; | |
19 | |
20 this.lightbar = app.get("lightbar"); | |
21 this.lines = []; | |
22 for(i = 0; i < 5; i++) { | |
23 var line = app.get("line" + (i + 1)); | |
24 this.lines.push(line); | |
25 } | |
26 this.line=0; | |
27 | |
28 this.items=[this.video, this.audio, this.picture, this.setting]; | |
29 this.item = 0; | |
30 | |
31 animate.run([new animate.scale(app,this.items[this.item], 1, 1.5)], 0, 0.1); | |
32 app.refresh(); | |
33 | |
34 app.addKeyListener(mbapp.KEY_LEFT, function() { self.key_left();}); | |
35 app.addKeyListener(mbapp.KEY_RIGHT, function() { self.key_right();}); | |
36 app.addKeyListener(mbapp.KEY_UP, function() {self.key_up();}); | |
37 app.addKeyListener(mbapp.KEY_DOWN, function() {self.key_down();}); | |
38 app.addKeyListener(mbapp.KEY_ENTER, function() {self.key_enter();}); | |
39 } | |
40 | |
41 MainMenu.prototype.key_left=function () | |
42 { | |
43 var old = this.items[this.item]; | |
44 this.item = this.item - 1; | |
45 if (this.item == -1) { | |
46 this.item = 0; | |
47 return; | |
48 } | |
49 | |
50 var target = this.items[this.item]; | |
51 | |
52 old.bbox.update(); | |
53 target.bbox.update(); | |
54 | |
55 var an = new animate.scale(this.app, old, 1, 1); | |
56 animate.run([an], 0, 0.1); | |
57 an = new animate.scale(this.app, target, 1, 1.5); | |
58 animate.run([an], 0, 0.3); | |
59 } | |
60 | |
61 MainMenu.prototype.key_right=function() | |
62 { | |
63 var old = this.items[this.item]; | |
64 this.item = this.item + 1; | |
65 if (this.item == this.items.length) { | |
66 this.item = this.item - 1; | |
67 return; | |
68 } | |
69 | |
70 var target = this.items[this.item]; | |
71 | |
72 old.bbox.update(); | |
73 target.bbox.update(); | |
74 | |
75 var an = new animate.scale(this.app, old, 1, 1); | |
76 animate.run([an], 0, 0.1); | |
77 an = new animate.scale(this.app, target, 1, 1.5); | |
78 animate.run([an], 0, 0.3); | |
79 } | |
80 | |
81 MainMenu.prototype.key_up=function() | |
82 { | |
83 var old = this.lines[this.line]; | |
84 this.line = this.line - 1; | |
85 if (this.line == -1) { | |
86 this.line = 0; | |
87 return; | |
88 } | |
89 var target = this.lines[this.line]; | |
90 var sy = target.center.y - this.lightbar.center.y; | |
91 var an = new animate.shift(this.app, this.lightbar, 0, sy); | |
92 animate.run([an], 0, 0.3); | |
93 } | |
94 | |
95 | |
96 MainMenu.prototype.key_down=function () | |
97 { | |
98 var old = this.lines[this.line]; | |
99 this.line = this.line + 1; | |
100 if (this.line == this.lines.length) { | |
101 this.line = this.line - 1; | |
102 return; | |
103 } | |
104 var target = this.lines[this.line]; | |
105 var sy = target.center.y - this.lightbar.center.y; | |
106 var an = new animate.shift(this.app, this.lightbar, 0, sy); | |
107 animate.run([an], 0, 0.3); | |
108 } | |
109 | |
110 MainMenu.prototype.key_enter=function() | |
111 { | |
112 var target = this.items[this.item]; | |
113 var sx = 500 - target.center.x; | |
114 var sy = 220 - target.center.y; | |
115 var an = new animate.shift(this.app,target,sx,sy,1); | |
116 an.start(); | |
117 for(i=0;i<this.items.length;i++) { | |
118 if (i == this.item) continue; | |
119 var x = Math.random(); | |
120 var y = Math.random(); | |
121 if (x > 0.5) x = 900; | |
122 else x = -500; | |
123 if (y > 0.5) y = 900; | |
124 else y = -500; | |
125 sx = x - this.items[i].center.x; | |
126 sy = y - this.items[i].center.y; | |
127 an = new animate.shift(this.app,this.items[i], sx, sy); | |
128 animate.run([an], 0, 2); | |
129 alpha = new animate.alpha(this.app,this.items[i], 0); | |
130 animate.run([an], 0, 1); | |
131 } | |
132 } | |
133 | |
134 exports.MainMenu=MainMenu; |