Mercurial > MadButterfly
changeset 978:78312b44f48c
Implement Scene API.
author | wycc |
---|---|
date | Sat, 20 Nov 2010 20:04:31 +0800 |
parents | 5cefabccfb76 |
children | 380464725e75 |
files | nodejs/mbapp.js nodejs/svg.js |
diffstat | 2 files changed, 78 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/mbapp.js Sat Nov 20 15:46:03 2010 +0800 +++ b/nodejs/mbapp.js Sat Nov 20 20:04:31 2010 +0800 @@ -145,6 +145,34 @@ } } + +app.prototype.changeScene=function(s) { + var nth; + if (typeof(s)=='number') { + var i; + nth = s; + } else { + nth = this.svg.getFrameNumber(s); + if (nth == -1) return; + } + var scenes = this.svg.scenes; + for(i=0;i<scenes.length;i++) { + try { + if (nth >=scenes[i].start && nth <=scenes[i].end) { + this.get(scenes[i].ref).show(); + } else { + this.get(scenes[i].ref).hide(); + } + } catch(e) { + sys.puts(e); + sys.puts(scenes[i].ref); + } + } +} +app.prototype.addSceneListener=function(n, cb) { + sys.puts("This is not implemented yet") +} + var app_with_win = function(display, win) { var self = this; var mb_rt;
--- a/nodejs/svg.js Sat Nov 20 15:46:03 2010 +0800 +++ b/nodejs/svg.js Sat Nov 20 20:04:31 2010 +0800 @@ -72,12 +72,16 @@ var n = nodes[k].name(); if (n == "defs") { this.parseDefs(coord,nodes[k]); + } else if (n == "metadata") { + this.parseMetadata(coord,nodes[k]); } else if (n == "g") { this.parseGroup(accu,coord,'root_coord',nodes[k]); } } } + + loadSVG.prototype.leaveSVG=function() { var p = this.pgstack.pop(); @@ -104,6 +108,12 @@ name = mbname.value(); mb_rt.mbnames[name] = obj; } + try { + var gname = n.attr('id').value(); + sys.puts(gname); + mb_rt.mbnames[gname] = obj; + } catch(e) { + } } function getInteger(n,name) @@ -1117,7 +1127,8 @@ href = href.value(); var hrefid = href.substring(1); pstops = this.stop_ref[hrefid]; - stops = pstops.concat(stops); + if (pstops) + stops = pstops.concat(stops); var hrefgr = this.gradients[hrefid]; if(typeof x1 == "undefined") @@ -1191,6 +1202,44 @@ this.stop_ref[id] = stops; } +loadSVG.prototype.parseScenes=function(coord,node) { + var nodes = node.childNodes(); + + for(k in nodes) { + var name = nodes[k].name(); + if (name == 'scene') { + var node = nodes[k]; + + scene = new Object(); + scene.start = parseInt(node.attr('start').value()); + try { + scene.end = parseInt(node.attr('end').value()); + } catch(e) { + scene.end = scene.start; + } + scene.ref = node.attr('ref').value(); + + try { + this.scenenames[node.attr('name').value()] = scene.start; + } catch(e) { + } + this.scenes.push(scene); + } + } +} + +loadSVG.prototype.parseMetadata=function(coord,node) { + var nodes = node.childNodes(); + + for(k in nodes) { + var name = nodes[k].name(); + if (name == 'scenes') { + this.scenes=[]; + this.scenenames={}; + this.parseScenes(coord,nodes[k]); + } + } +} loadSVG.prototype.parseDefs=function(root,n) { var k;