From eb97d206006e8f849de8861c6fefb5d96f1f7955 Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Sun, 16 Aug 2009 19:18:22 +0000 Subject: [PATCH] Fix Issue 92: Update rotation angle when selecting an element git-svn-id: http://svg-edit.googlecode.com/svn/trunk@392 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 2 +- editor/svgcanvas.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 3f4187ed..6f3ce2c8 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -156,7 +156,7 @@ function svg_edit_setup() { $('#line_panel').hide(); $('#text_panel').hide(); if (elem != null) { - // TODO: get element's rotation value and set the angle spinner + $('#angle').val(svgCanvas.getRotationAngle(elem)); $('#selected_panel').show(); // update contextual tools here switch(elem.tagName) { diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 20799bac..1fbc0f39 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -730,7 +730,7 @@ function SvgCanvas(c) // This fixes Firefox 2- behavior - which does not reset values when the attribute has // been removed, see https://bugzilla.mozilla.org/show_bug.cgi?id=320622 var angle = canvas.getRotationAngle(selected); - if (angle != null) { + if (angle) { var cx = remapx(box.x + box.width/2), cy = remapy(box.y + box.height/2); selected.setAttribute("transform", ["rotate(", angle, " ", cx, ",", cy, ")"].join('')); @@ -1198,7 +1198,7 @@ function SvgCanvas(c) var box = canvas.getBBox(selected); var angle = canvas.getRotationAngle(selected); - if (angle != null) { + if (angle) { var cx = box.x + box.width/2, cy = box.y + box.height/2; ts += [" rotate(", angle, " ", cx, ",", cy, ")"].join(''); @@ -1251,6 +1251,8 @@ function SvgCanvas(c) */ break; case "resize": + // TODO: update this to handle rotated elements + // we track the resize bounding box and translate/scale the selected element // while the mouse is down, when mouse goes up, we use this to recalculate // the shape's coordinates @@ -1292,7 +1294,7 @@ function SvgCanvas(c) var ts = ["translate(", (left+tx), ",", (top+ty), ") scale(", sx, ",", sy, ") translate(", -left, ",", -top, ")"].join(''); var angle = canvas.getRotationAngle(selected); - if (angle != null) { + if (angle) { var cx = selectedBBox.x + selectedBBox.width/2, cy = selectedBBox.y + selectedBBox.height/2; ts += [" rotate(", angle, " ", cx, ",", cy, ")"].join('') @@ -2075,7 +2077,7 @@ function SvgCanvas(c) // determine the bounding box if rotated (NOTE: this won't be // the tightest possible bounding box, for it will do) var angle = this.getRotationAngle(selected) * Math.PI / 180.0; - if (angle != null) { + if (angle) { var w2 = bbox.width/2, h2 = bbox.height/2, cx = bbox.x + w2, cy = bbox.y + h2; var pts = [ [-w2,-h2], [w2,-h2], @@ -2117,7 +2119,7 @@ function SvgCanvas(c) return xform.angle; } } - return null; + return 0; }; this.setRotationAngle = function(val) {