Fixes bbox not resizing in outpainting if partially off screen

This commit is contained in:
psychedelicious 2022-11-14 13:09:59 +11:00 committed by blessedcoolant
parent d7884432c9
commit 1bc1085542

View File

@ -109,8 +109,8 @@ const IAICanvasBoundingBox = (props: IAICanvasBoundingBoxPreviewProps) => {
if (activeTabName === 'inpainting' || !shouldSnapToGrid) { if (activeTabName === 'inpainting' || !shouldSnapToGrid) {
dispatch( dispatch(
setBoundingBoxCoordinates({ setBoundingBoxCoordinates({
x: e.target.x(), x: Math.floor(e.target.x()),
y: e.target.y(), y: Math.floor(e.target.y()),
}) })
); );
return; return;
@ -238,7 +238,7 @@ const IAICanvasBoundingBox = (props: IAICanvasBoundingBoxPreviewProps) => {
// We may not change anything, stash the old position // We may not change anything, stash the old position
let newCoordinate = { ...oldPos }; let newCoordinate = { ...oldPos };
console.log(oldPos, newPos);
// Set the new coords based on what snapped // Set the new coords based on what snapped
if (didSnapX && !didSnapY) { if (didSnapX && !didSnapY) {
newCoordinate = { newCoordinate = {
@ -269,25 +269,21 @@ const IAICanvasBoundingBox = (props: IAICanvasBoundingBoxPreviewProps) => {
* Unlike anchorDragBoundFunc, it does get a width and height, so * Unlike anchorDragBoundFunc, it does get a width and height, so
* the logic to constrain the size of the bounding box is very simple. * the logic to constrain the size of the bounding box is very simple.
*/ */
if (!baseCanvasImage && activeTabName !== 'outpainting')
return oldBoundBox; // On the Inpainting canvas, the bounding box needs to stay in the stage
if ( if (
newBoundBox.width + newBoundBox.x > stageDimensions.width || activeTabName === 'inpainting' &&
newBoundBox.height + newBoundBox.y > stageDimensions.height || (newBoundBox.width + newBoundBox.x > stageDimensions.width ||
newBoundBox.x < 0 || newBoundBox.height + newBoundBox.y > stageDimensions.height ||
newBoundBox.y < 0 newBoundBox.x < 0 ||
newBoundBox.y < 0)
) { ) {
return oldBoundBox; return oldBoundBox;
} }
return newBoundBox; return newBoundBox;
}, },
[ [activeTabName, stageDimensions.height, stageDimensions.width]
activeTabName,
baseCanvasImage,
stageDimensions.height,
stageDimensions.width,
]
); );
const handleStartedTransforming = () => { const handleStartedTransforming = () => {