refactor(transform): resolve target bounds

This commit is contained in:
syntaxbullet
2026-07-03 16:12:26 +02:00
parent ff5bb43382
commit a3b4a4a1b0
8 changed files with 151 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
import type { ImageDocument } from "@core/document";
import type { EditorState } from "@editor/state";
import { resolveTransformTargetBounds, selectedTransformTarget } from "@editor/transform-targets";
import { clearScreenRect } from "./clear-rect";
import { documentRectToScreenRect } from "./screen-rect";
import type { RgbaColor, ScreenRect, WebGlRendererContext } from "./types";
@@ -8,13 +9,11 @@ const handleColor: RgbaColor = [1, 1, 1, 1];
const handleBorderColor: RgbaColor = [0.1, 0.65, 1, 1];
export function renderTransformControls(context: WebGlRendererContext, document: ImageDocument, editor: EditorState) {
const selectedArtboard = editor.selection.artboardId
? document.artboards.find((artboard) => artboard.id === editor.selection.artboardId)
: undefined;
const target = selectedTransformTarget(document, editor.selection);
const bounds = target ? resolveTransformTargetBounds(document, target) : undefined;
if (!bounds) return;
if (!selectedArtboard) return;
const rect = documentRectToScreenRect(context.canvas, selectedArtboard.bounds, editor.viewport);
const rect = documentRectToScreenRect(context.canvas, bounds, editor.viewport);
for (const handle of transformHandleRects(rect)) {
clearScreenRect(context, handle.border, handleBorderColor);
clearScreenRect(context, handle.fill, handleColor);