From af25d00964a571381cb4bd1605bfd0f00a527092 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:23:08 +1000 Subject: [PATCH] tidy(ui): use const for brush spacing --- .../src/features/regionalPrompts/hooks/mouseEventHooks.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/invokeai/frontend/web/src/features/regionalPrompts/hooks/mouseEventHooks.ts b/invokeai/frontend/web/src/features/regionalPrompts/hooks/mouseEventHooks.ts index 0bcd6f4e10..fc58de60ed 100644 --- a/invokeai/frontend/web/src/features/regionalPrompts/hooks/mouseEventHooks.ts +++ b/invokeai/frontend/web/src/features/regionalPrompts/hooks/mouseEventHooks.ts @@ -44,6 +44,8 @@ const syncCursorPos = (stage: Konva.Stage): Vector2d | null => { return pos; }; +const BRUSH_SPACING = 20; + export const useMouseEvents = () => { const dispatch = useAppDispatch(); const selectedLayerId = useAppSelector((s) => s.regionalPrompts.present.selectedLayerId); @@ -67,7 +69,6 @@ export const useMouseEvents = () => { if (!selectedLayerId) { return; } - // const tool = getTool(); if (tool === 'brush' || tool === 'eraser') { dispatch( maskLayerLineAdded({ @@ -121,7 +122,8 @@ export const useMouseEvents = () => { } if (getIsFocused(stage) && $isMouseOver.get() && $isMouseDown.get() && (tool === 'brush' || tool === 'eraser')) { if (lastCursorPosRef.current) { - if (Math.hypot(lastCursorPosRef.current[0] - pos.x, lastCursorPosRef.current[1] - pos.y) < 20) { + // Dispatching redux events impacts perf substantially - using brush spacing keeps dispatches to a reasonable number + if (Math.hypot(lastCursorPosRef.current[0] - pos.x, lastCursorPosRef.current[1] - pos.y) < BRUSH_SPACING) { return; } }