commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r984041 - in /commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool: behaviour/canvas.xml transform.js
Date Tue, 10 Aug 2010 14:21:06 GMT
Author: jbeard
Date: Tue Aug 10 14:21:05 2010
New Revision: 984041

URL: http://svn.apache.org/viewvc?rev=984041&view=rev
Log:
Scaling now works.

Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/canvas.xml
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/transform.js

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/canvas.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/canvas.xml?rev=984041&r1=984040&r2=984041&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/canvas.xml (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/canvas.xml Tue Aug
10 14:21:05 2010
@@ -391,7 +391,7 @@ In both:
 						&& In(ready_to_rotate)"/>
 
 				<transition target="scaling" event="mousedown" 
-					cond="_event.data.target === rotationHandle 
+					cond="_event.data.target === scaleHandle 
 						&amp;&amp; In(ready_to_scale)"/>
 			</state>
 
@@ -553,7 +553,7 @@ In both:
 						for(var i=0,l=selectedNodes.length; i < l; i++){
 							var n = selectedNodes[i];
 
-							transformModule.scale(n,eventStamp,_event.data)
+							transformModule.scale(n,eventStamp,_event.data,cachedBBox)
 						}
 					]]></script>
 					<assign location="cachedBBox" expr="getAggregateBBox(selectedNodes)"/>

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/transform.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/transform.js?rev=984041&r1=984040&r2=984041&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/transform.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/transform.js Tue Aug 10 14:21:05
2010
@@ -66,6 +66,24 @@ function(){
 		return r*180/Math.PI;
 	}
 
+	function   _computeScaleTransform(pt1,pt2,bbox,svg){
+		  var ptDiff = {
+			x:pt2.x-pt1.x,
+			y:pt2.y-pt1.y
+		  }
+		  
+		  //compute his translation and scale factors
+		  //southeast only
+		  var sx = 1+ptDiff.x / bbox.width
+		  var sy = 1+ptDiff.y / bbox.height
+		  var tx = bbox.x * (1-sx)
+		  var ty = bbox.y * (1-sy)
+		  
+		  var g = svg.createSVGMatrix();
+		  var m  = g.translate(tx,ty).scaleNonUniform(sx,sy);		  
+		  return m;
+	}
+
 	return {
 		translate : function(rawNode,tDelta){
 			var tl = rawNode.transform.baseVal;
@@ -78,7 +96,6 @@ function(){
 		},
 
 		rotate : function (rawNode,d,cx,cy){
-			//rawNode : isa csGraphObj || SVGElement
 			cx = cx || 0;
 			cy = cy || 0;
 
@@ -98,15 +115,14 @@ function(){
 			this.rotate(rawNode,raidansToDegrees(radians),cx,cy);
 		},
 
-		scale : function (rawNode,e1,e2){
-			//rawNode : isa csGraphObj || SVGElement
+		scale : function (rawNode,e1,e2,bbox){
 			var tl = rawNode.transform.baseVal;
 			var t = tl.numberOfItems ? tl.getItem(0) : rawNode.ownerSVGElement.createSVGTransform();
 			var m = t.matrix;
 
-			var pt1 = {x:e1.localX,y:e1.localY},pt2 = {x:e2.localX,y:e2.localY}
-			var bbox = rawNode.cachedBBox || getBoundingBoxInCanvasCoordinates(csGraphObj);
-			var scaleTransform = _computeScaleTransform(pt1,pt2,bbox);
+			var pt1 = {x:e1.clientX,y:e1.clientY},pt2 = {x:e2.clientX,y:e2.clientY}
+			var bbox = bbox || getBoundingBoxInCanvasCoordinates(rawNode);
+			var scaleTransform = _computeScaleTransform(pt1,pt2,bbox,rawNode.ownerSVGElement);
 
 			var newM = scaleTransform.multiply(m);
 			t.setMatrix(newM);



Mime
View raw message