From fdf347af2670127911b630c1f388d50a97723794 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sat, 15 Jun 2024 23:04:21 +1000 Subject: [PATCH] refactor(ui): add scaled bbox state --- .../controlLayers/store/canvasV2Slice.ts | 5 ++++ .../src/features/controlLayers/store/types.ts | 28 ++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/invokeai/frontend/web/src/features/controlLayers/store/canvasV2Slice.ts b/invokeai/frontend/web/src/features/controlLayers/store/canvasV2Slice.ts index 3cf24a0fa5..1142a8cab7 100644 --- a/invokeai/frontend/web/src/features/controlLayers/store/canvasV2Slice.ts +++ b/invokeai/frontend/web/src/features/controlLayers/store/canvasV2Slice.ts @@ -44,6 +44,11 @@ const initialState: CanvasV2State = { width: 512, height: 512, }, + scaledBbox: { + width: 512, + height: 512, + scaleMethod: 'auto', + }, controlAdapters: [], ipAdapters: [], regions: [], diff --git a/invokeai/frontend/web/src/features/controlLayers/store/types.ts b/invokeai/frontend/web/src/features/controlLayers/store/types.ts index a38b6500ec..86ded89ed4 100644 --- a/invokeai/frontend/web/src/features/controlLayers/store/types.ts +++ b/invokeai/frontend/web/src/features/controlLayers/store/types.ts @@ -1,10 +1,7 @@ import { deepClone } from 'common/util/deepClone'; import { zModelIdentifierField } from 'features/nodes/types/common'; import type { AspectRatioState } from 'features/parameters/components/ImageSize/types'; -import type { - ParameterHeight, - ParameterWidth, -} from 'features/parameters/types/parameterSchemas'; +import type { ParameterHeight, ParameterWidth } from 'features/parameters/types/parameterSchemas'; import { zAutoNegative, zParameterNegativePrompt, @@ -748,9 +745,19 @@ export const imageDTOToImageWithDims = ({ image_name, width, height }: ImageDTO) height, }); +const zBoundingBoxScaleMethod = z.enum(['none', 'auto', 'manual']); +export type BoundingBoxScaleMethod = z.infer; +export const isBoundingBoxScaleMethod = (v: unknown): v is BoundingBoxScaleMethod => + zBoundingBoxScaleMethod.safeParse(v).success; + export type CanvasEntity = LayerData | IPAdapterData | ControlAdapterData | RegionalGuidanceData | InpaintMaskData; export type CanvasEntityIdentifier = Pick; +export type Dimensions = { + width: number; + height: number; +}; + export type CanvasV2State = { _version: 3; selectedEntityIdentifier: CanvasEntityIdentifier | null; @@ -758,12 +765,8 @@ export type CanvasV2State = { selected: Tool; selectedBuffer: Tool | null; invertScroll: boolean; - brush: { - width: number; - }; - eraser: { - width: number; - }; + brush: { width: number }; + eraser: { width: number }; fill: RgbaColor; }; document: { @@ -772,6 +775,11 @@ export type CanvasV2State = { aspectRatio: AspectRatioState; }; bbox: IRect; + scaledBbox: { + scaleMethod: BoundingBoxScaleMethod; + width: ParameterWidth; + height: ParameterHeight; + }; layers: LayerData[]; controlAdapters: ControlAdapterData[]; ipAdapters: IPAdapterData[];