Polygon: Standard-Modus + Schließen-Button

- Polygon ist jetzt der Standard-Modus beim Öffnen
- Neuer Button "Polygon schließen" erscheint im Polygon-Modus
- Button aktiviert sich nach dem 2. gesetzten Punkt
- Klick schließt das Polygon automatisch (kein Doppelklick mehr nötig)
- Auswahl hinzufügen schließt offenes Polygon ebenfalls automatisch

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 21:07:51 +02:00
parent 83fdce80c7
commit 8219a5445c
2 changed files with 24 additions and 2 deletions

View File

@@ -13,6 +13,7 @@ const imageCache = new Map<string, HTMLImageElement>()
export interface DrawCanvasHandle { export interface DrawCanvasHandle {
getCurrentSelection: () => Selection | null getCurrentSelection: () => Selection | null
resetSelection: () => void resetSelection: () => void
closePolygon: () => void
} }
interface Props { interface Props {
@@ -200,7 +201,11 @@ export default forwardRef<DrawCanvasHandle, Props>(function DrawCanvas(
}, },
} }
} else { } else {
if (!isPolygonClosed.current || polygonPoints.current.length < 3) return null if (polygonPoints.current.length < 2) return null
if (!isPolygonClosed.current) {
isPolygonClosed.current = true
redraw()
}
return { return {
mode: 'polygon', mode: 'polygon',
polygon: polygonPoints.current.map(p => ({ polygon: polygonPoints.current.map(p => ({
@@ -219,6 +224,13 @@ export default forwardRef<DrawCanvasHandle, Props>(function DrawCanvas(
onHasSelectionRef.current(false) onHasSelectionRef.current(false)
redraw() redraw()
}, },
closePolygon() {
if (polygonPoints.current.length >= 2) {
isPolygonClosed.current = true
onHasSelectionRef.current(true)
redraw()
}
},
}), [redraw]) }), [redraw])
// Reset drawing when mode changes // Reset drawing when mode changes
@@ -306,6 +318,7 @@ export default forwardRef<DrawCanvasHandle, Props>(function DrawCanvas(
} }
polygonPoints.current.push({ x, y }) polygonPoints.current.push({ x, y })
isDragging.current = true isDragging.current = true
if (polygonPoints.current.length >= 2) onHasSelectionRef.current(true)
} }
redraw() redraw()
} }

View File

@@ -35,7 +35,7 @@ export default function DrawIt() {
const [userNotes, setUserNotes] = useState('') const [userNotes, setUserNotes] = useState('')
const [parentId, setParentId] = useState<string | null>(null) const [parentId, setParentId] = useState<string | null>(null)
const [editingNotes, setEditingNotes] = useState<{ id: string; notes: string } | null>(null) const [editingNotes, setEditingNotes] = useState<{ id: string; notes: string } | null>(null)
const [mode, setMode] = useState<'rect' | 'polygon'>('rect') const [mode, setMode] = useState<'rect' | 'polygon'>('polygon')
const [hasSelection, setHasSelection] = useState(false) const [hasSelection, setHasSelection] = useState(false)
const [saving, setSaving] = useState(false) const [saving, setSaving] = useState(false)
const [status, setStatus] = useState('') const [status, setStatus] = useState('')
@@ -258,6 +258,15 @@ export default function DrawIt() {
</label> </label>
</div> </div>
<div className="action-group"> <div className="action-group">
{mode === 'polygon' && (
<button
className="btn-primary btn-sm btn-block"
onClick={() => canvasRef.current?.closePolygon()}
disabled={!hasSelection}
>
Polygon schließen
</button>
)}
<button className="btn-ghost btn-sm btn-block" onClick={() => canvasRef.current?.resetSelection()}> <button className="btn-ghost btn-sm btn-block" onClick={() => canvasRef.current?.resetSelection()}>
Auswahl zurücksetzen Auswahl zurücksetzen
</button> </button>