diff --git a/src/tools/brush-selection.ts b/src/tools/brush-selection.ts index 71c5ad9..95b2c3e 100644 --- a/src/tools/brush-selection.ts +++ b/src/tools/brush-selection.ts @@ -24,6 +24,7 @@ class BrushSelection { const prev = { x: 0, y: 0 }; let dragId: number | undefined; + let wheelModeBrushSize = false; const update = (e: PointerEvent) => { const x = e.offsetX; @@ -104,12 +105,37 @@ class BrushSelection { } }; + const wheel = (e: WheelEvent) => { + if(wheelModeBrushSize){ + if(e.deltaY > 0) + radius = Math.max(1, radius * 1.05); + else + radius = Math.max(1, radius / 1.05); + circle.setAttribute('r', radius.toString()); + e.preventDefault(); + e.stopPropagation(); + } + }; + + const keydown = (e: KeyboardEvent) => { + if (e.shiftKey) { + wheelModeBrushSize = true; + } + }; + + const keyup = (e: KeyboardEvent) => { + wheelModeBrushSize = false; + }; + this.activate = () => { svg.style.display = 'inline'; parent.style.display = 'block'; parent.addEventListener('pointerdown', pointerdown); parent.addEventListener('pointermove', pointermove); parent.addEventListener('pointerup', pointerup); + parent.addEventListener('wheel', wheel); + document.addEventListener('keydown', keydown); + document.addEventListener('keyup', keyup); }; this.deactivate = () => { @@ -122,6 +148,10 @@ class BrushSelection { parent.removeEventListener('pointerdown', pointerdown); parent.removeEventListener('pointermove', pointermove); parent.removeEventListener('pointerup', pointerup); + parent.removeEventListener('wheel', wheel); + document.removeEventListener('keydown', keydown); + document.removeEventListener('keyup', keyup); + wheelModeBrushSize = false; }; events.on('tool.brushSelection.smaller', () => {