Made poly points moveable after rotation. Oh yes.

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@802 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Alexis Deveria
2009-10-12 14:29:21 +00:00
parent 93232fa6fb
commit 83f1c79e6b

View File

@@ -1658,6 +1658,7 @@ function BatchCommand(text) {
newText.textContent = "text"; newText.textContent = "text";
break; break;
case "poly": case "poly":
setPointContainerTransform("");
started = true; started = true;
break; break;
case "polyedit": case "polyedit":
@@ -2781,8 +2782,8 @@ function BatchCommand(text) {
// otherwise, close the poly // otherwise, close the poly
if (i == 0 && len >= 6) { if (i == 0 && len >= 6) {
// Create end segment // Create end segment
var abs_x = getPolyPoint(0)[0]; var abs_x = current_poly_pts[0];
var abs_y = getPolyPoint(0)[1]; var abs_y = current_poly_pts[1];
d_attr += ['L',abs_x,',',abs_y,'z'].join(''); d_attr += ['L',abs_x,',',abs_y,'z'].join('');
poly.setAttribute("d", d_attr); poly.setAttribute("d", d_attr);
} else if(len < 3) { } else if(len < 3) {
@@ -2833,33 +2834,32 @@ function BatchCommand(text) {
// its old center, then determine the new center, then rotate it back // its old center, then determine the new center, then rotate it back
// This is because we want the poly to remember its rotation // This is because we want the poly to remember its rotation
var angle = canvas.getRotationAngle(current_poly) * Math.PI / 180.0; var angle = canvas.getRotationAngle(current_poly) * Math.PI / 180.0;
if (angle) { if (angle) {
var box = canvas.getBBox(current_poly); var box = canvas.getBBox(current_poly);
var oldbox = selectedBBoxes[0]; var oldbox = selectedBBoxes[0];
var oldcx = round(oldbox.x + oldbox.width/2), var oldcx = oldbox.x + oldbox.width/2,
oldcy = round(oldbox.y + oldbox.height/2), oldcy = oldbox.y + oldbox.height/2,
newcx = round(box.x + box.width/2), newcx = box.x + box.width/2,
newcy = round(box.y + box.height/2); newcy = box.y + box.height/2;
// un-rotate the new center to the proper position // un-rotate the new center to the proper position
var dx = newcx - oldcx, var dx = newcx - oldcx,
dy = newcy - oldcy; dy = newcy - oldcy;
var r = Math.sqrt(dx*dx + dy*dy); var r = Math.sqrt(dx*dx + dy*dy);
var theta = Math.atan2(dy,dx) + angle; var theta = Math.atan2(dy,dx) + angle;
newcx = round(r * Math.cos(theta) + oldcx); newcx = r * Math.cos(theta) + oldcx;
newcy = round(r * Math.sin(theta) + oldcy); newcy = r * Math.sin(theta) + oldcy;
var i = current_poly_pts.length; var getRotVals = function(x, y) {
while (i) { dx = x - oldcx;
i -= 2; dy = y - oldcy;
dx = current_poly_pts[i] - oldcx;
dy = current_poly_pts[i+1] - oldcy;
// rotate the point around the old center // rotate the point around the old center
r = Math.sqrt(dx*dx + dy*dy); r = Math.sqrt(dx*dx + dy*dy);
theta = Math.atan2(dy,dx) + angle; theta = Math.atan2(dy,dx) + angle;
current_poly_pts[i] = dx = r * Math.cos(theta) + oldcx; dx = r * Math.cos(theta) + oldcx;
current_poly_pts[i+1] = dy = r * Math.sin(theta) + oldcy; dy = r * Math.sin(theta) + oldcy;
// dx,dy should now hold the actual coordinates of each // dx,dy should now hold the actual coordinates of each
// point after being rotated // point after being rotated
@@ -2871,34 +2871,28 @@ function BatchCommand(text) {
r = Math.sqrt(dx*dx + dy*dy); r = Math.sqrt(dx*dx + dy*dy);
theta = Math.atan2(dy,dx) - angle; theta = Math.atan2(dy,dx) - angle;
current_poly_pts[i] = round(r * Math.cos(theta) + newcx); return {'x':(r * Math.cos(theta) + newcx)/1,
current_poly_pts[i+1] = round(r * Math.sin(theta) + newcy); 'y':(r * Math.sin(theta) + newcy)/1};
} // loop for each point }
// now set the d attribute to the new value of current_poly_pts var list = current_poly.pathSegList;
var oldd = current_poly.getAttribute("d"); var i = list.numberOfItems;
var closedPath = (oldd[oldd.length-1] == 'z' || oldd[oldd.length-1] == 'Z'); while (i) {
var len = current_poly_pts.length/2; i -= 1;
var arr = new Array(len+1); var seg = list.getItem(i);
var curx = current_poly_pts[0]/current_zoom, var type = seg.pathSegType;
cury = current_poly_pts[1]/current_zoom; if(type == 1) continue;
arr[0] = ["M", curx, ",", cury].join('');
assignAttributes(document.getElementById("polypointgrip_0"), var rvals = getRotVals(seg.x,seg.y);
{"cx":curx,"cy":cury}, 100); var points = [rvals.x, rvals.y];
for (var j = 1; j < len; ++j) { if(seg.x1 != null && seg.x2 != null) {
var px = current_poly_pts[j*2]/current_zoom, c_vals1 = getRotVals(seg.x1, seg.y1);
py = current_poly_pts[j*2+1]/current_zoom; c_vals2 = getRotVals(seg.x2, seg.y2);
arr[j] = ["l", round(px-curx), ",", round(py-cury)].join(''); points.splice(points.length, 0, c_vals1.x , c_vals1.y, c_vals2.x, c_vals2.y);
curx = px; }
cury = py; replacePathSeg(type, i, points);
assignAttributes(document.getElementById("polypointgrip_"+j), } // loop for each point
{"cx":px,"cy":py}, 100);
}
if (closedPath) {
arr[len] = "z";
}
current_poly.setAttribute("d", arr.join(' '));
box = canvas.getBBox(current_poly); box = canvas.getBBox(current_poly);
selectedBBoxes[0].x = box.x; selectedBBoxes[0].y = box.y; selectedBBoxes[0].x = box.x; selectedBBoxes[0].y = box.y;
selectedBBoxes[0].width = box.width; selectedBBoxes[0].height = box.height; selectedBBoxes[0].width = box.width; selectedBBoxes[0].height = box.height;
@@ -2907,13 +2901,15 @@ function BatchCommand(text) {
var rotate = "rotate(" + (angle * 180.0 / Math.PI) + " " + newcx + "," + newcy + ")"; var rotate = "rotate(" + (angle * 180.0 / Math.PI) + " " + newcx + "," + newcy + ")";
oldvalues["transform"] = current_poly.getAttribute("rotate"); oldvalues["transform"] = current_poly.getAttribute("rotate");
current_poly.setAttribute("transform", rotate); current_poly.setAttribute("transform", rotate);
if(document.getElementById("polypointgrip_container")) { if(document.getElementById("polypointgrip_container")) {
var pcx = newcx * current_zoom, var pcx = newcx * current_zoom,
pcy = newcy * current_zoom; pcy = newcy * current_zoom;
var xform = ["rotate(", (angle*180.0/Math.PI), " ", pcx, ",", pcy, ")"].join(""); var xform = ["rotate(", (angle*180.0/Math.PI), " ", pcx, ",", pcy, ")"].join("");
setPointContainerTransform(xform); setPointContainerTransform(xform);
} }
resetPointGrips();
} // if rotated } // if rotated
batchCmd.addSubCommand(new ChangeElementCommand(current_poly, oldvalues, "poly points")); batchCmd.addSubCommand(new ChangeElementCommand(current_poly, oldvalues, "poly points"));
@@ -2966,7 +2962,6 @@ function BatchCommand(text) {
if(current_mode == "poly") { if(current_mode == "poly") {
current_poly = element; current_poly = element;
// selectedBBoxes[0] = canvas.getBBox(current_poly);
current_mode = "polyedit"; current_mode = "polyedit";
recalcPolyPoints(); recalcPolyPoints();
addAllPointGripsToPoly(current_poly_pts.length/2 - 1); addAllPointGripsToPoly(current_poly_pts.length/2 - 1);
@@ -3496,8 +3491,6 @@ function BatchCommand(text) {
this.clonePolyNode = function() { this.clonePolyNode = function() {
// fixWebkitNodes();
var pt = current_poly_pt, list = current_poly.pathSegList; var pt = current_poly_pt, list = current_poly.pathSegList;
var next_item = list.getItem(pt+1); var next_item = list.getItem(pt+1);