Fix Issue 384: Pick fill/stroke properties for groups

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1322 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Jeff Schiller 2010-02-02 05:48:33 +00:00
parent 0e0f98a1de
commit 2bb41c0c73
1 changed files with 63 additions and 16 deletions

View File

@ -289,7 +289,6 @@ function BatchCommand(text) {
// private members // private members
// ************************************************************************************** // **************************************************************************************
// FIXME: what's the right way to make this 'class' private to the SelectorManager?
function Selector(id, elem) { function Selector(id, elem) {
// this is the selector's unique number // this is the selector's unique number
this.id = id; this.id = id;
@ -2194,8 +2193,8 @@ function BatchCommand(text) {
if (elem == null) break; if (elem == null) break;
selectorManager.releaseSelector(elem); selectorManager.releaseSelector(elem);
selectedElements[i] = null; selectedElements[i] = null;
if (i==0) selectedBBoxes[i] = null;
} }
selectedBBoxes[0] = null;
} }
call("selected", selectedElements); call("selected", selectedElements);
}; };
@ -2240,10 +2239,10 @@ function BatchCommand(text) {
} }
call("selected", selectedElements); call("selected", selectedElements);
if(showGrips) { if (showGrips || selectedElements.length == 1) {
selectorManager.requestSelector(selectedElements[0]).showGrips(true); selectorManager.requestSelector(selectedElements[0]).showGrips(true);
} }
else if (selectedElements.length > 1) { else {
selectorManager.requestSelector(selectedElements[0]).showGrips(false); selectorManager.requestSelector(selectedElements[0]).showGrips(false);
} }
@ -5883,13 +5882,29 @@ function BatchCommand(text) {
return cur_properties.stroke; return cur_properties.stroke;
}; };
// TODO: rewrite setFillColor(), setStrokeColor(), setStrokeWidth(), setStrokeStyle()
// to use a common function?
this.setStrokeColor = function(val,preventUndo) { this.setStrokeColor = function(val,preventUndo) {
cur_shape.stroke = val; cur_shape.stroke = val;
cur_properties.stroke_paint = {type:"solidColor"}; cur_properties.stroke_paint = {type:"solidColor"};
if (!preventUndo) var elems = [];
this.changeSelectedAttribute("stroke", val); var i = selectedElements.length;
else while (i--) {
this.changeSelectedAttributeNoUndo("stroke", val); var elem = selectedElements[i];
if (elem) {
if (elem.tagName == "g")
walkTree(elem, function(e){if(e.nodeName!="g") elems.push(e);});
else
elems.push(elem);
}
}
if (elems.length > 0) {
if (!preventUndo)
this.changeSelectedAttribute("stroke", val, elems);
else
this.changeSelectedAttributeNoUndo("stroke", val, elems);
}
}; };
this.getFillColor = function() { this.getFillColor = function() {
@ -5900,12 +5915,16 @@ function BatchCommand(text) {
cur_properties.fill = val; cur_properties.fill = val;
cur_properties.fill_paint = {type:"solidColor"}; cur_properties.fill_paint = {type:"solidColor"};
// take out any path/line elements when setting fill // take out any path/line elements when setting fill
// add all descendants of groups (but remove groups)
var elems = []; var elems = [];
var i = selectedElements.length; var i = selectedElements.length;
while(i--) { while (i--) {
var elem = selectedElements[i]; var elem = selectedElements[i];
if (elem && elem.tagName != "polyline" && elem.tagName != "line") { if (elem) {
elems.push(elem); if (elem.tagName == "g")
walkTree(elem, function(e){if(e.nodeName!="g") elems.push(e);});
else if (elem.tagName != "polyline" && elem.tagName != "line")
elems.push(elem);
} }
} }
if (elems.length > 0) { if (elems.length > 0) {
@ -6046,7 +6065,19 @@ function BatchCommand(text) {
return; return;
} }
cur_properties.stroke_width = val; cur_properties.stroke_width = val;
this.changeSelectedAttribute("stroke-width", val);
var elems = [];
var i = selectedElements.length;
while (i--) {
var elem = selectedElements[i];
if (elem) {
if (elem.tagName == "g")
walkTree(elem, function(e){if(e.nodeName!="g") elems.push(e);});
}
}
if (elems.length > 0) {
this.changeSelectedAttribute("stroke-width", val, elems);
}
}; };
this.getStrokeStyle = function() { this.getStrokeStyle = function() {
@ -6055,7 +6086,18 @@ function BatchCommand(text) {
this.setStrokeStyle = function(val) { this.setStrokeStyle = function(val) {
cur_shape.stroke_style = val; cur_shape.stroke_style = val;
this.changeSelectedAttribute("stroke-dasharray", val); var elems = [];
var i = selectedElements.length;
while (i--) {
var elem = selectedElements[i];
if (elem) {
if (elem.tagName == "g")
walkTree(elem, function(e){if(e.nodeName!="g") elems.push(e);});
}
}
if (elems.length > 0) {
this.changeSelectedAttribute("stroke-dasharray", val, elems);
}
}; };
this.getOpacity = function() { this.getOpacity = function() {
@ -6418,9 +6460,14 @@ function BatchCommand(text) {
} }
} }
// Timeout needed for Opera & Firefox // Timeout needed for Opera & Firefox
setTimeout(function() { // codedread: it is now possible for this function to be called with elements
selectorManager.requestSelector(elem).resize(); // that are not in the selectedElements array, we need to only request a
},0); // selector if the element is in that array
if ($.inArray(elem, selectedElements) != -1) {
setTimeout(function() {
selectorManager.requestSelector(elem).resize();
},0);
}
// if this element was rotated, and we changed the position of this element // if this element was rotated, and we changed the position of this element
// we need to update the rotational transform attribute // we need to update the rotational transform attribute
var angle = canvas.getRotationAngle(elem); var angle = canvas.getRotationAngle(elem);