mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tidy(ui): removed unused state related to non-buffered drawing
This commit is contained in:
parent
84305d4e73
commit
b252ded366
@ -90,11 +90,11 @@ export class CanvasInpaintMask {
|
||||
return;
|
||||
}
|
||||
if (this.drawingBuffer.type === 'brush_line') {
|
||||
this.manager.stateApi.onBrushLineAdded2({ id: this.id, brushLine: this.drawingBuffer }, 'inpaint_mask');
|
||||
this.manager.stateApi.onBrushLineAdded({ id: this.id, brushLine: this.drawingBuffer }, 'inpaint_mask');
|
||||
} else if (this.drawingBuffer.type === 'eraser_line') {
|
||||
this.manager.stateApi.onEraserLineAdded2({ id: this.id, eraserLine: this.drawingBuffer }, 'inpaint_mask');
|
||||
this.manager.stateApi.onEraserLineAdded({ id: this.id, eraserLine: this.drawingBuffer }, 'inpaint_mask');
|
||||
} else if (this.drawingBuffer.type === 'rect_shape') {
|
||||
this.manager.stateApi.onRectShapeAdded2({ id: this.id, rectShape: this.drawingBuffer }, 'inpaint_mask');
|
||||
this.manager.stateApi.onRectShapeAdded({ id: this.id, rectShape: this.drawingBuffer }, 'inpaint_mask');
|
||||
}
|
||||
this.setDrawingBuffer(null);
|
||||
}
|
||||
|
@ -85,11 +85,11 @@ export class CanvasLayer {
|
||||
return;
|
||||
}
|
||||
if (this.drawingBuffer.type === 'brush_line') {
|
||||
this.manager.stateApi.onBrushLineAdded2({ id: this.id, brushLine: this.drawingBuffer }, 'layer');
|
||||
this.manager.stateApi.onBrushLineAdded({ id: this.id, brushLine: this.drawingBuffer }, 'layer');
|
||||
} else if (this.drawingBuffer.type === 'eraser_line') {
|
||||
this.manager.stateApi.onEraserLineAdded2({ id: this.id, eraserLine: this.drawingBuffer }, 'layer');
|
||||
this.manager.stateApi.onEraserLineAdded({ id: this.id, eraserLine: this.drawingBuffer }, 'layer');
|
||||
} else if (this.drawingBuffer.type === 'rect_shape') {
|
||||
this.manager.stateApi.onRectShapeAdded2({ id: this.id, rectShape: this.drawingBuffer }, 'layer');
|
||||
this.manager.stateApi.onRectShapeAdded({ id: this.id, rectShape: this.drawingBuffer }, 'layer');
|
||||
}
|
||||
this.setDrawingBuffer(null);
|
||||
}
|
||||
|
@ -90,11 +90,11 @@ export class CanvasRegion {
|
||||
return;
|
||||
}
|
||||
if (this.drawingBuffer.type === 'brush_line') {
|
||||
this.manager.stateApi.onBrushLineAdded2({ id: this.id, brushLine: this.drawingBuffer }, 'regional_guidance');
|
||||
this.manager.stateApi.onBrushLineAdded({ id: this.id, brushLine: this.drawingBuffer }, 'regional_guidance');
|
||||
} else if (this.drawingBuffer.type === 'eraser_line') {
|
||||
this.manager.stateApi.onEraserLineAdded2({ id: this.id, eraserLine: this.drawingBuffer }, 'regional_guidance');
|
||||
this.manager.stateApi.onEraserLineAdded({ id: this.id, eraserLine: this.drawingBuffer }, 'regional_guidance');
|
||||
} else if (this.drawingBuffer.type === 'rect_shape') {
|
||||
this.manager.stateApi.onRectShapeAdded2({ id: this.id, rectShape: this.drawingBuffer }, 'regional_guidance');
|
||||
this.manager.stateApi.onRectShapeAdded({ id: this.id, rectShape: this.drawingBuffer }, 'regional_guidance');
|
||||
}
|
||||
this.setDrawingBuffer(null);
|
||||
}
|
||||
|
@ -15,39 +15,28 @@ import {
|
||||
bboxChanged,
|
||||
brushWidthChanged,
|
||||
caBboxChanged,
|
||||
caScaled,
|
||||
caTranslated,
|
||||
eraserWidthChanged,
|
||||
imBboxChanged,
|
||||
imBrushLineAdded,
|
||||
imBrushLineAdded2,
|
||||
imEraserLineAdded,
|
||||
imEraserLineAdded2,
|
||||
imImageCacheChanged,
|
||||
imLinePointAdded,
|
||||
imRectAdded,
|
||||
imRectShapeAdded2,
|
||||
imRectShapeAdded,
|
||||
imScaled,
|
||||
imTranslated,
|
||||
layerBboxChanged,
|
||||
layerBrushLineAdded,
|
||||
layerBrushLineAdded2,
|
||||
layerEraserLineAdded,
|
||||
layerEraserLineAdded2,
|
||||
layerImageCacheChanged,
|
||||
layerLinePointAdded,
|
||||
layerRectAdded,
|
||||
layerRectShapeAdded2,
|
||||
layerRectShapeAdded,
|
||||
layerScaled,
|
||||
layerTranslated,
|
||||
rgBboxChanged,
|
||||
rgBrushLineAdded,
|
||||
rgBrushLineAdded2,
|
||||
rgEraserLineAdded,
|
||||
rgEraserLineAdded2,
|
||||
rgImageCacheChanged,
|
||||
rgLinePointAdded,
|
||||
rgRectAdded,
|
||||
rgRectShapeAdded2,
|
||||
rgRectShapeAdded,
|
||||
rgScaled,
|
||||
rgTranslated,
|
||||
toolBufferChanged,
|
||||
@ -56,14 +45,10 @@ import {
|
||||
import type {
|
||||
BboxChangedArg,
|
||||
BrushLine,
|
||||
BrushLineAddedArg,
|
||||
CanvasEntity,
|
||||
EraserLine,
|
||||
EraserLineAddedArg,
|
||||
PointAddedToLineArg,
|
||||
PosChangedArg,
|
||||
RectShape,
|
||||
RectShapeAddedArg,
|
||||
ScaleChangedArg,
|
||||
Tool,
|
||||
} from 'features/controlLayers/store/types';
|
||||
@ -89,12 +74,12 @@ export class CanvasStateApi {
|
||||
log.debug('onPosChanged');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerTranslated(arg));
|
||||
} else if (entityType === 'control_adapter') {
|
||||
this.store.dispatch(caTranslated(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgTranslated(arg));
|
||||
} else if (entityType === 'inpaint_mask') {
|
||||
this.store.dispatch(imTranslated(arg));
|
||||
} else if (entityType === 'control_adapter') {
|
||||
this.store.dispatch(caTranslated(arg));
|
||||
}
|
||||
};
|
||||
onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntity['type']) => {
|
||||
@ -105,6 +90,8 @@ export class CanvasStateApi {
|
||||
this.store.dispatch(imScaled(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgScaled(arg));
|
||||
} else if (entityType === 'control_adapter') {
|
||||
this.store.dispatch(caScaled(arg));
|
||||
}
|
||||
};
|
||||
onBboxChanged = (arg: BboxChangedArg, entityType: CanvasEntity['type']) => {
|
||||
@ -119,7 +106,7 @@ export class CanvasStateApi {
|
||||
this.store.dispatch(imBboxChanged(arg));
|
||||
}
|
||||
};
|
||||
onBrushLineAdded = (arg: BrushLineAddedArg, entityType: CanvasEntity['type']) => {
|
||||
onBrushLineAdded = (arg: { id: string; brushLine: BrushLine }, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Brush line added');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerBrushLineAdded(arg));
|
||||
@ -129,7 +116,7 @@ export class CanvasStateApi {
|
||||
this.store.dispatch(imBrushLineAdded(arg));
|
||||
}
|
||||
};
|
||||
onEraserLineAdded = (arg: EraserLineAddedArg, entityType: CanvasEntity['type']) => {
|
||||
onEraserLineAdded = (arg: { id: string; eraserLine: EraserLine }, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Eraser line added');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerEraserLineAdded(arg));
|
||||
@ -139,54 +126,14 @@ export class CanvasStateApi {
|
||||
this.store.dispatch(imEraserLineAdded(arg));
|
||||
}
|
||||
};
|
||||
onBrushLineAdded2 = (arg: { id: string; brushLine: BrushLine }, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Brush line added');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerBrushLineAdded2(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgBrushLineAdded2(arg));
|
||||
} else if (entityType === 'inpaint_mask') {
|
||||
this.store.dispatch(imBrushLineAdded2(arg));
|
||||
}
|
||||
};
|
||||
onEraserLineAdded2 = (arg: { id: string; eraserLine: EraserLine }, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Eraser line added');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerEraserLineAdded2(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgEraserLineAdded2(arg));
|
||||
} else if (entityType === 'inpaint_mask') {
|
||||
this.store.dispatch(imEraserLineAdded2(arg));
|
||||
}
|
||||
};
|
||||
onPointAddedToLine = (arg: PointAddedToLineArg, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Point added to line');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerLinePointAdded(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgLinePointAdded(arg));
|
||||
} else if (entityType === 'inpaint_mask') {
|
||||
this.store.dispatch(imLinePointAdded(arg));
|
||||
}
|
||||
};
|
||||
onRectShapeAdded = (arg: RectShapeAddedArg, entityType: CanvasEntity['type']) => {
|
||||
onRectShapeAdded = (arg: { id: string; rectShape: RectShape }, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Rect shape added');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerRectAdded(arg));
|
||||
this.store.dispatch(layerRectShapeAdded(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgRectAdded(arg));
|
||||
this.store.dispatch(rgRectShapeAdded(arg));
|
||||
} else if (entityType === 'inpaint_mask') {
|
||||
this.store.dispatch(imRectAdded(arg));
|
||||
}
|
||||
};
|
||||
onRectShapeAdded2 = (arg: { id: string; rectShape: RectShape }, entityType: CanvasEntity['type']) => {
|
||||
log.debug('Rect shape added');
|
||||
if (entityType === 'layer') {
|
||||
this.store.dispatch(layerRectShapeAdded2(arg));
|
||||
} else if (entityType === 'regional_guidance') {
|
||||
this.store.dispatch(rgRectShapeAdded2(arg));
|
||||
} else if (entityType === 'inpaint_mask') {
|
||||
this.store.dispatch(imRectShapeAdded2(arg));
|
||||
this.store.dispatch(imRectShapeAdded(arg));
|
||||
}
|
||||
};
|
||||
onBboxTransformed = (bbox: IRect) => {
|
||||
|
@ -209,14 +209,13 @@ export const {
|
||||
layerOpacityChanged,
|
||||
layerTranslated,
|
||||
layerBboxChanged,
|
||||
layerBrushLineAdded,
|
||||
layerEraserLineAdded,
|
||||
layerLinePointAdded,
|
||||
layerRectAdded,
|
||||
layerImageAdded,
|
||||
layerAllDeleted,
|
||||
layerImageCacheChanged,
|
||||
layerScaled,
|
||||
layerBrushLineAdded,
|
||||
layerEraserLineAdded,
|
||||
layerRectShapeAdded,
|
||||
// IP Adapters
|
||||
ipaAdded,
|
||||
ipaRecalled,
|
||||
@ -251,6 +250,7 @@ export const {
|
||||
caProcessorPendingBatchIdChanged,
|
||||
caWeightChanged,
|
||||
caBeginEndStepPctChanged,
|
||||
caScaled,
|
||||
// Regions
|
||||
rgAdded,
|
||||
rgRecalled,
|
||||
@ -277,11 +277,10 @@ export const {
|
||||
rgIPAdapterMethodChanged,
|
||||
rgIPAdapterModelChanged,
|
||||
rgIPAdapterCLIPVisionModelChanged,
|
||||
rgScaled,
|
||||
rgBrushLineAdded,
|
||||
rgEraserLineAdded,
|
||||
rgLinePointAdded,
|
||||
rgRectAdded,
|
||||
rgScaled,
|
||||
rgRectShapeAdded,
|
||||
// Compositing
|
||||
setInfillMethod,
|
||||
setInfillTileSize,
|
||||
@ -334,11 +333,10 @@ export const {
|
||||
imBboxChanged,
|
||||
imFillChanged,
|
||||
imImageCacheChanged,
|
||||
imScaled,
|
||||
imBrushLineAdded,
|
||||
imEraserLineAdded,
|
||||
imLinePointAdded,
|
||||
imRectAdded,
|
||||
imScaled,
|
||||
imRectShapeAdded,
|
||||
// Staging
|
||||
stagingAreaStartedStaging,
|
||||
stagingAreaImageAdded,
|
||||
@ -347,15 +345,6 @@ export const {
|
||||
stagingAreaCanceledStaging,
|
||||
stagingAreaNextImageSelected,
|
||||
stagingAreaPreviousImageSelected,
|
||||
layerBrushLineAdded2,
|
||||
layerEraserLineAdded2,
|
||||
layerRectShapeAdded2,
|
||||
rgBrushLineAdded2,
|
||||
rgEraserLineAdded2,
|
||||
rgRectShapeAdded2,
|
||||
imBrushLineAdded2,
|
||||
imEraserLineAdded2,
|
||||
imRectShapeAdded2,
|
||||
} = canvasV2Slice.actions;
|
||||
|
||||
export const selectCanvasV2Slice = (state: RootState) => state.canvasV2;
|
||||
|
@ -1,5 +1,4 @@
|
||||
import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit';
|
||||
import { getBrushLineId, getEraserLineId, getRectShapeId } from 'features/controlLayers/konva/naming';
|
||||
import type {
|
||||
BrushLine,
|
||||
CanvasV2State,
|
||||
@ -8,13 +7,11 @@ import type {
|
||||
RectShape,
|
||||
ScaleChangedArg,
|
||||
} from 'features/controlLayers/store/types';
|
||||
import { imageDTOToImageWithDims, RGBA_RED } from 'features/controlLayers/store/types';
|
||||
import { imageDTOToImageWithDims } from 'features/controlLayers/store/types';
|
||||
import type { IRect } from 'konva/lib/types';
|
||||
import type { ImageDTO } from 'services/api/types';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import type { BrushLineAddedArg, EraserLineAddedArg, PointAddedToLineArg, RectShapeAddedArg, RgbColor } from './types';
|
||||
import { isLine } from './types';
|
||||
import type { RgbColor } from './types';
|
||||
|
||||
export const inpaintMaskReducers = {
|
||||
imReset: (state) => {
|
||||
@ -70,85 +67,22 @@ export const inpaintMaskReducers = {
|
||||
const { imageDTO } = action.payload;
|
||||
state.inpaintMask.imageCache = imageDTO ? imageDTOToImageWithDims(imageDTO) : null;
|
||||
},
|
||||
imBrushLineAdded: {
|
||||
reducer: (state, action: PayloadAction<Omit<BrushLineAddedArg, 'id'> & { lineId: string }>) => {
|
||||
const { points, lineId, width, clip } = action.payload;
|
||||
state.inpaintMask.objects.push({
|
||||
id: getBrushLineId(state.inpaintMask.id, lineId),
|
||||
type: 'brush_line',
|
||||
points,
|
||||
strokeWidth: width,
|
||||
color: RGBA_RED,
|
||||
clip,
|
||||
});
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.inpaintMask.imageCache = null;
|
||||
},
|
||||
prepare: (payload: Omit<BrushLineAddedArg, 'id'>) => ({
|
||||
payload: { ...payload, lineId: uuidv4() },
|
||||
}),
|
||||
},
|
||||
imBrushLineAdded2: (state, action: PayloadAction<{ brushLine: BrushLine }>) => {
|
||||
imBrushLineAdded: (state, action: PayloadAction<{ brushLine: BrushLine }>) => {
|
||||
const { brushLine } = action.payload;
|
||||
state.inpaintMask.objects.push(brushLine);
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
imEraserLineAdded2: (state, action: PayloadAction<{ eraserLine: EraserLine }>) => {
|
||||
imEraserLineAdded: (state, action: PayloadAction<{ eraserLine: EraserLine }>) => {
|
||||
const { eraserLine } = action.payload;
|
||||
state.inpaintMask.objects.push(eraserLine);
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
imRectShapeAdded2: (state, action: PayloadAction<{ rectShape: RectShape }>) => {
|
||||
imRectShapeAdded: (state, action: PayloadAction<{ rectShape: RectShape }>) => {
|
||||
const { rectShape } = action.payload;
|
||||
state.inpaintMask.objects.push(rectShape);
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
imEraserLineAdded: {
|
||||
reducer: (state, action: PayloadAction<Omit<EraserLineAddedArg, 'id'> & { lineId: string }>) => {
|
||||
const { points, lineId, width, clip } = action.payload;
|
||||
state.inpaintMask.objects.push({
|
||||
id: getEraserLineId(state.inpaintMask.id, lineId),
|
||||
type: 'eraser_line',
|
||||
points,
|
||||
strokeWidth: width,
|
||||
clip,
|
||||
});
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.inpaintMask.imageCache = null;
|
||||
},
|
||||
prepare: (payload: Omit<EraserLineAddedArg, 'id'>) => ({
|
||||
payload: { ...payload, lineId: uuidv4() },
|
||||
}),
|
||||
},
|
||||
imLinePointAdded: (state, action: PayloadAction<Omit<PointAddedToLineArg, 'id'>>) => {
|
||||
const { point } = action.payload;
|
||||
const lastObject = state.inpaintMask.objects[state.inpaintMask.objects.length - 1];
|
||||
if (!lastObject || !isLine(lastObject)) {
|
||||
return;
|
||||
}
|
||||
lastObject.points.push(...point);
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.inpaintMask.imageCache = null;
|
||||
},
|
||||
imRectAdded: {
|
||||
reducer: (state, action: PayloadAction<Omit<RectShapeAddedArg, 'id'> & { rectId: string }>) => {
|
||||
const { rect, rectId } = action.payload;
|
||||
if (rect.height === 0 || rect.width === 0) {
|
||||
// Ignore zero-area rectangles
|
||||
return;
|
||||
}
|
||||
state.inpaintMask.objects.push({
|
||||
type: 'rect_shape',
|
||||
id: getRectShapeId(state.inpaintMask.id, rectId),
|
||||
...rect,
|
||||
color: RGBA_RED,
|
||||
});
|
||||
state.inpaintMask.bboxNeedsUpdate = true;
|
||||
state.inpaintMask.imageCache = null;
|
||||
},
|
||||
prepare: (payload: Omit<RectShapeAddedArg, 'id'>) => ({ payload: { ...payload, rectId: uuidv4() } }),
|
||||
},
|
||||
} satisfies SliceCaseReducers<CanvasV2State>;
|
||||
|
@ -1,6 +1,5 @@
|
||||
import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit';
|
||||
import { moveOneToEnd, moveOneToStart, moveToEnd, moveToStart } from 'common/util/arrayUtils';
|
||||
import { getBrushLineId, getEraserLineId, getRectShapeId } from 'features/controlLayers/konva/naming';
|
||||
import type { IRect } from 'konva/lib/types';
|
||||
import type { ImageDTO } from 'services/api/types';
|
||||
import { assert } from 'tsafe';
|
||||
@ -8,18 +7,14 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import type {
|
||||
BrushLine,
|
||||
BrushLineAddedArg,
|
||||
CanvasV2State,
|
||||
EraserLine,
|
||||
EraserLineAddedArg,
|
||||
ImageObjectAddedArg,
|
||||
LayerEntity,
|
||||
PointAddedToLineArg,
|
||||
RectShape,
|
||||
RectShapeAddedArg,
|
||||
ScaleChangedArg,
|
||||
} from './types';
|
||||
import { imageDTOToImageObject, imageDTOToImageWithDims, isLine } from './types';
|
||||
import { imageDTOToImageObject, imageDTOToImageWithDims } from './types';
|
||||
|
||||
export const selectLayer = (state: CanvasV2State, id: string) => state.layers.entities.find((layer) => layer.id === id);
|
||||
export const selectLayerOrThrow = (state: CanvasV2State, id: string) => {
|
||||
@ -155,7 +150,7 @@ export const layersReducers = {
|
||||
moveToStart(state.layers.entities, layer);
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
layerBrushLineAdded2: (state, action: PayloadAction<{ id: string; brushLine: BrushLine }>) => {
|
||||
layerBrushLineAdded: (state, action: PayloadAction<{ id: string; brushLine: BrushLine }>) => {
|
||||
const { id, brushLine } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
@ -166,7 +161,7 @@ export const layersReducers = {
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
layerEraserLineAdded2: (state, action: PayloadAction<{ id: string; eraserLine: EraserLine }>) => {
|
||||
layerEraserLineAdded: (state, action: PayloadAction<{ id: string; eraserLine: EraserLine }>) => {
|
||||
const { id, eraserLine } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
@ -177,7 +172,7 @@ export const layersReducers = {
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
layerRectShapeAdded2: (state, action: PayloadAction<{ id: string; rectShape: RectShape }>) => {
|
||||
layerRectShapeAdded: (state, action: PayloadAction<{ id: string; rectShape: RectShape }>) => {
|
||||
const { id, rectShape } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
@ -188,29 +183,6 @@ export const layersReducers = {
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
layerBrushLineAdded: {
|
||||
reducer: (state, action: PayloadAction<BrushLineAddedArg & { lineId: string }>) => {
|
||||
const { id, points, lineId, color, width, clip } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
|
||||
layer.objects.push({
|
||||
id: getBrushLineId(id, lineId),
|
||||
type: 'brush_line',
|
||||
points,
|
||||
strokeWidth: width,
|
||||
color,
|
||||
clip,
|
||||
});
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
prepare: (payload: BrushLineAddedArg) => ({
|
||||
payload: { ...payload, lineId: uuidv4() },
|
||||
}),
|
||||
},
|
||||
layerScaled: (state, action: PayloadAction<ScaleChangedArg>) => {
|
||||
const { id, scale, x, y } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
@ -241,64 +213,6 @@ export const layersReducers = {
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
layerEraserLineAdded: {
|
||||
reducer: (state, action: PayloadAction<EraserLineAddedArg & { lineId: string }>) => {
|
||||
const { id, points, lineId, width, clip } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
|
||||
layer.objects.push({
|
||||
id: getEraserLineId(id, lineId),
|
||||
type: 'eraser_line',
|
||||
points,
|
||||
strokeWidth: width,
|
||||
clip,
|
||||
});
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
prepare: (payload: EraserLineAddedArg) => ({
|
||||
payload: { ...payload, lineId: uuidv4() },
|
||||
}),
|
||||
},
|
||||
layerLinePointAdded: (state, action: PayloadAction<PointAddedToLineArg>) => {
|
||||
const { id, point } = action.payload;
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
const lastObject = layer.objects[layer.objects.length - 1];
|
||||
if (!lastObject || !isLine(lastObject)) {
|
||||
return;
|
||||
}
|
||||
lastObject.points.push(...point);
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
layerRectAdded: {
|
||||
reducer: (state, action: PayloadAction<RectShapeAddedArg & { rectId: string }>) => {
|
||||
const { id, rect, rectId, color } = action.payload;
|
||||
if (rect.height === 0 || rect.width === 0) {
|
||||
// Ignore zero-area rectangles
|
||||
return;
|
||||
}
|
||||
const layer = selectLayer(state, id);
|
||||
if (!layer) {
|
||||
return;
|
||||
}
|
||||
layer.objects.push({
|
||||
type: 'rect_shape',
|
||||
id: getRectShapeId(id, rectId),
|
||||
...rect,
|
||||
color,
|
||||
});
|
||||
layer.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
prepare: (payload: RectShapeAddedArg) => ({ payload: { ...payload, rectId: uuidv4() } }),
|
||||
},
|
||||
layerImageAdded: {
|
||||
reducer: (
|
||||
state,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import type { PayloadAction, SliceCaseReducers } from '@reduxjs/toolkit';
|
||||
import { moveOneToEnd, moveOneToStart, moveToEnd, moveToStart } from 'common/util/arrayUtils';
|
||||
import { getBrushLineId, getEraserLineId, getRectShapeId } from 'features/controlLayers/konva/naming';
|
||||
import type {
|
||||
BrushLine,
|
||||
CanvasV2State,
|
||||
@ -10,7 +9,7 @@ import type {
|
||||
RectShape,
|
||||
ScaleChangedArg,
|
||||
} from 'features/controlLayers/store/types';
|
||||
import { imageDTOToImageObject, imageDTOToImageWithDims, RGBA_RED } from 'features/controlLayers/store/types';
|
||||
import { imageDTOToImageObject, imageDTOToImageWithDims } from 'features/controlLayers/store/types';
|
||||
import { zModelIdentifierField } from 'features/nodes/types/common';
|
||||
import type { ParameterAutoNegative } from 'features/parameters/types/parameterSchemas';
|
||||
import type { IRect } from 'konva/lib/types';
|
||||
@ -19,16 +18,7 @@ import type { ImageDTO, IPAdapterModelConfig } from 'services/api/types';
|
||||
import { assert } from 'tsafe';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import type {
|
||||
BrushLineAddedArg,
|
||||
EraserLineAddedArg,
|
||||
IPAdapterEntity,
|
||||
PointAddedToLineArg,
|
||||
RectShapeAddedArg,
|
||||
RegionEntity,
|
||||
RgbColor,
|
||||
} from './types';
|
||||
import { isLine } from './types';
|
||||
import type { IPAdapterEntity, RegionEntity, RgbColor } from './types';
|
||||
|
||||
export const selectRG = (state: CanvasV2State, id: string) => state.regions.entities.find((rg) => rg.id === id);
|
||||
export const selectRGOrThrow = (state: CanvasV2State, id: string) => {
|
||||
@ -340,29 +330,7 @@ export const regionsReducers = {
|
||||
}
|
||||
ipa.clipVisionModel = clipVisionModel;
|
||||
},
|
||||
rgBrushLineAdded: {
|
||||
reducer: (state, action: PayloadAction<BrushLineAddedArg & { lineId: string }>) => {
|
||||
const { id, points, lineId, width, clip } = action.payload;
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
return;
|
||||
}
|
||||
rg.objects.push({
|
||||
id: getBrushLineId(id, lineId),
|
||||
type: 'brush_line',
|
||||
points,
|
||||
strokeWidth: width,
|
||||
color: RGBA_RED,
|
||||
clip,
|
||||
});
|
||||
rg.bboxNeedsUpdate = true;
|
||||
rg.imageCache = null;
|
||||
},
|
||||
prepare: (payload: BrushLineAddedArg) => ({
|
||||
payload: { ...payload, lineId: uuidv4() },
|
||||
}),
|
||||
},
|
||||
rgBrushLineAdded2: (state, action: PayloadAction<{ id: string; brushLine: BrushLine }>) => {
|
||||
rgBrushLineAdded: (state, action: PayloadAction<{ id: string; brushLine: BrushLine }>) => {
|
||||
const { id, brushLine } = action.payload;
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
@ -373,7 +341,7 @@ export const regionsReducers = {
|
||||
rg.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
rgEraserLineAdded2: (state, action: PayloadAction<{ id: string; eraserLine: EraserLine }>) => {
|
||||
rgEraserLineAdded: (state, action: PayloadAction<{ id: string; eraserLine: EraserLine }>) => {
|
||||
const { id, eraserLine } = action.payload;
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
@ -384,7 +352,7 @@ export const regionsReducers = {
|
||||
rg.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
rgRectShapeAdded2: (state, action: PayloadAction<{ id: string; rectShape: RectShape }>) => {
|
||||
rgRectShapeAdded: (state, action: PayloadAction<{ id: string; rectShape: RectShape }>) => {
|
||||
const { id, rectShape } = action.payload;
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
@ -395,61 +363,4 @@ export const regionsReducers = {
|
||||
rg.bboxNeedsUpdate = true;
|
||||
state.layers.imageCache = null;
|
||||
},
|
||||
rgEraserLineAdded: {
|
||||
reducer: (state, action: PayloadAction<EraserLineAddedArg & { lineId: string }>) => {
|
||||
const { id, points, lineId, width, clip } = action.payload;
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
return;
|
||||
}
|
||||
rg.objects.push({
|
||||
id: getEraserLineId(id, lineId),
|
||||
type: 'eraser_line',
|
||||
points,
|
||||
strokeWidth: width,
|
||||
clip,
|
||||
});
|
||||
rg.bboxNeedsUpdate = true;
|
||||
rg.imageCache = null;
|
||||
},
|
||||
prepare: (payload: EraserLineAddedArg) => ({
|
||||
payload: { ...payload, lineId: uuidv4() },
|
||||
}),
|
||||
},
|
||||
rgLinePointAdded: (state, action: PayloadAction<PointAddedToLineArg>) => {
|
||||
const { id, point } = action.payload;
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
return;
|
||||
}
|
||||
const lastObject = rg.objects[rg.objects.length - 1];
|
||||
if (!lastObject || !isLine(lastObject)) {
|
||||
return;
|
||||
}
|
||||
lastObject.points.push(...point);
|
||||
rg.bboxNeedsUpdate = true;
|
||||
rg.imageCache = null;
|
||||
},
|
||||
rgRectAdded: {
|
||||
reducer: (state, action: PayloadAction<RectShapeAddedArg & { rectId: string }>) => {
|
||||
const { id, rect, rectId } = action.payload;
|
||||
if (rect.height === 0 || rect.width === 0) {
|
||||
// Ignore zero-area rectangles
|
||||
return;
|
||||
}
|
||||
const rg = selectRG(state, id);
|
||||
if (!rg) {
|
||||
return;
|
||||
}
|
||||
rg.objects.push({
|
||||
type: 'rect_shape',
|
||||
id: getRectShapeId(id, rectId),
|
||||
...rect,
|
||||
color: RGBA_RED,
|
||||
});
|
||||
rg.bboxNeedsUpdate = true;
|
||||
rg.imageCache = null;
|
||||
},
|
||||
prepare: (payload: RectShapeAddedArg) => ({ payload: { ...payload, rectId: uuidv4() } }),
|
||||
},
|
||||
} satisfies SliceCaseReducers<CanvasV2State>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user