Skip to content

Commit

Permalink
web: adjust the page zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhan005 committed Nov 30, 2024
1 parent c3b5732 commit a6c59c1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ const handleMouseDown = (event: MouseEvent) => {
event.preventDefault()
if (isPainting.value) {
const x = Math.floor(event.offsetX / ratio.value - deltaX.value)
const y = Math.floor(event.offsetY / ratio.value - deltaY.value)
// #1 If the web page is zoomed in, we need to adjust the offset.
const paintingCanvasRatio = paintingCanvas.value!.getBoundingClientRect().width / paintingCanvas.value!.width
const x = Math.floor(event.offsetX / ratio.value / paintingCanvasRatio - deltaX.value)
const y = Math.floor(event.offsetY / ratio.value / paintingCanvasRatio - deltaY.value)
const pixel = {x, y, color: currentColor.value}
if (paintedPixels.value.some(p => p.x === pixel.x && p.y === pixel.y)) {
Expand Down

0 comments on commit a6c59c1

Please sign in to comment.