* Stop using getTransform Fixes #861 The original motivation behind this is to make it work with Firefox. But it also helped make the code more intentional. Test Plan: - Create one square, select it, zoom in repeatedly, make sure that it zooms centered in the screen and everything looks good - Scroll at various zoom levels, things look good - Export a small scene at 1x and 3x, make sure the background is properly set and look good * fix selection element
24 lines
662 B
TypeScript
24 lines
662 B
TypeScript
export function getZoomOrigin(canvas: HTMLCanvasElement | null) {
|
|
if (canvas === null) {
|
|
return { x: 0, y: 0 };
|
|
}
|
|
const context = canvas.getContext("2d");
|
|
if (context === null) {
|
|
return { x: 0, y: 0 };
|
|
}
|
|
|
|
const normalizedCanvasWidth = canvas.width / context.getTransform().a;
|
|
const normalizedCanvasHeight = canvas.height / context.getTransform().d;
|
|
|
|
return {
|
|
x: normalizedCanvasWidth / 2,
|
|
y: normalizedCanvasHeight / 2,
|
|
};
|
|
}
|
|
|
|
export function getNormalizedZoom(zoom: number): number {
|
|
const normalizedZoom = parseFloat(zoom.toFixed(2));
|
|
const clampedZoom = Math.max(0.1, Math.min(normalizedZoom, 2));
|
|
return clampedZoom;
|
|
}
|