refactor(renderer): extract artboard checkerboard drawing
This commit is contained in:
21
renderer/artboard.ts
Normal file
21
renderer/artboard.ts
Normal 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)),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user