fix palette

master
JFH 2020-11-29 01:19:09 +01:00
parent a7766d0764
commit 8ab5d331c8
3 changed files with 32 additions and 8 deletions

View File

@ -56,10 +56,17 @@ export class SEPalette extends HTMLElement {
* @returns {void} * @returns {void}
*/ */
connectedCallback () { connectedCallback () {
this.$strip.addEventListener('click', (e) => { this.$strip.addEventListener('click', (evt) => {
e.preventDefault(); evt.preventDefault();
console.log(e); // shift key or right click for stroke
this.dispatchEvent(this.$event); 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);
}); });
} }
} }

View File

@ -685,11 +685,13 @@ input[type=text] {
#tools_bottom { #tools_bottom {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
width: 100%; left: 40px;
height: 40px; right: 20px;
display: flex; display: flex;
flex-flow: row nowrap; flex-flow: row nowrap;
overflow-x: auto; overflow-x: auto;
align-items: center;
justify-content: space-between;
} }
.dropdown li.tool_button { .dropdown li.tool_button {

View File

@ -3778,6 +3778,20 @@ editor.init = () => {
updateWireFrame(); 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({ $('#svg_docprops_container, #svg_prefs_container').draggable({
cancel: 'button,fieldset', cancel: 'button,fieldset',
containment: 'window' containment: 'window'
@ -4152,8 +4166,8 @@ editor.init = () => {
const cur = curConfig[type === 'fill' ? 'initFill' : 'initStroke']; const cur = curConfig[type === 'fill' ? 'initFill' : 'initStroke'];
// set up gradients to be used for the buttons // set up gradients to be used for the buttons
const svgdocbox = new DOMParser().parseFromString( const svgdocbox = new DOMParser().parseFromString(
`<svg xmlns="http://www.w3.org/2000/svg"> `<svg xmlns="http://www.w3.org/2000/svg" width="16.5" height="16.5">
<rect width="16.5" height="16.5" <rect
fill="#${cur.color}" opacity="${cur.opacity}"/> fill="#${cur.color}" opacity="${cur.opacity}"/>
<defs><linearGradient id="gradbox_${PaintBox.ctr++}"/></defs> <defs><linearGradient id="gradbox_${PaintBox.ctr++}"/></defs>
</svg>`, </svg>`,
@ -4681,6 +4695,7 @@ editor.init = () => {
$id('tool_bold').addEventListener('click', clickBold); $id('tool_bold').addEventListener('click', clickBold);
$id('tool_italic').addEventListener('click', clickItalic); $id('tool_italic').addEventListener('click', clickItalic);
$id('palette').addEventListener('change', handlePalette);
const toolButtons = [ const toolButtons = [
{sel: '#tool_clear', fn: clickClear, evt: 'mouseup', key: ['N', true]}, {sel: '#tool_clear', fn: clickClear, evt: 'mouseup', key: ['N', true]},