feat(renderer): draw selection overlay

This commit is contained in:
syntaxbullet
2026-07-03 16:04:43 +02:00
parent 28fcbdceda
commit 4d77288450
4 changed files with 43 additions and 11 deletions

View File

@@ -1,21 +1,13 @@
import type { Artboard } from "@core/artboard";
import type { ViewportState } from "@editor/state";
import { renderCheckerboard } from "./checkerboard";
import type { ScreenRect, WebGlRendererContext } from "./types";
import { documentRectToScreenRect } from "./screen-rect";
import type { WebGlRendererContext } from "./types";
export function renderArtboard(context: WebGlRendererContext, artboard: Artboard, viewport: ViewportState) {
const rect = artboardScreenRect(context.canvas, artboard, viewport);
const rect = documentRectToScreenRect(context.canvas, artboard.bounds, 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)),
};
}