WIP
This commit is contained in:
+3
-3
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user