Skip to content

Commit

Permalink
fix: coordinate calculate after zoom (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
devlzl authored Feb 2, 2024
1 parent 77f8914 commit 30ce5ac
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Kernel/Zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export class Zoom {

updateEvent = new EventManager<number>()

get value() {
return this._zoom
}

get changeByHandle() {
return this._changeByHandle
}
Expand Down
8 changes: 4 additions & 4 deletions src/UserInterface/Slide/SlideContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const handleMouseUp = () => {
selectionManager.clear()
blocks.forEach((block) => {
const { x, y, width, height } = block
const blockLeft = x + slideRectX
const blockTop = y + slideRectY
const blockRight = blockLeft + width
const blockBottom = blockTop + height
const blockLeft = x * zoom.value + slideRectX
const blockTop = y * zoom.value + slideRectY
const blockRight = blockLeft + width * zoom.value
const blockBottom = blockTop + height * zoom.value
if (
dragAreaX <= blockLeft &&
dragAreaX + dragAreaWidth >= blockRight &&
Expand Down
4 changes: 3 additions & 1 deletion src/Utils/toSlideCoords.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { zoom } from '@Kernel/index'

export const toSlideCoords = (slideElement: HTMLElement, clientX: number, clientY: number) => {
const { x, y } = slideElement.getBoundingClientRect()
return { x: clientX - x, y: clientY - y }
return { x: (clientX - x) / zoom.value, y: (clientY - y) / zoom.value }
}

0 comments on commit 30ce5ac

Please sign in to comment.