refactor(renderer): extract artboard checkerboard drawing

This commit is contained in:
syntaxbullet
2026-07-03 09:56:03 +02:00
parent 3d32e8fbef
commit fb0c424745
7 changed files with 75 additions and 26 deletions

21
renderer/artboard.ts Normal file
View File

@@ -0,0 +1,21 @@
import type { Artboard } from "@core/artboard";
import type { ViewportState } from "@editor/state";
import { renderCheckerboard } from "./checkerboard";
import type { ScreenRect, WebGlRendererContext } from "./types";
export function renderArtboard(context: WebGlRendererContext, artboard: Artboard, viewport: ViewportState) {
const rect = artboardScreenRect(context.canvas, artboard, viewport);
if (artboard.backgroundColor === "transparent") {
renderCheckerboard(context, rect, Math.max(4, Math.round(12 * viewport.zoom)));
}
}
function artboardScreenRect(canvas: HTMLCanvasElement, artboard: Artboard, viewport: ViewportState): ScreenRect {
return {
x: Math.round(canvas.width / 2 + (artboard.bounds.x - viewport.center.x) * viewport.zoom),
y: Math.round(canvas.height / 2 + (artboard.bounds.y - viewport.center.y) * viewport.zoom),
w: Math.max(0, Math.round(artboard.bounds.w * viewport.zoom)),
h: Math.max(0, Math.round(artboard.bounds.h * viewport.zoom)),
};
}