Keep the brush guide round and show the feather in it.

The local brush cursor took its height from the canvas aspect and its width
from the frame window, so a cropped or zoomed photo drew an oval cursor
over a round mask, and the stroke preview was scaled the same wrong way.
Both now convert the brush radius through the visible frame on each axis,
which matches the baked mask at any crop or zoom.

The feather band was also invisible in the guide: the preview painted one
flat band and the cursor was a single ring. Painted strokes now show the
soft band under the solid core, and the cursor adds an inner ring at
1 - feather of the radius.

Masks shrink their width instead of clamping their height, so tall or wide
frames keep square mask pixels and round dabs.
This commit is contained in:
2026-11-28 17:09:02 +00:00
parent 69a327cd45
commit c05dbce580
4 changed files with 106 additions and 23 deletions
+56 -20
View File
@@ -2198,10 +2198,18 @@ export default function Develop({
y: ((f.y - view.y) / view.h) * 100,
};
};
const xScale = bitmap.width / (frame.w * view.w);
const canvasEl = canvasRef.current;
const canvasW = canvasEl?.clientWidth || 1;
const canvasH = canvasEl?.clientHeight || 1;
// A brush radius is a fraction of the source width, but the
// overlay's 100×100 box is stretched over the canvas, so the
// two axes are converted separately. Using one frame term for
// both (or the canvas aspect) turns the circle into an oval as
// soon as the photo is cropped or zoomed.
const radiusU = (r: number) => (r * bitmap.width * 100) / (frame.w * view.w);
const radiusV = (r: number) => (r * bitmap.width * 100) / (frame.h * view.h);
/** Brush diameter in canvas pixels, for the stroke preview. */
const diameterPx = (r: number) => (r * 2 * bitmap.width * canvasW) / (frame.w * view.w);
const feather = Math.max(0, Math.min(1, activeComponent.feather / 100));
const strokes = localDraft
? [...activeComponent.brush.strokes, localDraft]
: activeComponent.brush.strokes;
@@ -2211,15 +2219,25 @@ export default function Develop({
strokes.map((stroke, i) => {
if (!stroke.points.length) return null;
const points = stroke.points.map(marker).map((p) => `${p.x},${p.y}`).join(' ');
const width = Math.max(1, stroke.size * 2 * canvasW);
const width = Math.max(1, diameterPx(stroke.size));
const core = Math.max(1, width * (1 - feather));
return (
<polyline
key={i}
points={points}
className={`local-brush ${stroke.erase ? 'erase' : ''}`}
strokeWidth={width}
vectorEffect="non-scaling-stroke"
/>
<g key={i}>
{core < width - 0.5 && (
<polyline
points={points}
className={`local-brush band ${stroke.erase ? 'erase' : ''}`}
strokeWidth={width}
vectorEffect="non-scaling-stroke"
/>
)}
<polyline
points={points}
className={`local-brush ${stroke.erase ? 'erase' : ''}`}
strokeWidth={core}
vectorEffect="non-scaling-stroke"
/>
</g>
);
})}
{activeComponent.kind === 'radial' && (() => {
@@ -2266,16 +2284,34 @@ export default function Develop({
</g>
);
})()}
{activeComponent.kind === 'brush' && localHover && !localDrag.current && (
<ellipse
cx={marker(localHover).x}
cy={marker(localHover).y}
rx={localRadius() * xScale * 100}
ry={localRadius() * 100 * (canvasW / canvasH)}
className="local-cursor"
vectorEffect="non-scaling-stroke"
/>
)}
{activeComponent.kind === 'brush' && localHover && !localDrag.current && (() => {
const c = marker(localHover);
const r = localRadius();
// Feather is the soft band inside the rim, so the inner
// ring marks where the dab is still at full strength.
return (
<g>
<ellipse
cx={c.x}
cy={c.y}
rx={radiusU(r)}
ry={radiusV(r)}
className="local-cursor"
vectorEffect="non-scaling-stroke"
/>
{feather > 0.02 && (
<ellipse
cx={c.x}
cy={c.y}
rx={radiusU(r * (1 - feather))}
ry={radiusV(r * (1 - feather))}
className="local-cursor inner"
vectorEffect="non-scaling-stroke"
/>
)}
</g>
);
})()}
</svg>
);
})()}