changeset 862:3ce9daa9558b abs_n_rel_center

Scale an object according bbox.orig
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 21 Sep 2010 00:40:36 +0800
parents e69f551e4a37
children 881efcd8a18f
files nodejs/animate.js nodejs/testdesktop.js
diffstat 2 files changed, 30 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/animate.js	Tue Sep 21 00:28:44 2010 +0800
+++ b/nodejs/animate.js	Tue Sep 21 00:40:36 2010 +0800
@@ -128,8 +128,8 @@
     if (this.end == 1) return;
     var percent = (Date.now() - this.starttime)/this.duration;
     if (percent > 1) percent = 1;
-    var sx = 1 + (this.targetx - 1) * percent;
-    var sy = 1 + (this.targety - 1) * percent;
+    var sx = 1 + (this.totalsx - 1) * percent;
+    var sy = 1 + (this.totalsy - 1) * percent;
     var sh1 = [1, 0, -this.center_x, 0, 1, -this.center_y];
     var sh2 = [1, 0, this.center_x, 0, 1, this.center_y];
     var scale=[sx, 0, 0, 0, sy, 0];
@@ -156,25 +156,26 @@
     obj.animated_scale = null;
 }
 
-function scale(app,obj,targetx,targety, duration) {
+function scale(app, obj, fact_x, fact_y, duration) {
+    var bbox;
+    
     try {
         if (obj.animated_scale) {
-	    //obj[0] = obj.animated_scale.targetx;
-	    //obj[4] = obj.animated_scale.targety;
-	    //obj[2] = obj.animated_scale.final_offset_x;
-	    //obj[5] = obj.aninated_scale.final_offset_y;
 	    obj.animated_scale.end = 1;
 	}
     } catch(e) {
 	    
     }
+
+    bbox = obj.bbox;
+    bbox.update();
     obj.animated_scale = this;
     this.app = app;
     this.obj = obj;
     this.end = 0;
     this.starttime = Date.now();
-    this.targetx = targetx;
-    this.targety = targety;
+    this.totalsx = fact_x * bbox.orig.width / bbox.width;
+    this.totalsy = fact_y * bbox.orig.height / bbox.height;
     this.duration = duration*1000;
     this.center_x = obj.center.rel.x;
     this.center_y = obj.center.rel.y;
--- a/nodejs/testdesktop.js	Tue Sep 21 00:28:44 2010 +0800
+++ b/nodejs/testdesktop.js	Tue Sep 21 00:40:36 2010 +0800
@@ -17,13 +17,15 @@
 setting = app.get("setting");
 
 lightbar = app.get("lightbar");
-lines=[app.get("line1"),app.get("line2"),app.get("line3"), app.get("line4"),app.get("line5")];
-for(i=0;i<lines.length;i++) {
-    sys.puts("["+i+"]="+lines[i].center.x);
+lines = [];
+for(i = 0; i < 5; i++) {
+    line = app.get("line" + (i + 1));
+    lines.push(line);
 }
 line=0;
 
-items=[video,audio,picture,setting];
+items=[video, audio, picture, setting];
+
 item = 0;
 an = new animate.scale(app,items[item],1,1.5,0.1);
 an.start();
@@ -35,10 +37,15 @@
 	item = 0;
 	return;
     }
+    
     var target = items[item];
-    var an = new animate.scale(app,old,1,1/1.5,0.1);
+
+    old.bbox.update();
+    target.bbox.update();
+    
+    var an = new animate.scale(app, old, 1, 1, 0.1);
     an.start();
-    an = new animate.scale(app,target,1,1.5,0.3);
+    an = new animate.scale(app, target, 1, 1.5, 0.3);
     an.start();
 });
 
@@ -49,10 +56,15 @@
 	item = item - 1;
 	return;
     }
+    
     var target = items[item];
-    var an = new animate.scale(app,old,1,1/1.5,0.1);
+
+    old.bbox.update();
+    target.bbox.update();
+    
+    var an = new animate.scale(app, old, 1, 1, 0.1);
     an.start();
-    an = new animate.scale(app,target,1,1.5,0.3);
+    an = new animate.scale(app, target, 1, 1.5, 0.3);
     an.start();
 });