Skip to content

Commit 5e38517

Browse files
committed
Implement eraser drawing using destination-out mode
The eraser tool now uses the canvas 'destination-out' composite operation to visually erase drawn content, rather than being handled solely by element removal. Minor whitespace adjustments were also made.
1 parent f93abc3 commit 5e38517

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

lib/features/whiteboard/whiteboard-local.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ export function drawElement(
299299
drawText(ctx, element.text!, element.startPoint!, element.fontSize!, scale)
300300
break
301301
case "eraser":
302-
// Eraser is handled by removing elements, not drawing
302+
ctx.globalCompositeOperation = "destination-out"
303+
drawFreehand(ctx, element.points, scale)
304+
ctx.globalCompositeOperation = "source-over"
303305
break
304306
}
305307

@@ -431,7 +433,7 @@ export function getTouchPos(canvas: HTMLCanvasElement, evt: TouchEvent): Point {
431433

432434
export function clearCanvas(ctx: CanvasRenderingContext2D, width: number, height: number): void {
433435
ctx.clearRect(0, 0, width, height)
434-
436+
435437
// Set white background
436438
ctx.fillStyle = "#FFFFFF"
437439
ctx.fillRect(0, 0, width, height)
@@ -567,7 +569,7 @@ export function undo(state: WhiteboardState): WhiteboardState {
567569
if (state.undoStack.length === 0) return state
568570

569571
const previousElements = state.undoStack[state.undoStack.length - 1]
570-
572+
571573
return {
572574
...state,
573575
elements: previousElements,

0 commit comments

Comments
 (0)