mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
Compensate drag for scale
This commit is contained in:
@@ -32,4 +32,8 @@ export default class UEBlueprintDraggableObject extends HTMLElement {
|
||||
return this.location
|
||||
}
|
||||
|
||||
getScale() {
|
||||
return getComputedStyle(this).getPropertyValue('--ueb-scale')
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user