From 12f5fd9bcefc74819ca8e636aad2a9e37fd2718f Mon Sep 17 00:00:00 2001 From: Bruno Heridet Date: Tue, 19 Feb 2013 13:17:27 +0000 Subject: [PATCH] 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 --- editor/svg-editor.js | 24 ++++++++---------------- editor/svgcanvas.js | 13 +++++++++++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 89c72ae6..f7b08917 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -1910,12 +1910,11 @@ inp.focus().remove(); }); - $('.palette_item').mousedown(function(evt){ - var right_click = evt.button === 2; - var isStroke = evt.shiftKey || right_click; - var picker = isStroke ? 'stroke' : 'fill'; - var color = $(this).attr('data-rgb'); - var paint = null; + $('.palette_item').mousedown(function(evt) { + // shift key or right click for stroke + var picker = evt.shiftKey || evt.button === 2 ? 'stroke' : 'fill'; + var color = $(this).data('rgb'); + var paint; // Webkit-based browsers returned 'initial' here for no stroke if (color === 'none' || color === 'transparent' || color === 'initial') { @@ -1926,17 +1925,10 @@ } paintBox[picker].setPaint(paint); + svgCanvas.setColor(picker, color); - if (isStroke) { - svgCanvas.setColor('stroke', color); - 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); - } + if (color !== 'none' && svgCanvas.getPaintOpacity(picker) !== 1) { + svgCanvas.setPaintOpacity(picker, 1.0); } updateToolButtonState(); }).bind('contextmenu', function(e) {e.preventDefault();}); diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 2f2f3922..f61687e3 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -6860,6 +6860,15 @@ this.setPaintOpacity = function(type, val, preventUndo) { 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 // 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 this.getBlur = function(elem) { var val = 0; -// var elem = selectedElements[0]; - +// var elem = selectedElements[0]; + if (elem) { var filter_url = elem.getAttribute('filter'); if (filter_url) {