22 lines
1000 B
TypeScript
22 lines
1000 B
TypeScript
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)),
|
|
};
|
|
}
|