mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
feat(ui): regional guidance supports merge visible
This commit is contained in:
@@ -25,7 +25,10 @@ export const CanvasEntityGroupList = memo(({ isSelected, type, children }: Props
|
||||
const title = useEntityTypeTitle(type);
|
||||
const informationalPopoverFeature = useEntityTypeInformationalPopover(type);
|
||||
const collapse = useBoolean(true);
|
||||
const canMergeVisible = useMemo(() => type === 'raster_layer' || type === 'inpaint_mask', [type]);
|
||||
const canMergeVisible = useMemo(
|
||||
() => type === 'raster_layer' || type === 'inpaint_mask' || type === 'regional_guidance',
|
||||
[type]
|
||||
);
|
||||
const canHideAll = useMemo(() => type !== 'reference_image', [type]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useCanvasManager } from 'features/controlLayers/contexts/CanvasManagerP
|
||||
import { useCanvasIsBusy } from 'features/controlLayers/hooks/useCanvasIsBusy';
|
||||
import { useEntityTypeCount } from 'features/controlLayers/hooks/useEntityTypeCount';
|
||||
import type { CanvasManager } from 'features/controlLayers/konva/CanvasManager';
|
||||
import { inpaintMaskAdded, rasterLayerAdded } from 'features/controlLayers/store/canvasSlice';
|
||||
import { inpaintMaskAdded, rasterLayerAdded, rgAdded } from 'features/controlLayers/store/canvasSlice';
|
||||
import type { CanvasEntityType } from 'features/controlLayers/store/types';
|
||||
import { imageDTOToImageObject } from 'features/controlLayers/store/util';
|
||||
import { toast } from 'features/toast/toast';
|
||||
@@ -75,6 +75,32 @@ const mergeInpaintMasks = async (canvasManager: CanvasManager, dispatch: AppDisp
|
||||
toast({ title: t('controlLayers.mergeVisibleOk') });
|
||||
};
|
||||
|
||||
const mergeRegionalGuidance = async (canvasManager: CanvasManager, dispatch: AppDispatch) => {
|
||||
const rect = canvasManager.stage.getVisibleRect('regional_guidance');
|
||||
const adapters = canvasManager.compositor.getVisibleAdaptersOfType('regional_guidance');
|
||||
const result = await withResultAsync(() =>
|
||||
canvasManager.compositor.getCompositeImageDTO(adapters, rect, { is_intermediate: true })
|
||||
);
|
||||
|
||||
if (result.isErr()) {
|
||||
log.error({ error: serializeError(result.error) }, 'Failed to merge visible');
|
||||
toast({ title: t('controlLayers.mergeVisibleError'), status: 'error' });
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(
|
||||
rgAdded({
|
||||
isSelected: true,
|
||||
overrides: {
|
||||
objects: [imageDTOToImageObject(result.value)],
|
||||
position: { x: Math.floor(rect.x), y: Math.floor(rect.y) },
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
toast({ title: t('controlLayers.mergeVisibleOk') });
|
||||
};
|
||||
|
||||
export const CanvasEntityMergeVisibleButton = memo(({ type }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const dispatch = useAppDispatch();
|
||||
@@ -89,6 +115,9 @@ export const CanvasEntityMergeVisibleButton = memo(({ type }: Props) => {
|
||||
case 'inpaint_mask':
|
||||
mergeInpaintMasks(canvasManager, dispatch);
|
||||
break;
|
||||
case 'regional_guidance':
|
||||
mergeRegionalGuidance(canvasManager, dispatch);
|
||||
break;
|
||||
default:
|
||||
log.error({ type }, 'Unsupported type for merge visible');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user