Unify Brush and Eraser Sizes

This commit is contained in:
blessedcoolant 2022-11-18 22:36:17 +13:00
parent a96af7a15d
commit 2bda3d6d2f
4 changed files with 13 additions and 20 deletions

View File

@ -13,7 +13,6 @@ const canvasBrushPreviewSelector = createSelector(
cursorPosition, cursorPosition,
stageDimensions: { width, height }, stageDimensions: { width, height },
brushSize, brushSize,
eraserSize,
maskColor, maskColor,
brushColor, brushColor,
tool, tool,
@ -28,7 +27,7 @@ const canvasBrushPreviewSelector = createSelector(
cursorPosition, cursorPosition,
width, width,
height, height,
radius: tool === 'brush' ? brushSize / 2 : eraserSize / 2, radius: brushSize / 2,
brushColorString: rgbaColorToString( brushColorString: rgbaColorToString(
layer === 'mask' ? { ...maskColor, a: 0.5 } : brushColor layer === 'mask' ? { ...maskColor, a: 0.5 } : brushColor
), ),

View File

@ -1,5 +1,5 @@
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { setEraserSize, setTool } from 'features/canvas/store/canvasSlice'; import { setBrushSize, setTool } from 'features/canvas/store/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';
@ -16,11 +16,11 @@ import {
export const selector = createSelector( export const selector = createSelector(
[canvasSelector, isStagingSelector], [canvasSelector, isStagingSelector],
(canvas, isStaging) => { (canvas, isStaging) => {
const { eraserSize, tool } = canvas; const { brushSize, tool } = canvas;
return { return {
tool, tool,
eraserSize, brushSize,
isStaging, isStaging,
}; };
}, },
@ -32,7 +32,7 @@ export const selector = createSelector(
); );
const IAICanvasEraserButtonPopover = () => { const IAICanvasEraserButtonPopover = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const { tool, eraserSize, isStaging } = useAppSelector(selector); const { tool, brushSize, isStaging } = useAppSelector(selector);
const handleSelectEraserTool = () => dispatch(setTool('eraser')); const handleSelectEraserTool = () => dispatch(setTool('eraser'));
@ -51,25 +51,25 @@ const IAICanvasEraserButtonPopover = () => {
useHotkeys( useHotkeys(
['['], ['['],
() => { () => {
dispatch(setEraserSize(Math.max(eraserSize - 5, 5))); dispatch(setBrushSize(Math.max(brushSize - 5, 5)));
}, },
{ {
enabled: () => true, enabled: () => true,
preventDefault: true, preventDefault: true,
}, },
[eraserSize] [brushSize]
); );
useHotkeys( useHotkeys(
[']'], [']'],
() => { () => {
dispatch(setEraserSize(Math.min(eraserSize + 5, 500))); dispatch(setBrushSize(Math.min(brushSize + 5, 500)));
}, },
{ {
enabled: () => true, enabled: () => true,
preventDefault: true, preventDefault: true,
}, },
[eraserSize] [brushSize]
); );
return ( return (
@ -89,9 +89,9 @@ const IAICanvasEraserButtonPopover = () => {
<Flex minWidth={'15rem'} direction={'column'} gap={'1rem'}> <Flex minWidth={'15rem'} direction={'column'} gap={'1rem'}>
<IAISlider <IAISlider
label="Size" label="Size"
value={eraserSize} value={brushSize}
withInput withInput
onChange={(newSize) => dispatch(setEraserSize(newSize))} onChange={(newSize) => dispatch(setBrushSize(newSize))}
/> />
</Flex> </Flex>
</IAIPopover> </IAIPopover>

View File

@ -47,7 +47,6 @@ const initialCanvasState: CanvasState = {
canvasContainerDimensions: { width: 0, height: 0 }, canvasContainerDimensions: { width: 0, height: 0 },
cursorPosition: null, cursorPosition: null,
doesCanvasNeedScaling: false, doesCanvasNeedScaling: false,
eraserSize: 50,
futureLayerStates: [], futureLayerStates: [],
inpaintReplace: 0.1, inpaintReplace: 0.1,
isCanvasInitialized: false, isCanvasInitialized: false,
@ -115,9 +114,6 @@ export const canvasSlice = createSlice({
setBrushSize: (state, action: PayloadAction<number>) => { setBrushSize: (state, action: PayloadAction<number>) => {
state.brushSize = action.payload; state.brushSize = action.payload;
}, },
setEraserSize: (state, action: PayloadAction<number>) => {
state.eraserSize = action.payload;
},
clearMask: (state) => { clearMask: (state) => {
state.pastLayerStates.push(state.layerState); state.pastLayerStates.push(state.layerState);
state.layerState.objects = state.layerState.objects.filter( state.layerState.objects = state.layerState.objects.filter(
@ -275,11 +271,11 @@ export const canvasSlice = createSlice({
}; };
}, },
addLine: (state, action: PayloadAction<number[]>) => { addLine: (state, action: PayloadAction<number[]>) => {
const { tool, layer, brushColor, brushSize, eraserSize } = state; const { tool, layer, brushColor, brushSize } = state;
if (tool === 'move') return; if (tool === 'move') return;
const newStrokeWidth = tool === 'brush' ? brushSize / 2 : eraserSize / 2; const newStrokeWidth = brushSize / 2;
// set & then spread this to only conditionally add the "color" key // set & then spread this to only conditionally add the "color" key
const newColor = const newColor =
@ -608,7 +604,6 @@ export const {
setLayer, setLayer,
setBrushColor, setBrushColor,
setBrushSize, setBrushSize,
setEraserSize,
addLine, addLine,
addPointToCurrentLine, addPointToCurrentLine,
setShouldPreserveMaskedArea, setShouldPreserveMaskedArea,

View File

@ -76,7 +76,6 @@ export interface CanvasState {
canvasContainerDimensions: Dimensions; canvasContainerDimensions: Dimensions;
cursorPosition: Vector2d | null; cursorPosition: Vector2d | null;
doesCanvasNeedScaling: boolean; doesCanvasNeedScaling: boolean;
eraserSize: number;
futureLayerStates: CanvasLayerState[]; futureLayerStates: CanvasLayerState[];
inpaintReplace: number; inpaintReplace: number;
intermediateImage?: InvokeAI.Image; intermediateImage?: InvokeAI.Image;