From 028a63ea342d9cb1502c5f2787643dc5956d3e18 Mon Sep 17 00:00:00 2001 From: Sanster Date: Sun, 6 Feb 2022 19:52:45 +0800 Subject: [PATCH] use space to toggle pan mode --- lama_cleaner/app/src/Editor.tsx | 42 +++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/lama_cleaner/app/src/Editor.tsx b/lama_cleaner/app/src/Editor.tsx index 9361964..2036a64 100644 --- a/lama_cleaner/app/src/Editor.tsx +++ b/lama_cleaner/app/src/Editor.tsx @@ -71,6 +71,7 @@ export default function Editor(props: EditorProps) { const [historyLineCount, setHistoryLineCount] = useState([]) const [{ x, y }, setCoords] = useState({ x: -1, y: -1 }) const [showBrush, setShowBrush] = useState(false) + const [isPanning, setIsPanning] = useState(false) const [showOriginal, setShowOriginal] = useState(false) const [isInpaintingLoading, setIsInpaintingLoading] = useState(false) const [showSeparator, setShowSeparator] = useState(false) @@ -280,6 +281,9 @@ export default function Editor(props: EditorProps) { } const onMouseDrag = (ev: SyntheticEvent) => { + if (isPanning) { + return + } if (!isDraging) { return } @@ -290,6 +294,9 @@ export default function Editor(props: EditorProps) { } const onPointerUp = () => { + if (isPanning) { + return + } if (!original.src) { return } @@ -319,6 +326,9 @@ export default function Editor(props: EditorProps) { } const onMouseDown = (ev: SyntheticEvent) => { + if (isPanning) { + return + } if (!original.src) { return } @@ -409,11 +419,35 @@ export default function Editor(props: EditorProps) { } const toggleShowBrush = (newState: boolean) => { - if (newState !== showBrush) { + if (newState !== showBrush && !isPanning) { setShowBrush(newState) } } + const getCursor = useCallback(() => { + if (isPanning) { + return 'grab' + } + if (showBrush) { + return 'none' + } + return undefined + }, [showBrush, isPanning]) + + // Toggle clean/zoom tool on spacebar. + useKey( + ' ', + ev => { + ev?.preventDefault() + setShowBrush(!showBrush) + setIsPanning(!isPanning) + }, + { + event: 'keydown', + }, + [isPanning, showBrush] + ) + if (!original || !scale || !minScale) { return <> } @@ -435,7 +469,7 @@ export default function Editor(props: EditorProps) { viewportRef.current = r } }} - panning={{ disabled: true, velocityDisabled: true }} + panning={{ disabled: !isPanning, velocityDisabled: true }} wheel={{ step: 0.05 }} centerZoomedOut alignmentAnimation={{ disabled: true }} @@ -462,7 +496,7 @@ export default function Editor(props: EditorProps) { <> { e.preventDefault() }} @@ -514,7 +548,7 @@ export default function Editor(props: EditorProps) { - {showBrush && !isInpaintingLoading && ( + {showBrush && !isInpaintingLoading && !isPanning && (