This commit is contained in:
kolaflash
2026-01-24 17:53:31 +01:00
parent f9a2409dad
commit 175ea1b726
5 changed files with 16 additions and 8 deletions
+3 -3
View File
@@ -54,11 +54,11 @@ function adjustPointerPosition(
clientX: number,
clientY: number,
): void {
const { ctx, translation: position, initialScale } = viewport;
const { ctx, translation: position, scale } = viewport;
const clientRect = ctx.canvas.getBoundingClientRect();
pointer.position.x = (clientX - clientRect.x + position.x) / initialScale;
pointer.position.y = (clientY - clientRect.y + position.y) / initialScale;
pointer.position.x = (clientX - clientRect.x + position.x) / scale;
pointer.position.y = (clientY - clientRect.y + position.y) / scale;
}
export function listenPointer(): () => void {
+4 -4
View File
@@ -1,7 +1,7 @@
import { createVector, type Vector } from "#/lib/Vector.ts";
export type Viewport = {
initialScale: number;
scale: number;
imageSmoothing: CanvasImageSmoothing;
translation: Vector;
ctx: CanvasRenderingContext2D;
@@ -11,7 +11,7 @@ export type Viewport = {
};
export const viewport: Viewport = {
initialScale: 4,
scale: 4,
imageSmoothing: {
imageSmoothingEnabled: false,
imageSmoothingQuality: "low",
@@ -45,13 +45,13 @@ export function initViewport(): void {
}
export function setScale(scale: number): void {
viewport.initialScale = scale;
viewport.scale = scale;
self.dispatchEvent(new Event("resize"));
}
export function resizeCanvas(width: number, height: number): void {
const {
initialScale,
scale: initialScale,
imageSmoothing,
ctx,
canvas,