みてるぞ 4 days ago
parent
commit
f1770b31f5
1 changed files with 16 additions and 9 deletions
  1. +16
    -9
      frontend/src/components/threads/ThreadCanvas.tsx

+ 16
- 9
frontend/src/components/threads/ThreadCanvas.tsx View File

@@ -68,11 +68,18 @@ export default () => {
const activeLayer = layers.find (l => l.id === activeLayerId) const activeLayer = layers.find (l => l.id === activeLayerId)


const handleMouseDown = (ev: Konva.KonvaEventObject<MouseEvent | TouchEvent>) => { const handleMouseDown = (ev: Konva.KonvaEventObject<MouseEvent | TouchEvent>) => {
const pos = ev.target.getStage ()?.getPointerPosition ()
if (!(pos) || !(activeLayer))
if (!(activeLayer))
return return


drawingRef.current = true drawingRef.current = true

updateActiveLayerHistory ([...activeLayer.history, activeLayer.lines])
updateActiveLayerFuture ([])

const pos = ev.target.getStage ()?.getPointerPosition ()
if (!(pos))
return

const lines: Line[] = [ const lines: Line[] = [
...activeLayer.lines, ...activeLayer.lines,
{ mode, { mode,
@@ -106,20 +113,20 @@ export default () => {
if (!(activeLayer) || activeLayer.lines.length === 0) if (!(activeLayer) || activeLayer.lines.length === 0)
return return


const prev = activeLayer.lines.slice (0, -1)
const popped = activeLayer.lines[activeLayer.lines.length - 1]
updateActiveLayerHistory ([...activeLayer.history, activeLayer.lines])
updateActiveLayerFuture ([popped, ...activeLayer.future])
const prev = activeLayer.history[activeLayer.history.length - 1]
updateActiveLayerFuture ([...activeLayer.future, activeLayer.lines])
updateActiveLayerLines (prev) updateActiveLayerLines (prev)
updateActiveLayerHistory (activeLayer.history.slice (0, -1))
} }


const handleRedo = () => { const handleRedo = () => {
if (!(activeLayer) || activeLayer.future.length === 0) if (!(activeLayer) || activeLayer.future.length === 0)
return return


const [redoStroke, ...rest] = activeLayer.future
updateActiveLayerLines ([...activeLayer.lines, redoStroke])
updateActiveLayerFuture (rest)
const next = activeLayer.future[activeLayer.future.length - 1]
updateActiveLayerHistory ([...activeLayer.history, activeLayer.lines])
updateActiveLayerLines (next)
updateActiveLayerFuture (activeLayer.future.slice (0, -1))
} }


const handleImportImage: ChangeEventHandler<HTMLInputElement> = ev => { const handleImportImage: ChangeEventHandler<HTMLInputElement> = ev => {


Loading…
Cancel
Save