feat(editor): edit the crop box on the preview, locked to the output proportions
The Camera step now shows its crop box on the Source picture with its mask on
by default, and the box is moved and resized right there (owner review 1, R5).
A press takes a handle within 6 px, then the wipe divider, then the inside of
the box, then pans; a resize stays anchored at the opposite corner or edge and
locked to the ratio, Alt resizes about the centre. Esc cancels a drag, and once
the box is taken (a press on it or Enter) the arrows, + and - nudge it. Cursors
follow the same priority and screen readers read "x, y, size" from a read-only
value pattern.
Each finished drag goes through CropCommit to CommitCropCommand as one undo
step; a run of key presses merges into one ("Camera.Crop"). The commit writes
the locked box with the offsets at 0, so the render keeps it as drawn. Editing
is gated on the Camera step, the mask on, an editable project, a current
format and frames to show.
PreviewRenderer frames Source through ViewFor, so the turned, mirrored and
straightened view frame is what the box is drawn on; the mask comes from
EditableCrop on the Camera step and FootprintInView elsewhere, and the horizon
overlay is mapped into the view. A straighten grid shows while IsStraightening.
xaml-lint now requires a tooltip on PreviewViewport.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aaf9c0bba7
commit
6f15717463
13 files changed
+1298
-65
No files matched your search
@@ -1,3 +1,4 @@
|
||||
using Chronos.Core.Imaging.Geometry;
|
||||
using Chronos.Testing;
|
||||
using Chronos.Ui.Visuals;
|
||||
|
||||
@@ -69,4 +70,75 @@ public sealed class ViewportMathTests
|
||||
Assert.Approximately(Math.Round(10.4 * 1.5), t.OffsetX * 1.5, 1e-9);
|
||||
Assert.Approximately(Math.Round(-3.1 * 1.5), t.OffsetY * 1.5, 1e-9);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ACropPressTakesAHandleWithinTheGripThenTheInsideAtEveryZoom()
|
||||
{
|
||||
// A 400×300 image with the box [0.25, 0.2, 0.5, 0.6]: the grip is 6 view units whatever the zoom.
|
||||
var crop = new RectD(0.25, 0.2, 0.5, 0.6);
|
||||
foreach (var view in new[] { new ViewTransform(0.25, 40, 10), new ViewTransform(1, -30, 5), new ViewTransform(4, -500, -300) })
|
||||
{
|
||||
CropHandle Hit(double nx, double ny, double dx, double dy)
|
||||
{
|
||||
var (x, y) = view.ToView(nx * 400, ny * 300);
|
||||
return ViewportMath.HitCrop(view, 400, 300, crop, x + dx, y + dy, 6);
|
||||
}
|
||||
var zoom = $"scale {view.Scale}";
|
||||
Assert.Equal(CropHandle.TopLeft, Hit(0.25, 0.2, -5, 4), zoom);
|
||||
Assert.Equal(CropHandle.BottomRight, Hit(0.75, 0.8, 6, -6), zoom);
|
||||
Assert.Equal(CropHandle.Top, Hit(0.5, 0.2, 3, -2), zoom);
|
||||
Assert.Equal(CropHandle.Left, Hit(0.25, 0.5, 2, 0), zoom);
|
||||
Assert.Equal(CropHandle.Inside, Hit(0.25, 0.5, 0, 7), "beside a handle, inside the box: a move");
|
||||
Assert.Equal(CropHandle.None, Hit(0.25, 0.5, -7, 0), "outside the box and the grip: a pan");
|
||||
Assert.Equal(CropHandle.Inside, Hit(0.5, 0.5, 0, 0), zoom);
|
||||
Assert.Equal(CropHandle.None, Hit(0.1, 0.1, 0, 0), zoom);
|
||||
}
|
||||
Assert.Equal(CropHandle.None, ViewportMath.HitCrop(new ViewTransform(0, 0, 0), 400, 300, crop, 0, 0, 6), "no view yet");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheNearestHandleWinsOnATinyBox()
|
||||
{
|
||||
// At 1/4 zoom a box of 40×30 image pixels is 10×7.5 view units: every handle is within the grip of the centre.
|
||||
var view = new ViewTransform(0.25, 0, 0);
|
||||
var crop = new RectD(0.45, 0.45, 0.1, 0.1);
|
||||
var (x, y) = view.ToView(0.55 * 400, 0.55 * 300);
|
||||
Assert.Equal(CropHandle.BottomRight, ViewportMath.HitCrop(view, 400, 300, crop, x - 1, y - 1, 6));
|
||||
var (cx, cy) = view.ToView(0.5 * 400, 0.45 * 300);
|
||||
Assert.Equal(CropHandle.Top, ViewportMath.HitCrop(view, 400, 300, crop, cx, cy + 0.5, 6));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheHandlesSitOnTheCornersAndTheEdgeMidpoints()
|
||||
{
|
||||
var crop = new RectD(0.1, 0.2, 0.4, 0.6);
|
||||
Assert.Count(8, ViewportMath.CropHandles);
|
||||
Assert.Within(0.1, 0.2, ViewportMath.HandleAt(crop, CropHandle.TopLeft).X, ViewportMath.HandleAt(crop, CropHandle.TopLeft).Y, 1e-12);
|
||||
Assert.Within(0.3, 0.8, ViewportMath.HandleAt(crop, CropHandle.Bottom).X, ViewportMath.HandleAt(crop, CropHandle.Bottom).Y, 1e-12);
|
||||
Assert.Within(0.5, 0.5, ViewportMath.HandleAt(crop, CropHandle.Right).X, ViewportMath.HandleAt(crop, CropHandle.Right).Y, 1e-12);
|
||||
Assert.Within(0.3, 0.5, ViewportMath.HandleAt(crop, CropHandle.Inside).X, ViewportMath.HandleAt(crop, CropHandle.Inside).Y, 1e-12);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PlusAndMinusResizeAboutTheCentreLockedAndWithinTheLimits()
|
||||
{
|
||||
const double ratio = 0.5;
|
||||
var largest = CropFrame.Largest(ratio);
|
||||
var box = CropFrame.FromRows(0.5, 0, 0, ratio);
|
||||
var grown = ViewportMath.ResizeCrop(box, 0.02, ratio);
|
||||
Assert.Approximately(box.Height + 0.02 * largest.Height, grown.Height, 1e-12);
|
||||
Assert.Approximately(ratio, grown.Width / grown.Height, 1e-12);
|
||||
Assert.Within(box.CenterX, box.CenterY, grown.CenterX, grown.CenterY, 1e-12);
|
||||
|
||||
var smallest = CropFrame.FromRows(CropFrame.MinimumShare, 0, 0, ratio);
|
||||
Assert.Approximately(smallest.Height, ViewportMath.ResizeCrop(smallest, -0.02, ratio).Height, 1e-12, "not below the minimum");
|
||||
var whole = ViewportMath.ResizeCrop(largest, 0.02, ratio);
|
||||
Assert.Approximately(largest.Height, whole.Height, 1e-12, "not beyond the largest box");
|
||||
|
||||
// At an edge the grown box moves back inside the view.
|
||||
var corner = CropFrame.FromRows(0.9, 1, 1, ratio);
|
||||
var pushed = ViewportMath.ResizeCrop(corner, 0.08, ratio);
|
||||
Assert.LessOrEqual(pushed.Right, 1 + 1e-12);
|
||||
Assert.LessOrEqual(pushed.Bottom, 1 + 1e-12);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user