mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-17 03:14:41 +08:00
Zoom over node scale correction
This commit is contained in:
@@ -246,13 +246,6 @@ export default class UEBlueprint extends HTMLElement {
|
||||
|
||||
|
||||
if (center) {
|
||||
|
||||
let point = document.createElement('div');
|
||||
point.style.width = '2px'
|
||||
point.style.height = '2px'
|
||||
point.style.background = 'red'
|
||||
point.style.position = 'absolute'
|
||||
document.querySelector('.ueb-grid').appendChild(point)
|
||||
let relativeScale = this.getScale() / initialScale
|
||||
let newCenter = [
|
||||
relativeScale * center[0],
|
||||
@@ -262,8 +255,6 @@ export default class UEBlueprint extends HTMLElement {
|
||||
(newCenter[0] - center[0]) * initialScale,
|
||||
(newCenter[1] - center[1]) * initialScale
|
||||
])
|
||||
point.style.left = `${center[0]}px`
|
||||
point.style.top = `${center[1]}px`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,10 @@ export default class UEBlueprintDragScroll extends UEBlueprintDrag {
|
||||
e.preventDefault()
|
||||
let zoomLevel = self.blueprintNode.getZoom()
|
||||
zoomLevel -= Math.sign(e.deltaY)
|
||||
let scale = self.blueprintNode.getScale()
|
||||
let scaleCorrection = 1 / self.blueprintNode.getScale()
|
||||
const targetOffset = e.target.getBoundingClientRect()
|
||||
const currentTargetOffset = e.currentTarget.getBoundingClientRect()
|
||||
let offset = [e.offsetX + targetOffset.x - currentTargetOffset.x, e.offsetY + targetOffset.y - currentTargetOffset.y]
|
||||
console.log([offset[0] - e.x, offset[1] - e.y])
|
||||
let offset = [e.offsetX + targetOffset.x * scaleCorrection - currentTargetOffset.x * scaleCorrection, e.offsetY + targetOffset.y * scaleCorrection - currentTargetOffset.y * scaleCorrection]
|
||||
self.blueprintNode.setZoom(zoomLevel, offset)
|
||||
|
||||
}
|
||||
|
||||
@@ -87,11 +87,10 @@ class UEBlueprintDragScroll extends UEBlueprintDrag {
|
||||
e.preventDefault();
|
||||
let zoomLevel = self.blueprintNode.getZoom();
|
||||
zoomLevel -= Math.sign(e.deltaY);
|
||||
self.blueprintNode.getScale();
|
||||
let scaleCorrection = 1 / self.blueprintNode.getScale();
|
||||
const targetOffset = e.target.getBoundingClientRect();
|
||||
const currentTargetOffset = e.currentTarget.getBoundingClientRect();
|
||||
let offset = [e.offsetX + targetOffset.x - currentTargetOffset.x, e.offsetY + targetOffset.y - currentTargetOffset.y];
|
||||
console.log([offset[0] - e.x, offset[1] - e.y]);
|
||||
let offset = [e.offsetX + targetOffset.x * scaleCorrection - currentTargetOffset.x * scaleCorrection, e.offsetY + targetOffset.y * scaleCorrection - currentTargetOffset.y * scaleCorrection];
|
||||
self.blueprintNode.setZoom(zoomLevel, offset);
|
||||
|
||||
};
|
||||
@@ -352,13 +351,6 @@ class UEBlueprint extends HTMLElement {
|
||||
|
||||
|
||||
if (center) {
|
||||
|
||||
let point = document.createElement('div');
|
||||
point.style.width = '2px';
|
||||
point.style.height = '2px';
|
||||
point.style.background = 'red';
|
||||
point.style.position = 'absolute';
|
||||
document.querySelector('.ueb-grid').appendChild(point);
|
||||
let relativeScale = this.getScale() / initialScale;
|
||||
let newCenter = [
|
||||
relativeScale * center[0],
|
||||
@@ -368,8 +360,6 @@ class UEBlueprint extends HTMLElement {
|
||||
(newCenter[0] - center[0]) * initialScale,
|
||||
(newCenter[1] - center[1]) * initialScale
|
||||
]);
|
||||
point.style.left = `${center[0]}px`;
|
||||
point.style.top = `${center[1]}px`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user