diff --git a/src/editor/components/sePalette.js b/src/editor/components/sePalette.js index 16ae9a1a..b5c2d73b 100644 --- a/src/editor/components/sePalette.js +++ b/src/editor/components/sePalette.js @@ -56,10 +56,17 @@ export class SEPalette extends HTMLElement { * @returns {void} */ connectedCallback () { - this.$strip.addEventListener('click', (e) => { - e.preventDefault(); - console.log(e); - this.dispatchEvent(this.$event); + this.$strip.addEventListener('click', (evt) => { + evt.preventDefault(); + // shift key or right click for stroke + const picker = evt.shiftKey || evt.button === 2 ? 'stroke' : 'fill'; + let color = this.$strip.currentItem.dataset.rgb; + // Webkit-based browsers returned 'initial' here for no stroke + if (color === 'none' || color === 'transparent' || color === 'initial') { + color = 'none'; + } + const paletteEvent = new CustomEvent('change', {detail: {picker, color}, bubbles: false}); + this.dispatchEvent(paletteEvent); }); } } diff --git a/src/editor/svgedit.css b/src/editor/svgedit.css index ddc65037..d69e84c5 100644 --- a/src/editor/svgedit.css +++ b/src/editor/svgedit.css @@ -685,11 +685,13 @@ input[type=text] { #tools_bottom { position: fixed; bottom: 0; - width: 100%; - height: 40px; + left: 40px; + right: 20px; display: flex; flex-flow: row nowrap; overflow-x: auto; + align-items: center; + justify-content: space-between; } .dropdown li.tool_button { diff --git a/src/editor/svgedit.js b/src/editor/svgedit.js index 744c6b06..7c3cfa17 100644 --- a/src/editor/svgedit.js +++ b/src/editor/svgedit.js @@ -3778,6 +3778,20 @@ editor.init = () => { updateWireFrame(); }; + const handlePalette = (e) => { + e.preventDefault(); + // shift key or right click for stroke + const {picker, color} = e.detail; + // Webkit-based browsers returned 'initial' here for no stroke + const paint = color === 'none' ? new $.jGraduate.Paint() : new $.jGraduate.Paint({alpha: 100, solidColor: color.substr(1)}); + paintBox[picker].setPaint(paint); + svgCanvas.setColor(picker, color); + if (color !== 'none' && svgCanvas.getPaintOpacity(picker) !== 1) { + svgCanvas.setPaintOpacity(picker, 1.0); + } + updateToolButtonState(); + }; + $('#svg_docprops_container, #svg_prefs_container').draggable({ cancel: 'button,fieldset', containment: 'window' @@ -4152,8 +4166,8 @@ editor.init = () => { const cur = curConfig[type === 'fill' ? 'initFill' : 'initStroke']; // set up gradients to be used for the buttons const svgdocbox = new DOMParser().parseFromString( - ` - + `, @@ -4681,6 +4695,7 @@ editor.init = () => { $id('tool_bold').addEventListener('click', clickBold); $id('tool_italic').addEventListener('click', clickItalic); + $id('palette').addEventListener('change', handlePalette); const toolButtons = [ {sel: '#tool_clear', fn: clickClear, evt: 'mouseup', key: ['N', true]},