web: give a mask its knobs as rulers and let the ramp be turned
A mask's knobs were a card of small sliders side by side, three abreast under the colour they were moving, which is the shape the mixer needs because its whole point is reading three bands at once. A mask has nothing to read against: its knobs are a list, and the strip beside the photo has always had the shape for a list — the ruler, one parameter to a row, with its own name, its own value and the width to aim with. So the card goes and the rows come: EXPOSURE, CONTRAST, SATURATION, and FEATHER below them for the shape that fades over one, each the same ruler the FX panel opens, stacked in the mask's own column next to the chip that says which shape is chosen. Only the ramp could be moved and not aimed. An ellipse is stored as an angle, so turning it is writing a new one; a line is stored as the two points it falls between, and turning one is moving both of them about their own middle by the same turn — which is the point of doing it that way: the length survives, the middle survives, and only the direction the gradient falls in changes. The turn handle a chosen ramp now wears hangs clear of its middle along the ramp's own normal, so it never sits on the pin the shape is dragged by, and the angle the hand asks for is measured in the photo's own pixels, so a quarter turn of the hand is a quarter turn of the ramp however the photo is shaped or zoomed. Both handles for both kinds now come out of one list and one map, which is how a ramp and an ellipse ended up wearing the same class, the round one that says "this turns me". ponytail: the ruler row takes no data-key of its own — the parameter's key is already on the chip that opened it, and the panel's fourth column opens a ruler under the same name a strip chip answers to, so a second element carrying it would make an existing selector ambiguous. The mask's rows are found by the label they print; if a probe ever needs to hook a row directly, the key belongs on the row and the panel's ruler needs its own name first. Highlights/Shadows and per-mask invert and range are still out, as before. Verified: tsc clean; mask-probe 42/0 on the dev server and again on 8090 — the three rows share an edge and stack, a linear mask carries no feather row, a radial one carries it fourth, and dragging the ramp's turn handle stands the gradient up the photo: 61 at the top and 244 at the bottom where it was 61 -> 244 across — brush-edit 33/0, heal-idle 23/0, heal-zoom-drag 28/0, landing/pro-gate/ award-column/otp-code/tone-curve all ALL PASS, backend 180/0.
This commit is contained in:
@@ -39,8 +39,9 @@ export interface SliderDef {
|
||||
onChange: (value: number) => void;
|
||||
// Double-clicking the track puts the parameter back to its default.
|
||||
onReset: () => void;
|
||||
// "<" — closes the ruler and reopens the strip it was launched from.
|
||||
onBack: () => void;
|
||||
// "<" — closes the ruler and reopens the strip it was launched from. Left out
|
||||
// by a panel that IS the strip: a mask's own column has nowhere to go back to.
|
||||
onBack?: () => void;
|
||||
}
|
||||
|
||||
export function ChipRow({ chips }: { chips: ChipDef[] }) {
|
||||
@@ -96,8 +97,13 @@ export function SliderRow({ slider }: { slider: SliderDef }) {
|
||||
return () => el.removeEventListener('wheel', onWheel);
|
||||
}, []);
|
||||
return (
|
||||
// No data-key on the row itself: the parameter's own key is already on the
|
||||
// chip that opened it, and a second element answering to it would make a
|
||||
// probe's own selector ambiguous.
|
||||
<div className="slider-row" ref={rowRef}>
|
||||
<button type="button" className="back" onClick={slider.onBack} aria-label="back"><</button>
|
||||
{slider.onBack ? (
|
||||
<button type="button" className="back" onClick={slider.onBack} aria-label="back"><</button>
|
||||
) : null}
|
||||
<div className="ruler">
|
||||
<div className="head">
|
||||
<span>{slider.label}</span>
|
||||
|
||||
@@ -167,7 +167,10 @@ const maskFromDrag = (
|
||||
// is projected onto the axis the handle rides, so a hand that wanders across it
|
||||
// does not shrink it — and its rotation handle sits on the +ry axis, so the
|
||||
// angle is simply the direction from the centre to the pointer, one quarter turn
|
||||
// back. 'move' takes the whole of it, the pin's own drag.
|
||||
// back. A line has no angle to store, so turning one is moving its two ends
|
||||
// about its own middle by the same turn, which keeps the ramp's length and its
|
||||
// place — the gradient falls in the new direction and nowhere else changes.
|
||||
// 'move' takes the whole of it, the pin's own drag.
|
||||
const maskDragged = (
|
||||
m: GradientMask,
|
||||
part: MaskPart,
|
||||
@@ -188,8 +191,26 @@ const maskDragged = (
|
||||
const ddy = p.fy - m.y;
|
||||
return { ...m, x: p.fx, y: p.fy, ex: m.ex + ddx, ey: m.ey + ddy };
|
||||
}
|
||||
case 'rot':
|
||||
return { ...m, angle: Math.atan2(dy, dx) - Math.PI / 2 };
|
||||
case 'rot': {
|
||||
if (m.kind === 'radial') return { ...m, angle: Math.atan2(dy, dx) - Math.PI / 2 };
|
||||
const cx = (m.x + m.ex) / 2;
|
||||
const cy = (m.y + m.ey) / 2;
|
||||
// The turn is asked for in the photo's own pixels, so the angle the hand
|
||||
// asks for and the angle the ramp lies at are measured the same way.
|
||||
const turn =
|
||||
Math.atan2((p.fy - cy) * box.height, (p.fx - cx) * box.width) -
|
||||
Math.atan2((m.ey - cy) * box.height, (m.ex - cx) * box.width);
|
||||
const ca = Math.cos(turn);
|
||||
const sa = Math.sin(turn);
|
||||
const spin = (x: number, y: number) => {
|
||||
const ox = (x - cx) * box.width;
|
||||
const oy = (y - cy) * box.height;
|
||||
return { x: cx + (ox * ca - oy * sa) / box.width, y: cy + (ox * sa + oy * ca) / box.height };
|
||||
};
|
||||
const s = spin(m.x, m.y);
|
||||
const e = spin(m.ex, m.ey);
|
||||
return { ...m, x: s.x, y: s.y, ex: e.x, ey: e.y };
|
||||
}
|
||||
case 'rx':
|
||||
return { ...m, rx: Math.max(MASK_MIN, Math.abs(dx * Math.cos(m.angle) + dy * Math.sin(m.angle)) / box.width) };
|
||||
default:
|
||||
@@ -991,19 +1012,30 @@ export function ImageStage({
|
||||
// renderer's own measurement, so an ellipse stays the same ellipse on any
|
||||
// photo shape), which is why a y offset is turned back into a fraction of the
|
||||
// height here. The rotation handle rides just outside the +ry axis, a fixed
|
||||
// number of SCREEN pixels clear of the rim, so it stays reachable at any zoom.
|
||||
// number of SCREEN pixels clear of the rim, so it stays reachable at any zoom;
|
||||
// a linear mask has no ry to hang it on, so it rides clear of the ramp's
|
||||
// middle along the ramp's own normal, the direction the gradient falls in.
|
||||
const maskGeom = (m: GradientMask) => {
|
||||
const u = { x: Math.cos(m.angle), y: Math.sin(m.angle) };
|
||||
const v = { x: -Math.sin(m.angle), y: Math.cos(m.angle) };
|
||||
const w = box?.width ?? 0;
|
||||
const h = box?.height ?? 0;
|
||||
const k = box && box.height > 0 ? box.width / box.height : 1;
|
||||
const clear = 24 / Math.max(1, view.s) / Math.max(1, w);
|
||||
const at = (dx: number, dy: number) => ({ x: m.x + dx, y: m.y + dy * k });
|
||||
// The point a shape is moved by: an ellipse's centre, the middle of a ramp —
|
||||
// which is what the pin sits on and what the handles are placed around.
|
||||
const pin = m.kind === 'linear' ? { x: (m.x + m.ex) / 2, y: (m.y + m.ey) / 2 } : { x: m.x, y: m.y };
|
||||
const at = (dx: number, dy: number) => ({ x: pin.x + dx, y: pin.y + dy * k });
|
||||
const rx = (m.ex - m.x) * w;
|
||||
const ry = (m.ey - m.y) * h;
|
||||
const len = Math.hypot(rx, ry) || 1;
|
||||
return {
|
||||
at,
|
||||
axis: (sx: number, sy: number) =>
|
||||
at(sx * m.rx * u.x + sy * m.ry * v.x, sx * m.rx * u.y + sy * m.ry * v.y),
|
||||
rot: at(v.x * (m.ry + clear), v.y * (m.ry + clear)),
|
||||
rot:
|
||||
m.kind === 'linear'
|
||||
? at((-ry / len) * clear, (rx / len) * clear)
|
||||
: at(v.x * (m.ry + clear), v.y * (m.ry + clear)),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1615,7 +1647,8 @@ export function ImageStage({
|
||||
them is chosen at all — and the chosen one adds the outline of what
|
||||
the render will do (the two ends of a linear ramp and the ramp
|
||||
between them; an ellipse and the inner ellipse its feather fades
|
||||
to) plus the handles that resize it. */}
|
||||
to) plus the handles that resize it and the one that turns it: the
|
||||
angle of an ellipse, or the direction a ramp falls in. */}
|
||||
{maskTool && !cropEditing && box ? (
|
||||
<div
|
||||
className="mask-layer"
|
||||
@@ -1669,40 +1702,32 @@ export function ImageStage({
|
||||
</span>
|
||||
))}
|
||||
{selMask && selGeom
|
||||
? selMask.kind === 'linear'
|
||||
? ([
|
||||
{ part: 'p0' as const, at: { x: selMask.x, y: selMask.y }, k: 'l0' },
|
||||
{ part: 'p1' as const, at: { x: selMask.ex, y: selMask.ey }, k: 'l1' },
|
||||
].map(({ part, at, k }) => (
|
||||
<span
|
||||
key={k}
|
||||
className="mask-handle"
|
||||
data-key={`mask-handle-${part}`}
|
||||
style={{ left: `${at.x * 100}%`, top: `${at.y * 100}%`, ...maskScale }}
|
||||
onPointerDown={(e) => grabMask(maskSel as number, part, e)}
|
||||
onPointerMove={moveMask}
|
||||
onPointerUp={endMask}
|
||||
onPointerCancel={endMask}
|
||||
/>
|
||||
)))
|
||||
: ([
|
||||
{ part: 'rx' as const, at: selGeom.axis(1, 0), k: 'x1' },
|
||||
{ part: 'rx' as const, at: selGeom.axis(-1, 0), k: 'x2' },
|
||||
{ part: 'ry' as const, at: selGeom.axis(0, 1), k: 'y1' },
|
||||
{ part: 'ry' as const, at: selGeom.axis(0, -1), k: 'y2' },
|
||||
{ part: 'rot' as const, at: selGeom.rot, k: 'rot' },
|
||||
].map(({ part, at, k }) => (
|
||||
<span
|
||||
key={k}
|
||||
className={`mask-handle${part === 'rot' ? ' rot' : ''}`}
|
||||
data-key={`mask-handle-${part}-${k}`}
|
||||
style={{ left: `${at.x * 100}%`, top: `${at.y * 100}%`, ...maskScale }}
|
||||
onPointerDown={(e) => grabMask(maskSel as number, part, e)}
|
||||
onPointerMove={moveMask}
|
||||
onPointerUp={endMask}
|
||||
onPointerCancel={endMask}
|
||||
/>
|
||||
)))
|
||||
? (selMask.kind === 'linear'
|
||||
? [
|
||||
{ part: 'p0' as const, at: { x: selMask.x, y: selMask.y }, k: 'p0' },
|
||||
{ part: 'p1' as const, at: { x: selMask.ex, y: selMask.ey }, k: 'p1' },
|
||||
// The ramp's angle, which is the direction it falls in.
|
||||
{ part: 'rot' as const, at: selGeom.rot, k: 'rot' },
|
||||
]
|
||||
: [
|
||||
{ part: 'rx' as const, at: selGeom.axis(1, 0), k: 'rx-x1' },
|
||||
{ part: 'rx' as const, at: selGeom.axis(-1, 0), k: 'rx-x2' },
|
||||
{ part: 'ry' as const, at: selGeom.axis(0, 1), k: 'ry-y1' },
|
||||
{ part: 'ry' as const, at: selGeom.axis(0, -1), k: 'ry-y2' },
|
||||
{ part: 'rot' as const, at: selGeom.rot, k: 'rot-rot' },
|
||||
]
|
||||
).map(({ part, at, k }) => (
|
||||
<span
|
||||
key={k}
|
||||
className={`mask-handle${part === 'rot' ? ' rot' : ''}`}
|
||||
data-key={`mask-handle-${k}`}
|
||||
style={{ left: `${at.x * 100}%`, top: `${at.y * 100}%`, ...maskScale }}
|
||||
onPointerDown={(e) => grabMask(maskSel as number, part, e)}
|
||||
onPointerMove={moveMask}
|
||||
onPointerUp={endMask}
|
||||
onPointerCancel={endMask}
|
||||
/>
|
||||
))
|
||||
: null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
Reference in New Issue
Block a user