# HG changeset patch # User wycc # Date 1287676615 -28800 # Node ID e4474cac20da26116dd97342cdc46a488684c680 # Parent 85b647f5aeffbd60d248a30cd2e7b6ff634dabfb Implement the page stack diff -r 85b647f5aeff -r e4474cac20da nodejs/mbapp.js --- a/nodejs/mbapp.js Thu Oct 21 23:56:14 2010 +0800 +++ b/nodejs/mbapp.js Thu Oct 21 23:56:55 2010 +0800 @@ -100,9 +100,10 @@ this.mb_rt.kbevents.add_event_observer(exports.EVT_KB_PRESS, function(evt) { self.KeyPress(evt);}); this.keymap={}; this.onKeyPress = null; + this.svg = new svg.loadSVG(this.mb_rt,this.mb_rt.root,null); } app.prototype.loadSVG=function(fname) { - svg.loadSVG(this.mb_rt,this.mb_rt.root,fname); + this.svg.load(this.mb_rt,this.mb_rt.root,fname) } app.prototype.KeyPress = function(evt) { diff -r 85b647f5aeff -r e4474cac20da nodejs/svg.js --- a/nodejs/svg.js Thu Oct 21 23:56:14 2010 +0800 +++ b/nodejs/svg.js Thu Oct 21 23:56:55 2010 +0800 @@ -32,12 +32,15 @@ return [r, g, b]; } -exports.loadSVG=function(mb_rt,root,filename) { - return new loadSVG(mb_rt, root, filename); -}; - +exports.loadSVG=loadSVG; function loadSVG(mb_rt, root, filename) { + this.pgstack=[]; + if (filename) + this.load(mb_rt,root,filename); +} + +loadSVG.prototype.load=function(mb_rt, root, filename) { var doc = libxml.parseXmlFile(filename); var _root = doc.root(); var nodes = _root.childNodes(); @@ -48,9 +51,13 @@ this.stop_ref={}; this.gradients={}; this.radials = {}; - root.center=new Object(); - root.center.x = 10000; - root.center.y = 10000; + coord.center=new Object(); + coord.center.x = 10000; + coord.center.y = 10000; + if (this.pgstack.length > 0) + this.pgstack[this.pgstack.length-1].hide(); + this.pgstack.push(coord); + if(_root.attr("width")) { k = _root.attr("width").value(); @@ -64,13 +71,21 @@ for(k in nodes) { var n = nodes[k].name(); if (n == "defs") { - this.parseDefs(root,nodes[k]); + this.parseDefs(coord,nodes[k]); } else if (n == "g") { - this.parseGroup(accu,root,'root_coord',nodes[k]); + this.parseGroup(accu,coord,'root_coord',nodes[k]); } } } +loadSVG.prototype.leaveSVG=function() +{ + var p = this.pgstack.pop(); + p.hide(); + if (this.pgstack.length > 0) + this.pgstack[this.pgstack.length-1].show(); +} + function make_mbnames(mb_rt, n, obj) { var mbname; var name;