feat(editor): visual crop, rotate/mirror/flip/straighten, colour looks (owner review 1 phase 4) (#26)
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
CI / Build and test (push) Successful in 8m19s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 12m9s
CI / PostgreSQL 16 integration (push) Successful in 7m49s
CI / PostgreSQL 17 integration (push) Successful in 7m19s
CI / Docker image (push) Successful in 46s
Release / Server image (push) Successful in 1m14s
Owner review 1 R5 + R6. Camera rotation, mirror, flip, straighten and crop handles locked to the output; an Exposure Look group; Export output size ("proportions win"); settings format 2 with older-node gates. Also fixes project text and hashes differing between Windows and Linux.
Closes #19
Closes #20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #26.
This commit is contained in:
1 parent
db389a54f2
commit
188b2c2e55
355 files changed
+10549
-1061
No files matched your search
@@ -278,6 +278,230 @@ public sealed class VisualsSmokeTests
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void ACropDragMovesThenResizesLockedAndIsReportedOncePerDrag() => WpfHost.Run(() =>
|
||||
{
|
||||
var preview = CropPreview(new Rect(0.3, 0.2, 0.3, 0.6), ratio: 0.5);
|
||||
Render(preview, 800, 450);
|
||||
var edits = new List<CropEditEventArgs>();
|
||||
preview.CropEditCompleted += (_, e) => edits.Add(e);
|
||||
|
||||
// Inside the box: a move; only the overlay follows the pointer until the button is released.
|
||||
preview.Press(At(preview, 0.45, 0.5));
|
||||
Assert.Equal(PreviewViewport.DragMode.MoveCrop, preview.Dragging);
|
||||
preview.DragTo(At(preview, 0.55, 0.55), aboutCentre: false);
|
||||
Assert.Empty(edits, "nothing is reported while dragging");
|
||||
Assert.Approximately(0.4, preview.ShownCrop.X, 1e-6, "the overlay follows");
|
||||
Assert.Approximately(0.3, preview.EditCrop.X, 0, "the box itself waits for the release");
|
||||
preview.EndDrag(commit: true);
|
||||
var moved = Assert.Contains(edits, _ => true).Crop;
|
||||
Assert.Within(0.4, 0.25, moved.X, moved.Y, 1e-6);
|
||||
Assert.False(edits[0].IsNudge);
|
||||
Assert.Equal(moved, preview.EditCrop, "the finished box is the edited one");
|
||||
|
||||
// The bottom-right handle, dragged far outside: anchored at the top-left corner, locked, clamped to the view.
|
||||
preview.Press(At(preview, 0.7, 0.85));
|
||||
Assert.Equal(PreviewViewport.DragMode.ResizeCrop, preview.Dragging);
|
||||
preview.DragTo(At(preview, 1.5, 1.5), aboutCentre: false);
|
||||
preview.EndDrag(commit: true);
|
||||
Assert.Count(2, edits);
|
||||
var resized = edits[1].Crop;
|
||||
Assert.Within(0.4, 0.25, resized.X, resized.Y, 1e-9, "anchored at the opposite corner");
|
||||
Assert.Approximately(0.5, resized.Width / resized.Height, 1e-9, "the ratio stays locked");
|
||||
Assert.Approximately(1, resized.Bottom, 1e-9, "as large as the view lets it be");
|
||||
Assert.LessOrEqual(resized.Right, 1);
|
||||
|
||||
// Alt resizes about the centre.
|
||||
preview.Press(At(preview, resized.Right, resized.Bottom));
|
||||
preview.DragTo(At(preview, resized.Right - 0.05, resized.Bottom - 0.1), aboutCentre: true);
|
||||
preview.EndDrag(commit: true);
|
||||
var centred = edits[2].Crop;
|
||||
Assert.Within(resized.X + resized.Width / 2, resized.Y + resized.Height / 2, centred.X + centred.Width / 2, centred.Y + centred.Height / 2, 1e-9);
|
||||
Assert.Approximately(0.5, centred.Width / centred.Height, 1e-9);
|
||||
|
||||
// A press released where it started, and a pan outside the box, report nothing.
|
||||
preview.Press(At(preview, centred.X + centred.Width / 2, centred.Y + centred.Height / 2));
|
||||
preview.EndDrag(commit: true);
|
||||
preview.Press(At(preview, 0.05, 0.05));
|
||||
Assert.Equal(PreviewViewport.DragMode.Pan, preview.Dragging);
|
||||
preview.DragTo(At(preview, 0.1, 0.1), aboutCentre: false);
|
||||
preview.EndDrag(commit: true);
|
||||
Assert.Count(3, edits);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void APressTakesAHandleThenTheDividerThenTheBoxThenPansAtEveryZoom() => WpfHost.Run(() =>
|
||||
{
|
||||
var preview = CropPreview(new Rect(0.4, 0.4, 0.2, 0.2), ratio: 1);
|
||||
preview.OriginalSource = Bitmap(2000, 1500);
|
||||
preview.IsCompareEnabled = true;
|
||||
preview.WipePosition = 0.5;
|
||||
Render(preview, 800, 450);
|
||||
var surface = Assert.NotNull(FindChild<PreviewSurface>(preview));
|
||||
foreach (var zoom in new double?[] { null, 1, 2 })
|
||||
{
|
||||
if (zoom is { } z) preview.Zoom = z;
|
||||
var label = zoom is null ? "fit" : $"zoom {zoom}";
|
||||
// The image column under the divider, and a box of 0.06 × 0.12 around it (corner handles well away).
|
||||
var divider = surface.ActualWidth / 2;
|
||||
var nx = preview.View.ToImage(divider, 0).X / 2000;
|
||||
var y = At(preview, 0, 0.5).Y;
|
||||
PreviewViewport.DragMode Take(Rect box, double x)
|
||||
{
|
||||
preview.EditCrop = box;
|
||||
preview.Press(new Point(x, y));
|
||||
var mode = preview.Dragging;
|
||||
preview.EndDrag(commit: false);
|
||||
return mode;
|
||||
}
|
||||
Assert.Equal(PreviewViewport.DragMode.ResizeCrop, Take(new Rect(nx, 0.44, 0.06, 0.12), divider), $"{label}: a handle on the divider");
|
||||
Assert.Equal(PreviewViewport.DragMode.Wipe, Take(new Rect(nx - 0.03, 0.44, 0.06, 0.12), divider), $"{label}: the divider inside the box");
|
||||
Assert.Equal(PreviewViewport.DragMode.MoveCrop, Take(new Rect(nx - 0.03, 0.44, 0.06, 0.12), At(preview, nx + 0.012, 0.5).X), $"{label}: inside");
|
||||
Assert.Equal(PreviewViewport.DragMode.Pan, Take(new Rect(nx - 0.03, 0.44, 0.06, 0.12), At(preview, nx + 0.06, 0.5).X), $"{label}: outside");
|
||||
}
|
||||
|
||||
// A box that spans the view both ways (no crop) cannot move: zoomed in, a press inside pans; the middle button pans
|
||||
// anywhere, inside a box that can move too.
|
||||
preview.IsCompareEnabled = false;
|
||||
preview.Zoom = 2;
|
||||
preview.EditCrop = new Rect(0, 0, 1, 1);
|
||||
preview.Press(At(preview, 0.5, 0.5));
|
||||
Assert.Equal(PreviewViewport.DragMode.Pan, preview.Dragging, "zoomed, the whole view: pan");
|
||||
preview.EndDrag(commit: false);
|
||||
preview.EditCrop = new Rect(0.4, 0.4, 0.2, 0.2);
|
||||
preview.PressPan(At(preview, 0.5, 0.5));
|
||||
Assert.Equal(PreviewViewport.DragMode.Pan, preview.Dragging, "middle button inside a box");
|
||||
preview.EndDrag(commit: false);
|
||||
|
||||
// Not editable: no handle and no box to take, the divider and pan only.
|
||||
preview.CropEditable = false;
|
||||
preview.EditCrop = new Rect(0.4, 0.4, 0.2, 0.2);
|
||||
preview.Press(At(preview, 0.4, 0.4));
|
||||
Assert.Equal(PreviewViewport.DragMode.Pan, preview.Dragging);
|
||||
preview.EndDrag(commit: false);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void EscCancelsADragAndTheKeysNudgeTheBoxOnceItIsTaken() => WpfHost.Run(() =>
|
||||
{
|
||||
var preview = CropPreview(new Rect(0.3, 0.2, 0.3, 0.6), ratio: 0.5);
|
||||
var window = OffScreen(preview, 800, 450);
|
||||
try
|
||||
{
|
||||
var edits = new List<CropEditEventArgs>();
|
||||
preview.CropEditCompleted += (_, e) => edits.Add(e);
|
||||
Assert.False(Press(preview, Key.Right), "until the box is taken, the arrows step frames");
|
||||
|
||||
// Esc cancels a drag: the box stays, nothing is reported.
|
||||
preview.Press(At(preview, 0.45, 0.5));
|
||||
preview.DragTo(At(preview, 0.6, 0.6), aboutCentre: false);
|
||||
Assert.True(Press(preview, Key.Escape));
|
||||
Assert.Equal(PreviewViewport.DragMode.None, preview.Dragging);
|
||||
Assert.Equal(new Rect(0.3, 0.2, 0.3, 0.6), preview.EditCrop);
|
||||
Assert.Equal(new Rect(0.3, 0.2, 0.3, 0.6), preview.ShownCrop);
|
||||
Assert.Empty(edits);
|
||||
|
||||
// The press took the box: the arrows move it 1 %, + and − resize it about its centre, each reported as a nudge.
|
||||
Assert.True(preview.IsCropSelected);
|
||||
Assert.True(Press(preview, Key.Right));
|
||||
Assert.Count(1, edits);
|
||||
Assert.True(edits[0].IsNudge);
|
||||
Assert.Approximately(0.31, preview.EditCrop.X, 1e-9);
|
||||
Assert.True(preview.Nudge(Key.Down, ModifierKeys.Shift), "Shift moves 10 %");
|
||||
Assert.Approximately(0.3, preview.EditCrop.Y, 1e-9);
|
||||
var before = preview.EditCrop;
|
||||
Assert.True(Press(preview, Key.OemMinus));
|
||||
var shrunk = preview.EditCrop;
|
||||
Assert.Less(shrunk.Height, before.Height);
|
||||
Assert.Approximately(0.5, shrunk.Width / shrunk.Height, 1e-9);
|
||||
Assert.Within(before.X + before.Width / 2, before.Y + before.Height / 2, shrunk.X + shrunk.Width / 2, shrunk.Y + shrunk.Height / 2, 1e-9);
|
||||
Assert.Count(3, edits);
|
||||
|
||||
// Esc gives the arrows back; Enter takes the box from the keyboard.
|
||||
Assert.True(Press(preview, Key.Escape));
|
||||
Assert.False(preview.IsCropSelected);
|
||||
Assert.False(Press(preview, Key.Left));
|
||||
Assert.True(Press(preview, Key.Enter));
|
||||
Assert.True(Press(preview, Key.Left));
|
||||
Assert.Count(4, edits);
|
||||
|
||||
// A box that can no longer change gives the keys back.
|
||||
preview.CropEditable = false;
|
||||
Assert.False(preview.IsCropSelected);
|
||||
Assert.False(Press(preview, Key.Right));
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void TheEditableBoxDrawsItsHandlesAndScreenReadersReadIt() => WpfHost.Run(() =>
|
||||
{
|
||||
var card = ColorOf("Brush.Card");
|
||||
var preview = CropPreview(new Rect(0.25, 0.2, 0.5, 0.6), ratio: 0.5 / 0.6);
|
||||
Render(preview, 800, 450);
|
||||
var surface = Assert.NotNull(FindChild<PreviewSurface>(preview));
|
||||
Color HandlePixel(double nx, double ny)
|
||||
{
|
||||
var bitmap = Render(preview, 800, 450);
|
||||
var (x, y) = preview.View.ToView(nx * 2000, ny * 1500);
|
||||
var p = surface.TranslatePoint(new Point(x, y), preview);
|
||||
return PixelAt(bitmap, (int)Math.Round(p.X), (int)Math.Round(p.Y));
|
||||
}
|
||||
foreach (var (nx, ny) in new[] { (0.25, 0.2), (0.75, 0.8), (0.5, 0.2), (0.75, 0.5) })
|
||||
Assert.True(Near(HandlePixel(nx, ny), card, 8), $"a Card handle at ({nx}, {ny})");
|
||||
preview.CropMaskMode = CropMaskMode.ShowResult;
|
||||
Assert.True(Near(HandlePixel(0.25, 0.8), card, 8), "the handles draw in either mask mode");
|
||||
|
||||
var peer = UIElementAutomationPeer.CreatePeerForElement(preview);
|
||||
var value = Assert.NotNull(peer.GetPattern(PatternInterface.Value) as System.Windows.Automation.Provider.IValueProvider);
|
||||
Assert.Equal(Loc.L("Editor.Preview.CropValue", Loc.L("Common.Percent", 25), Loc.L("Common.Percent", 20), Loc.L("Common.Percent", 60)), value.Value);
|
||||
Assert.True(value.IsReadOnly);
|
||||
|
||||
preview.CropMaskMode = CropMaskMode.ShowLoss;
|
||||
preview.CropEditable = false;
|
||||
Assert.False(Near(HandlePixel(0.25, 0.2), card, 8), "no handles while the box cannot change");
|
||||
Assert.Null(peer.GetPattern(PatternInterface.Value), "and no value to read");
|
||||
});
|
||||
|
||||
private static PreviewViewport CropPreview(Rect crop, double ratio) => new()
|
||||
{
|
||||
Source = Bitmap(2000, 1500),
|
||||
ShowCropMask = true,
|
||||
CropEditable = true,
|
||||
CropLockRatio = ratio,
|
||||
EditCrop = crop,
|
||||
};
|
||||
|
||||
/// <summary>The surface point of the normalised image point (<paramref name="nx"/>, <paramref name="ny"/>) of a 2000 × 1500 preview.</summary>
|
||||
private static Point At(PreviewViewport preview, double nx, double ny)
|
||||
{
|
||||
var (x, y) = preview.View.ToView(nx * 2000, ny * 1500);
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
/// <summary>A window off screen around <paramref name="element"/>, so it has a presentation source for key events.</summary>
|
||||
private static Window OffScreen(FrameworkElement element, double width, double height)
|
||||
{
|
||||
var window = new Window
|
||||
{
|
||||
Content = new Border { Child = element },
|
||||
Width = width,
|
||||
Height = height,
|
||||
WindowStyle = WindowStyle.None,
|
||||
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||
Left = -20000,
|
||||
Top = -20000,
|
||||
ShowActivated = false,
|
||||
ShowInTaskbar = false,
|
||||
};
|
||||
window.Show();
|
||||
window.UpdateLayout();
|
||||
return window;
|
||||
}
|
||||
|
||||
private static IEnumerable<(string Name, FrameworkElement Element, double Width, double Height)> Samples()
|
||||
{
|
||||
var n = 120_000;
|
||||
@@ -342,6 +566,15 @@ public sealed class VisualsSmokeTests
|
||||
ShowCropMask = true,
|
||||
CropRect = new Rect(0.1, 0.1, 0.8, 0.8),
|
||||
}, 800, 450);
|
||||
yield return ("PreviewViewport.CropEdit", new PreviewViewport
|
||||
{
|
||||
Source = Bitmap(2000, 1500),
|
||||
ShowCropMask = true,
|
||||
CropEditable = true,
|
||||
CropLockRatio = 0.5,
|
||||
EditCrop = new Rect(0.3, 0.2, 0.3, 0.6),
|
||||
ShowGrid = true,
|
||||
}, 800, 450);
|
||||
|
||||
yield return ("SequenceCard", SampleCard(), 236, 208);
|
||||
yield return ("SegmentedControl", SampleSegments(), 120, 32);
|
||||
@@ -438,8 +671,13 @@ public sealed class VisualsSmokeTests
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Press(UIElement target, Key key) =>
|
||||
target.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.KeyDownEvent });
|
||||
/// <summary>Raises a key press on <paramref name="target"/>; true when something handled it.</summary>
|
||||
private static bool Press(UIElement target, Key key)
|
||||
{
|
||||
var args = new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(target)!, 0, key) { RoutedEvent = Keyboard.KeyDownEvent };
|
||||
target.RaiseEvent(args);
|
||||
return args.Handled;
|
||||
}
|
||||
|
||||
private static RenderTargetBitmap Render(FrameworkElement element, double width, double height)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user