make zooming zoom toward the mouse cursor

This commit is contained in:
りき萌 2025-06-26 16:34:01 +02:00
parent 385a691e3e
commit 2a783aba71
2 changed files with 22 additions and 2 deletions

View file

@ -433,12 +433,15 @@ class CanvasRenderer extends HTMLElement {
}
}
async #zoomingBehaviour() {
#zoomingBehaviour() {
this.addEventListener(
"wheel",
(event) => {
// TODO: Touchpad zoom
this.viewport.zoomIn(event.deltaY > 0 ? -1 : 1);
let windowSize = this.getWindowSize();
let ndcX = (event.clientX - this.clientLeft) / windowSize.width - 0.5;
let ndcY = (event.clientY - this.clientTop) / windowSize.height - 0.5;
this.viewport.zoomIntoPoint(event.deltaY > 0 ? -1 : 1, ndcX, ndcY, windowSize);
this.sendViewportUpdate();
this.dispatchEvent(new Event(".viewportUpdateEnd"));
},