changeset 421:63e921094f6d

svg-edit.editor.svgcanvas.js: updated to r630
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 13 Sep 2009 10:38:12 +0200
parents 792b9ee3d139
children b3f6d04627c9
files htdocs/svg-edit/CHANGES.current htdocs/svg-edit/editor/svgcanvas.js
diffstat 2 files changed, 39 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/htdocs/svg-edit/CHANGES.current	Sun Sep 13 10:18:58 2009 +0200
+++ b/htdocs/svg-edit/CHANGES.current	Sun Sep 13 10:38:12 2009 +0200
@@ -13,6 +13,6 @@
  * adjust coordinates for drawing tools (offset probably from relative)
  * Link Syntax for attachments
 
-SVG-edit is a lightweight, web-based, Javascript-driven SVG editor that works in any modern browser: version of svg-edit Revision r628 (http://code.google.com/p/svg-edit/) for moin-1.9
+SVG-edit is a lightweight, web-based, Javascript-driven SVG editor that works in any modern browser: version of svg-edit Revision r630 (http://code.google.com/p/svg-edit/) for moin-1.9
 
 htdocs/svg-edit must be linked into MoinMoin/web/static/htdocs
--- a/htdocs/svg-edit/editor/svgcanvas.js	Sun Sep 13 10:18:58 2009 +0200
+++ b/htdocs/svg-edit/editor/svgcanvas.js	Sun Sep 13 10:38:12 2009 +0200
@@ -1861,25 +1861,26 @@
 					if (angle) {
 						// calculate the shape's old center that was used for rotation
 						var box = selectedBBoxes[0];
-						var cx = parseInt(box.x + box.width/2), 
-							cy = parseInt(box.y + box.height/2);
+						var cx = parseInt(box.x + box.width/2) * current_zoom, 
+							cy = parseInt(box.y + box.height/2) * current_zoom;
 						var dx = mouse_x - cx, dy = mouse_y - cy;
  						var r = Math.sqrt( dx*dx + dy*dy );
 						var theta = Math.atan2(dy,dx) - angle;						
-						x = cx + r * Math.cos(theta);
-						y = cy + r * Math.sin(theta);
+						current_poly_pts[i] = mouse_x = cx + r * Math.cos(theta);
+						current_poly_pts[i+1] = mouse_y = cy + r * Math.sin(theta);
 					}
-
-					current_poly_pts[i] = x;
-					current_poly_pts[i+1] = y;
+					else {
+						current_poly_pts[i] = x * current_zoom;
+						current_poly_pts[i+1] = y * current_zoom;
+					}
 
 					// reset the path's d attribute using current_poly_pts
 					var oldd = current_poly.getAttribute("d");
 					var closedPath = (oldd[oldd.length-1] == 'z' || oldd[oldd.length-1] == 'Z');
 					var len = current_poly_pts.length/2;
 					var arr = new Array(len+1);
-					var curx = current_poly_pts[0],
-						cury = current_poly_pts[1];
+					var curx = current_poly_pts[0]/current_zoom,
+						cury = current_poly_pts[1]/current_zoom;
 					arr[0] = ["M", curx, ",", cury].join('');
 					for (var j = 1; j < len; ++j) {
 						var px = current_poly_pts[j*2]/current_zoom, py = current_poly_pts[j*2+1]/current_zoom;
@@ -1924,7 +1925,7 @@
 	};
 
 	var addAllPointGripsToPoly = function() {
-		// loop through and hide all pointgrips
+		// loop through and show all pointgrips
 		var len = current_poly_pts.length;
 		for (var i = 0; i < len; i += 2) {
 			var grip = document.getElementById("polypointgrip_"+i/2);
@@ -1940,7 +1941,16 @@
 			}
 		}
 		var pointGripContainer = document.getElementById("polypointgrip_container");
-		pointGripContainer.setAttribute("transform", current_poly.getAttribute("transform"));
+		// FIXME:  we cannot just use the same transform as the poly because we might be 
+		// at a different zoom level
+		var angle = canvas.getRotationAngle(current_poly);
+		if (angle) {
+			var bbox = canvas.getBBox(current_poly);
+			var cx = (bbox.x + bbox.width/2) * current_zoom,
+				cy = (bbox.y + bbox.height/2) * current_zoom;
+			var xform = ["rotate(", angle, " ", cx, ",", cy, ")"].join("");
+			pointGripContainer.setAttribute("transform", xform);
+		}
 	};
 
 	var addPointGripToPoly = function(x,y,index) {
@@ -2286,6 +2296,7 @@
 					// If the poly was rotated, we must now pay the piper:
 					// Every poly point must be rotated into the rotated coordinate system of 
 					// its old center, then determine the new center, then rotate it back
+					// This is because we want the poly to remember its rotation
 					var angle = canvas.getRotationAngle(current_poly) * Math.PI / 180.0;
 					if (angle) {
 						var box = canvas.getBBox(current_poly);
@@ -2334,13 +2345,14 @@
 						var closedPath = (oldd[oldd.length-1] == 'z' || oldd[oldd.length-1] == 'Z');
 						var len = current_poly_pts.length/2;
 						var arr = new Array(len+1);
-						var curx = current_poly_pts[0],
-							cury = current_poly_pts[1];
+						var curx = current_poly_pts[0]/current_zoom,
+							cury = current_poly_pts[1]/current_zoom;
 						arr[0] = ["M", curx, ",", cury].join('');
 						assignAttributes(document.getElementById("polypointgrip_0"), 
 										{"cx":curx,"cy":cury}, 100);
 						for (var j = 1; j < len; ++j) {
-							var px = current_poly_pts[j*2], py = current_poly_pts[j*2+1];
+							var px = current_poly_pts[j*2]/current_zoom, 
+								py = current_poly_pts[j*2+1]/current_zoom;
 							arr[j] = ["l", parseInt(px-curx), ",", parseInt(py-cury)].join('');
 							curx = px;
 							cury = py;
@@ -2363,7 +2375,10 @@
 						
 						var pointGripContainer = document.getElementById("polypointgrip_container");
 						if(pointGripContainer) {
-							pointGripContainer.setAttribute("transform", rotate);
+							var pcx = newcx * current_zoom,
+								pcy = newcy * current_zoom;
+							var xform = ["rotate(", (angle*180.0/Math.PI), " ", pcx, ",", pcy, ")"].join("");
+							pointGripContainer.setAttribute("transform", xform);
 						}
 					} // if rotated
 
@@ -3228,8 +3243,11 @@
 
 	this.moveSelectedElements = function(dx,dy,undoable) {
 		// if undoable is not sent, default to true
-		dx *= current_zoom;
-		dy *= current_zoom;
+		// if single values, scale them to the zoom
+		if (dx.constructor != Array) {
+			dx *= current_zoom;
+			dy *= current_zoom;
+		}
 		var undoable = undoable || true;
 		var batchCmd = new BatchCommand("position");
 		var i = selectedElements.length;
@@ -3239,12 +3257,12 @@
 				selectedBBoxes[i] = this.getBBox(selected);
 				// dx and dy could be arrays
 				if (dx.constructor == Array) {
-					selectedBBoxes[i].x += dx[i];
+					selectedBBoxes[i].x += dx[i] * current_zoom;
 				} else {
 					selectedBBoxes[i].x += dx;
 				}
 				if (dy.constructor == Array) {
-					selectedBBoxes[i].y += dy[i];
+					selectedBBoxes[i].y += dy[i] * current_zoom;
 				} else {
 					selectedBBoxes[i].y += dy;
 				}
@@ -3496,6 +3514,7 @@
 		this.moveSelectedElements(dx,dy);
 	};
 
+	this.getCurrentZoom = function() { return this.current_zoom; }
 }
 
 // Static class for various utility functions