Can now single-select by dragging the rubber-band box around. Still no multiselect

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@236 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2009-06-30 14:29:28 +00:00
parent 1207de3e61
commit 097649b330
2 changed files with 34 additions and 12 deletions

View File

@ -27,7 +27,9 @@ function svg_edit_setup() {
// always set the mode of the editor to select because // always set the mode of the editor to select because
// upon creation of a text element the editor is switched into // 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 // select mode and this event fires - we need our UI to be in sync
if (svgCanvas.getMode() != "multiselect") {
setSelectMode(); setSelectMode();
}
updateToolbar(); updateToolbar();
} // if (elem != null) } // if (elem != null)

View File

@ -255,6 +255,12 @@ function SvgCanvas(c)
initGroup(); initGroup();
} }
// if we've already acquired one for this element, return it
if (this.selectorMap[elem] ) {
this.selectorMap[elem].locked = true;
return this.selectorMap[elem];
}
for (var i = 0; i < N; ++i) { for (var i = 0; i < N; ++i) {
if (this.selectors[i] && !this.selectors[i].locked) { if (this.selectors[i] && !this.selectors[i].locked) {
this.selectors[i].locked = true; this.selectors[i].locked = true;
@ -569,6 +575,7 @@ function SvgCanvas(c)
var recalculateSelectedOutline = function() { var recalculateSelectedOutline = function() {
var selected = selectedElements[0]; var selected = selectedElements[0];
var theSelector = selectorManager.requestSelector(selected);
if (selected != null && theSelector != null) { if (selected != null && theSelector != null) {
theSelector.resize(selectedBBox); theSelector.resize(selectedBBox);
} }
@ -577,14 +584,24 @@ function SvgCanvas(c)
// public events // public events
// call this function to set a single selected element // call this function to set a single selected element
// call this function with null to clear the selected element // call this function with null to clear the selected element
var selectElement = function(newSelected) var selectElement = function(newSelected, multi)
{ {
var selected = selectedElements[0]; if (newSelected == selectorManager.getRubberBandBox()) {
if (selected == newSelected) return; return;
}
// remove selected outline from previously selected element var multi = multi || false;
if (theSelector != null) { for (var i = 0; i < selectedElements.length; ++i) {
selectorManager.releaseSelector(theSelector); if (selectedElements[i] == newSelected) {
return;
}
}
// this element is not in the selectedElements array
// if we're not in multi-mode, then clear the previous selector
var selected = selectedElements[0];
if (!multi && selected) {
selectorManager.releaseSelector(selected);
} }
selectedElements[0] = newSelected; selectedElements[0] = newSelected;
@ -594,7 +611,7 @@ function SvgCanvas(c)
selectedBBox = selected.getBBox(); selectedBBox = selected.getBBox();
// the manager gives us a selector // the manager gives us a selector
theSelector = selectorManager.requestSelector(selected); var theSelector = selectorManager.requestSelector(selected);
// recalculate size and then re-append to bottom of document // recalculate size and then re-append to bottom of document
recalculateSelectedOutline(); recalculateSelectedOutline();
@ -801,7 +818,7 @@ function SvgCanvas(c)
// we temporarily use a translate on the element being dragged // we temporarily use a translate on the element being dragged
// this transform is removed upon mouseUp and the element is relocated to the // this transform is removed upon mouseUp and the element is relocated to the
// new location // new location
if (selected != null && theSelector != null) { if (selected != null) {
var dx = x - start_x; var dx = x - start_x;
var dy = y - start_y; var dy = y - start_y;
selectedBBox = selected.getBBox(); selectedBBox = selected.getBBox();
@ -822,6 +839,10 @@ function SvgCanvas(c)
// evt.target is the element that the mouse pointer is passing over // evt.target is the element that the mouse pointer is passing over
// TODO: add new targets to the selectedElements array, create a // TODO: add new targets to the selectedElements array, create a
// selector for it, etc // selector for it, etc
var nodeName = evt.target.nodeName;
if (nodeName != "div" && nodeName != "svg") {
selectElement(evt.target);
}
break; break;
case "resize": case "resize":
// we track the resize bounding box and translate/scale the selected element // we track the resize bounding box and translate/scale the selected element
@ -881,7 +902,6 @@ function SvgCanvas(c)
shape.setAttributeNS(null, "x", start_x < x ? start_x : start_x - size); shape.setAttributeNS(null, "x", start_x < x ? start_x : start_x - size);
shape.setAttributeNS(null, "y", start_y < y ? start_y : start_y - size); shape.setAttributeNS(null, "y", start_y < y ? start_y : start_y - size);
break; break;
// case "select":
case "rect": case "rect":
shape.setAttributeNS(null, "x", Math.min(start_x,x)); shape.setAttributeNS(null, "x", Math.min(start_x,x));
shape.setAttributeNS(null, "y", Math.min(start_y,y)); shape.setAttributeNS(null, "y", Math.min(start_y,y));