diff --git a/src/Chronos.App/Editor/CameraTab.cs b/src/Chronos.App/Editor/CameraTab.cs index e04406cc..72655af4 100644 --- a/src/Chronos.App/Editor/CameraTab.cs +++ b/src/Chronos.App/Editor/CameraTab.cs @@ -4,6 +4,7 @@ using System.Windows.Input; using Chronos.App.Infrastructure; using Chronos.Core.Advice; using Chronos.Core.Export; +using Chronos.Core.Imaging.Geometry; using Chronos.Core.Localization; using Chronos.Core.Mathematics; using Chronos.Core.Project; @@ -13,9 +14,10 @@ using Chronos.Ui.Visuals; namespace Chronos.App.Editor; /// -/// Camera (BRIEF §12.3): the free crop of the frame (margins), the output aspect and its placement inside the crop, and +/// Camera (BRIEF §12.3, owner review 1 R5/R6): the output aspect, the orientation (quarter turns, mirror, flip, +/// straighten), the crop box locked to the aspect (its size and its place in the frame; the preview edits it too), and /// virtual-camera keyframes edited as a zoom curve over the sequence (X = frame, Y = zoom) with the selected keyframe's -/// framing below. +/// framing below. Reset framing clears the crop and the orientation, never the keyframes. /// public sealed class CameraTab : EditorTab { @@ -27,30 +29,99 @@ public sealed class CameraTab : EditorTab public CameraTab(EditorViewModel editor) : base(editor, "Camera", AdvisorSection.Camera) { - var s = editor.Session; - Rows = + Rows = FramingRows(editor.Session); + AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsLocked && Keys.All(k => k.Frame != Editor.CurrentIndex)); + RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsLocked && SelectedKey >= 0); + ResetFramingCommand = new RelayCommand(() => Editor.Session.ResetFraming(), () => !Editor.IsLocked && HasFraming); + CommitCurveCommand = new RelayCommand(CommitCurve); + Refresh(); + } + + /// + /// The step's rows, top to bottom: Aspect (a change refits the crop, ), + /// Rotation (a quarter turn per press, as the user sees the picture), Mirror, Flip, Straighten (±15°, the preview's + /// grid while it is used), and the crop box as Crop size (a share of the largest box the aspect allows), Crop X and + /// Crop Y (its centre within the frame's slack). The crop rows write the locked box itself with the offsets at 0, so a + /// legacy crop placed by offsets is baked in at its first edit (). + /// + public static IReadOnlyList FramingRows(EditorSession session) + { + ArgumentNullException.ThrowIfNull(session); + var s = session; + string? NoSlack(ProjectSettings p, bool horizontal) => + CropFrame.HasSlack(LockedBox(s, p), horizontal) ? null : Loc.L("Tooltips.Editor.NotApplicable.NoSlack"); + return [ - CropRow(s, CropSide.Left, "Editor.Camera.CropLeft"), - CropRow(s, CropSide.Right, "Editor.Camera.CropRight"), - CropRow(s, CropSide.Top, "Editor.Camera.CropTop"), - CropRow(s, CropSide.Bottom, "Editor.Camera.CropBottom"), new AutoChoiceRow(s, EditorSettings.Aspect, "Editor.Camera.Aspect", "Tooltips.Editor.Camera.Aspect", [ new Choice("source", "Editor.Aspect.Source"), new Choice("16:9", "Editor.Aspect.Ratio", "16:9"), new Choice("21:9", "Editor.Aspect.Ratio", "21:9"), new Choice("4:3", "Editor.Aspect.Ratio", "4:3"), new Choice("3:2", "Editor.Aspect.Ratio", "3:2"), new Choice("1:1", "Editor.Aspect.Ratio", "1:1"), new Choice("9:16", "Editor.Aspect.Ratio", "9:16"), new Choice("4:5", "Editor.Aspect.Ratio", "4:5"), ]), - new NumberRow(s, "Editor.Camera.OffsetX", "Tooltips.Editor.Camera.OffsetX", -1, 1, 0.05, p => p.Camera.OffsetX, - (p, v) => p with { Camera = p.Camera with { OffsetX = v } }, EditorText.Placement), - new NumberRow(s, "Editor.Camera.OffsetY", "Tooltips.Editor.Camera.OffsetY", -1, 1, 0.05, p => p.Camera.OffsetY, - (p, v) => p with { Camera = p.Camera with { OffsetY = v } }, EditorText.Placement), + new IconActionsRow("Editor.Camera.Rotation", "Tooltips.Editor.Camera.Rotation", + () => Loc.L("Editor.Value.Degrees", (FrameOrientation.TurnsOf(s.Project.Camera.Rotate) * 90).ToString(Loc.Culture)), + [ + new IconAction("Icon.RotateLeft", "Editor.Camera.RotateLeft", "Tooltips.Editor.Camera.RotateLeft", () => s.Orient(OrientationOp.RotateLeft)), + new IconAction("Icon.RotateRight", "Editor.Camera.RotateRight", "Tooltips.Editor.Camera.RotateRight", () => s.Orient(OrientationOp.RotateRight)), + ]), + new SwitchRow(s, "Editor.Camera.Mirror", "Tooltips.Editor.Camera.Mirror", p => p.Camera.Mirror, _ => s.Orient(OrientationOp.Mirror)), + new SwitchRow(s, "Editor.Camera.Flip", "Tooltips.Editor.Camera.Flip", p => p.Camera.Flip, _ => s.Orient(OrientationOp.Flip)), + new NumberRow(s, "Editor.Camera.Straighten", "Tooltips.Editor.Camera.Straighten", -FrameOrientation.MaxStraighten, FrameOrientation.MaxStraighten, 0.1, + p => FrameOrientation.StraightenOf(p.Camera.Straighten), + (p, v) => p with { Camera = p.Camera with { Straighten = double.Round(v, 1) + 0.0 } }, Degrees) + { ShowsGrid = true }, + new NumberRow(s, "Editor.Camera.CropSize", "Tooltips.Editor.Camera.CropSize", CropFrame.MinimumShare, 1, 0.01, p => CropRows(s, p).Size, + (p, v) => WithCropRows(s, p, size: v), v => Formatting.Percent(v)), + new NumberRow(s, "Editor.Camera.CropX", "Tooltips.Editor.Camera.CropX", -1, 1, 0.01, p => CropRows(s, p).X, + (p, v) => WithCropRows(s, p, x: v), EditorText.Placement, p => NoSlack(p, horizontal: true)), + new NumberRow(s, "Editor.Camera.CropY", "Tooltips.Editor.Camera.CropY", -1, 1, 0.01, p => CropRows(s, p).Y, + (p, v) => WithCropRows(s, p, y: v), EditorText.Placement, p => NoSlack(p, horizontal: false)), ]; - AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsLocked && Keys.All(k => k.Frame != Editor.CurrentIndex)); - RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsLocked && SelectedKey >= 0); - CommitCurveCommand = new RelayCommand(CommitCurve); - Refresh(); } + /// The crop box the editor shows for : the stored crop locked to the output proportions (). + public static RectD LockedBox(EditorSession session, ProjectSettings project) + { + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(project); + var camera = project.Camera; + return CropFrame.Locked(camera.Crop, session.CropLockRatio(project), camera.OffsetX, camera.OffsetY); + } + + /// The Crop size, Crop X and Crop Y rows of (). + public static (double Size, double X, double Y) CropRows(EditorSession session, ProjectSettings project) + { + ArgumentNullException.ThrowIfNull(session); + return CropFrame.ToRows(LockedBox(session, project), session.CropLockRatio(project)); + } + + /// + /// with one of the crop rows changed: the locked box of the rows written as the crop (null + /// for the whole view), the offsets at 0. + /// + public static ProjectSettings WithCropRows(EditorSession session, ProjectSettings project, double? size = null, double? x = null, double? y = null) + { + ArgumentNullException.ThrowIfNull(session); + ArgumentNullException.ThrowIfNull(project); + var ratio = session.CropLockRatio(project); + var rows = CropFrame.ToRows(LockedBox(session, project), ratio); + var box = CropFrame.FromRows(size ?? rows.Size, x ?? rows.X, y ?? rows.Y, ratio); + return project with { Camera = project.Camera with { Crop = CropFrame.ToCrop(box), OffsetX = 0, OffsetY = 0 } }; + } + + /// Straighten as its row shows it: "−1.2°", "0°". + public static string Degrees(double value) => Loc.L("Editor.Value.Degrees", value.ToString("0.0;−0.0;0", Loc.Culture)); + + /// Something Reset framing clears is set: a crop, offsets, a rotation, mirror, flip or straighten. + public bool HasFraming => EditorSession.HasFraming(Editor.Session.Project.Camera); + + /// Reset framing (next to Optimise section and Reset). + public ICommand ResetFramingCommand { get; } + + /// What Reset framing clears, that there is nothing to clear, or why it waits. + public string ResetFramingToolTip => Editor.LockedToolTip + ?? Loc.L(HasFraming ? "Tooltips.Editor.Camera.ResetFraming" : "Tooltips.Editor.Camera.ResetFramingNone"); + /// Keyframes as curve points: X = frame / (count − 1), Y = (zoom − 1) / ( − 1). Edited in place by the curve editor. public ObservableCollection KeyPoints { get; } = []; @@ -128,6 +199,8 @@ public sealed class CameraTab : EditorTab } if (SelectedKey >= Keys.Count) SelectedKey = Keys.Count - 1; OnSelectedKeyChanged(); + OnPropertyChanged(nameof(HasFraming)); + OnPropertyChanged(nameof(ResetFramingToolTip)); } /// The curve editor finished an edit (add, move, delete): the points become the keyframes, keeping each one's framing. @@ -157,13 +230,9 @@ public sealed class CameraTab : EditorTab OnPropertyChanged(nameof(AddKeyToolTip)); OnPropertyChanged(nameof(RemoveKeyToolTip)); OnPropertyChanged(nameof(CurveToolTip)); + OnPropertyChanged(nameof(ResetFramingToolTip)); } - /// A margin of the free crop (); all zero = the whole frame. - private static NumberRow CropRow(EditorSession session, CropSide side, string headerKey) => new(session, headerKey, "Tooltips.Editor.Camera.Crop", 0, - CropMargins.MaxMargin, 0.01, p => CropMargins.Of(p.Camera.Crop)[(int)side], - (p, v) => p with { Camera = p.Camera with { Crop = CropMargins.With(p.Camera.Crop, side, v) } }, v => Formatting.Percent(v)); - private Point ToPoint(CameraKey key) => new(Editor.FrameCount > 1 ? (double)key.Frame / (Editor.FrameCount - 1) : 0, (key.Zoom - 1) / (MaxZoom - 1)); private void AddKey() diff --git a/src/Chronos.App/Editor/CropMargins.cs b/src/Chronos.App/Editor/CropMargins.cs deleted file mode 100644 index 013bed30..00000000 --- a/src/Chronos.App/Editor/CropMargins.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace Chronos.App.Editor; - -/// Margins of the free crop, in the order of (opposites differ in the lowest bit). -public enum CropSide -{ - Left, - Right, - Top, - Bottom, -} - -/// -/// The Camera tab's crop margins over CameraSettings.Crop (a normalised x, y, width, height rectangle, null for the -/// whole frame): each margin at most , opposite margins leaving at least . -/// -public static class CropMargins -{ - public const double MaxMargin = 0.45; - - public const double MinSize = 0.1; - - /// Left, right, top and bottom margins of (zeros for none or an invalid one, which the render ignores too). - public static double[] Of(double[]? crop) => crop is [var x, var y, var w, var h] && double.IsFinite(x + y + w + h) - ? [double.Clamp(x, 0, 1), double.Clamp(1 - x - w, 0, 1), double.Clamp(y, 0, 1), double.Clamp(1 - y - h, 0, 1)] - : [0, 0, 0, 0]; - - /// with one margin changed; null when no margin is left (the whole frame). - public static double[]? With(double[]? crop, CropSide side, double value) - { - var margins = Of(crop); - var opposite = (int)side ^ 1; - margins[(int)side] = double.Clamp(value, 0, double.Min(MaxMargin, 1 - MinSize - margins[opposite])); - if (margins.All(m => m == 0)) return null; - var (left, right, top, bottom) = (margins[0], margins[1], margins[2], margins[3]); - return [left, top, 1 - left - right, 1 - top - bottom]; - } -} diff --git a/src/Chronos.App/Editor/EditorPanels.xaml b/src/Chronos.App/Editor/EditorPanels.xaml index 6bab5ad6..ed534cf6 100644 --- a/src/Chronos.App/Editor/EditorPanels.xaml +++ b/src/Chronos.App/Editor/EditorPanels.xaml @@ -101,9 +101,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +