Zoom over node scale correction

This commit is contained in:
barsdeveloper
2021-09-08 20:40:50 +02:00
parent 3f176ea4a4
commit b434868fa8
3 changed files with 4 additions and 24 deletions

View File

@@ -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`
}
}

View File

@@ -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)
}

View File

@@ -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`;
}
}