Skip to content

Commit

Permalink
feat: Moving won't stop when the mouse goes out of the canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
NriotHrreion committed Dec 10, 2023
1 parent 45b68d7 commit b11b345
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
5 changes: 0 additions & 5 deletions src/renderer/Render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ export default class Render {
this.stopMoving();
}

public handleMouseLeave(): void {
this.stopMoving();
this.mousePoint = this.center;
}

public handleWheel(dy: number): void {
const delta = 7;
const mouseOriginPoint = this.mousePoint.toCoordinates();
Expand Down
8 changes: 2 additions & 6 deletions src/views/graphing/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const Graphing: React.FC = memo(() => {
if(!workerRef.current) return;
workerRef.current.postMessage({ type: "mouse-down", rect: canvas.getBoundingClientRect(), cx: e.clientX, cy: e.clientY });
});
canvas.addEventListener("mousemove", (e: MouseEvent) => {
window.addEventListener("mousemove", (e: MouseEvent) => {
if(!workerRef.current) return;

var direction: MovingDirection;
Expand All @@ -98,14 +98,10 @@ const Graphing: React.FC = memo(() => {

workerRef.current.postMessage({ type: "mouse-move", rect: canvas.getBoundingClientRect(), cx: e.clientX, cy: e.clientY, direction });
});
canvas.addEventListener("mouseup", () => {
window.addEventListener("mouseup", () => {
if(!workerRef.current) return;
workerRef.current.postMessage({ type: "mouse-up" });
});
canvas.addEventListener("mouseleave", () => {
if(!workerRef.current) return;
workerRef.current.postMessage({ type: "mouse-leave" });
});
canvas.addEventListener("wheel", (e: WheelEvent) => {
if(!workerRef.current) return;
workerRef.current.postMessage({ type: "wheel", dy: e.deltaY });
Expand Down
3 changes: 0 additions & 3 deletions src/workers/graphing.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ ctx.addEventListener("message", (e) => {
case "mouse-up":
renderer.handleMouseUp();
break;
case "mouse-leave":
renderer.handleMouseLeave();
break;
case "wheel":
renderer.handleWheel(req.dy);
break;
Expand Down

1 comment on commit b11b345

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.