changeset 979:380464725e75

Add scene demo program
author wycc
date Sat, 20 Nov 2010 20:04:48 +0800
parents 78312b44f48c
children 37ac93ea9aaf
files nodejs/examples/scene/mainmenu.js nodejs/examples/scene/mbtest.svg nodejs/examples/scene/scene.js
diffstat 3 files changed, 445 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/examples/scene/mainmenu.js	Sat Nov 20 20:04:48 2010 +0800
@@ -0,0 +1,60 @@
+// -*- 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");
+/**
+ *   We will fetch the EPG file from the server and fetch all images required for the main category from it.
+ *   If these files are cached, we will not fetch it again. Otherwise, we will fetch them. The EPG class is
+ *   responsible for the cache management.
+ */
+function MainMenu(app) 
+{
+    var self = this;
+    this.n = 1;
+    this.app = app;
+    self.init(app);
+}
+MainMenu.prototype.init=function(app)
+{
+    var self = this;
+    app.loadSVG("mbtest.svg");
+
+    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();});
+    app.changeScene(this.n);
+}
+
+MainMenu.prototype.key_left=function () 
+{
+   this.n = this.n - 1;
+   this.app.changeScene(this.n);
+   sys.puts("scene "+this.n);
+}
+
+MainMenu.prototype.key_right=function() 
+{
+   this.n = this.n + 1;
+   this.app.changeScene(this.n);
+   sys.puts("scene "+this.n);
+}
+
+MainMenu.prototype.key_up=function() 
+{
+}
+
+
+MainMenu.prototype.key_down=function () 
+{
+}
+
+MainMenu.prototype.key_enter=function() 
+{
+}
+
+exports.MainMenu=MainMenu;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/examples/scene/mbtest.svg	Sat Nov 20 20:04:48 2010 +0800
@@ -0,0 +1,374 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:ns0="http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"
+   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="640px"
+   height="480px"
+   id="svg2383"
+   sodipodi:version="0.32"
+   inkscape:version="0.48+devel r9764 custom"
+   sodipodi:docname="mbtest.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape"
+   version="1.1">
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="1.6029106"
+     inkscape:cx="69.206233"
+     inkscape:cy="290.40921"
+     inkscape:current-layer="layer2"
+     inkscape:document-units="px"
+     showgrid="false"
+     inkscape:window-width="1400"
+     inkscape:window-height="974"
+     inkscape:window-x="271"
+     inkscape:window-y="25"
+     inkscape:window-maximized="0" />
+  <defs
+     id="defs2385">
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient3211">
+      <stop
+         style="stop-color:#001dff;stop-opacity:1;"
+         offset="0"
+         id="stop3213" />
+      <stop
+         style="stop-color:#001dff;stop-opacity:0;"
+         offset="1"
+         id="stop3215" />
+    </linearGradient>
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 240 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="640 : 240 : 1"
+       inkscape:persp3d-origin="320 : 160 : 1"
+       id="perspective2391" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211"
+       id="linearGradient3217"
+       x1="31.940987"
+       y1="28.009715"
+       x2="104.68548"
+       y2="28.009715"
+       gradientUnits="userSpaceOnUse" />
+    <filter
+       inkscape:collect="always"
+       id="filter3295">
+      <feGaussianBlur
+         inkscape:collect="always"
+         stdDeviation="0.67110109"
+         id="feGaussianBlur3297" />
+    </filter>
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211"
+       id="linearGradient3316"
+       gradientUnits="userSpaceOnUse"
+       x1="31.940987"
+       y1="28.009715"
+       x2="104.68548"
+       y2="28.009715" />
+    <linearGradient
+       y2="28.009715"
+       x2="104.68548"
+       y1="28.009715"
+       x1="31.940987"
+       gradientUnits="userSpaceOnUse"
+       id="linearGradient3542"
+       xlink:href="#linearGradient3211"
+       inkscape:collect="always" />
+    <linearGradient
+       y2="28.009715"
+       x2="104.68548"
+       y1="28.009715"
+       x1="31.940987"
+       gradientUnits="userSpaceOnUse"
+       id="linearGradient3544"
+       xlink:href="#linearGradient3211"
+       inkscape:collect="always" />
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient3211-0">
+      <stop
+         style="stop-color:#001dff;stop-opacity:1;"
+         offset="0"
+         id="stop3213-3" />
+      <stop
+         style="stop-color:#001dff;stop-opacity:0;"
+         offset="1"
+         id="stop3215-9" />
+    </linearGradient>
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211-0"
+       id="linearGradient3316-4"
+       gradientUnits="userSpaceOnUse"
+       x1="31.940987"
+       y1="28.009714"
+       x2="104.68548"
+       y2="28.009714" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211-0"
+       id="linearGradient3217-6"
+       x1="31.940987"
+       y1="28.009714"
+       x2="104.68548"
+       y2="28.009714"
+       gradientUnits="userSpaceOnUse" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211-0-5"
+       id="linearGradient3316-4-8"
+       gradientUnits="userSpaceOnUse"
+       x1="31.940987"
+       y1="28.009714"
+       x2="104.68548"
+       y2="28.009714" />
+    <linearGradient
+       inkscape:collect="always"
+       id="linearGradient3211-0-5">
+      <stop
+         style="stop-color:#001dff;stop-opacity:1;"
+         offset="0"
+         id="stop3213-3-8" />
+      <stop
+         style="stop-color:#001dff;stop-opacity:0;"
+         offset="1"
+         id="stop3215-9-4" />
+    </linearGradient>
+    <filter
+       color-interpolation-filters="sRGB"
+       inkscape:collect="always"
+       id="filter3295-1-3">
+      <feGaussianBlur
+         inkscape:collect="always"
+         stdDeviation="0.67110109"
+         id="feGaussianBlur3297-9-7" />
+    </filter>
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211-0-5"
+       id="linearGradient3217-6-1"
+       x1="31.940987"
+       y1="28.009714"
+       x2="104.68548"
+       y2="28.009714"
+       gradientUnits="userSpaceOnUse" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3211-0-5"
+       id="linearGradient3237"
+       gradientUnits="userSpaceOnUse"
+       x1="31.940987"
+       y1="28.009714"
+       x2="104.68548"
+       y2="28.009714" />
+  </defs>
+  <metadata
+     id="metadata2388">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+    <ns0:scenes>
+      <ns0:scene
+         start="1"
+         ref="g3189"
+         end="15" />
+      <ns0:scene
+         start="1"
+         ref="s4427" />
+      <ns0:scene
+         start="2"
+         ref="s4159" />
+      <ns0:scene
+         start="5"
+         ref="s9524"
+         end="10" />
+      <ns0:scene
+         start="15"
+         ref="s6546" />
+    </ns0:scenes>
+  </metadata>
+  <g
+     inkscape:groupmode="layer"
+     id="layer2"
+     inkscape:label="Background"
+     style="display:inline">
+    <g
+       id="g3189"
+       style="">
+      <rect
+         style="fill:#00ffff;fill-opacity:1;stroke:#000000;stroke-opacity:1;display:inline"
+         id="rect2437"
+         width="641.95721"
+         height="481.62387"
+         x="0.93578684"
+         y="-10.98185" />
+      <rect
+         style="fill:#ffcc1d;fill-opacity:1;stroke:none"
+         id="rect3698"
+         width="624.48901"
+         height="46.789886"
+         x="6.8625164"
+         y="5.8625031"
+         rx="10"
+         ry="10" />
+      <g
+         style="display:inline"
+         transform="translate(-11.385541,2.6514388)"
+         id="g3303">
+        <rect
+           y="15.22048"
+           x="32.440987"
+           height="25.57847"
+           width="71.744492"
+           id="rect2439"
+           style="fill:url(#linearGradient3237);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3)" />
+        <text
+           id="text3299"
+           y="33.312569"
+           x="39.927368"
+           style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+           xml:space="preserve"><tspan
+             style="font-size:16px"
+             y="33.312569"
+             x="39.927368"
+             id="tspan3301"
+             sodipodi:role="line">Action</tspan></text>
+      </g>
+      <g
+         style="display:inline"
+         id="g3308"
+         transform="translate(76.891374,2.9633707)">
+        <rect
+           y="15.22048"
+           x="32.440987"
+           height="25.57847"
+           width="71.744492"
+           id="rect3310"
+           style="fill:url(#linearGradient3316-4-8);fill-opacity:1;stroke:none;filter:url(#filter3295-1-3)" />
+        <text
+           id="text3312"
+           y="33.312569"
+           x="39.927368"
+           style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+           xml:space="preserve"><tspan
+             style="font-size:16px"
+             y="33.312569"
+             x="39.927368"
+             id="tspan3314"
+             sodipodi:role="line">Select</tspan></text>
+      </g>
+    </g>
+    <g
+       id="s4393"
+       style="" />
+  </g>
+  <g
+     inkscape:groupmode="layer"
+     id="layer3"
+     inkscape:label="Buton"
+     style="display:inline">
+    <g
+       id="s4427"
+       style="display:none" />
+    <g
+       id="s4159"
+       transform="translate(170.31517,0.62386544)"
+       style="display:none">
+      <g
+         transform="translate(4.9909171,0.3119319)"
+         id="g3370">
+        <rect
+           style="fill:url(#linearGradient3542);fill-opacity:1;stroke:none;filter:url(#filter3295)"
+           id="rect3372"
+           width="71.744492"
+           height="25.57847"
+           x="32.440987"
+           y="15.22048" />
+        <text
+           xml:space="preserve"
+           style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+           x="35.927368"
+           y="33.312569"
+           id="text3374"><tspan
+             sodipodi:role="line"
+             id="tspan3376"
+             x="35.927368"
+             y="33.312569"
+             style="font-size:16px">GNOME</tspan></text>
+      </g>
+      <g
+         transform="translate(102.93775,-0.9357981)"
+         id="g3380">
+        <rect
+           style="fill:url(#linearGradient3544);fill-opacity:1;stroke:none;filter:url(#filter3295)"
+           id="rect3382"
+           width="71.744492"
+           height="25.57847"
+           x="32.440987"
+           y="15.22048" />
+        <text
+           xml:space="preserve"
+           style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans"
+           x="39.927368"
+           y="33.312569"
+           id="text3384"><tspan
+             sodipodi:role="line"
+             id="tspan3386"
+             x="39.927368"
+             y="33.312569"
+             style="font-size:16px">AAA</tspan></text>
+      </g>
+    </g>
+    <g
+       id="s9524"
+       transform="translate(90.460441,64.258106)"
+       style="display:none">
+      <rect
+         x="0"
+         y="0"
+         width="100"
+         height="100"
+         id="rect3118" />
+    </g>
+    <g
+       id="s6546"
+       style="display:none">
+      <rect
+         x="0"
+         y="0"
+         width="100"
+         height="100"
+         style="fill:#ff00"
+         id="rect3116" />
+    </g>
+  </g>
+  <g
+     id="layer1"
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     style="display:inline" />
+</svg>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodejs/examples/scene/scene.js	Sat Nov 20 20:04:48 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(":0.0",800,600);
+scene=new main.MainMenu(app);
+app.loop();