changeset 914:e4474cac20da

Implement the page stack
author wycc
date Thu, 21 Oct 2010 23:56:55 +0800
parents 85b647f5aeff
children 80000948fcde
files nodejs/mbapp.js nodejs/svg.js
diffstat 2 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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) {
--- 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;