Skip to content

Commit

Permalink
Refactor of handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed Jul 2, 2024
1 parent 0d39861 commit 9e7c391
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/lib/drawer/2d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,15 @@ export class Drawer2d implements DrawerInterface {
event.preventDefault();
});

this.domElement.addEventListener('mousedown', (event: MouseEvent) => {
const mouseDownHandler = (event: MouseEvent) => {
mouseDownVector = createVector([event.offsetX, event.offsetY]);
document.body.style.cursor = 'grabbing';
});

document.body.addEventListener('mouseup', (event: MouseEvent) => {
mouseDownVector = null;
document.body.style.cursor = 'auto';
});

document.body.addEventListener('mouseleave', (event: MouseEvent) => {
};
const mouseUpHandler = (event: MouseEvent) => {
mouseDownVector = null;
document.body.style.cursor = 'auto';
});

this.domElement.addEventListener('mousemove', (event: MouseEvent) => {
};
const mouseMoveHandler = (event: MouseEvent) => {
if (mouseDownVector === null) {
return;
}
Expand All @@ -235,7 +228,12 @@ export class Drawer2d implements DrawerInterface {
this.viewConfig.offset[0] += diff[0];
this.viewConfig.offset[1] += diff[1];
mouseDownVector = coords;
});
};

this.domElement.addEventListener('mousedown', mouseDownHandler);
document.body.addEventListener('mouseup', mouseUpHandler);
document.body.addEventListener('mouseleave', mouseUpHandler);
this.domElement.addEventListener('mousemove', mouseMoveHandler);
}

get width(): number {
Expand Down

0 comments on commit 9e7c391

Please sign in to comment.