From 1842e45888a897ff07d05b44b5eb6db0b4c6c15e Mon Sep 17 00:00:00 2001 From: barsdeveloper Date: Mon, 4 Oct 2021 00:48:38 +0200 Subject: [PATCH] Compensate drag for scale --- js/UEBlueprintDraggableObject.js | 4 ++++ js/input/UDrag.js | 3 ++- js/input/UMouseWheel.js | 2 +- ueblueprint.js | 9 +++++++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/js/UEBlueprintDraggableObject.js b/js/UEBlueprintDraggableObject.js index 0ce3b48..36d1773 100644 --- a/js/UEBlueprintDraggableObject.js +++ b/js/UEBlueprintDraggableObject.js @@ -32,4 +32,8 @@ export default class UEBlueprintDraggableObject extends HTMLElement { return this.location } + getScale() { + return getComputedStyle(this).getPropertyValue('--ueb-scale') + } + } \ No newline at end of file diff --git a/js/input/UDrag.js b/js/input/UDrag.js index 4de87f4..567f485 100644 --- a/js/input/UDrag.js +++ b/js/input/UDrag.js @@ -24,7 +24,8 @@ export default class UDrag extends UMouseClickDrag { dragTo(e) { let mousePosition = this.snapToGrid(e.clientX, e.clientY) - const d = [mousePosition[0] - this.mousePosition[0], mousePosition[1] - this.mousePosition[1]] + let scaleCorrection = 1 / this.target.getScale() + const d = [(mousePosition[0] - this.mousePosition[0]) * scaleCorrection, (mousePosition[1] - this.mousePosition[1]) * scaleCorrection] if (d[0] == 0 && d[1] == 0) { return diff --git a/js/input/UMouseWheel.js b/js/input/UMouseWheel.js index be664b3..7acd2a1 100644 --- a/js/input/UMouseWheel.js +++ b/js/input/UMouseWheel.js @@ -23,7 +23,7 @@ export default class UMouseWheel { if (self.looseTarget) { /* * Compensating for having used the mouse wheel over a descendant of the target (the element listened for the 'wheel' event). - * We are interested to get the location relative to the listened target, not the exact target that caused the event. + * We are interested to get the location relative to the listened target, not the descendant target that caused the event. */ const targetOffset = e.target.getBoundingClientRect() const currentTargetOffset = e.currentTarget.getBoundingClientRect() diff --git a/ueblueprint.js b/ueblueprint.js index d2073b3..f2511f2 100644 --- a/ueblueprint.js +++ b/ueblueprint.js @@ -123,7 +123,8 @@ class UDrag extends UMouseClickDrag { dragTo(e) { let mousePosition = this.snapToGrid(e.clientX, e.clientY); - const d = [mousePosition[0] - this.mousePosition[0], mousePosition[1] - this.mousePosition[1]]; + let scaleCorrection = 1 / this.target.getScale(); + const d = [(mousePosition[0] - this.mousePosition[0]) * scaleCorrection, (mousePosition[1] - this.mousePosition[1]) * scaleCorrection]; if (d[0] == 0 && d[1] == 0) { return @@ -215,7 +216,7 @@ class UMouseWheel { if (self.looseTarget) { /* * Compensating for having used the mouse wheel over a descendant of the target (the element listened for the 'wheel' event). - * We are interested to get the location relative to the listened target, not the exact target that caused the event. + * We are interested to get the location relative to the listened target, not the descendant target that caused the event. */ const targetOffset = e.target.getBoundingClientRect(); const currentTargetOffset = e.currentTarget.getBoundingClientRect(); @@ -962,6 +963,10 @@ class UEBlueprintDraggableObject extends HTMLElement { return this.location } + getScale() { + return getComputedStyle(this).getPropertyValue('--ueb-scale') + } + } class UEBlueprintObject extends UEBlueprintDraggableObject {