mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-05-12 22:47:30 +08:00
Compensate drag for scale
This commit is contained in:
@@ -32,4 +32,8 @@ export default class UEBlueprintDraggableObject extends HTMLElement {
|
|||||||
return this.location
|
return this.location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getScale() {
|
||||||
|
return getComputedStyle(this).getPropertyValue('--ueb-scale')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,8 @@ export default class UDrag extends UMouseClickDrag {
|
|||||||
|
|
||||||
dragTo(e) {
|
dragTo(e) {
|
||||||
let mousePosition = this.snapToGrid(e.clientX, e.clientY)
|
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) {
|
if (d[0] == 0 && d[1] == 0) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default class UMouseWheel {
|
|||||||
if (self.looseTarget) {
|
if (self.looseTarget) {
|
||||||
/*
|
/*
|
||||||
* Compensating for having used the mouse wheel over a descendant of the target (the element listened for the 'wheel' event).
|
* 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 targetOffset = e.target.getBoundingClientRect()
|
||||||
const currentTargetOffset = e.currentTarget.getBoundingClientRect()
|
const currentTargetOffset = e.currentTarget.getBoundingClientRect()
|
||||||
|
|||||||
@@ -123,7 +123,8 @@ class UDrag extends UMouseClickDrag {
|
|||||||
|
|
||||||
dragTo(e) {
|
dragTo(e) {
|
||||||
let mousePosition = this.snapToGrid(e.clientX, e.clientY);
|
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) {
|
if (d[0] == 0 && d[1] == 0) {
|
||||||
return
|
return
|
||||||
@@ -215,7 +216,7 @@ class UMouseWheel {
|
|||||||
if (self.looseTarget) {
|
if (self.looseTarget) {
|
||||||
/*
|
/*
|
||||||
* Compensating for having used the mouse wheel over a descendant of the target (the element listened for the 'wheel' event).
|
* 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 targetOffset = e.target.getBoundingClientRect();
|
||||||
const currentTargetOffset = e.currentTarget.getBoundingClientRect();
|
const currentTargetOffset = e.currentTarget.getBoundingClientRect();
|
||||||
@@ -962,6 +963,10 @@ class UEBlueprintDraggableObject extends HTMLElement {
|
|||||||
return this.location
|
return this.location
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getScale() {
|
||||||
|
return getComputedStyle(this).getPropertyValue('--ueb-scale')
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UEBlueprintObject extends UEBlueprintDraggableObject {
|
class UEBlueprintObject extends UEBlueprintDraggableObject {
|
||||||
|
|||||||
Reference in New Issue
Block a user