mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
tidy(ui): remove layer scaling reducers
This commit is contained in:
parent
68af60e12e
commit
8ff92796df
@ -32,7 +32,6 @@ import {
|
|||||||
layerImageCacheChanged,
|
layerImageCacheChanged,
|
||||||
layerRectShapeAdded,
|
layerRectShapeAdded,
|
||||||
layerReset,
|
layerReset,
|
||||||
layerScaled,
|
|
||||||
layerTranslated,
|
layerTranslated,
|
||||||
rgBboxChanged,
|
rgBboxChanged,
|
||||||
rgBrushLineAdded,
|
rgBrushLineAdded,
|
||||||
@ -91,9 +90,7 @@ export class CanvasStateApi {
|
|||||||
};
|
};
|
||||||
onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntity['type']) => {
|
onScaleChanged = (arg: ScaleChangedArg, entityType: CanvasEntity['type']) => {
|
||||||
log.debug('onScaleChanged');
|
log.debug('onScaleChanged');
|
||||||
if (entityType === 'layer') {
|
if (entityType === 'inpaint_mask') {
|
||||||
this.store.dispatch(layerScaled(arg));
|
|
||||||
} else if (entityType === 'inpaint_mask') {
|
|
||||||
this.store.dispatch(imScaled(arg));
|
this.store.dispatch(imScaled(arg));
|
||||||
} else if (entityType === 'regional_guidance') {
|
} else if (entityType === 'regional_guidance') {
|
||||||
this.store.dispatch(rgScaled(arg));
|
this.store.dispatch(rgScaled(arg));
|
||||||
|
@ -66,7 +66,6 @@ const initialState: CanvasV2State = {
|
|||||||
eraser: {
|
eraser: {
|
||||||
width: 50,
|
width: 50,
|
||||||
},
|
},
|
||||||
isTransforming: false,
|
|
||||||
},
|
},
|
||||||
bbox: {
|
bbox: {
|
||||||
rect: { x: 0, y: 0, width: 512, height: 512 },
|
rect: { x: 0, y: 0, width: 512, height: 512 },
|
||||||
@ -221,7 +220,6 @@ export const {
|
|||||||
layerImageAdded,
|
layerImageAdded,
|
||||||
layerAllDeleted,
|
layerAllDeleted,
|
||||||
layerImageCacheChanged,
|
layerImageCacheChanged,
|
||||||
layerScaled,
|
|
||||||
layerBrushLineAdded,
|
layerBrushLineAdded,
|
||||||
layerEraserLineAdded,
|
layerEraserLineAdded,
|
||||||
layerRectShapeAdded,
|
layerRectShapeAdded,
|
||||||
|
@ -16,7 +16,6 @@ import type {
|
|||||||
LayerEntity,
|
LayerEntity,
|
||||||
PositionChangedArg,
|
PositionChangedArg,
|
||||||
RectShape,
|
RectShape,
|
||||||
ScaleChangedArg,
|
|
||||||
} from './types';
|
} from './types';
|
||||||
import { imageDTOToImageObject, imageDTOToImageWithDims } from './types';
|
import { imageDTOToImageObject, imageDTOToImageWithDims } from './types';
|
||||||
|
|
||||||
@ -179,35 +178,6 @@ export const layersReducers = {
|
|||||||
layer.objects.push(rectShape);
|
layer.objects.push(rectShape);
|
||||||
state.layers.imageCache = null;
|
state.layers.imageCache = null;
|
||||||
},
|
},
|
||||||
layerScaled: (state, action: PayloadAction<ScaleChangedArg>) => {
|
|
||||||
const { id, scale, position } = action.payload;
|
|
||||||
const layer = selectLayer(state, id);
|
|
||||||
if (!layer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const obj of layer.objects) {
|
|
||||||
if (obj.type === 'brush_line') {
|
|
||||||
obj.points = obj.points.map((point) => Math.round(point * scale));
|
|
||||||
obj.strokeWidth = Math.round(obj.strokeWidth * scale);
|
|
||||||
} else if (obj.type === 'eraser_line') {
|
|
||||||
obj.points = obj.points.map((point) => Math.round(point * scale));
|
|
||||||
obj.strokeWidth = Math.round(obj.strokeWidth * scale);
|
|
||||||
} else if (obj.type === 'rect_shape') {
|
|
||||||
obj.x = Math.round(obj.x * scale);
|
|
||||||
obj.y = Math.round(obj.y * scale);
|
|
||||||
obj.height = Math.round(obj.height * scale);
|
|
||||||
obj.width = Math.round(obj.width * scale);
|
|
||||||
} else if (obj.type === 'image') {
|
|
||||||
obj.x = Math.round(obj.x * scale);
|
|
||||||
obj.y = Math.round(obj.y * scale);
|
|
||||||
obj.height = Math.round(obj.height * scale);
|
|
||||||
obj.width = Math.round(obj.width * scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
layer.position.x = Math.round(position.x);
|
|
||||||
layer.position.y = Math.round(position.y);
|
|
||||||
state.layers.imageCache = null;
|
|
||||||
},
|
|
||||||
layerImageAdded: (
|
layerImageAdded: (
|
||||||
state,
|
state,
|
||||||
action: PayloadAction<ImageObjectAddedArg & { objectId: string; pos?: { x: number; y: number } }>
|
action: PayloadAction<ImageObjectAddedArg & { objectId: string; pos?: { x: number; y: number } }>
|
||||||
@ -240,12 +210,3 @@ export const layersReducers = {
|
|||||||
state.layers.imageCache = null;
|
state.layers.imageCache = null;
|
||||||
},
|
},
|
||||||
} satisfies SliceCaseReducers<CanvasV2State>;
|
} satisfies SliceCaseReducers<CanvasV2State>;
|
||||||
|
|
||||||
const scalePoints = (points: number[], scaleX: number, scaleY: number) => {
|
|
||||||
const newPoints: number[] = [];
|
|
||||||
for (let i = 0; i < points.length; i += 2) {
|
|
||||||
newPoints.push(points[i]! * scaleX);
|
|
||||||
newPoints.push(points[i + 1]! * scaleY);
|
|
||||||
}
|
|
||||||
return newPoints;
|
|
||||||
};
|
|
||||||
|
Loading…
Reference in New Issue
Block a user