Mercurial > MadButterfly
changeset 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 | 7c4df3c1027f |
children | 85b647f5aeff |
files | nodejs/examples/mce/desktop.svg nodejs/examples/mce/mainmenu.js nodejs/examples/mce/mbmce.js nodejs/examples/mce/music.png nodejs/examples/mce/photo.png nodejs/examples/mce/tool.png nodejs/examples/mce/video.png |
diffstat | 7 files changed, 652 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/mce/desktop.svg Tue Oct 19 04:07:47 2010 +0800 @@ -0,0 +1,507 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="744.09448" + height="480" + id="svg2" + version="1.1" + inkscape:version="0.47 r22583" + sodipodi:docname="desktop.svg"> + <defs + id="defs4"> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 240 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 240 : 1" + inkscape:persp3d-origin="372.04724 : 160 : 1" + id="perspective21" /> + <linearGradient + inkscape:collect="always" + id="linearGradient3706"> + <stop + style="stop-color:#000000;stop-opacity:1;" + offset="0" + id="stop3708" /> + <stop + style="stop-color:#000000;stop-opacity:0;" + offset="1" + id="stop3710" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3706" + id="linearGradient3712" + x1="0" + y1="240" + x2="747.27411" + y2="240" + gradientUnits="userSpaceOnUse" /> + <inkscape:perspective + id="perspective3711" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective2953" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective2981" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3009" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3037" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3065" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3093" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective2960" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective2988" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3016" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3016-0" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3016-6" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3016-7" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + <inkscape:perspective + id="perspective3016-5" + inkscape:persp3d-origin="0.5 : 0.33333333 : 1" + inkscape:vp_z="1 : 0.5 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_x="0 : 0.5 : 1" + sodipodi:type="inkscape:persp3d" /> + </defs> + <sodipodi:namedview + id="base" + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1.0" + inkscape:pageopacity="0.0" + inkscape:pageshadow="2" + inkscape:zoom="1.56875" + inkscape:cx="207.9" + inkscape:cy="290.99601" + inkscape:document-units="px" + inkscape:current-layer="layer1" + showgrid="false" + inkscape:window-width="1440" + inkscape:window-height="900" + inkscape:window-x="-1" + inkscape:window-y="-1" + inkscape:window-maximized="0" /> + <metadata + id="metadata7"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title /> + </cc:Work> + </rdf:RDF> + </metadata> + <g + inkscape:groupmode="layer" + id="layer3" + inkscape:label="background" + sodipodi:insensitive="true" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="0" + inkscape:bbox-y="0" + inkscape:bbox-width="747.27411" + inkscape:bbox-height="480"> + <rect + style="fill:url(#linearGradient3712);fill-opacity:1" + id="rect2928" + width="747.27411" + height="480" + x="0" + y="0" + ry="3.0304577" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="0" + inkscape:bbox-y="0" + inkscape:bbox-width="747.27411" + inkscape:bbox-height="480" /> + </g> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="35.355339" + inkscape:bbox-y="249.90203" + inkscape:bbox-width="641.44684" + inkscape:bbox-height="219.19541" + style="display:inline"> + <g + id="g2917" + transform="translate(-27.274116,-798.02051)" + mbname="video" + inkscape:transform-center-x="0" + inkscape:transform-center-y="42.294399" + inkscape:bbox-x="35.992421" + inkscape:bbox-y="383.87928" + inkscape:bbox-width="85.598946" + inkscape:bbox-height="84.588799"> + <image + sodipodi:absref="/usr/home/thinker/progm/MadButterfly/nodejs/video.png" + xlink:href="video.png" + width="85.598946" + height="84.588799" + id="image2983" + x="63.266537" + y="809.55243" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="35.992421" + inkscape:bbox-y="383.87928" + inkscape:bbox-width="85.598946" + inkscape:bbox-height="84.588799" /> + </g> + <g + id="g2917-8" + transform="translate(126.77414,-798.02053)" + mbname="audio" + inkscape:transform-center-x="0" + inkscape:transform-center-y="38.464287" + inkscape:bbox-x="189.7836" + inkscape:bbox-y="386.37278" + inkscape:bbox-width="86.5" + inkscape:bbox-height="76.928574"> + <image + sodipodi:absref="/usr/home/thinker/progm/MadButterfly/nodejs/music.png" + xlink:href="music.png" + width="86.5" + height="76.928574" + id="image3048" + x="63.00946" + y="814.71918" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="189.7836" + inkscape:bbox-y="386.37278" + inkscape:bbox-width="86.5" + inkscape:bbox-height="76.928574" /> + </g> + <g + id="g2917-88" + transform="translate(290.67139,-799.03067)" + mbname="picture" + inkscape:transform-center-x="0" + inkscape:transform-center-y="38.07143" + inkscape:bbox-x="354.2955" + inkscape:bbox-y="392.95458" + inkscape:bbox-width="84" + inkscape:bbox-height="76.14286"> + <image + sodipodi:absref="/usr/home/thinker/progm/MadButterfly/nodejs/photo.png" + xlink:href="photo.png" + width="84" + height="76.14286" + id="image3049" + x="63.624115" + y="809.93323" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="354.2955" + inkscape:bbox-y="392.95458" + inkscape:bbox-width="84" + inkscape:bbox-height="76.14286" /> + </g> + <g + id="g2917-8-6" + transform="translate(462.9024,-794.99007)" + mbname="setting" + inkscape:transform-center-x="0" + inkscape:transform-center-y="37.57143" + inkscape:bbox-x="526.42387" + inkscape:bbox-y="389.0568" + inkscape:bbox-width="84.571426" + inkscape:bbox-height="75.14286"> + <image + sodipodi:absref="/usr/home/thinker/progm/MadButterfly/nodejs/tool.png" + xlink:href="tool.png" + width="84.571426" + height="75.14286" + id="image3168" + x="63.521473" + y="810.79041" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="526.42387" + inkscape:bbox-y="389.0568" + inkscape:bbox-width="84.571426" + inkscape:bbox-height="75.14286" /> + </g> + <rect + style="fill:#dfdf49;fill-opacity:1" + id="rect2929" + width="641.44684" + height="71.720833" + x="35.355339" + y="158.37714" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + rx="10" + ry="10" + inkscape:bbox-x="35.355339" + inkscape:bbox-y="249.90203" + inkscape:bbox-width="641.44684" + inkscape:bbox-height="71.720833" + mbname="lightbar" /> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" + x="124.96794" + y="185.925" + id="text2931" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="126.28044" + inkscape:bbox-y="271.84843" + inkscape:bbox-width="488.15625" + inkscape:bbox-height="32.382812" + mbname="line1"><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="185.925" + id="tspan2935" + style="font-size:16px" + inkscape:bbox-x="126.53825" + inkscape:bbox-y="288.74687" + inkscape:bbox-width="487.89844" + inkscape:bbox-height="15.484375">Lim JeongHee (J.Lim) & JoKwon (2AM) - The Road to Break Up</tspan><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="205.925" + style="font-size:16px" + inkscape:bbox-x="126.28044" + inkscape:bbox-y="271.84843" + inkscape:bbox-width="75.335938" + inkscape:bbox-height="12.101562" + id="tspan2941">7:00-7:30</tspan></text> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans" + x="124.96794" + y="247.75766" + id="text2931-20" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="126.28044" + inkscape:bbox-y="210.01578" + inkscape:bbox-width="488.15625" + inkscape:bbox-height="32.382812" + mbname="line2"><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="247.75766" + id="tspan2935-1" + style="font-size:16px" + inkscape:bbox-x="126.53825" + inkscape:bbox-y="226.91422" + inkscape:bbox-width="487.89844" + inkscape:bbox-height="15.484375">Lim JeongHee (J.Lim) & JoKwon (2AM) - The Road to Break Up</tspan><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="267.75766" + style="font-size:16px" + inkscape:bbox-x="126.28044" + inkscape:bbox-y="210.01578" + inkscape:bbox-width="75.335938" + inkscape:bbox-height="12.101562" + id="tspan2941-9">7:30-8:30</tspan></text> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans" + x="124.96794" + y="309.59033" + id="text2931-21" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="126.05388" + inkscape:bbox-y="152.18311" + inkscape:bbox-width="488.38281" + inkscape:bbox-height="32.382812" + mbname="line3"><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="309.59033" + id="tspan2935-2" + style="font-size:16px" + inkscape:bbox-x="126.53825" + inkscape:bbox-y="169.08154" + inkscape:bbox-width="487.89844" + inkscape:bbox-height="15.484375">Lim JeongHee (J.Lim) & JoKwon (2AM) - The Road to Break Up</tspan><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="329.59033" + style="font-size:16px" + inkscape:bbox-x="126.05388" + inkscape:bbox-y="152.18311" + inkscape:bbox-width="75.5625" + inkscape:bbox-height="12.101562" + id="tspan2941-0">8:30-9:30</tspan></text> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans" + x="124.96794" + y="371.423" + id="text2931-3" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="125.97575" + inkscape:bbox-y="90.350433" + inkscape:bbox-width="488.46094" + inkscape:bbox-height="32.382812" + mbname="line4"><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="371.423" + id="tspan2935-11" + style="font-size:16px" + inkscape:bbox-x="126.53825" + inkscape:bbox-y="107.24887" + inkscape:bbox-width="487.89844" + inkscape:bbox-height="15.484375">Lim JeongHee (J.Lim) & JoKwon (2AM) - The Road to Break Up</tspan><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="391.423" + style="font-size:16px" + inkscape:bbox-x="125.97575" + inkscape:bbox-y="90.350433" + inkscape:bbox-width="85.828125" + inkscape:bbox-height="12.101562" + id="tspan2941-90">9:30-10:30</tspan></text> + <text + xml:space="preserve" + style="font-size:40px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;display:inline;font-family:Bitstream Vera Sans" + x="124.96794" + y="433.25568" + id="text2931-6" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="126.53825" + inkscape:bbox-y="28.517761" + inkscape:bbox-width="487.89844" + inkscape:bbox-height="32.382812" + mbname="line5"><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="433.25568" + id="tspan2935-7" + style="font-size:16px" + inkscape:bbox-x="126.53825" + inkscape:bbox-y="45.416199" + inkscape:bbox-width="487.89844" + inkscape:bbox-height="15.484375">Lim JeongHee (J.Lim) & JoKwon (2AM) - The Road to Break Up</tspan><tspan + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + x="124.96794" + y="453.25568" + style="font-size:16px" + inkscape:bbox-x="126.72575" + inkscape:bbox-y="28.517761" + inkscape:bbox-width="95.265625" + inkscape:bbox-height="12.101562" + id="tspan2941-7">10:30-11:30</tspan></text> + </g> +</svg>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/mce/mainmenu.js Tue Oct 19 04:07:47 2010 +0800 @@ -0,0 +1,134 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +var svg = require("svg"); +var mbapp = require("mbapp"); +var sys=require("sys"); +var animate=require("animate"); +var fs = require("fs"); + +function MainMenu(app) +{ + var self = this; + app.loadSVG("desktop.svg"); + + this.video = app.get("video"); + this.audio = app.get("audio"); + this.picture = app.get("picture"); + this.setting = app.get("setting"); + this.app = app; + + this.lightbar = app.get("lightbar"); + this.lines = []; + for(i = 0; i < 5; i++) { + var line = app.get("line" + (i + 1)); + this.lines.push(line); + } + this.line=0; + + this.items=[this.video, this.audio, this.picture, this.setting]; + this.item = 0; + + animate.run([new animate.scale(app,this.items[this.item], 1, 1.5)], 0, 0.1); + app.refresh(); + + app.addKeyListener(mbapp.KEY_LEFT, function() { self.key_left();}); + app.addKeyListener(mbapp.KEY_RIGHT, function() { self.key_right();}); + app.addKeyListener(mbapp.KEY_UP, function() {self.key_up();}); + app.addKeyListener(mbapp.KEY_DOWN, function() {self.key_down();}); + app.addKeyListener(mbapp.KEY_ENTER, function() {self.key_enter();}); +} + +MainMenu.prototype.key_left=function () +{ + var old = this.items[this.item]; + this.item = this.item - 1; + if (this.item == -1) { + this.item = 0; + return; + } + + var target = this.items[this.item]; + + old.bbox.update(); + target.bbox.update(); + + var an = new animate.scale(this.app, old, 1, 1); + animate.run([an], 0, 0.1); + an = new animate.scale(this.app, target, 1, 1.5); + animate.run([an], 0, 0.3); +} + +MainMenu.prototype.key_right=function() +{ + var old = this.items[this.item]; + this.item = this.item + 1; + if (this.item == this.items.length) { + this.item = this.item - 1; + return; + } + + var target = this.items[this.item]; + + old.bbox.update(); + target.bbox.update(); + + var an = new animate.scale(this.app, old, 1, 1); + animate.run([an], 0, 0.1); + an = new animate.scale(this.app, target, 1, 1.5); + animate.run([an], 0, 0.3); +} + +MainMenu.prototype.key_up=function() +{ + var old = this.lines[this.line]; + this.line = this.line - 1; + if (this.line == -1) { + this.line = 0; + return; + } + var target = this.lines[this.line]; + var sy = target.center.y - this.lightbar.center.y; + var an = new animate.shift(this.app, this.lightbar, 0, sy); + animate.run([an], 0, 0.3); +} + + +MainMenu.prototype.key_down=function () +{ + var old = this.lines[this.line]; + this.line = this.line + 1; + if (this.line == this.lines.length) { + this.line = this.line - 1; + return; + } + var target = this.lines[this.line]; + var sy = target.center.y - this.lightbar.center.y; + var an = new animate.shift(this.app, this.lightbar, 0, sy); + animate.run([an], 0, 0.3); +} + +MainMenu.prototype.key_enter=function() +{ + var target = this.items[this.item]; + var sx = 500 - target.center.x; + var sy = 220 - target.center.y; + var an = new animate.shift(this.app,target,sx,sy,1); + an.start(); + for(i=0;i<this.items.length;i++) { + if (i == this.item) continue; + var x = Math.random(); + var y = Math.random(); + if (x > 0.5) x = 900; + else x = -500; + if (y > 0.5) y = 900; + else y = -500; + sx = x - this.items[i].center.x; + sy = y - this.items[i].center.y; + an = new animate.shift(this.app,this.items[i], sx, sy); + animate.run([an], 0, 2); + alpha = new animate.alpha(this.app,this.items[i], 0); + animate.run([an], 0, 1); + } +} + +exports.MainMenu=MainMenu;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nodejs/examples/mce/mbmce.js Tue Oct 19 04:07:47 2010 +0800 @@ -0,0 +1,11 @@ +// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- +// vim: sw=4:ts=8:sts=4 +var svg = require("svg"); +var mbapp = require("mbapp"); +var sys=require("sys"); +var animate=require("animate"); +var fs = require("fs"); +var main=require("./mainmenu"); +app = new mbapp.app(); +scene=new main.MainMenu(app); +app.loop();