From d9a06e417a10526268d8df2f35ac81705a2c7c17 Mon Sep 17 00:00:00 2001 From: Skyler Lehmkuhl Date: Wed, 18 Dec 2024 17:48:42 -0500 Subject: [PATCH] Fix mouse coordinates inside transformed graphics objects --- src/main.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.js b/src/main.js index a272cba..209710b 100644 --- a/src/main.js +++ b/src/main.js @@ -1979,6 +1979,14 @@ class GraphicsObject { } } } + transformMouse(mouse) { + if (this.parent) { + mouse = this.parent.transformMouse(mouse) + } + mouse.x -= this.x + mouse.y -= this.y + return mouse + } addShape(shape, sendToBack=false) { if (sendToBack) { this.currentFrame.shapes.unshift(shape) @@ -2749,6 +2757,7 @@ function stage() { scroller.appendChild(stageWrapper) stage.addEventListener("mousedown", (e) => { let mouse = getMousePos(stage, e) + mouse = context.activeObject.transformMouse(mouse) switch (mode) { case "rectangle": case "ellipse": @@ -2909,6 +2918,7 @@ function stage() { context.dragDirection = undefined context.selectionRect = undefined let mouse = getMousePos(stage, e) + mouse = context.activeObject.transformMouse(mouse) switch (mode) { case "draw": if (context.activeShape) { @@ -2963,6 +2973,7 @@ function stage() { }) stage.addEventListener("mousemove", (e) => { let mouse = getMousePos(stage, e) + mouse = context.activeObject.transformMouse(mouse) context.mousePos = mouse switch (mode) { case "draw":