Skip to content

Add free drawing mode for freehand canvas input#346

Open
olavl wants to merge 1 commit intojeffeb3:masterfrom
olavl:feature/free-drawing-mode
Open

Add free drawing mode for freehand canvas input#346
olavl wants to merge 1 commit intojeffeb3:masterfrom
olavl:feature/free-drawing-mode

Conversation

@olavl
Copy link

@olavl olavl commented Feb 18, 2026

Summary

  • Adds a draw mode toggle (pencil button) to the preview toolbar that lets users draw freehand on the canvas with mouse or touch
  • Mouse-up finalizes the stroke as a new Drawing layer with configurable Douglas-Peucker simplification and Chaikin corner-cutting smoothing
  • Drawing layers support free scaling (independent width/height) and all existing transforms and effects

How it works

  1. Click the pencil button to enter draw mode (cursor becomes crosshair)
  2. Click and drag on the canvas to draw a freehand stroke (live green preview)
  3. On mouse-up the stroke becomes a new "Drawing" layer in the sidebar
  4. Adjust simplification tolerance and smoothing iterations in the layer options
  5. Press Escape to cancel without creating a layer

Files changed

  • src/features/shapes/Drawing.js — new shape type with Douglas-Peucker + Chaikin smoothing
  • src/features/shapes/shapeFactory.js — register Drawing shape
  • src/features/preview/previewSlice.js — drawing mode state and actions
  • src/features/preview/previewSlice.spec.js — updated test for new initial state
  • src/features/preview/PreviewWindow.js — mouse/touch event handling and live stroke preview
  • src/features/preview/PreviewManager.js — draw toggle button and Escape key handling

Test plan

  • npm test — all 125 tests pass
  • vite build — production build succeeds
  • Draw on canvas with mouse, verify layer created
  • Draw on canvas with touch, verify layer created
  • Verify simplify and smoothing sliders work on Drawing layer
  • Verify layer can be moved, scaled (non-uniform), rotated
  • Verify effects can be applied to Drawing layers
  • Verify GCode export produces valid output
  • Verify Escape cancels drawing without creating a layer

🤖 Generated with Claude Code

Allow users to draw directly on the preview canvas with mouse or touch.
A pencil toggle button activates draw mode; mouse-up finalizes the stroke
as a new Drawing layer with Douglas-Peucker simplification and Chaikin
corner-cutting smoothing. Layers support free scaling and all existing
transforms/effects.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant