Fixtransforms branch: Fixed issues 346 and 347, changed resetPathOrientation() to use transformPoint()
git-svn-id: http://svg-edit.googlecode.com/svn/branches/fixtransforms@999 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
789c977594
commit
fecc1da764
|
@ -197,16 +197,21 @@ function svg_edit_setup() {
|
||||||
|
|
||||||
// called when any element has changed
|
// called when any element has changed
|
||||||
var elementChanged = function(window,elems) {
|
var elementChanged = function(window,elems) {
|
||||||
// selectedElement must be updated here in case it was changed
|
|
||||||
selectedElement = (elems.length == 1 || elems[1] == null ? elems[0] : null);
|
|
||||||
for (var i = 0; i < elems.length; ++i) {
|
for (var i = 0; i < elems.length; ++i) {
|
||||||
var elem = elems[i];
|
var elem = elems[i];
|
||||||
|
|
||||||
// if the element changed was the svg, then it could be a resolution change
|
// if the element changed was the svg, then it could be a resolution change
|
||||||
if (elem && elem.tagName == "svg" && elem.getAttribute("viewBox")) {
|
if (elem && elem.tagName == "svg" && elem.getAttribute("viewBox")) {
|
||||||
var vb = elem.getAttribute("viewBox").split(' ');
|
var vb = elem.getAttribute("viewBox").split(' ');
|
||||||
changeResolution(parseInt(vb[2]),
|
changeResolution(parseInt(vb[2]),
|
||||||
parseInt(vb[3]));
|
parseInt(vb[3]));
|
||||||
}
|
}
|
||||||
|
// Update selectedElement if element is no longer part of the image.
|
||||||
|
// This occurs for the text elements in Firefox
|
||||||
|
else if(elem && selectedElement && selectedElement.parentNode == null) {
|
||||||
|
selectedElement = elem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we update the contextual panel with potentially new
|
// we update the contextual panel with potentially new
|
||||||
|
@ -340,8 +345,9 @@ function svg_edit_setup() {
|
||||||
var updateContextPanel = function() {
|
var updateContextPanel = function() {
|
||||||
var elem = selectedElement;
|
var elem = selectedElement;
|
||||||
var currentLayer = svgCanvas.getCurrentLayer();
|
var currentLayer = svgCanvas.getCurrentLayer();
|
||||||
|
var currentMode = svgCanvas.getMode();
|
||||||
// No need to update anything else in rotate mode
|
// No need to update anything else in rotate mode
|
||||||
if (svgCanvas.getMode() == 'rotate' && elem != null) {
|
if (currentMode == 'rotate' && elem != null) {
|
||||||
$('#angle').val(svgCanvas.getRotationAngle(elem));
|
$('#angle').val(svgCanvas.getRotationAngle(elem));
|
||||||
return;
|
return;
|
||||||
} else if(svgCanvas.addedNew && elem != null && elname == 'image') {
|
} else if(svgCanvas.addedNew && elem != null && elname == 'image') {
|
||||||
|
@ -356,7 +362,7 @@ function svg_edit_setup() {
|
||||||
var angle = svgCanvas.getRotationAngle(elem);
|
var angle = svgCanvas.getRotationAngle(elem);
|
||||||
$('#angle').val(angle);
|
$('#angle').val(angle);
|
||||||
|
|
||||||
if(!is_node) {
|
if(!is_node && currentMode != 'pathedit') {
|
||||||
$('#selected_panel').show();
|
$('#selected_panel').show();
|
||||||
// Elements in this array already have coord fields
|
// Elements in this array already have coord fields
|
||||||
if($.inArray(elname, ['line', 'circle', 'ellipse']) != -1) {
|
if($.inArray(elname, ['line', 'circle', 'ellipse']) != -1) {
|
||||||
|
|
|
@ -1476,6 +1476,7 @@ function BatchCommand(text) {
|
||||||
// TODO: find the transformed translation
|
// TODO: find the transformed translation
|
||||||
// Is this taken care of by recalculateDimensions?
|
// Is this taken care of by recalculateDimensions?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// update the transform list with translate,scale,translate
|
// update the transform list with translate,scale,translate
|
||||||
|
@ -2188,6 +2189,7 @@ function BatchCommand(text) {
|
||||||
// insert a dummy transform so if the element(s) are moved it will have
|
// insert a dummy transform so if the element(s) are moved it will have
|
||||||
// a transform to use for its translate
|
// a transform to use for its translate
|
||||||
for (var i = 0; i < selectedElements.length; ++i) {
|
for (var i = 0; i < selectedElements.length; ++i) {
|
||||||
|
if(selectedElements[i] == null) continue;
|
||||||
var slist = canvas.getTransformList(selectedElements[i]);
|
var slist = canvas.getTransformList(selectedElements[i]);
|
||||||
slist.insertItemBefore(svgroot.createSVGTransform(), 0);
|
slist.insertItemBefore(svgroot.createSVGTransform(), 0);
|
||||||
}
|
}
|
||||||
|
@ -2796,7 +2798,7 @@ function BatchCommand(text) {
|
||||||
};
|
};
|
||||||
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
|
batchCmd.addSubCommand(new ChangeElementCommand(elem, changes));
|
||||||
canvas.clearSelection();
|
canvas.clearSelection();
|
||||||
resetPathOrientation(elem, angle);
|
resetPathOrientation(elem);
|
||||||
addCommandToHistory(batchCmd);
|
addCommandToHistory(batchCmd);
|
||||||
current_path = elem;
|
current_path = elem;
|
||||||
setPointContainerTransform(""); // Maybe this should be in resetPointGrips?
|
setPointContainerTransform(""); // Maybe this should be in resetPointGrips?
|
||||||
|
@ -2808,20 +2810,12 @@ function BatchCommand(text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rotate all points of a path and remove its transform value
|
// Rotate all points of a path and remove its transform value
|
||||||
var resetPathOrientation = function(path, angle) {
|
var resetPathOrientation = function(path) {
|
||||||
if(path == null || path.nodeName != 'path') return false;
|
if(path == null || path.nodeName != 'path') return false;
|
||||||
var angle = angle * Math.PI / 180.0;
|
|
||||||
if(!angle) return false;
|
var tlist = canvas.getTransformList(path);
|
||||||
|
var m = transformListToTransform(tlist).matrix;
|
||||||
path.removeAttribute("transform");
|
path.removeAttribute("transform");
|
||||||
var bb = path.getBBox();
|
|
||||||
var cx = bb.x + bb.width/2,
|
|
||||||
cy = bb.y + bb.height/2;
|
|
||||||
var rotate = function(x,y) {
|
|
||||||
x -= cx; y -= cy;
|
|
||||||
var r = Math.sqrt(x*x + y*y);
|
|
||||||
var theta = Math.atan2(y,x) + angle;
|
|
||||||
return [r * Math.cos(theta) + cx, r * Math.sin(theta) + cy];
|
|
||||||
}
|
|
||||||
|
|
||||||
var segList = path.pathSegList;
|
var segList = path.pathSegList;
|
||||||
var len = segList.numberOfItems;
|
var len = segList.numberOfItems;
|
||||||
|
@ -2834,7 +2828,8 @@ function BatchCommand(text) {
|
||||||
$.each(['',1,2], function(j, n) {
|
$.each(['',1,2], function(j, n) {
|
||||||
var x = seg['x'+n], y = seg['y'+n];
|
var x = seg['x'+n], y = seg['y'+n];
|
||||||
if(x && y) {
|
if(x && y) {
|
||||||
$.merge(pts, rotate(x,y));
|
var pt = transformPoint(x, y, m);
|
||||||
|
pts.splice(pts.length, 0, pt.x, pt.y);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
replacePathSeg(type, i, pts, path);
|
replacePathSeg(type, i, pts, path);
|
||||||
|
@ -2990,7 +2985,7 @@ function BatchCommand(text) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Get the correct BBox of the new path, then discard it
|
// Get the correct BBox of the new path, then discard it
|
||||||
resetPathOrientation(path, angle);
|
resetPathOrientation(path);
|
||||||
var bb = false;
|
var bb = false;
|
||||||
try {
|
try {
|
||||||
bb = path.getBBox();
|
bb = path.getBBox();
|
||||||
|
|
Loading…
Reference in New Issue