Skip to content

Commit

Permalink
Allow to change the brush-size with the mouse-wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbethke committed Nov 7, 2024
1 parent 9407aa5 commit 723a0e4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/tools/brush-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = () => {
Expand All @@ -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', () => {
Expand Down

0 comments on commit 723a0e4

Please sign in to comment.