Adds staging area

This commit is contained in:
psychedelicious 2022-11-13 22:43:45 +11:00 committed by blessedcoolant
parent 73099af6ec
commit 179656d541
26 changed files with 631 additions and 240 deletions

View File

@ -35,6 +35,7 @@
"react-icons": "^4.4.0", "react-icons": "^4.4.0",
"react-image-pan-zoom-rotate": "^1.6.0", "react-image-pan-zoom-rotate": "^1.6.0",
"react-konva": "^18.2.3", "react-konva": "^18.2.3",
"react-konva-utils": "^0.3.0",
"react-redux": "^8.0.2", "react-redux": "^8.0.2",
"react-transition-group": "^4.4.5", "react-transition-group": "^4.4.5",
"redux-deep-persist": "^1.0.6", "redux-deep-persist": "^1.0.6",

View File

@ -38,7 +38,7 @@ import {
requestSystemConfig, requestSystemConfig,
} from './actions'; } from './actions';
import { import {
addImageToOutpaintingSesion, addImageToOutpainting,
setImageToInpaint, setImageToInpaint,
} from 'features/canvas/canvasSlice'; } from 'features/canvas/canvasSlice';
import { tabMap } from 'features/tabs/InvokeTabs'; import { tabMap } from 'features/tabs/InvokeTabs';
@ -119,7 +119,7 @@ const makeSocketIOListeners = (
if (data.generationMode === 'outpainting' && data.boundingBox) { if (data.generationMode === 'outpainting' && data.boundingBox) {
const { boundingBox } = data; const { boundingBox } = data;
dispatch( dispatch(
addImageToOutpaintingSesion({ addImageToOutpainting({
image: newImage, image: newImage,
boundingBox, boundingBox,
}) })

View File

@ -94,6 +94,18 @@ export const store = configureStore({
immutableCheck: false, immutableCheck: false,
serializableCheck: false, serializableCheck: false,
}).concat(socketioMiddleware()), }).concat(socketioMiddleware()),
devTools: {
actionsDenylist: [
// 'canvas/setCursorPosition',
// 'canvas/setStageCoordinates',
// 'canvas/setStageScale',
// 'canvas/setIsDrawing',
// 'canvas/setBoundingBoxCoordinates',
// 'canvas/setBoundingBoxDimensions',
// 'canvas/setIsDrawing',
// 'canvas/addPointToCurrentLine',
],
},
}); });
export type AppGetState = typeof store.getState; export type AppGetState = typeof store.getState;

View File

@ -111,7 +111,7 @@ export const frontendToBackendParameters = (
canvasImageLayerRef.current canvasImageLayerRef.current
) { ) {
const { const {
objects, layerState: { objects },
boundingBoxCoordinates, boundingBoxCoordinates,
boundingBoxDimensions, boundingBoxDimensions,
inpaintReplace, inpaintReplace,

View File

@ -9,6 +9,7 @@ import { useAppSelector } from 'app/store';
import { import {
baseCanvasImageSelector, baseCanvasImageSelector,
currentCanvasSelector, currentCanvasSelector,
isStagingSelector,
outpaintingCanvasSelector, outpaintingCanvasSelector,
} from 'features/canvas/canvasSlice'; } from 'features/canvas/canvasSlice';
@ -33,17 +34,16 @@ import IAICanvasObjectRenderer from './IAICanvasObjectRenderer';
import IAICanvasGrid from './IAICanvasGrid'; import IAICanvasGrid from './IAICanvasGrid';
import IAICanvasIntermediateImage from './IAICanvasIntermediateImage'; import IAICanvasIntermediateImage from './IAICanvasIntermediateImage';
import IAICanvasStatusText from './IAICanvasStatusText'; import IAICanvasStatusText from './IAICanvasStatusText';
import { Box, Button } from '@chakra-ui/react'; import IAICanvasStagingArea from './IAICanvasStagingArea';
import { rgbaColorToRgbString, rgbaColorToString } from './util/colorToString';
const canvasSelector = createSelector( const canvasSelector = createSelector(
[ [
currentCanvasSelector, currentCanvasSelector,
outpaintingCanvasSelector, outpaintingCanvasSelector,
baseCanvasImageSelector, isStagingSelector,
activeTabNameSelector, activeTabNameSelector,
], ],
(currentCanvas, outpaintingCanvas, baseCanvasImage, activeTabName) => { (currentCanvas, outpaintingCanvas, isStaging, activeTabName) => {
const { const {
isMaskEnabled, isMaskEnabled,
stageScale, stageScale,
@ -54,29 +54,23 @@ const canvasSelector = createSelector(
stageDimensions, stageDimensions,
stageCoordinates, stageCoordinates,
tool, tool,
layer,
boundingBoxCoordinates,
boundingBoxDimensions,
isMovingStage, isMovingStage,
maskColor,
} = currentCanvas; } = currentCanvas;
const { shouldShowGrid } = outpaintingCanvas; const { shouldShowGrid } = outpaintingCanvas;
let stageCursor: string | undefined = ''; let stageCursor: string | undefined = '';
if (tool === 'move') { if (tool === 'move' || isStaging) {
if (isTransformingBoundingBox) {
stageCursor = undefined;
} else if (isMouseOverBoundingBox) {
stageCursor = 'move';
} else if (activeTabName === 'outpainting') {
if (isMovingStage) { if (isMovingStage) {
stageCursor = 'grabbing'; stageCursor = 'grabbing';
} else { } else {
stageCursor = 'grab'; stageCursor = 'grab';
} }
} } else if (isTransformingBoundingBox) {
stageCursor = undefined;
} else if (isMouseOverBoundingBox) {
stageCursor = 'move';
} else { } else {
stageCursor = 'none'; stageCursor = 'none';
} }
@ -91,11 +85,8 @@ const canvasSelector = createSelector(
stageDimensions, stageDimensions,
stageScale, stageScale,
tool, tool,
layer, isOnOutpaintingTab: activeTabName === 'outpainting',
boundingBoxCoordinates, isStaging,
boundingBoxDimensions,
maskColorString: rgbaColorToString({ ...maskColor, a: 0.5 }),
outpaintingOnly: activeTabName === 'outpainting',
}; };
}, },
{ {
@ -120,11 +111,8 @@ const IAICanvas = () => {
stageDimensions, stageDimensions,
stageScale, stageScale,
tool, tool,
layer, isOnOutpaintingTab,
outpaintingOnly, isStaging,
boundingBoxCoordinates,
boundingBoxDimensions,
maskColorString,
} = useAppSelector(canvasSelector); } = useAppSelector(canvasSelector);
useCanvasHotkeys(); useCanvasHotkeys();
@ -151,25 +139,15 @@ const IAICanvas = () => {
const { handleDragStart, handleDragMove, handleDragEnd } = const { handleDragStart, handleDragMove, handleDragEnd } =
useCanvasDragMove(); useCanvasDragMove();
const panelTop = boundingBoxCoordinates.y + boundingBoxDimensions.height;
const panelLeft = boundingBoxCoordinates.x + boundingBoxDimensions.width;
return ( return (
<div className="inpainting-canvas-container"> <div className="inpainting-canvas-container">
<div className="inpainting-canvas-wrapper"> <div className="inpainting-canvas-wrapper">
<Stage <Stage
tabIndex={-1} tabIndex={-1}
ref={stageRef} ref={stageRef}
className={'inpainting-canvas-stage'}
style={{ style={{
outline: 'none',
...(stageCursor ? { cursor: stageCursor } : {}), ...(stageCursor ? { cursor: stageCursor } : {}),
border: `1px solid var(--border-color-light)`,
borderRadius: '0.5rem',
boxShadow: `inset 0 0 20px ${layer === 'mask' ? '1px' : '1px'} ${
layer === 'mask'
? 'var(--accent-color)'
: 'var(--border-color-light)'
}`,
}} }}
x={stageCoordinates.x} x={stageCoordinates.x}
y={stageCoordinates.y} y={stageCoordinates.y}
@ -186,9 +164,11 @@ const IAICanvas = () => {
onDragMove={handleDragMove} onDragMove={handleDragMove}
onDragEnd={handleDragEnd} onDragEnd={handleDragEnd}
onWheel={handleWheel} onWheel={handleWheel}
listening={tool === 'move' && !isModifyingBoundingBox} listening={(tool === 'move' || isStaging) && !isModifyingBoundingBox}
draggable={ draggable={
tool === 'move' && !isModifyingBoundingBox && outpaintingOnly (tool === 'move' || isStaging) &&
!isModifyingBoundingBox &&
isOnOutpaintingTab
} }
> >
<Layer id={'grid'} visible={shouldShowGrid}> <Layer id={'grid'} visible={shouldShowGrid}>
@ -209,14 +189,21 @@ const IAICanvas = () => {
<IAICanvasMaskCompositer listening={false} /> <IAICanvasMaskCompositer listening={false} />
</Layer> </Layer>
<Layer id={'tool'}> <Layer id={'tool'}>
{!isStaging && (
<>
<IAICanvasBoundingBox visible={shouldShowBoundingBox} /> <IAICanvasBoundingBox visible={shouldShowBoundingBox} />
<IAICanvasBrushPreview <IAICanvasBrushPreview
visible={tool !== 'move'} visible={tool !== 'move'}
listening={false} listening={false}
/> />
</>
)}
</Layer>
<Layer imageSmoothingEnabled={false}>
{isStaging && <IAICanvasStagingArea />}
</Layer> </Layer>
</Stage> </Stage>
{outpaintingOnly && <IAICanvasStatusText />} {isOnOutpaintingTab && <IAICanvasStatusText />}
</div> </div>
</div> </div>
); );

View File

@ -1,13 +1,12 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { import {
currentCanvasSelector, currentCanvasSelector,
outpaintingCanvasSelector, isStagingSelector,
setBrushColor, setBrushColor,
setBrushSize, setBrushSize,
setTool, setTool,
} from './canvasSlice'; } from './canvasSlice';
import { useAppDispatch, useAppSelector } from 'app/store'; import { useAppDispatch, useAppSelector } from 'app/store';
import { activeTabNameSelector } from 'features/options/optionsSelectors';
import _ from 'lodash'; import _ from 'lodash';
import IAIIconButton from 'common/components/IAIIconButton'; import IAIIconButton from 'common/components/IAIIconButton';
import { FaPaintBrush } from 'react-icons/fa'; import { FaPaintBrush } from 'react-icons/fa';
@ -17,35 +16,15 @@ import IAISlider from 'common/components/IAISlider';
import { Flex } from '@chakra-ui/react'; import { Flex } from '@chakra-ui/react';
export const selector = createSelector( export const selector = createSelector(
[currentCanvasSelector, outpaintingCanvasSelector, activeTabNameSelector], [currentCanvasSelector, isStagingSelector],
(currentCanvas, outpaintingCanvas, activeTabName) => { (currentCanvas, isStaging) => {
const { const { brushColor, brushSize, tool } = currentCanvas;
layer,
maskColor,
brushColor,
brushSize,
eraserSize,
tool,
shouldDarkenOutsideBoundingBox,
shouldShowIntermediates,
} = currentCanvas;
const { shouldShowGrid, shouldSnapToGrid, shouldAutoSave } =
outpaintingCanvas;
return { return {
layer,
tool, tool,
maskColor,
brushColor, brushColor,
brushSize, brushSize,
eraserSize, isStaging,
activeTabName,
shouldShowGrid,
shouldSnapToGrid,
shouldAutoSave,
shouldDarkenOutsideBoundingBox,
shouldShowIntermediates,
}; };
}, },
{ {
@ -57,7 +36,7 @@ export const selector = createSelector(
const IAICanvasBrushButtonPopover = () => { const IAICanvasBrushButtonPopover = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool, brushColor, brushSize } = useAppSelector(selector); const { tool, brushColor, brushSize, isStaging } = useAppSelector(selector);
return ( return (
<IAIPopover <IAIPopover
@ -67,8 +46,9 @@ const IAICanvasBrushButtonPopover = () => {
aria-label="Brush (B)" aria-label="Brush (B)"
tooltip="Brush (B)" tooltip="Brush (B)"
icon={<FaPaintBrush />} icon={<FaPaintBrush />}
data-selected={tool === 'brush'} data-selected={tool === 'brush' && !isStaging}
onClick={() => dispatch(setTool('brush'))} onClick={() => dispatch(setTool('brush'))}
isDisabled={isStaging}
/> />
} }
> >

View File

@ -18,9 +18,10 @@ import { useToast } from '@chakra-ui/react';
const canvasMaskClearSelector = createSelector( const canvasMaskClearSelector = createSelector(
[currentCanvasSelector, activeTabNameSelector], [currentCanvasSelector, activeTabNameSelector],
(currentCanvas, activeTabName) => { (currentCanvas, activeTabName) => {
const { isMaskEnabled, objects } = currentCanvas as const {
| InpaintingCanvasState isMaskEnabled,
| OutpaintingCanvasState; layerState: { objects },
} = currentCanvas as InpaintingCanvasState | OutpaintingCanvasState;
return { return {
isMaskEnabled, isMaskEnabled,

View File

@ -11,10 +11,10 @@ import _ from 'lodash';
const canvasRedoSelector = createSelector( const canvasRedoSelector = createSelector(
[currentCanvasSelector, activeTabNameSelector], [currentCanvasSelector, activeTabNameSelector],
(currentCanvas, activeTabName) => { (currentCanvas, activeTabName) => {
const { futureObjects } = currentCanvas; const { futureLayerStates } = currentCanvas;
return { return {
canRedo: futureObjects.length > 0, canRedo: futureLayerStates.length > 0,
activeTabName, activeTabName,
}; };
}, },
@ -34,7 +34,7 @@ export default function IAICanvasRedoButton() {
}; };
useHotkeys( useHotkeys(
['meta+shift+z', 'control+shift+z', 'control+y', 'meta+y'], ['meta+shift+z', 'ctrl+shift+z', 'control+y', 'meta+y'],
() => { () => {
handleRedo(); handleRedo();
}, },

View File

@ -11,10 +11,10 @@ import { activeTabNameSelector } from 'features/options/optionsSelectors';
const canvasUndoSelector = createSelector( const canvasUndoSelector = createSelector(
[currentCanvasSelector, activeTabNameSelector], [currentCanvasSelector, activeTabNameSelector],
(canvas, activeTabName) => { (canvas, activeTabName) => {
const { pastObjects } = canvas; const { pastLayerStates } = canvas;
return { return {
canUndo: pastObjects.length > 0, canUndo: pastLayerStates.length > 0,
activeTabName, activeTabName,
}; };
}, },
@ -35,7 +35,7 @@ export default function IAICanvasUndoButton() {
}; };
useHotkeys( useHotkeys(
['meta+z', 'control+z'], ['meta+z', 'ctrl+z'],
() => { () => {
handleUndo(); handleUndo();
}, },

View File

@ -1,5 +1,10 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { currentCanvasSelector, setEraserSize, setTool } from './canvasSlice'; import {
currentCanvasSelector,
isStagingSelector,
setEraserSize,
setTool,
} from './canvasSlice';
import { useAppDispatch, useAppSelector } from 'app/store'; import { useAppDispatch, useAppSelector } from 'app/store';
import _ from 'lodash'; import _ from 'lodash';
import IAIIconButton from 'common/components/IAIIconButton'; import IAIIconButton from 'common/components/IAIIconButton';
@ -10,13 +15,14 @@ import { Flex } from '@chakra-ui/react';
import { useHotkeys } from 'react-hotkeys-hook'; import { useHotkeys } from 'react-hotkeys-hook';
export const selector = createSelector( export const selector = createSelector(
[currentCanvasSelector], [currentCanvasSelector, isStagingSelector],
(currentCanvas) => { (currentCanvas, isStaging) => {
const { eraserSize, tool } = currentCanvas; const { eraserSize, tool } = currentCanvas;
return { return {
tool, tool,
eraserSize, eraserSize,
isStaging,
}; };
}, },
{ {
@ -27,7 +33,7 @@ export const selector = createSelector(
); );
const IAICanvasEraserButtonPopover = () => { const IAICanvasEraserButtonPopover = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool, eraserSize } = useAppSelector(selector); const { tool, eraserSize, isStaging } = useAppSelector(selector);
const handleSelectEraserTool = () => dispatch(setTool('eraser')); const handleSelectEraserTool = () => dispatch(setTool('eraser'));
@ -51,7 +57,8 @@ const IAICanvasEraserButtonPopover = () => {
aria-label="Eraser (E)" aria-label="Eraser (E)"
tooltip="Eraser (E)" tooltip="Eraser (E)"
icon={<FaEraser />} icon={<FaEraser />}
data-selected={tool === 'eraser'} data-selected={tool === 'eraser' && !isStaging}
isDisabled={isStaging}
onClick={() => dispatch(setTool('eraser'))} onClick={() => dispatch(setTool('eraser'))}
/> />
} }

View File

@ -148,7 +148,17 @@ const IAICanvasMaskCompositer = (props: IAICanvasMaskCompositerProps) => {
return () => clearInterval(timer); return () => clearInterval(timer);
}, []); }, []);
if (!fillPatternImage) return null; if (
!(
fillPatternImage &&
stageCoordinates.x &&
stageCoordinates.y &&
stageScale &&
stageDimensions.width &&
stageDimensions.height
)
)
return null;
return ( return (
<Rect <Rect

View File

@ -13,13 +13,8 @@ import _ from 'lodash';
export const canvasLinesSelector = createSelector( export const canvasLinesSelector = createSelector(
currentCanvasSelector, currentCanvasSelector,
(currentCanvas: GenericCanvasState) => { (currentCanvas) => {
const { objects } = currentCanvas as return currentCanvas.layerState.objects;
| InpaintingCanvasState
| OutpaintingCanvasState;
return {
objects,
};
}, },
{ {
memoizeOptions: { memoizeOptions: {
@ -37,7 +32,7 @@ type InpaintingCanvasLinesProps = GroupConfig;
*/ */
const IAICanvasLines = (props: InpaintingCanvasLinesProps) => { const IAICanvasLines = (props: InpaintingCanvasLinesProps) => {
const { ...rest } = props; const { ...rest } = props;
const { objects } = useAppSelector(canvasLinesSelector); const objects = useAppSelector(canvasLinesSelector);
return ( return (
<Group listening={false} {...rest}> <Group listening={false} {...rest}>

View File

@ -1,4 +1,4 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector, current } from '@reduxjs/toolkit';
import { useAppSelector } from 'app/store'; import { useAppSelector } from 'app/store';
import _ from 'lodash'; import _ from 'lodash';
import { Group, Line } from 'react-konva'; import { Group, Line } from 'react-konva';
@ -13,7 +13,10 @@ import { rgbaColorToString } from './util/colorToString';
const selector = createSelector( const selector = createSelector(
[currentCanvasSelector], [currentCanvasSelector],
(currentCanvas) => { (currentCanvas) => {
return currentCanvas.objects; const { objects } = currentCanvas.layerState;
return {
objects,
};
}, },
{ {
memoizeOptions: { memoizeOptions: {
@ -23,7 +26,7 @@ const selector = createSelector(
); );
const IAICanvasObjectRenderer = () => { const IAICanvasObjectRenderer = () => {
const objects = useAppSelector(selector); const { objects } = useAppSelector(selector);
if (!objects) return null; if (!objects) return null;

View File

@ -2,6 +2,7 @@ import { ButtonGroup } from '@chakra-ui/react';
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { import {
currentCanvasSelector, currentCanvasSelector,
isStagingSelector,
resetCanvas, resetCanvas,
setTool, setTool,
uploadOutpaintingMergedImage, uploadOutpaintingMergedImage,
@ -27,12 +28,13 @@ import IAICanvasBrushButtonPopover from './IAICanvasBrushButtonPopover';
import IAICanvasMaskButtonPopover from './IAICanvasMaskButtonPopover'; import IAICanvasMaskButtonPopover from './IAICanvasMaskButtonPopover';
export const canvasControlsSelector = createSelector( export const canvasControlsSelector = createSelector(
[currentCanvasSelector], [currentCanvasSelector, isStagingSelector],
(currentCanvas) => { (currentCanvas, isStaging) => {
const { tool } = currentCanvas; const { tool } = currentCanvas;
return { return {
tool, tool,
isStaging,
}; };
}, },
{ {
@ -44,7 +46,7 @@ export const canvasControlsSelector = createSelector(
const IAICanvasOutpaintingControls = () => { const IAICanvasOutpaintingControls = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool } = useAppSelector(canvasControlsSelector); const { tool, isStaging } = useAppSelector(canvasControlsSelector);
return ( return (
<div className="inpainting-settings"> <div className="inpainting-settings">
@ -56,7 +58,7 @@ const IAICanvasOutpaintingControls = () => {
aria-label="Move (M)" aria-label="Move (M)"
tooltip="Move (M)" tooltip="Move (M)"
icon={<FaArrowsAlt />} icon={<FaArrowsAlt />}
data-selected={tool === 'move'} data-selected={tool === 'move' || isStaging}
onClick={() => dispatch(setTool('move'))} onClick={() => dispatch(setTool('move'))}
/> />
</ButtonGroup> </ButtonGroup>

View File

@ -0,0 +1,164 @@
import { background, ButtonGroup, ChakraProvider } from '@chakra-ui/react';
import { CacheProvider } from '@emotion/react';
import { createSelector } from '@reduxjs/toolkit';
import { useAppDispatch, useAppSelector } from 'app/store';
import IAIButton from 'common/components/IAIButton';
import IAIIconButton from 'common/components/IAIIconButton';
import { GroupConfig } from 'konva/lib/Group';
import _ from 'lodash';
import { emotionCache } from 'main';
import { useState } from 'react';
import {
FaArrowLeft,
FaArrowRight,
FaCheck,
FaEye,
FaEyeSlash,
FaTrash,
} from 'react-icons/fa';
import { Group, Rect } from 'react-konva';
import { Html } from 'react-konva-utils';
import {
commitStagingAreaImage,
currentCanvasSelector,
discardStagedImages,
nextStagingAreaImage,
prevStagingAreaImage,
} from './canvasSlice';
import IAICanvasImage from './IAICanvasImage';
const selector = createSelector(
[currentCanvasSelector],
(currentCanvas) => {
const {
layerState: {
stagingArea: { images, selectedImageIndex },
},
} = currentCanvas;
return {
currentStagingAreaImage:
images.length > 0 ? images[selectedImageIndex] : undefined,
isOnFirstImage: selectedImageIndex === 0,
isOnLastImage: selectedImageIndex === images.length - 1,
};
},
{
memoizeOptions: {
resultEqualityCheck: _.isEqual,
},
}
);
type Props = GroupConfig;
const IAICanvasStagingArea = (props: Props) => {
const { ...rest } = props;
const dispatch = useAppDispatch();
const { isOnFirstImage, isOnLastImage, currentStagingAreaImage } =
useAppSelector(selector);
const [shouldShowStagedImage, setShouldShowStagedImage] =
useState<boolean>(true);
if (!currentStagingAreaImage) return null;
const {
x,
y,
image: { width, height, url },
} = currentStagingAreaImage;
return (
<Group {...rest}>
<Group>
{shouldShowStagedImage && <IAICanvasImage url={url} x={x} y={y} />}
<Rect
x={x}
y={y}
width={width}
height={height}
strokeWidth={1}
stroke={'black'}
strokeScaleEnabled={false}
/>
<Rect
x={x}
y={y}
width={width}
height={height}
dash={[4, 4]}
strokeWidth={1}
stroke={'white'}
strokeScaleEnabled={false}
/>
</Group>
<Html>
<CacheProvider value={emotionCache}>
<ChakraProvider>
<div
style={{
position: 'absolute',
top: y + height,
left: x + width / 2 - 216 / 2,
padding: '0.5rem',
filter: 'drop-shadow(0 0.5rem 1rem rgba(0,0,0))',
}}
>
<ButtonGroup isAttached>
<IAIIconButton
tooltip="Previous"
tooltipProps={{ placement: 'bottom' }}
aria-label="Previous"
icon={<FaArrowLeft />}
onClick={() => dispatch(prevStagingAreaImage())}
data-selected={true}
isDisabled={isOnFirstImage}
/>
<IAIIconButton
tooltip="Next"
tooltipProps={{ placement: 'bottom' }}
aria-label="Next"
icon={<FaArrowRight />}
onClick={() => dispatch(nextStagingAreaImage())}
data-selected={true}
isDisabled={isOnLastImage}
/>
<IAIIconButton
tooltip="Accept"
tooltipProps={{ placement: 'bottom' }}
aria-label="Accept"
icon={<FaCheck />}
onClick={() => dispatch(commitStagingAreaImage())}
data-selected={true}
/>
<IAIIconButton
tooltip="Show/Hide"
tooltipProps={{ placement: 'bottom' }}
aria-label="Show/Hide"
data-alert={!shouldShowStagedImage}
icon={shouldShowStagedImage ? <FaEye /> : <FaEyeSlash />}
onClick={() =>
setShouldShowStagedImage(!shouldShowStagedImage)
}
data-selected={true}
/>
<IAIIconButton
tooltip="Discard All"
tooltipProps={{ placement: 'bottom' }}
aria-label="Discard All"
icon={<FaTrash />}
onClick={() => dispatch(discardStagedImages())}
data-selected={true}
/>
</ButtonGroup>
</div>
</ChakraProvider>
</CacheProvider>
</Html>
</Group>
);
};
export default IAICanvasStagingArea;

View File

@ -47,6 +47,9 @@ export interface GenericCanvasState {
intermediateImage?: InvokeAI.Image; intermediateImage?: InvokeAI.Image;
shouldShowIntermediates: boolean; shouldShowIntermediates: boolean;
maxHistory: number; maxHistory: number;
layerState: CanvasLayerState;
pastLayerStates: CanvasLayerState[];
futureLayerStates: CanvasLayerState[];
} }
export type CanvasLayer = 'base' | 'mask'; export type CanvasLayer = 'base' | 'mask';
@ -84,7 +87,19 @@ export type CanvasLine = CanvasAnyLine & {
color?: RgbaColor; color?: RgbaColor;
}; };
type CanvasObject = CanvasImage | CanvasLine | CanvasMaskLine; export type CanvasObject = CanvasImage | CanvasLine | CanvasMaskLine;
export type CanvasLayerState = {
objects: CanvasObject[];
stagingArea: {
x: number;
y: number;
width: number;
height: number;
images: CanvasImage[];
selectedImageIndex: number;
};
};
// type guards // type guards
export const isCanvasMaskLine = (obj: CanvasObject): obj is CanvasMaskLine => export const isCanvasMaskLine = (obj: CanvasObject): obj is CanvasMaskLine =>
@ -102,24 +117,13 @@ export const isCanvasAnyLine = (
export type OutpaintingCanvasState = GenericCanvasState & { export type OutpaintingCanvasState = GenericCanvasState & {
layer: CanvasLayer; layer: CanvasLayer;
objects: CanvasObject[];
pastObjects: CanvasObject[][];
futureObjects: CanvasObject[][];
shouldShowGrid: boolean; shouldShowGrid: boolean;
shouldSnapToGrid: boolean; shouldSnapToGrid: boolean;
shouldAutoSave: boolean; shouldAutoSave: boolean;
stagingArea: {
images: CanvasImage[];
selectedImageIndex: number;
};
}; };
export type InpaintingCanvasState = GenericCanvasState & { export type InpaintingCanvasState = GenericCanvasState & {
layer: 'mask'; layer: 'mask';
objects: CanvasObject[];
pastObjects: CanvasObject[][];
futureObjects: CanvasObject[][];
imageToInpaint?: InvokeAI.Image;
}; };
export type BaseCanvasState = InpaintingCanvasState | OutpaintingCanvasState; export type BaseCanvasState = InpaintingCanvasState | OutpaintingCanvasState;
@ -133,6 +137,18 @@ export interface CanvasState {
outpainting: OutpaintingCanvasState; outpainting: OutpaintingCanvasState;
} }
const initialLayerState: CanvasLayerState = {
objects: [],
stagingArea: {
x: -1,
y: -1,
width: -1,
height: -1,
images: [],
selectedImageIndex: -1,
},
};
const initialGenericCanvasState: GenericCanvasState = { const initialGenericCanvasState: GenericCanvasState = {
tool: 'brush', tool: 'brush',
brushColor: { r: 90, g: 90, b: 255, a: 1 }, brushColor: { r: 90, g: 90, b: 255, a: 1 },
@ -164,7 +180,10 @@ const initialGenericCanvasState: GenericCanvasState = {
isMoveStageKeyHeld: false, isMoveStageKeyHeld: false,
shouldShowIntermediates: true, shouldShowIntermediates: true,
isMovingStage: false, isMovingStage: false,
maxHistory: 256, maxHistory: 128,
layerState: initialLayerState,
futureLayerStates: [],
pastLayerStates: [],
}; };
const initialCanvasState: CanvasState = { const initialCanvasState: CanvasState = {
@ -172,20 +191,10 @@ const initialCanvasState: CanvasState = {
doesCanvasNeedScaling: false, doesCanvasNeedScaling: false,
inpainting: { inpainting: {
layer: 'mask', layer: 'mask',
objects: [],
pastObjects: [],
futureObjects: [],
...initialGenericCanvasState, ...initialGenericCanvasState,
}, },
outpainting: { outpainting: {
layer: 'base', layer: 'base',
objects: [],
pastObjects: [],
futureObjects: [],
stagingArea: {
images: [],
selectedImageIndex: 0,
},
shouldShowGrid: true, shouldShowGrid: true,
shouldSnapToGrid: true, shouldSnapToGrid: true,
shouldAutoSave: false, shouldAutoSave: false,
@ -230,14 +239,13 @@ export const canvasSlice = createSlice({
state[state.currentCanvas].eraserSize = action.payload; state[state.currentCanvas].eraserSize = action.payload;
}, },
clearMask: (state) => { clearMask: (state) => {
state[state.currentCanvas].pastObjects.push( const currentCanvas = state[state.currentCanvas];
state[state.currentCanvas].objects currentCanvas.pastLayerStates.push(currentCanvas.layerState);
); currentCanvas.layerState.objects = state[
state[state.currentCanvas].objects = state[
state.currentCanvas state.currentCanvas
].objects.filter((obj) => !isCanvasMaskLine(obj)); ].layerState.objects.filter((obj) => !isCanvasMaskLine(obj));
state[state.currentCanvas].futureObjects = []; currentCanvas.futureLayerStates = [];
state[state.currentCanvas].shouldPreserveMaskedArea = false; currentCanvas.shouldPreserveMaskedArea = false;
}, },
toggleShouldInvertMask: (state) => { toggleShouldInvertMask: (state) => {
state[state.currentCanvas].shouldPreserveMaskedArea = state[state.currentCanvas].shouldPreserveMaskedArea =
@ -271,9 +279,9 @@ export const canvasSlice = createSlice({
state[state.currentCanvas].cursorPosition = action.payload; state[state.currentCanvas].cursorPosition = action.payload;
}, },
clearImageToInpaint: (state) => { clearImageToInpaint: (state) => {
state.inpainting.imageToInpaint = undefined; // TODO
// state.inpainting.imageToInpaint = undefined;
}, },
setImageToOutpaint: (state, action: PayloadAction<InvokeAI.Image>) => { setImageToOutpaint: (state, action: PayloadAction<InvokeAI.Image>) => {
const { width: canvasWidth, height: canvasHeight } = const { width: canvasWidth, height: canvasHeight } =
state.outpainting.stageDimensions; state.outpainting.stageDimensions;
@ -307,8 +315,10 @@ export const canvasSlice = createSlice({
state.outpainting.boundingBoxDimensions = newDimensions; state.outpainting.boundingBoxDimensions = newDimensions;
state.outpainting.boundingBoxCoordinates = newCoordinates; state.outpainting.boundingBoxCoordinates = newCoordinates;
// state.outpainting.imageToInpaint = action.payload; state.outpainting.pastLayerStates.push(state.outpainting.layerState);
state.outpainting.objects = [ state.outpainting.layerState = {
...initialLayerState,
objects: [
{ {
kind: 'image', kind: 'image',
layer: 'base', layer: 'base',
@ -316,7 +326,9 @@ export const canvasSlice = createSlice({
y: 0, y: 0,
image: action.payload, image: action.payload,
}, },
]; ],
};
state.outpainting.futureLayerStates = [];
state.doesCanvasNeedScaling = true; state.doesCanvasNeedScaling = true;
}, },
setImageToInpaint: (state, action: PayloadAction<InvokeAI.Image>) => { setImageToInpaint: (state, action: PayloadAction<InvokeAI.Image>) => {
@ -352,8 +364,11 @@ export const canvasSlice = createSlice({
state.inpainting.boundingBoxDimensions = newDimensions; state.inpainting.boundingBoxDimensions = newDimensions;
state.inpainting.boundingBoxCoordinates = newCoordinates; state.inpainting.boundingBoxCoordinates = newCoordinates;
// state.inpainting.imageToInpaint = action.payload; state.inpainting.pastLayerStates.push(state.inpainting.layerState);
state.inpainting.objects = [
state.inpainting.layerState = {
...initialLayerState,
objects: [
{ {
kind: 'image', kind: 'image',
layer: 'base', layer: 'base',
@ -361,7 +376,10 @@ export const canvasSlice = createSlice({
y: 0, y: 0,
image: action.payload, image: action.payload,
}, },
]; ],
};
state.outpainting.futureLayerStates = [];
state.doesCanvasNeedScaling = true; state.doesCanvasNeedScaling = true;
}, },
setStageDimensions: (state, action: PayloadAction<Dimensions>) => { setStageDimensions: (state, action: PayloadAction<Dimensions>) => {
@ -487,8 +505,8 @@ export const canvasSlice = createSlice({
state[state.currentCanvas].isDrawing = action.payload; state[state.currentCanvas].isDrawing = action.payload;
}, },
setClearBrushHistory: (state) => { setClearBrushHistory: (state) => {
state[state.currentCanvas].pastObjects = []; state[state.currentCanvas].pastLayerStates = [];
state[state.currentCanvas].futureObjects = []; state[state.currentCanvas].futureLayerStates = [];
}, },
setShouldUseInpaintReplace: (state, action: PayloadAction<boolean>) => { setShouldUseInpaintReplace: (state, action: PayloadAction<boolean>) => {
state[state.currentCanvas].shouldUseInpaintReplace = action.payload; state[state.currentCanvas].shouldUseInpaintReplace = action.payload;
@ -524,7 +542,7 @@ export const canvasSlice = createSlice({
setCurrentCanvas: (state, action: PayloadAction<ValidCanvasName>) => { setCurrentCanvas: (state, action: PayloadAction<ValidCanvasName>) => {
state.currentCanvas = action.payload; state.currentCanvas = action.payload;
}, },
addImageToOutpaintingSesion: ( addImageToOutpainting: (
state, state,
action: PayloadAction<{ action: PayloadAction<{
boundingBox: IRect; boundingBox: IRect;
@ -536,23 +554,151 @@ export const canvasSlice = createSlice({
if (!boundingBox || !image) return; if (!boundingBox || !image) return;
const { x, y } = boundingBox; const { x, y } = boundingBox;
const { width, height } = image;
const currentCanvas = state.outpainting; const currentCanvas = state.outpainting;
currentCanvas.pastObjects.push([...currentCanvas.objects]); // const {
// x: stagingX,
// y: stagingY,
// width: stagingWidth,
// height: stagingHeight,
// images: stagedImages,
// } = currentCanvas.layerState.stagingArea;
if (currentCanvas.pastObjects.length > currentCanvas.maxHistory) { currentCanvas.pastLayerStates.push(_.cloneDeep(currentCanvas.layerState));
currentCanvas.pastObjects.shift();
if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
currentCanvas.pastLayerStates.shift();
} }
currentCanvas.futureObjects = []; currentCanvas.layerState.stagingArea.images.push({
currentCanvas.objects.push({
kind: 'image', kind: 'image',
layer: 'base', layer: 'base',
x, x,
y, y,
image, image,
}); });
currentCanvas.layerState.stagingArea.selectedImageIndex =
currentCanvas.layerState.stagingArea.images.length - 1;
currentCanvas.futureLayerStates = [];
// // If the new image is in the staging area region, push it to staging area
// if (
// x === stagingX &&
// y === stagingY &&
// width === stagingWidth &&
// height === stagingHeight
// ) {
// console.log('pushing new image to staging area images');
// currentCanvas.pastLayerStates.push(
// _.cloneDeep(currentCanvas.layerState)
// );
// if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
// currentCanvas.pastLayerStates.shift();
// }
// currentCanvas.layerState.stagingArea.images.push({
// kind: 'image',
// layer: 'base',
// x,
// y,
// image,
// });
// currentCanvas.layerState.stagingArea.selectedImageIndex =
// currentCanvas.layerState.stagingArea.images.length - 1;
// currentCanvas.futureLayerStates = [];
// }
// // Else, if the staging area is empty, set it to this image
// else if (stagedImages.length === 0) {
// console.log('setting staging area image to be this one image');
// // add new image to staging area
// currentCanvas.pastLayerStates.push(
// _.cloneDeep(currentCanvas.layerState)
// );
// if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
// currentCanvas.pastLayerStates.shift();
// }
// currentCanvas.layerState.stagingArea = {
// images: [
// {
// kind: 'image',
// layer: 'base',
// x,
// y,
// image,
// },
// ],
// x,
// y,
// width: image.width,
// height: image.height,
// selectedImageIndex: 0,
// };
// currentCanvas.futureLayerStates = [];
// } else {
// // commit the current staging area image & set the new image as the only staging area image
// currentCanvas.pastLayerStates.push(
// _.cloneDeep(currentCanvas.layerState)
// );
// if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
// currentCanvas.pastLayerStates.shift();
// }
// if (stagedImages.length === 1) {
// // commit the current staging area image
// console.log('committing current image');
// const {
// x: currentStagedX,
// y: currentStagedY,
// image: currentStagedImage,
// } = stagedImages[0];
// currentCanvas.layerState.objects.push({
// kind: 'image',
// layer: 'base',
// x: currentStagedX,
// y: currentStagedY,
// image: currentStagedImage,
// });
// }
// console.log('setting staging area to this singel new image');
// currentCanvas.layerState.stagingArea = {
// images: [
// {
// kind: 'image',
// layer: 'base',
// x,
// y,
// image,
// },
// ],
// x,
// y,
// width: image.width,
// height: image.height,
// selectedImageIndex: 0,
// };
// currentCanvas.futureLayerStates = [];
// }
},
discardStagedImages: (state) => {
const currentCanvas = state[state.currentCanvas];
currentCanvas.layerState.stagingArea = {
...initialLayerState.stagingArea,
};
}, },
addLine: (state, action: PayloadAction<number[]>) => { addLine: (state, action: PayloadAction<number[]>) => {
const currentCanvas = state[state.currentCanvas]; const currentCanvas = state[state.currentCanvas];
@ -567,13 +713,13 @@ export const canvasSlice = createSlice({
const newColor = const newColor =
layer === 'base' && tool === 'brush' ? { color: brushColor } : {}; layer === 'base' && tool === 'brush' ? { color: brushColor } : {};
currentCanvas.pastObjects.push(currentCanvas.objects); currentCanvas.pastLayerStates.push(currentCanvas.layerState);
if (currentCanvas.pastObjects.length > currentCanvas.maxHistory) { if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
currentCanvas.pastObjects.shift(); currentCanvas.pastLayerStates.shift();
} }
currentCanvas.objects.push({ currentCanvas.layerState.objects.push({
kind: 'line', kind: 'line',
layer, layer,
tool, tool,
@ -582,11 +728,11 @@ export const canvasSlice = createSlice({
...newColor, ...newColor,
}); });
currentCanvas.futureObjects = []; currentCanvas.futureLayerStates = [];
}, },
addPointToCurrentLine: (state, action: PayloadAction<number[]>) => { addPointToCurrentLine: (state, action: PayloadAction<number[]>) => {
const lastLine = const lastLine =
state[state.currentCanvas].objects.findLast(isCanvasAnyLine); state[state.currentCanvas].layerState.objects.findLast(isCanvasAnyLine);
if (!lastLine) return; if (!lastLine) return;
@ -594,36 +740,33 @@ export const canvasSlice = createSlice({
}, },
undo: (state) => { undo: (state) => {
const currentCanvas = state[state.currentCanvas]; const currentCanvas = state[state.currentCanvas];
if (currentCanvas.objects.length === 0) return;
const newObjects = currentCanvas.pastObjects.pop(); const targetState = currentCanvas.pastLayerStates.pop();
if (!newObjects) return; if (!targetState) return;
currentCanvas.futureObjects.unshift(currentCanvas.objects); currentCanvas.futureLayerStates.unshift(currentCanvas.layerState);
if (currentCanvas.futureObjects.length > currentCanvas.maxHistory) { if (currentCanvas.futureLayerStates.length > currentCanvas.maxHistory) {
currentCanvas.futureObjects.pop(); currentCanvas.futureLayerStates.pop();
} }
currentCanvas.objects = newObjects; currentCanvas.layerState = targetState;
}, },
redo: (state) => { redo: (state) => {
const currentCanvas = state[state.currentCanvas]; const currentCanvas = state[state.currentCanvas];
if (currentCanvas.futureObjects.length === 0) return; const targetState = currentCanvas.futureLayerStates.shift();
const newObjects = currentCanvas.futureObjects.shift(); if (!targetState) return;
if (!newObjects) return; currentCanvas.pastLayerStates.push(currentCanvas.layerState);
currentCanvas.pastObjects.push(currentCanvas.objects); if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
currentCanvas.pastLayerStates.shift();
if (currentCanvas.pastObjects.length > currentCanvas.maxHistory) {
currentCanvas.pastObjects.shift();
} }
currentCanvas.objects = newObjects; currentCanvas.layerState = targetState;
}, },
setShouldShowGrid: (state, action: PayloadAction<boolean>) => { setShouldShowGrid: (state, action: PayloadAction<boolean>) => {
state.outpainting.shouldShowGrid = action.payload; state.outpainting.shouldShowGrid = action.payload;
@ -641,21 +784,69 @@ export const canvasSlice = createSlice({
state[state.currentCanvas].shouldShowIntermediates = action.payload; state[state.currentCanvas].shouldShowIntermediates = action.payload;
}, },
resetCanvas: (state) => { resetCanvas: (state) => {
state[state.currentCanvas].pastObjects.push( state[state.currentCanvas].pastLayerStates.push(
state[state.currentCanvas].objects state[state.currentCanvas].layerState
); );
state[state.currentCanvas].objects = []; state[state.currentCanvas].layerState = initialLayerState;
state[state.currentCanvas].futureObjects = []; state[state.currentCanvas].futureLayerStates = [];
},
nextStagingAreaImage: (state) => {
const currentIndex =
state.outpainting.layerState.stagingArea.selectedImageIndex;
const length = state.outpainting.layerState.stagingArea.images.length;
state.outpainting.layerState.stagingArea.selectedImageIndex = Math.min(
currentIndex + 1,
length - 1
);
},
prevStagingAreaImage: (state) => {
const currentIndex =
state.outpainting.layerState.stagingArea.selectedImageIndex;
state.outpainting.layerState.stagingArea.selectedImageIndex = Math.max(
currentIndex - 1,
0
);
},
commitStagingAreaImage: (state) => {
const currentCanvas = state[state.currentCanvas];
const { images, selectedImageIndex } =
currentCanvas.layerState.stagingArea;
currentCanvas.pastLayerStates.push(_.cloneDeep(currentCanvas.layerState));
if (currentCanvas.pastLayerStates.length > currentCanvas.maxHistory) {
currentCanvas.pastLayerStates.shift();
}
const { x, y, image } = images[selectedImageIndex];
currentCanvas.layerState.objects.push({
kind: 'image',
layer: 'base',
x,
y,
image,
});
currentCanvas.layerState.stagingArea = {
...initialLayerState.stagingArea,
};
currentCanvas.futureLayerStates = [];
}, },
}, },
extraReducers: (builder) => { extraReducers: (builder) => {
builder.addCase(uploadOutpaintingMergedImage.fulfilled, (state, action) => { builder.addCase(uploadOutpaintingMergedImage.fulfilled, (state, action) => {
if (!action.payload) return; if (!action.payload) return;
state.outpainting.pastObjects.push([...state.outpainting.objects]); state.outpainting.pastLayerStates.push({
state.outpainting.futureObjects = []; ...state.outpainting.layerState,
});
state.outpainting.futureLayerStates = [];
state.outpainting.objects = [ state.outpainting.layerState.objects = [
{ {
kind: 'image', kind: 'image',
layer: 'base', layer: 'base',
@ -709,13 +900,17 @@ export const {
setIsMoveStageKeyHeld, setIsMoveStageKeyHeld,
setStageCoordinates, setStageCoordinates,
setCurrentCanvas, setCurrentCanvas,
addImageToOutpaintingSesion, addImageToOutpainting,
resetCanvas, resetCanvas,
setShouldShowGrid, setShouldShowGrid,
setShouldSnapToGrid, setShouldSnapToGrid,
setShouldAutoSave, setShouldAutoSave,
setShouldShowIntermediates, setShouldShowIntermediates,
setIsMovingStage, setIsMovingStage,
nextStagingAreaImage,
prevStagingAreaImage,
commitStagingAreaImage,
discardStagedImages,
} = canvasSlice.actions; } = canvasSlice.actions;
export default canvasSlice.reducer; export default canvasSlice.reducer;
@ -783,6 +978,10 @@ export const uploadOutpaintingMergedImage = createAsyncThunk(
export const currentCanvasSelector = (state: RootState): BaseCanvasState => export const currentCanvasSelector = (state: RootState): BaseCanvasState =>
state.canvas[state.canvas.currentCanvas]; state.canvas[state.canvas.currentCanvas];
export const isStagingSelector = (state: RootState): boolean =>
state.canvas[state.canvas.currentCanvas].layerState.stagingArea.images
.length > 0;
export const outpaintingCanvasSelector = ( export const outpaintingCanvasSelector = (
state: RootState state: RootState
): OutpaintingCanvasState => state.canvas.outpainting; ): OutpaintingCanvasState => state.canvas.outpainting;
@ -794,6 +993,6 @@ export const inpaintingCanvasSelector = (
export const baseCanvasImageSelector = createSelector( export const baseCanvasImageSelector = createSelector(
[currentCanvasSelector], [currentCanvasSelector],
(currentCanvas) => { (currentCanvas) => {
return currentCanvas.objects.find(isCanvasBaseImage); return currentCanvas.layerState.objects.find(isCanvasBaseImage);
} }
); );

View File

@ -6,17 +6,18 @@ import _ from 'lodash';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { import {
currentCanvasSelector, currentCanvasSelector,
isStagingSelector,
setIsMovingStage, setIsMovingStage,
setStageCoordinates, setStageCoordinates,
} from '../canvasSlice'; } from '../canvasSlice';
const selector = createSelector( const selector = createSelector(
[currentCanvasSelector, activeTabNameSelector], [currentCanvasSelector, isStagingSelector, activeTabNameSelector],
(canvas, activeTabName) => { (canvas, isStaging, activeTabName) => {
const { tool } = canvas; const { tool } = canvas;
return { return {
tool, tool,
isStaging,
activeTabName, activeTabName,
}; };
}, },
@ -25,24 +26,26 @@ const selector = createSelector(
const useCanvasDrag = () => { const useCanvasDrag = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool, activeTabName } = useAppSelector(selector); const { tool, activeTabName, isStaging } = useAppSelector(selector);
return { return {
handleDragStart: useCallback(() => { handleDragStart: useCallback(() => {
if (tool !== 'move' || activeTabName !== 'outpainting') return; if (!(tool === 'move' || isStaging)) return;
dispatch(setIsMovingStage(true)); dispatch(setIsMovingStage(true));
}, [activeTabName, dispatch, tool]), }, [dispatch, isStaging, tool]),
handleDragMove: useCallback( handleDragMove: useCallback(
(e: KonvaEventObject<MouseEvent>) => { (e: KonvaEventObject<MouseEvent>) => {
if (tool !== 'move' || activeTabName !== 'outpainting') return; if (!(tool === 'move' || isStaging)) return;
dispatch(setStageCoordinates(e.target.getPosition())); dispatch(setStageCoordinates(e.target.getPosition()));
}, },
[activeTabName, dispatch, tool] [dispatch, isStaging, tool]
), ),
handleDragEnd: useCallback(() => { handleDragEnd: useCallback(() => {
if (tool !== 'move' || activeTabName !== 'outpainting') return; if (!(tool === 'move' || isStaging)) return;
dispatch(setIsMovingStage(false)); dispatch(setIsMovingStage(false));
}, [activeTabName, dispatch, tool]), }, [dispatch, isStaging, tool]),
}; };
}; };

View File

@ -8,18 +8,20 @@ import { MutableRefObject, useCallback } from 'react';
import { import {
addLine, addLine,
currentCanvasSelector, currentCanvasSelector,
isStagingSelector,
setIsDrawing, setIsDrawing,
setIsMovingStage, setIsMovingStage,
} from '../canvasSlice'; } from '../canvasSlice';
import getScaledCursorPosition from '../util/getScaledCursorPosition'; import getScaledCursorPosition from '../util/getScaledCursorPosition';
const selector = createSelector( const selector = createSelector(
[activeTabNameSelector, currentCanvasSelector], [activeTabNameSelector, currentCanvasSelector, isStagingSelector],
(activeTabName, currentCanvas) => { (activeTabName, currentCanvas, isStaging) => {
const { tool } = currentCanvas; const { tool } = currentCanvas;
return { return {
tool, tool,
activeTabName, activeTabName,
isStaging,
}; };
}, },
{ memoizeOptions: { resultEqualityCheck: _.isEqual } } { memoizeOptions: { resultEqualityCheck: _.isEqual } }
@ -27,14 +29,15 @@ const selector = createSelector(
const useCanvasMouseDown = (stageRef: MutableRefObject<Konva.Stage | null>) => { const useCanvasMouseDown = (stageRef: MutableRefObject<Konva.Stage | null>) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool } = useAppSelector(selector); const { tool, isStaging } = useAppSelector(selector);
return useCallback( return useCallback(
(e: KonvaEventObject<MouseEvent>) => { (e: KonvaEventObject<MouseEvent>) => {
if (!stageRef.current) return; if (!stageRef.current) return;
stageRef.current.container().focus(); stageRef.current.container().focus();
if (tool === 'move') { if (tool === 'move' || isStaging) {
dispatch(setIsMovingStage(true)); dispatch(setIsMovingStage(true));
return; return;
} }
@ -50,7 +53,7 @@ const useCanvasMouseDown = (stageRef: MutableRefObject<Konva.Stage | null>) => {
// Add a new line starting from the current cursor position. // Add a new line starting from the current cursor position.
dispatch(addLine([scaledCursorPosition.x, scaledCursorPosition.y])); dispatch(addLine([scaledCursorPosition.x, scaledCursorPosition.y]));
}, },
[stageRef, dispatch, tool] [stageRef, tool, isStaging, dispatch]
); );
}; };

View File

@ -5,16 +5,22 @@ import Konva from 'konva';
import { KonvaEventObject } from 'konva/lib/Node'; import { KonvaEventObject } from 'konva/lib/Node';
import _ from 'lodash'; import _ from 'lodash';
import { MutableRefObject, useCallback } from 'react'; import { MutableRefObject, useCallback } from 'react';
import { addLine, currentCanvasSelector, setIsDrawing } from '../canvasSlice'; import {
addLine,
currentCanvasSelector,
isStagingSelector,
setIsDrawing,
} from '../canvasSlice';
import getScaledCursorPosition from '../util/getScaledCursorPosition'; import getScaledCursorPosition from '../util/getScaledCursorPosition';
const selector = createSelector( const selector = createSelector(
[activeTabNameSelector, currentCanvasSelector], [activeTabNameSelector, currentCanvasSelector, isStagingSelector],
(activeTabName, currentCanvas) => { (activeTabName, currentCanvas, isStaging) => {
const { tool } = currentCanvas; const { tool } = currentCanvas;
return { return {
tool, tool,
activeTabName, activeTabName,
isStaging,
}; };
}, },
{ memoizeOptions: { resultEqualityCheck: _.isEqual } } { memoizeOptions: { resultEqualityCheck: _.isEqual } }
@ -24,7 +30,7 @@ const useCanvasMouseEnter = (
stageRef: MutableRefObject<Konva.Stage | null> stageRef: MutableRefObject<Konva.Stage | null>
) => { ) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool } = useAppSelector(selector); const { tool, isStaging } = useAppSelector(selector);
return useCallback( return useCallback(
(e: KonvaEventObject<MouseEvent>) => { (e: KonvaEventObject<MouseEvent>) => {
@ -34,14 +40,14 @@ const useCanvasMouseEnter = (
const scaledCursorPosition = getScaledCursorPosition(stageRef.current); const scaledCursorPosition = getScaledCursorPosition(stageRef.current);
if (!scaledCursorPosition || tool === 'move') return; if (!scaledCursorPosition || tool === 'move' || isStaging) return;
dispatch(setIsDrawing(true)); dispatch(setIsDrawing(true));
// Add a new line starting from the current cursor position. // Add a new line starting from the current cursor position.
dispatch(addLine([scaledCursorPosition.x, scaledCursorPosition.y])); dispatch(addLine([scaledCursorPosition.x, scaledCursorPosition.y]));
}, },
[stageRef, tool, dispatch] [stageRef, tool, isStaging, dispatch]
); );
}; };

View File

@ -9,18 +9,20 @@ import {
addPointToCurrentLine, addPointToCurrentLine,
currentCanvasSelector, currentCanvasSelector,
GenericCanvasState, GenericCanvasState,
isStagingSelector,
setCursorPosition, setCursorPosition,
} from '../canvasSlice'; } from '../canvasSlice';
import getScaledCursorPosition from '../util/getScaledCursorPosition'; import getScaledCursorPosition from '../util/getScaledCursorPosition';
const selector = createSelector( const selector = createSelector(
[activeTabNameSelector, currentCanvasSelector], [activeTabNameSelector, currentCanvasSelector, isStagingSelector],
(activeTabName, canvas: GenericCanvasState) => { (activeTabName, currentCanvas, isStaging) => {
const { tool, isDrawing } = canvas; const { tool, isDrawing } = currentCanvas;
return { return {
tool, tool,
isDrawing, isDrawing,
activeTabName, activeTabName,
isStaging,
}; };
}, },
{ memoizeOptions: { resultEqualityCheck: _.isEqual } } { memoizeOptions: { resultEqualityCheck: _.isEqual } }
@ -32,7 +34,7 @@ const useCanvasMouseMove = (
lastCursorPositionRef: MutableRefObject<Vector2d> lastCursorPositionRef: MutableRefObject<Vector2d>
) => { ) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { isDrawing, tool } = useAppSelector(selector); const { isDrawing, tool, isStaging } = useAppSelector(selector);
return useCallback(() => { return useCallback(() => {
if (!stageRef.current) return; if (!stageRef.current) return;
@ -45,7 +47,7 @@ const useCanvasMouseMove = (
lastCursorPositionRef.current = scaledCursorPosition; lastCursorPositionRef.current = scaledCursorPosition;
if (!isDrawing || tool === 'move') return; if (!isDrawing || tool === 'move' || isStaging) return;
didMouseMoveRef.current = true; didMouseMoveRef.current = true;
dispatch( dispatch(
@ -55,6 +57,7 @@ const useCanvasMouseMove = (
didMouseMoveRef, didMouseMoveRef,
dispatch, dispatch,
isDrawing, isDrawing,
isStaging,
lastCursorPositionRef, lastCursorPositionRef,
stageRef, stageRef,
tool, tool,

View File

@ -9,19 +9,21 @@ import {
addPointToCurrentLine, addPointToCurrentLine,
currentCanvasSelector, currentCanvasSelector,
GenericCanvasState, GenericCanvasState,
isStagingSelector,
setIsDrawing, setIsDrawing,
setIsMovingStage, setIsMovingStage,
} from '../canvasSlice'; } from '../canvasSlice';
import getScaledCursorPosition from '../util/getScaledCursorPosition'; import getScaledCursorPosition from '../util/getScaledCursorPosition';
const selector = createSelector( const selector = createSelector(
[activeTabNameSelector, currentCanvasSelector], [activeTabNameSelector, currentCanvasSelector, isStagingSelector],
(activeTabName, canvas: GenericCanvasState) => { (activeTabName, currentCanvas, isStaging) => {
const { tool, isDrawing } = canvas; const { tool, isDrawing } = currentCanvas;
return { return {
tool, tool,
isDrawing, isDrawing,
activeTabName, activeTabName,
isStaging,
}; };
}, },
{ memoizeOptions: { resultEqualityCheck: _.isEqual } } { memoizeOptions: { resultEqualityCheck: _.isEqual } }
@ -32,10 +34,10 @@ const useCanvasMouseUp = (
didMouseMoveRef: MutableRefObject<boolean> didMouseMoveRef: MutableRefObject<boolean>
) => { ) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool, isDrawing } = useAppSelector(selector); const { tool, isDrawing, isStaging } = useAppSelector(selector);
return useCallback(() => { return useCallback(() => {
if (tool === 'move') { if (tool === 'move' || isStaging) {
dispatch(setIsMovingStage(false)); dispatch(setIsMovingStage(false));
return; return;
} }
@ -58,7 +60,7 @@ const useCanvasMouseUp = (
didMouseMoveRef.current = false; didMouseMoveRef.current = false;
} }
dispatch(setIsDrawing(false)); dispatch(setIsDrawing(false));
}, [didMouseMoveRef, dispatch, isDrawing, stageRef, tool]); }, [didMouseMoveRef, dispatch, isDrawing, isStaging, stageRef, tool]);
}; };
export default useCanvasMouseUp; export default useCanvasMouseUp;

View File

@ -13,12 +13,12 @@ import _ from 'lodash';
const clearBrushHistorySelector = createSelector( const clearBrushHistorySelector = createSelector(
currentCanvasSelector, currentCanvasSelector,
(currentCanvas) => { (currentCanvas) => {
const { pastObjects, futureObjects } = currentCanvas as const { pastLayerStates, futureLayerStates } = currentCanvas as
| InpaintingCanvasState | InpaintingCanvasState
| OutpaintingCanvasState; | OutpaintingCanvasState;
return { return {
mayClearBrushHistory: mayClearBrushHistory:
futureObjects.length > 0 || pastObjects.length > 0 ? false : true, futureLayerStates.length > 0 || pastLayerStates.length > 0 ? false : true,
}; };
}, },
{ {

View File

@ -69,10 +69,13 @@
} }
.inpainting-canvas-stage { .inpainting-canvas-stage {
// border-radius: 0.5rem; outline: none;
// border: 1px solid var(--border-color-light); border-radius: 0.5rem;
border: 1px solid var(--border-color-light);
overflow: hidden;
canvas { canvas {
outline: none;
border-radius: 0.5rem; border-radius: 0.5rem;
} }
} }

View File

@ -17,7 +17,9 @@ const outpaintingDisplaySelector = createSelector(
(canvas: CanvasState) => { (canvas: CanvasState) => {
const { const {
doesCanvasNeedScaling, doesCanvasNeedScaling,
outpainting: { objects }, outpainting: {
layerState: { objects },
},
} = canvas; } = canvas;
return { return {
doesCanvasNeedScaling, doesCanvasNeedScaling,

View File

@ -13,7 +13,7 @@ export const persistor = persistStore(store);
import Loading from './Loading'; import Loading from './Loading';
import App from './app/App'; import App from './app/App';
const emotionCache = createCache({ export const emotionCache = createCache({
key: 'invokeai-style-cache', key: 'invokeai-style-cache',
prepend: true, prepend: true,
}); });

View File

@ -3420,7 +3420,15 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b" resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
react-konva@^18.2.3: react-konva-utils@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/react-konva-utils/-/react-konva-utils-0.3.0.tgz#d9099ad1a767286b24fb1b08377af2dfa5c9f176"
integrity sha512-yH5FVpDGQ8gHeClyHY533M4oSLjEfYuvn+Z29zXm9osjhuulhtJrh5k+wtyY6QSC0MG0ioqE0cjiudGl1WGB9A==
dependencies:
react-konva "^18.0.0-0"
use-image "^1.0.12"
react-konva@^18.0.0-0, react-konva@^18.2.3:
version "18.2.3" version "18.2.3"
resolved "https://registry.yarnpkg.com/react-konva/-/react-konva-18.2.3.tgz#75c658fca493bdf515b38f2a8d544fa7a9c754c4" resolved "https://registry.yarnpkg.com/react-konva/-/react-konva-18.2.3.tgz#75c658fca493bdf515b38f2a8d544fa7a9c754c4"
integrity sha512-OPxjBTgaEGU9pt/VJSVM7QNXYHEZ5CkulX+4fTTvbaH+Wh+vMLbXmH3yjWw4kT/5Qi6t0UQKHPPmirCv8/9sdg== integrity sha512-OPxjBTgaEGU9pt/VJSVM7QNXYHEZ5CkulX+4fTTvbaH+Wh+vMLbXmH3yjWw4kT/5Qi6t0UQKHPPmirCv8/9sdg==
@ -3942,7 +3950,7 @@ use-callback-ref@^1.3.0:
dependencies: dependencies:
tslib "^2.0.0" tslib "^2.0.0"
use-image@^1.1.0: use-image@^1.0.12, use-image@^1.1.0:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/use-image/-/use-image-1.1.0.tgz#dc244c34506d3cf3a8177c1f0bbfb158b9beefe5" resolved "https://registry.yarnpkg.com/use-image/-/use-image-1.1.0.tgz#dc244c34506d3cf3a8177c1f0bbfb158b9beefe5"
integrity sha512-+cBHRR/44ZyMUS873O0vbVylgMM0AbdTunEplAWXvIQ2p69h2sIo2Qq74zeUsq6AMo+27e5lERQvXzd1crGiMg== integrity sha512-+cBHRR/44ZyMUS873O0vbVylgMM0AbdTunEplAWXvIQ2p69h2sIo2Qq74zeUsq6AMo+27e5lERQvXzd1crGiMg==