changeset 1392:cd5fb45bc247

Check if the scenes is defined. Disable the changeScene function if the scenes is not defined for the pure MB program.
author wycc
date Sun, 27 Mar 2011 08:27:03 +0800
parents ff8122c59648
children 2d56ed5b0995
files nodejs/mbapp.js nodejs/svg.js
diffstat 2 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/mbapp.js	Fri Mar 25 09:24:44 2011 +0800
+++ b/nodejs/mbapp.js	Sun Mar 27 08:27:03 2011 +0800
@@ -192,13 +192,17 @@
 app.prototype.generateScaleTweenObject=function(coord,src,dest,p) {
     sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty);
     sys.puts("dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty);
+    if (src == null) return;
+    sys.puts("src.center="+src.center);
     var p1 = 1-p;
+    var x1 = src.center.x;
+    var y1 = src.center.y;
     var sx = src.sx*p+dest.sx*p1;
     var sy = src.sy*p+dest.sy*p1;
     var r = src.r*p+dest.r*p1;
-    var tx = src.tx*p+dest.tx*p1;
-    var ty = src.ty*p+dest.ty*p1;
-    var mt = [1, 0, -src.tx, 0, 1, -src.ty];
+    var tx = src.tx*p+dest.tx*p1-src.tx;
+    var ty = src.ty*p+dest.ty*p1-src.ty;
+    var mt = [1, 0, -x1, 0, 1, -y1];
     var opacity;
     var ms;
 
@@ -211,9 +215,12 @@
         ms= [Math.cos(r), Math.sin(r),0,-Math.sin(r), Math.cos(r),0];
 	m = mul(ms,mt);
     }
+    sys.puts("x1="+x1);
+    sys.puts("y1="+y1);
     m = mul([sx,0,0,0,sy,0],m);
+    m = mul([1,0,x1,0,1,y1],m);
     m = mul([1,0,tx,0,1,ty],m);
-    m[2] = -m[2];
+    //m[2] = -m[2];
     coord[0] = m[0];
     coord[1] = m[1];
     coord[2] = m[2];
@@ -221,7 +228,7 @@
     coord[4] = m[4];
     coord[5] = m[5];
     //sys.puts(coord);
-    //sys.puts("p="+p+" "+m[0]+","+m[1]+","+m[2]+","+m[3]+","+m[4]+","+m[5]);
+    sys.puts("p="+p+" "+m[0]+","+m[1]+","+m[2]+","+m[3]+","+m[4]+","+m[5]);
 }
 
 app.prototype.changeScene=function(s) {
@@ -238,6 +245,7 @@
     sys.puts("goto to scene "+nth);
     this.currentScene = nth;
     var scenes = this.svg.scenes;
+    if (scenes == null) return;
     for(i=0;i<scenes.length-1;i++) {
         try {
             if (nth >=scenes[i].start && nth <=scenes[i].end) {
--- a/nodejs/svg.js	Fri Mar 25 09:24:44 2011 +0800
+++ b/nodejs/svg.js	Sun Mar 27 08:27:03 2011 +0800
@@ -1216,16 +1216,16 @@
     attr = n.attr('duplicate-src');
     if (attr) {
         var id = attr.value();
-        var orign = this.mb_rt.mbnames[id].node;
-        sys.puts("xxxxxxxxxxxxxx");
-        var nw = getInteger(orign,'width');
-        var nh = getInteger(orign,'height');
-	sys.puts("nw="+nw);
-	sys.puts("nh="+nh);
-	sys.puts("w="+w);
-	sys.puts("h="+h);
-	tcoord.sx *= w/nw;
-	tcoord.sy *= h/nh;
+	var origcoord = this.mb_rt.mbnames[id];
+	if (origcoord==null) {
+	    sys.puts("Unknown reference "+id);
+	} else {
+            var orign = origcoord.node;
+            var nw = getInteger(orign,'width');
+            var nh = getInteger(orign,'height');
+	    tcoord.sx *= w/nw;
+	    tcoord.sy *= h/nh;
+	}
     }
     nx = tcoord[0]*x+tcoord[1]*y+tcoord[2];
     ny = tcoord[3]*x+tcoord[4]*y+tcoord[5];
@@ -1234,7 +1234,6 @@
     if (tcoord.center.y > ny)
 	tcoord.center.y = ny;
     var img = this.mb_rt.image_new(x,y,w,h);
-    sys.puts('----'+ref);
     var img_data = ldr.load(ref);
     try {
         var paint = this.mb_rt.paint_image_new(img_data);