refactor(transform): resolve target bounds
This commit is contained in:
@@ -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";
|
||||
@@ -7,13 +8,11 @@ import type { RgbaColor, ScreenRect, WebGlRendererContext } from "./types";
|
||||
const selectionColor: RgbaColor = [0.1, 0.65, 1, 1];
|
||||
|
||||
export function renderSelectionOverlay(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);
|
||||
renderScreenRectStroke(context, rect, 3, selectionColor);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user