added getPaintOpacity() on svgCanvas, used it to simplify mouseDown callback on palette in svgEditor

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2430 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Bruno Heridet 2013-02-19 13:17:27 +00:00
parent bccb227cdd
commit 12f5fd9bce
2 changed files with 19 additions and 18 deletions

View File

@ -1910,12 +1910,11 @@
inp.focus().remove(); inp.focus().remove();
}); });
$('.palette_item').mousedown(function(evt){ $('.palette_item').mousedown(function(evt) {
var right_click = evt.button === 2; // shift key or right click for stroke
var isStroke = evt.shiftKey || right_click; var picker = evt.shiftKey || evt.button === 2 ? 'stroke' : 'fill';
var picker = isStroke ? 'stroke' : 'fill'; var color = $(this).data('rgb');
var color = $(this).attr('data-rgb'); var paint;
var paint = null;
// Webkit-based browsers returned 'initial' here for no stroke // Webkit-based browsers returned 'initial' here for no stroke
if (color === 'none' || color === 'transparent' || color === 'initial') { if (color === 'none' || color === 'transparent' || color === 'initial') {
@ -1926,17 +1925,10 @@
} }
paintBox[picker].setPaint(paint); paintBox[picker].setPaint(paint);
svgCanvas.setColor(picker, color);
if (isStroke) { if (color !== 'none' && svgCanvas.getPaintOpacity(picker) !== 1) {
svgCanvas.setColor('stroke', color); svgCanvas.setPaintOpacity(picker, 1.0);
if (color != 'none' && svgCanvas.getStrokeOpacity() != 1) {
svgCanvas.setPaintOpacity('stroke', 1.0);
}
} else {
svgCanvas.setColor('fill', color);
if (color != 'none' && svgCanvas.getFillOpacity() != 1) {
svgCanvas.setPaintOpacity('fill', 1.0);
}
} }
updateToolButtonState(); updateToolButtonState();
}).bind('contextmenu', function(e) {e.preventDefault();}); }).bind('contextmenu', function(e) {e.preventDefault();});

View File

@ -6860,6 +6860,15 @@ this.setPaintOpacity = function(type, val, preventUndo) {
changeSelectedAttributeNoUndo(type + "-opacity", val); changeSelectedAttributeNoUndo(type + "-opacity", val);
}; };
// Function: getPaintOpacity
// Gets the current fill/stroke opacity
//
// Parameters:
// type - String with "fill" or "stroke"
this.getPaintOpacity = function(type) {
return type === 'fill' ? this.getFillOpacity() : this.getStrokeOpacity();
};
// Function: getBlur // Function: getBlur
// Gets the stdDeviation blur value of the given element // Gets the stdDeviation blur value of the given element
// //
@ -6867,8 +6876,8 @@ this.setPaintOpacity = function(type, val, preventUndo) {
// elem - The element to check the blur value for // elem - The element to check the blur value for
this.getBlur = function(elem) { this.getBlur = function(elem) {
var val = 0; var val = 0;
// var elem = selectedElements[0]; // var elem = selectedElements[0];
if (elem) { if (elem) {
var filter_url = elem.getAttribute('filter'); var filter_url = elem.getAttribute('filter');
if (filter_url) { if (filter_url) {