Rotation angle now preserved with drag/move
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@389 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
1a97363ea9
commit
121a6c148d
|
@ -708,7 +708,7 @@ function SvgCanvas(c)
|
||||||
'l', 'l', 'l', 'l', // TODO: be less lazy below and map them to h and v
|
'l', 'l', 'l', 'l', // TODO: be less lazy below and map them to h and v
|
||||||
's', 's', 't', 't' ];
|
's', 's', 't', 't' ];
|
||||||
|
|
||||||
// this function returns the command which resulted from th selected change
|
// this function returns the command which resulted from the selected change
|
||||||
var recalculateSelectedDimensions = function(i) {
|
var recalculateSelectedDimensions = function(i) {
|
||||||
var selected = selectedElements[i];
|
var selected = selectedElements[i];
|
||||||
if (selected == null) return null;
|
if (selected == null) return null;
|
||||||
|
@ -730,11 +730,20 @@ function SvgCanvas(c)
|
||||||
|
|
||||||
var changes = {};
|
var changes = {};
|
||||||
|
|
||||||
// This fixes Firefox 2- behavior - which does not reset values when
|
// if there was a rotation transform, re-set it, otherwise empty out the transform attribute
|
||||||
// the attribute has been removed
|
// This fixes Firefox 2- behavior - which does not reset values when the attribute has
|
||||||
// see https://bugzilla.mozilla.org/show_bug.cgi?id=320622
|
// been removed, see https://bugzilla.mozilla.org/show_bug.cgi?id=320622
|
||||||
|
var angle = canvas.getRotationAngle(selected);
|
||||||
|
if (angle != null) {
|
||||||
|
var cx = remapx(box.x + box.width/2),
|
||||||
|
cy = remapy(box.y + box.height/2);
|
||||||
|
selected.setAttribute("transform", ["rotate(", angle, " ", cx, ",", cy, ")"].join(''));
|
||||||
|
}
|
||||||
|
else {
|
||||||
selected.setAttribute("transform", "");
|
selected.setAttribute("transform", "");
|
||||||
selected.removeAttribute("transform");
|
selected.removeAttribute("transform");
|
||||||
|
}
|
||||||
|
|
||||||
switch (selected.tagName)
|
switch (selected.tagName)
|
||||||
{
|
{
|
||||||
// NOTE: there's no way to create an actual polygon element except by editing source
|
// NOTE: there's no way to create an actual polygon element except by editing source
|
||||||
|
@ -1190,8 +1199,15 @@ function SvgCanvas(c)
|
||||||
for (var i = 0; i < len; ++i) {
|
for (var i = 0; i < len; ++i) {
|
||||||
var selected = selectedElements[i];
|
var selected = selectedElements[i];
|
||||||
if (selected == null) break;
|
if (selected == null) break;
|
||||||
selected.setAttribute("transform", ts);
|
|
||||||
var box = selected.getBBox();
|
var box = selected.getBBox();
|
||||||
|
var angle = canvas.getRotationAngle(selected);
|
||||||
|
if (angle != null) {
|
||||||
|
var cx = box.x + box.width/2,
|
||||||
|
cy = box.y + box.height/2;
|
||||||
|
ts += [" rotate(", angle, " ", cx, ",", cy, ")"].join('');
|
||||||
|
}
|
||||||
|
selected.setAttribute("transform", ts);
|
||||||
box.x += dx; box.y += dy;
|
box.x += dx; box.y += dy;
|
||||||
selectorManager.requestSelector(selected).resize(box);
|
selectorManager.requestSelector(selected).resize(box);
|
||||||
selectedBBoxes[i] = box;
|
selectedBBoxes[i] = box;
|
||||||
|
@ -1276,8 +1292,16 @@ function SvgCanvas(c)
|
||||||
selectedBBox.height = -selectedBBox.height;
|
selectedBBox.height = -selectedBBox.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
selected.setAttribute("transform", ("translate(" + (left+tx) + "," + (top+ty) +
|
// find the rotation transform and prepend it
|
||||||
") scale(" + (sx) + "," + (sy) + ") translate(" + (-left) + "," + (-top) + ")"));
|
var ts = ["translate(", (left+tx), ",", (top+ty), ") scale(", sx, ",", sy,
|
||||||
|
") translate(", -left, ",", -top, ")"].join('');
|
||||||
|
var angle = canvas.getRotationAngle(selected);
|
||||||
|
if (angle != null) {
|
||||||
|
var cx = selectedBBox.x + selectedBBox.width/2,
|
||||||
|
cy = selectedBBox.y + selectedBBox.height/2;
|
||||||
|
ts += [" rotate(", angle, " ", cx, ",", cy, ")"].join('')
|
||||||
|
}
|
||||||
|
selected.setAttribute("transform", ts);
|
||||||
selectorManager.requestSelector(selected).resize(selectedBBox);
|
selectorManager.requestSelector(selected).resize(selectedBBox);
|
||||||
break;
|
break;
|
||||||
case "text":
|
case "text":
|
||||||
|
@ -2048,6 +2072,21 @@ function SvgCanvas(c)
|
||||||
this.changeSelectedAttribute("stroke-opacity", val);
|
this.changeSelectedAttribute("stroke-opacity", val);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getRotationAngle = function(elem) {
|
||||||
|
var selected = elem || selectedElements[0];
|
||||||
|
// find the rotation transform (if any) and set it
|
||||||
|
var tlist = selected.transform.baseVal;
|
||||||
|
var t = tlist.numberOfItems;
|
||||||
|
var foundRot = false;
|
||||||
|
while (t--) {
|
||||||
|
var xform = tlist.getItem(t);
|
||||||
|
if (xform.type == 4) {
|
||||||
|
return xform.angle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
this.setRotationAngle = function(val) {
|
this.setRotationAngle = function(val) {
|
||||||
var elem = selectedElements[0];
|
var elem = selectedElements[0];
|
||||||
var bbox = elem.getBBox();
|
var bbox = elem.getBBox();
|
||||||
|
|
Loading…
Reference in New Issue