Skip to content

feat(image-editor): wire Gradient (G) — drag to define linear gradient#40

Merged
lyfuci merged 1 commit intomainfrom
feat/image-editor-gradient
Apr 24, 2026
Merged

feat(image-editor): wire Gradient (G) — drag to define linear gradient#40
lyfuci merged 1 commit intomainfrom
feat/image-editor-gradient

Conversation

@lyfuci
Copy link
Copy Markdown
Owner

@lyfuci lyfuci commented Apr 24, 2026

Summary

Promotes the Gradient tool from stub to functional. Drag from start to
end on the canvas → linear FG→BG gradient lands as a new image-shape
layer covering the full canvas.

Implementation

  • New `Interaction` kind in `Canvas.tsx`: `gradient-drawing` (start +
    current end in canvas-pixel space). mousedown → start; mousemove →
    update end; mouseup → `onCommitGradient(start, end)` if the drag is
    non-trivial.
  • Live preview overlay (white dashed line + black-outlined endpoint
    dots) drawn after `renderTo`, identity transform for pixel-perfect
    placement. Same pattern as the crop overlay; never bleeds into export.
  • `ImageEditor.handleCommitGradient` shifts coords by crop origin if a
    crop is active, scales to source pixels, and renders the gradient via
    `ctx.createLinearGradient` onto a baseW × baseH canvas. SOURCE-res
    bitmap → sharp exports.
  • New `OptionsBar` variant: FG + BG color pickers + a hint reminding
    start = FG, end = BG.

Removes `gradient` from `STUB_TOOLS`.

Branched from `main` (independent of #38, #39).

Test plan

  • Press G — gradient variant appears in options bar with FG + BG color pickers.
  • Drag across canvas — dashed preview line shows from cursor-down to cursor.
  • Release — new layer appears, gradient goes from FG (start) to BG (end).
  • Switch FG/BG with X — next gradient swaps.
  • Crop the image first, then gradient inside the cropped view — gradient lands correctly within the crop.
  • Cmd+Z undoes the gradient layer.
  • Export PNG — gradient renders at source resolution (smooth, not blurry).
  • Save/reload .json — gradient layer round-trips.

🤖 Generated with Claude Code

Promotes the Gradient tool from stub to functional. Drag from start to
end on the canvas to define a linear gradient that goes FG → BG; result
lands as a new image-shape layer covering the full canvas.

- New \`Interaction\` kind in \`Canvas.tsx\`: \`gradient-drawing\` (start +
  current end in canvas-pixel space). mousedown → start; mousemove →
  update end; mouseup → call \`onCommitGradient(start, end)\` if the drag
  is non-trivial.
- Live preview overlay (white dashed line + black-outlined endpoint
  dots) drawn after \`renderTo\` so it sits on top, identity transform
  for pixel-perfect placement. Same pattern as the crop overlay; never
  bleeds into the export canvas.
- \`ImageEditor.handleCommitGradient\` re-derives source-pixel coords
  (shifting by crop origin if a crop is active) and renders a linear
  gradient using \`ctx.createLinearGradient\` onto a baseW × baseH
  canvas. The bitmap is stored at SOURCE resolution so exports are
  sharp; layer rect spans the full preview canvas.
- New \`OptionsBar\` variant: FG + BG color pickers and a hint reminding
  the user that the start gets FG and the end gets BG. Shape-tools
  variant signature gains \`bgColor\`/\`setBgColor\`.

Removes \`gradient\` from \`STUB_TOOLS\`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lyfuci lyfuci force-pushed the feat/image-editor-gradient branch from c026152 to 53fc2ee Compare April 24, 2026 11:03
@lyfuci lyfuci merged commit ceb7e63 into main Apr 24, 2026
2 checks passed
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