tidy(ui): remove extraneous cursor sync

This commit is contained in:
psychedelicious 2024-04-23 11:47:01 +10:00
parent 5196a2efec
commit fca718bdd3

View File

@ -38,15 +38,6 @@ export const getScaledFlooredCursorPosition = (stage: Konva.Stage) => {
}; };
}; };
const syncCursorPos = (stage: Konva.Stage) => {
const pos = getScaledFlooredCursorPosition(stage);
if (!pos) {
return null;
}
$cursorPosition.set(pos);
return pos;
};
export const useMouseEvents = () => { export const useMouseEvents = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const selectedLayerId = useAppSelector((s) => s.regionalPrompts.present.selectedLayerId); const selectedLayerId = useAppSelector((s) => s.regionalPrompts.present.selectedLayerId);
@ -61,7 +52,7 @@ export const useMouseEvents = () => {
if (!stage) { if (!stage) {
return; return;
} }
const pos = syncCursorPos(stage); const pos = $cursorPosition.get();
if (!pos) { if (!pos) {
return; return;
} }
@ -118,13 +109,14 @@ export const useMouseEvents = () => {
if (!stage) { if (!stage) {
return; return;
} }
const pos = syncCursorPos(stage); const pos = getScaledFlooredCursorPosition(stage);
if (!pos || !selectedLayerId) { if (!pos || !selectedLayerId) {
return; return;
} }
$cursorPosition.set(pos);
if (getIsFocused(stage) && $isMouseOver.get() && $isMouseDown.get() && (tool === 'brush' || tool === 'eraser')) { if (getIsFocused(stage) && $isMouseOver.get() && $isMouseDown.get() && (tool === 'brush' || tool === 'eraser')) {
if (lastCursorPosRef.current) { if (lastCursorPosRef.current) {
if (Math.hypot(lastCursorPosRef.current[0] - pos.x, lastCursorPosRef.current[1] - pos.y) < 10) { if (Math.hypot(lastCursorPosRef.current[0] - pos.x, lastCursorPosRef.current[1] - pos.y) < 20) {
return; return;
} }
} }
@ -152,7 +144,7 @@ export const useMouseEvents = () => {
return; return;
} }
$isMouseOver.set(true); $isMouseOver.set(true);
const pos = syncCursorPos(stage); const pos = $cursorPosition.get();
if (!pos) { if (!pos) {
return; return;
} }