diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 928a1d7a..5a949e48 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -24,7 +24,6 @@ function svg_edit_setup() { // if elems[1] is present, then we have more than one element selectedElement = (elems.length == 1 || elems[1] == null ? elems[0] : null); if (selectedElement != null) { - // unless we're already in always set the mode of the editor to select because // upon creation of a text element the editor is switched into // select mode and this event fires - we need our UI to be in sync @@ -39,11 +38,14 @@ function svg_edit_setup() { } // called when any element has changed - var elementChanged = function(window,elem) { - // if the element changed was the svg, then it must be a resolution change - if (elem && elem.tagName == "svg") { - changeResolution(parseInt(elem.getAttribute("width")), - parseInt(elem.getAttribute("height"))); + var elementChanged = function(window,elems) { + for (var i = 0; i < elems.length; ++i) { + var elem = elems[i]; + // if the element changed was the svg, then it must be a resolution change + if (elem && elem.tagName == "svg") { + changeResolution(parseInt(elem.getAttribute("width")), + parseInt(elem.getAttribute("height"))); + } } // we update the contextual panel with potentially new diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 76c9d091..1f214bc6 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -515,28 +515,29 @@ function SvgCanvas(c) }; // end svgToString() var recalculateSelectedDimensions = function() { - var selected = selectedElements[0]; - var selectedBBox = selectedBBoxes[0]; - var box = selected.getBBox(); + for (var i = 0; i < selectedElements.length; ++i) { + var selected = selectedElements[i]; + var selectedBBox = selectedBBoxes[i]; + var box = selected.getBBox(); - // if we have not moved/resized, then immediately leave - if (box.x == selectedBBox.x && box.y == selectedBBox.y && - box.width == selectedBBox.width && box.height == selectedBBox.height) { - return; - } + // if we have not moved/resized, then immediately leave + if (box.x == selectedBBox.x && box.y == selectedBBox.y && + box.width == selectedBBox.width && box.height == selectedBBox.height) { + return; + } - // after this point, we have some change + // after this point, we have some change - var remapx = function(x) {return ((x-box.x)/box.width)*selectedBBox.width + selectedBBox.x;} - var remapy = function(y) {return ((y-box.y)/box.height)*selectedBBox.height + selectedBBox.y;} - var scalew = function(w) {return w*selectedBBox.width/box.width;} - var scaleh = function(h) {return h*selectedBBox.height/box.height;} + var remapx = function(x) {return ((x-box.x)/box.width)*selectedBBox.width + selectedBBox.x;} + var remapy = function(y) {return ((y-box.y)/box.height)*selectedBBox.height + selectedBBox.y;} + var scalew = function(w) {return w*selectedBBox.width/box.width;} + var scaleh = function(h) {return h*selectedBBox.height/box.height;} - var changes = {}; + var changes = {}; - selected.removeAttribute("transform"); - switch (selected.tagName) - { + selected.removeAttribute("transform"); + switch (selected.tagName) + { case "path": // extract the x,y from the path, adjust it and write back the new path // but first, save the old path @@ -610,21 +611,26 @@ function SvgCanvas(c) default: // rect console.log("Unknown shape type: " + selected.tagName); break; + } + // fire changed event + if (changes) { + var text = (current_resize_mode == "none" ? "position" : "size"); + // TODO: store these changes in a batch command + addCommandToHistory(new ChangeElementCommand(selected, changes, text)); + } } - // fire changed event - if (changes) { - var text = (current_resize_mode == "none" ? "position" : "size"); - addCommandToHistory(new ChangeElementCommand(selected, changes, text)); - } - call("changed", selected); + // TODO: add the batch command to history + call("changed", selectedElements); }; var recalculateSelectedOutline = function() { - var selected = selectedElements[0]; - var selectedBBox = selectedBBoxes[0] - var theSelector = selectorManager.requestSelector(selected); - if (selected != null && theSelector != null) { - theSelector.resize(selectedBBox); + for (var i = 0; i < selectedElements.length; ++i) { + var selected = selectedElements[i]; + var selectedBBox = selectedBBoxes[i] + var theSelector = selectorManager.requestSelector(selected); + if (selected != null && theSelector != null) { + theSelector.resize(selectedBBox); + } } }; @@ -725,8 +731,12 @@ function SvgCanvas(c) var t = evt.target; // WebKit returns