feat(editor): step controls for orientation, crop, look and output size

Owner review 1 asked for the Camera step to frame the picture the way the
mockup does, so the step now offers Aspect, Rotation (icon buttons), Mirror
and Flip switches, Straighten, Crop size, Crop X and Crop Y, and Reset
framing. Cropping by margins is gone: the crop box is now held to the chosen
aspect.

- EditorSession gains Orient and ResetFraming. Edit and Optimise refit a
  box that was already held to the aspect whenever the aspect or the export
  box changes, and do it in the same undo step. A crop from an older project
  that was placed by offsets is left for the render to fit.
- Straighten drives the preview's grid through the new SliderActivity
  attached behaviour, which a NumberRow switches on with ShowsGrid.
- Exposure gains a Look group with Filter and Strength. A newer project's
  extra look data is kept as it is.
- Export: Width and Height now edit the preset's own box, and a new Output
  size row shows the size after the chosen proportions are applied, marked
  Capped when the encoder shrinks it. ExportPlan carries OutputSize and
  EncodedSize.
- New SwitchRow, IconActionsRow and GroupRow rows with their panel
  templates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 20:24:03 +01:00
1 parent aaf9c0bba7
commit 7413b72ecc
14 files changed
+1030 -100

No files matched your search

+90 -21
View File
@@ -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;
/// <summary>
/// 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.
/// </summary>
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();
}
/// <summary>
/// The step's rows, top to bottom: Aspect (a change refits the crop, <see cref="EditorSession.KeepCropLocked"/>),
/// 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 (<see cref="CropFrame.Locked"/>).
/// </summary>
public static IReadOnlyList<SettingRow> 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<string>(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();
}
/// <summary>The crop box the editor shows for <paramref name="project"/>: the stored crop locked to the output proportions (<see cref="CropFrame.Locked"/>).</summary>
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);
}
/// <summary>The Crop size, Crop X and Crop Y rows of <paramref name="project"/> (<see cref="CropFrame.ToRows"/>).</summary>
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));
}
/// <summary>
/// <paramref name="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.
/// </summary>
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 } };
}
/// <summary>Straighten as its row shows it: "−1.2°", "0°".</summary>
public static string Degrees(double value) => Loc.L("Editor.Value.Degrees", value.ToString("0.0;−0.0;0", Loc.Culture));
/// <summary>Something Reset framing clears is set: a crop, offsets, a rotation, mirror, flip or straighten.</summary>
public bool HasFraming => EditorSession.HasFraming(Editor.Session.Project.Camera);
/// <summary>Reset framing (next to Optimise section and Reset).</summary>
public ICommand ResetFramingCommand { get; }
/// <summary>What Reset framing clears, that there is nothing to clear, or why it waits.</summary>
public string ResetFramingToolTip => Editor.LockedToolTip
?? Loc.L(HasFraming ? "Tooltips.Editor.Camera.ResetFraming" : "Tooltips.Editor.Camera.ResetFramingNone");
/// <summary>Keyframes as curve points: X = frame / (count − 1), Y = (zoom − 1) / (<see cref="MaxZoom"/> − 1). Edited in place by the curve editor.</summary>
public ObservableCollection<Point> 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));
}
/// <summary>The curve editor finished an edit (add, move, delete): the points become the keyframes, keeping each one's framing.</summary>
@@ -157,13 +230,9 @@ public sealed class CameraTab : EditorTab
OnPropertyChanged(nameof(AddKeyToolTip));
OnPropertyChanged(nameof(RemoveKeyToolTip));
OnPropertyChanged(nameof(CurveToolTip));
OnPropertyChanged(nameof(ResetFramingToolTip));
}
/// <summary>A margin of the free crop (<see cref="CropMargins"/>); all zero = the whole frame.</summary>
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()
-37
View File
@@ -1,37 +0,0 @@
namespace Chronos.App.Editor;
/// <summary>Margins of the free crop, in the order of <see cref="CropMargins.Of"/> (opposites differ in the lowest bit).</summary>
public enum CropSide
{
Left,
Right,
Top,
Bottom,
}
/// <summary>
/// The Camera tab's crop margins over <c>CameraSettings.Crop</c> (a normalised x, y, width, height rectangle, null for the
/// whole frame): each margin at most <see cref="MaxMargin"/>, opposite margins leaving at least <see cref="MinSize"/>.
/// </summary>
public static class CropMargins
{
public const double MaxMargin = 0.45;
public const double MinSize = 0.1;
/// <summary>Left, right, top and bottom margins of <paramref name="crop"/> (zeros for none or an invalid one, which the render ignores too).</summary>
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];
/// <summary><paramref name="crop"/> with one margin changed; null when no margin is left (the whole frame).</summary>
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];
}
}
+90 -17
View File
@@ -101,9 +101,62 @@
<Setter TargetName="NotApplicable" Property="Visibility" Value="Visible" />
<Setter TargetName="Slider" Property="IsEnabled" Value="False" />
</DataTrigger>
<!-- Straighten: while the slider is dragged or focused, the preview shows its fine grid (owner review 1, R6). -->
<DataTrigger Binding="{Binding ShowsGrid}" Value="True">
<Setter TargetName="Slider" Property="e:SliderActivity.Tracks" Value="True" />
<Setter TargetName="Slider" Property="e:SliderActivity.IsActive"
Value="{Binding DataContext.Editor.IsStraightening, RelativeSource={RelativeSource AncestorType=ItemsControl}, Mode=OneWayToSource}" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<!-- A plain switch (Mirror, Flip): one toggle is one undo step. -->
<DataTemplate DataType="{x:Type e:SwitchRow}">
<Grid Margin="0,0,0,12" MinHeight="26">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Header}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding ToolTip}" />
<CheckBox Grid.Column="1" Style="{StaticResource CheckBox.Switch}" Margin="8,0,0,0" IsChecked="{Binding IsOn}" VerticalAlignment="Center"
ToolTip="{Binding ToolTip}" AutomationProperties.Name="{Binding Header}" />
</Grid>
</DataTemplate>
<!-- Label, value, then 28 px icon-only buttons (Rotation: "90°", Rotate left, Rotate right). -->
<DataTemplate DataType="{x:Type e:IconActionsRow}">
<Grid Margin="0,0,0,12" MinHeight="28">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Header}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding ToolTip}" />
<TextBlock Grid.Column="1" Style="{StaticResource Text.RowValue}" Text="{Binding Value}" Margin="8,0,0,0" ToolTip="{Binding ToolTip}" />
<ItemsControl Grid.Column="2" ItemsSource="{Binding Actions}" Focusable="False" VerticalAlignment="Center">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type e:IconAction}">
<Button Style="{StaticResource Button.Icon}" Width="28" Height="28" MinWidth="28" Margin="6,0,0,0" ui:ButtonIcon.Glyph="{Binding Glyph}"
Command="{Binding Command}" ToolTip="{Binding ToolTip}" ToolTipService.ShowOnDisabled="True" AutomationProperties.Name="{Binding Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
</DataTemplate>
<!-- A group inside a step's column (Look on Exposure): a 1 px divider, then its name. -->
<DataTemplate DataType="{x:Type e:GroupRow}">
<StackPanel Margin="0,2,0,12">
<Border Height="1" Background="{DynamicResource Brush.Stroke}" Margin="0,0,0,12" />
<TextBlock Text="{Binding Header}" Style="{StaticResource Text.Body}" FontWeight="SemiBold" TextTrimming="CharacterEllipsis" ToolTip="{Binding ToolTip}" />
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type e:ChoiceRow}">
<Grid Margin="0,0,0,12" MinHeight="32">
<Grid.ColumnDefinitions>
@@ -135,18 +188,28 @@
</DataTemplate.Triggers>
</DataTemplate>
<!-- ===================== Section frame: title, rows, extra content, Optimise section · Reset ===================== -->
<!--
===================== Section frame: title, rows, extra content, Optimise section · Reset =====================
The ContentControl's Tag is a step's own action, on its line above them (Camera: Reset framing; the three buttons do
not fit one line of the 320 px column).
-->
<ControlTemplate x:Key="Template.SectionPanel" TargetType="ContentControl">
<Border Style="{StaticResource Border.EditorPanel}">
<DockPanel>
<TextBlock DockPanel.Dock="Top" Text="{Binding Header}" Style="{StaticResource Text.Section}" Margin="0,0,0,14" />
<Grid DockPanel.Dock="Bottom" Margin="0,12,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button Content="{l:Loc Editor.OptimiseSection}" Command="{Binding OptimiseCommand}" ToolTip="{Binding OptimiseToolTip}" ToolTipService.ShowOnDisabled="True" />
<Button Grid.Column="1" Style="{StaticResource Button.SectionReset}" Content="{l:Loc Editor.Reset}" Margin="8,0,0,0" Command="{Binding ResetCommand}"
<ContentPresenter Grid.ColumnSpan="2" Content="{TemplateBinding Tag}" HorizontalAlignment="Right" Margin="0,0,0,8"
Visibility="{TemplateBinding Tag, Converter={x:Static ui:NullToCollapsedConverter.Instance}}" />
<Button Grid.Row="1" Content="{l:Loc Editor.OptimiseSection}" Command="{Binding OptimiseCommand}" ToolTip="{Binding OptimiseToolTip}" ToolTipService.ShowOnDisabled="True" />
<Button Grid.Row="1" Grid.Column="1" Style="{StaticResource Button.SectionReset}" Content="{l:Loc Editor.Reset}" Margin="8,0,0,0" Command="{Binding ResetCommand}"
ToolTip="{Binding ResetToolTip}" Visibility="{Binding CanReset, Converter={StaticResource BoolToVisibility}}" />
</Grid>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Focusable="False">
@@ -211,9 +274,13 @@
<ContentControl Template="{StaticResource Template.SectionPanel}" Focusable="False" />
</DataTemplate>
<!-- Camera: rows, then the selected keyframe's framing. -->
<!-- Camera: rows (aspect, orientation, crop), then the keyframes and the selected keyframe's framing; Reset framing above Optimise section · Reset. -->
<DataTemplate DataType="{x:Type e:CameraTab}">
<ContentControl Template="{StaticResource Template.SectionPanel}" Focusable="False">
<ContentControl.Tag>
<Button Style="{StaticResource Button.SectionReset}" Content="{l:Loc Editor.Camera.ResetFraming}" Command="{Binding ResetFramingCommand}"
ToolTip="{Binding ResetFramingToolTip}" ToolTipService.ShowOnDisabled="True" />
</ContentControl.Tag>
<StackPanel Margin="0,4,0,0">
<Grid MinHeight="26" Margin="0,0,0,8">
<Grid.ColumnDefinitions>
@@ -364,6 +431,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Container}" ToolTip="{l:Loc Editor.Export.Container}" />
<ComboBox Grid.Column="1" Margin="0,0,0,8" ItemsSource="{Binding Containers}" SelectedItem="{Binding SelectedContainer}" DisplayMemberPath="Label"
@@ -389,8 +457,13 @@
<TextBlock Grid.Column="3" Text="{Binding AspectText}" Style="{StaticResource Text.Hint}" FontSize="{StaticResource Size.Secondary}" Margin="6,0,0,0" />
</Grid>
<TextBlock Grid.Row="3" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.FrameRate}" ToolTip="{l:Loc Editor.Export.FrameRate}" />
<Grid Grid.Row="3" Grid.Column="1" Margin="0,0,0,8">
<!-- What is rendered: the chosen proportions fitted in the box above (owner review 1, R5), "(capped)" when the encoder shrinks it. -->
<TextBlock Grid.Row="3" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.OutputSize}" ToolTip="{l:Loc Editor.Export.OutputSize}" />
<TextBlock Grid.Row="3" Grid.Column="1" Margin="0,0,0,8" MinHeight="24" Style="{StaticResource Text.Number}" Text="{Binding OutputSizeText}"
ToolTip="{Binding OutputSizeToolTip}" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" />
<TextBlock Grid.Row="4" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.FrameRate}" ToolTip="{l:Loc Editor.Export.FrameRate}" />
<Grid Grid.Row="4" Grid.Column="1" Margin="0,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
@@ -406,8 +479,8 @@
Visibility="{Binding IsFrameRateAuto, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
</Grid>
<TextBlock Grid.Row="4" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Quality}" ToolTip="{l:Loc Editor.Export.Quality}" />
<Grid Grid.Row="4" Grid.Column="1" Margin="0,0,0,8" MinHeight="32">
<TextBlock Grid.Row="5" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Quality}" ToolTip="{l:Loc Editor.Export.Quality}" />
<Grid Grid.Row="5" Grid.Column="1" Margin="0,0,0,8" MinHeight="32">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" MinWidth="64" />
@@ -421,8 +494,8 @@
Visibility="{Binding IsQualityApplicable, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
</Grid>
<TextBlock Grid.Row="5" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Encoder}" ToolTip="{l:Loc Editor.Export.Encoder}" />
<Grid Grid.Row="5" Grid.Column="1" Margin="0,0,0,8">
<TextBlock Grid.Row="6" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Encoder}" ToolTip="{l:Loc Editor.Export.Encoder}" />
<Grid Grid.Row="6" Grid.Column="1" Margin="0,0,0,8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
@@ -443,18 +516,18 @@
</TextBlock>
</Grid>
<TextBlock Grid.Row="6" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Colour}" ToolTip="{l:Loc Editor.Export.Colour}" />
<ComboBox Grid.Row="6" Grid.Column="1" Margin="0,0,0,8" ItemsSource="{Binding Depths}" SelectedItem="{Binding SelectedDepth}" DisplayMemberPath="Label"
<TextBlock Grid.Row="7" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.Colour}" ToolTip="{l:Loc Editor.Export.Colour}" />
<ComboBox Grid.Row="7" Grid.Column="1" Margin="0,0,0,8" ItemsSource="{Binding Depths}" SelectedItem="{Binding SelectedDepth}" DisplayMemberPath="Label"
IsEnabled="{Binding CanChooseDepth}" ToolTip="{l:Loc Tooltips.Editor.Export.Colour}" ToolTipService.ShowOnDisabled="True"
AutomationProperties.Name="{l:Loc Editor.Export.Colour}" />
<TextBlock Grid.Row="7" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.FileName}" ToolTip="{l:Loc Editor.Export.FileName}" />
<TextBox Grid.Row="7" Grid.Column="1" Margin="0,0,0,8" Text="{Binding NameTemplate.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
<TextBlock Grid.Row="8" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.FileName}" ToolTip="{l:Loc Editor.Export.FileName}" />
<TextBox Grid.Row="8" Grid.Column="1" Margin="0,0,0,8" Text="{Binding NameTemplate.Text, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"
shell:EditBehavior.Field="{Binding NameTemplate}" ToolTip="{Binding NameTemplate.ToolTip}" AutomationProperties.Name="{l:Loc Editor.Export.FileName}" />
<TextBlock Grid.Row="8" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.SaveTo}" ToolTip="{l:Loc Editor.Export.SaveTo}" />
<TextBlock Grid.Row="9" Style="{StaticResource Text.Label}" Text="{l:Loc Editor.Export.SaveTo}" ToolTip="{l:Loc Editor.Export.SaveTo}" />
<!-- The folder ends in an ellipsis (its full path is in the tooltip). -->
<ComboBox Grid.Row="8" Grid.Column="1" ItemsSource="{Binding SaveChoices}" SelectedItem="{Binding SelectedSave}" IsEnabled="{Binding CanChooseFolder}"
<ComboBox Grid.Row="9" Grid.Column="1" ItemsSource="{Binding SaveChoices}" SelectedItem="{Binding SelectedSave}" IsEnabled="{Binding CanChooseFolder}"
ToolTip="{Binding SaveToolTip}" ToolTipService.ShowOnDisabled="True" AutomationProperties.Name="{l:Loc Editor.Export.SaveTo}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type e:SaveChoice}">
@@ -464,7 +537,7 @@
</ComboBox>
<!-- Export.html "Sync" (12 px): also send the render to the server the sequence is linked to. Under the folder rather than beside
it, as in the mockup, so that neither is cut in the 194 px field column in longer languages. -->
<CheckBox Grid.Row="9" Grid.Column="1" Margin="0,6,0,0" HorizontalAlignment="Left" FontSize="{StaticResource Size.Secondary}"
<CheckBox Grid.Row="10" Grid.Column="1" Margin="0,6,0,0" HorizontalAlignment="Left" FontSize="{StaticResource Size.Secondary}"
Content="{l:Loc Editor.Export.Sync}" IsChecked="{Binding SyncToServer}" IsEnabled="{Binding CanSync}" ToolTip="{Binding SyncToolTip}"
ToolTipService.ShowOnDisabled="True" />
</Grid>
+76 -4
View File
@@ -1,7 +1,9 @@
using Chronos.Core.Advice;
using Chronos.Core.Diagnostics;
using Chronos.Core.Export;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Project;
using Chronos.Core.Render;
using Chronos.Core.Video;
using Chronos.Data.Archiving.Jobs;
using Chronos.Data.Processing;
@@ -109,12 +111,81 @@ public sealed class EditorSession : IAsyncDisposable
/// </summary>
public ProjectConflictException? Conflict { get; private set; }
/// <summary>Applies <paramref name="change"/> as an undoable step; false when it changes nothing.</summary>
/// <summary>
/// Applies <paramref name="change"/> as an undoable step; false when it changes nothing. A crop box locked to the
/// output proportions follows a change of them (<see cref="KeepCropLocked"/>) in the same step.
/// </summary>
/// <param name="mergeKey">Consecutive edits with the same key are one undo step (a slider drag).</param>
public bool Edit(Func<ProjectSettings, ProjectSettings> change, string? mergeKey = null)
{
ArgumentNullException.ThrowIfNull(change);
return !IsReadOnly && History.Apply(change(Project), mergeKey);
if (IsReadOnly) return false;
var before = Project;
return History.Apply(KeepCropLocked(before, change(before), Content.SourceWidth, Content.SourceHeight), mergeKey);
}
/// <summary>
/// One press of the Camera step's orientation controls (Rotate left or right, Mirror, Flip) as one undo step: the
/// picture turns or mirrors as the user sees it, and the crop and the keyframes with it (<see cref="OrientationEdit"/>,
/// owner review 1, R6).
/// </summary>
public bool Orient(OrientationOp op) => Edit(p => OrientationEdit.Apply(p, op));
/// <summary>
/// "Reset framing": the crop, its offsets, the rotation, mirror, flip and straighten cleared as one undo step; the
/// keyframes stay (<see cref="WithoutFraming"/>).
/// </summary>
public bool ResetFraming() => Edit(WithoutFraming);
/// <summary>The crop's width over its height in normalised view units for <paramref name="project"/> (<see cref="LockRatioOf"/>).</summary>
public double CropLockRatio(ProjectSettings project) => LockRatioOf(project, Content.SourceWidth, Content.SourceHeight);
/// <summary>
/// The lock ratio of the Camera step's crop (<see cref="RenderGeometry.LockRatio"/>): the output ratio the render fits
/// the crop to, in units of the view frame of a source of the given size; a 1×1 view when the size is unknown.
/// </summary>
public static double LockRatioOf(ProjectSettings project, int sourceWidth, int sourceHeight)
{
ArgumentNullException.ThrowIfNull(project);
var (width, height) = sourceWidth > 0 && sourceHeight > 0 ? (sourceWidth, sourceHeight) : (1, 1);
return RenderGeometry.Create(project.Camera, ExportResolver.Resolve(project.Export), width, height).LockRatio;
}
/// <summary>The project without framing: no crop, no offsets, no rotation, mirror, flip or straighten; keyframes and the aspect stay.</summary>
public static ProjectSettings WithoutFraming(ProjectSettings project)
{
ArgumentNullException.ThrowIfNull(project);
return project with { Camera = project.Camera with { Crop = null, OffsetX = 0, OffsetY = 0, Rotate = 0, Mirror = false, Flip = false, Straighten = 0 } };
}
/// <summary>Something <see cref="ResetFraming"/> clears is set.</summary>
public static bool HasFraming(CameraSettings camera)
{
ArgumentNullException.ThrowIfNull(camera);
return camera.Crop is not null || camera.OffsetX != 0 || camera.OffsetY != 0 || camera.Rotate != 0 || camera.Mirror || camera.Flip || camera.Straighten != 0;
}
/// <summary>
/// <paramref name="after"/> with its crop refitted to new output proportions (owner review 1, R5: an aspect change, a
/// turn of a "source" aspect, an export preset of another shape): a box that was locked to the proportions before keeps
/// its centre and area at the new ratio (<see cref="CropFrame.Refit"/>). A legacy free crop, one placed by offsets, and a
/// box already at the new ratio stay as they are (the render fits them, <see cref="AspectRatio.FitCrop"/>).
/// </summary>
public static ProjectSettings KeepCropLocked(ProjectSettings before, ProjectSettings after, int sourceWidth, int sourceHeight)
{
ArgumentNullException.ThrowIfNull(before);
ArgumentNullException.ThrowIfNull(after);
var camera = after.Camera;
if (CropFrame.IsWhole(camera.Crop) || camera.OffsetX != 0 || camera.OffsetY != 0) return after;
if (ReferenceEquals(before.Camera, camera) && ReferenceEquals(before.Export, after.Export)) return after;
var ratio = LockRatioOf(after, sourceWidth, sourceHeight);
var box = CropFrame.Of(camera.Crop);
if (IsLocked(box, ratio)) return after;
if (before.Camera.OffsetX != 0 || before.Camera.OffsetY != 0 || !IsLocked(CropFrame.Of(before.Camera.Crop), LockRatioOf(before, sourceWidth, sourceHeight)))
return after;
return after with { Camera = camera with { Crop = CropFrame.ToCrop(CropFrame.Refit(box, ratio)) } };
static bool IsLocked(RectD box, double lockRatio) => double.Abs(box.Width / box.Height / lockRatio - 1) < 1e-6;
}
/// <summary>The drag or key press behind a run of merged edits ended (<see cref="ProjectHistory.EndRun"/>).</summary>
@@ -148,7 +219,8 @@ public sealed class EditorSession : IAsyncDisposable
/// <summary>
/// Applies a sequence preset (BRIEF §10.3) as one undoable step: its timing, exposure, motion, aspect and export
/// preset; the user's frames (exclusions, hero), crop, keyframes, remap curve, exposure offset and output naming stay.
/// preset; the user's frames (exclusions, hero), crop (refitted to the preset's aspect), orientation, keyframes, remap
/// curve, exposure offset, look and output naming stay.
/// </summary>
public bool ApplyPreset(SequencePreset preset)
{
@@ -444,7 +516,7 @@ public sealed class EditorSession : IAsyncDisposable
settings = result.Settings;
changes.AddRange(result.Changes);
}
History.Apply(settings);
History.Apply(KeepCropLocked(Project, settings, Content.SourceWidth, Content.SourceHeight));
return changes;
}
+15 -1
View File
@@ -22,6 +22,18 @@ public sealed record ExportChoice(string Id, string Name, string ExportPresetId,
public sealed record ExportPlan(ResolvedExport Export, RenderSetup Setup, ExportEstimate Estimate, string FileName, string? NameError)
{
public string PresetName => ProcessingJobs.PresetName(Export);
/// <summary>
/// The size the render asks for (<see cref="RenderSize.Of"/>, owner review 1 R5: the preset's box fitted to the chosen
/// proportions, 4K at 9:16 = 2160×3840), before the encoder caps it.
/// </summary>
public (int Width, int Height) OutputSize { get; init; }
/// <summary>The size the encoder makes (<see cref="OutputSize"/> or smaller, when the encoder takes no more).</summary>
public (int Width, int Height) EncodedSize => (Setup.Encoder.Settings.Width, Setup.Encoder.Settings.Height);
/// <summary>The encoder shrank the output (by more than the rounding to even sizes every encoder makes).</summary>
public bool IsCapped => EncodedSize.Width < OutputSize.Width - 1 || EncodedSize.Height < OutputSize.Height - 1;
}
/// <summary>
@@ -74,7 +86,9 @@ public sealed class ExportPlanner(SequenceContent content, IReadOnlyList<IVideoE
};
var setup = RenderSetup.Create(input, new RenderTarget(resolved, ExportNaming.FallbackName), Encoders, host);
var (name, error) = FileName(export.NameTemplate, resolved, setup);
return new ExportPlan(resolved, setup, setup.Estimate(model), name, error);
// The estimates follow the setup, which renders the adapted size the encoder may cap (RenderSetup.Create).
var size = RenderSize.Of(input.Project.Camera, resolved, content.SourceWidth, content.SourceHeight, RenderOptions.Default.MaxWorkingLongEdge);
return new ExportPlan(resolved, setup, setup.Estimate(model), name, error) { OutputSize = size };
}
/// <summary>The first problem of a name template, localised; null when it is valid.</summary>
+52 -3
View File
@@ -280,6 +280,27 @@ public sealed class ExportTab : EditorTab
public EditableField Height { get; }
/// <summary>
/// "2160 × 3840": what the render makes of the box (Width × Height) and the chosen proportions (owner review 1, R5),
/// "(capped)" when the encoder takes no more; null before the plan.
/// </summary>
public string? OutputSizeText => Editor.Plan is { } plan ? OutputSizeOf(plan) : null;
/// <summary>Where the output size comes from, or the largest size the encoder takes when it capped it.</summary>
public string OutputSizeToolTip => OutputSizeToolTipOf(Editor.Plan);
/// <summary>The Output size row of <paramref name="plan"/>: "2160 × 3840", or "1080 × 1920 (capped)".</summary>
public static string OutputSizeOf(ExportPlan plan)
{
ArgumentNullException.ThrowIfNull(plan);
return plan.IsCapped ? Loc.L("Editor.Export.Capped", SizeText(plan.EncodedSize)) : SizeText(plan.OutputSize);
}
/// <summary>The Output size row's tooltip for <paramref name="plan"/>.</summary>
public static string OutputSizeToolTipOf(ExportPlan? plan) => plan is { IsCapped: true }
? Loc.L("Tooltips.Editor.Export.OutputCapped", SizeText(LargestTaken(plan)))
: Loc.L("Tooltips.Editor.Export.OutputSize");
/// <summary>"16:9".</summary>
public string AspectText => Editor.Plan is { } plan ? Aspect(plan.Setup.Encoder.Settings.Width, plan.Setup.Encoder.Settings.Height) : string.Empty;
@@ -473,6 +494,7 @@ public sealed class ExportTab : EditorTab
try
{
UpdateLists();
LoadBox();
SaveChoices = !CanChooseFolder ? [new SaveChoice(null)]
: Export.Folder is { } folder ? [new SaveChoice(null), new SaveChoice(folder), new SaveChoice(null, Browse: true)]
: [new SaveChoice(null), new SaveChoice(null, Browse: true)];
@@ -493,9 +515,7 @@ public sealed class ExportTab : EditorTab
_refreshing = true;
try
{
var settings = Editor.Plan?.Setup.Encoder.Settings;
if (!Width.IsDirty) Width.Load(settings?.Width.ToString(CultureInfo.InvariantCulture) ?? string.Empty);
if (!Height.IsDirty) Height.Load(settings?.Height.ToString(CultureInfo.InvariantCulture) ?? string.Empty);
LoadBox();
UpdateLists();
Notices = Editor.Plan is { } plan ? PlanNotices(plan) : [];
OnAllPropertiesChanged();
@@ -547,6 +567,35 @@ public sealed class ExportTab : EditorTab
base.Dispose();
}
/// <summary>
/// Width and Height edit the preset's box, which the chosen proportions are fitted in (owner review 1, R5): they show the
/// resolved box (empty for a side the preset leaves to the source), not the size rendered (Output size).
/// </summary>
private void LoadBox()
{
var resolved = Resolved;
if (!Width.IsDirty) Width.Load(resolved.Width > 0 ? resolved.Width.ToString(CultureInfo.InvariantCulture) : string.Empty);
if (!Height.IsDirty) Height.Load(resolved.Height > 0 ? resolved.Height.ToString(CultureInfo.InvariantCulture) : string.Empty);
}
/// <summary>"2160 × 3840".</summary>
private static string SizeText((int Width, int Height) size) =>
size.Width.ToString(Loc.Culture) + " × " + size.Height.ToString(Loc.Culture);
/// <summary>
/// The encoder's largest size turned as the output is (as <see cref="EncoderSelector"/> fits it) when the output is
/// larger; otherwise the codec level capped it, and the size made is the largest it takes.
/// </summary>
private static (int Width, int Height) LargestTaken(ExportPlan plan)
{
var (width, height) = plan.OutputSize;
if (plan.Setup.Encoder.Capability is not { } capability) return plan.EncodedSize;
var (maxWidth, maxHeight) = (width >= height) == (capability.MaxWidth >= capability.MaxHeight)
? (capability.MaxWidth, capability.MaxHeight)
: (capability.MaxHeight, capability.MaxWidth);
return width > maxWidth || height > maxHeight ? (maxWidth, maxHeight) : plan.EncodedSize;
}
/// <summary>The choices that depend on the resolved codec (new lists only when they change, so selections stay bound).</summary>
private void UpdateLists()
{
+39 -1
View File
@@ -1,4 +1,6 @@
using Chronos.App.Infrastructure;
using Chronos.Core.Advice;
using Chronos.Core.Imaging.Color;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Core.Render;
@@ -20,7 +22,7 @@ public enum ExposureChart
}
/// <summary>
/// Exposure (BRIEF §12.3): deflicker, regions, holy-grail transitions and white balance. The luminance chart shows the
/// Exposure (BRIEF §12.3): deflicker, regions, holy-grail transitions, white balance and the look. The luminance chart shows the
/// measured luminance (Sun) against the target curve the corrections produce (Accent), the sky region (dashed) and the
/// exposure steps as received; the flicker chart the frame-to-frame change before and after correction; the waveform
/// the luma distribution of the corrected frame on screen.
@@ -58,11 +60,47 @@ public sealed class ExposureTab : EditorTab
new InfoRow("Editor.Exposure.Temperature", "Tooltips.Editor.Exposure.Temperature", Temperature),
new NumberRow(s, "Editor.Exposure.Offset", "Tooltips.Editor.Exposure.Offset", -3, 3, 0.1, p => p.Exposure.ExposureOffsetEv,
(p, v) => p with { Exposure = p.Exposure with { ExposureOffsetEv = v } }, v => Loc.L("Editor.Value.Ev", EditorText.Ev(v))),
.. LookRows(s),
];
Refresh();
BuildChart();
}
/// <summary>
/// The Look group at the end of the step (owner review 1, R6): the filter (None, Mono, Sepia, Warm, Cool, Vivid, Muted,
/// Fade) and its strength, "n/a" without a filter. The look is a project setting outside Exposure, so moving these never
/// measures again (<see cref="WithLook"/>).
/// </summary>
public static IReadOnlyList<SettingRow> LookRows(EditorSession session)
{
ArgumentNullException.ThrowIfNull(session);
string? NoLook(ProjectSettings p) => HasFilter(p) ? null : Loc.L("Tooltips.Editor.NotApplicable.NoLook");
return
[
new GroupRow("Editor.Look.Group", "Tooltips.Editor.Look.Group"),
new ChoiceRow(session, "Editor.Look.Filter", "Tooltips.Editor.Look.Filter",
[.. LookFilter.Names.Select(n => new Choice(n, "Editor.Look." + char.ToUpperInvariant(n[0]) + n[1..]))],
p => p.Look?.Filter ?? LookFilter.None, (p, v) => WithLook(p, (string)v, p.Look?.Strength)),
new NumberRow(session, "Editor.Look.Strength", "Tooltips.Editor.Look.Strength", 0, 1, 0.01, p => HasFilter(p) ? p.Look!.Strength ?? 1 : 1,
(p, v) => WithLook(p, p.Look?.Filter, double.Round(v, 2)), v => Formatting.Percent(v), NoLook),
];
}
/// <summary>
/// <paramref name="project"/> with the look <paramref name="filter"/> at <paramref name="strength"/>: none when the filter
/// is None (so a project without a look keeps settings format 1 and its text), the strength omitted at 100 %. Values of
/// a newer Chronos inside the look are kept.
/// </summary>
public static ProjectSettings WithLook(ProjectSettings project, string? filter, double? strength)
{
ArgumentNullException.ThrowIfNull(project);
if (filter is null || filter == LookFilter.None) return project with { Look = null };
var look = (project.Look ?? new LookSettings()) with { Filter = filter, Strength = strength is >= 1 ? null : strength };
return project with { Look = look };
}
private static bool HasFilter(ProjectSettings project) => project.Look?.Filter is { } filter && filter != LookFilter.None && LookFilter.IsKnown(filter);
/// <summary>Luminance, flicker or waveform (the switch beside the chart).</summary>
public ExposureChart ChartMode
{
+89
View File
@@ -3,6 +3,7 @@ using System.Windows.Input;
using Chronos.Core.Advice;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
namespace Chronos.App.Editor;
@@ -306,6 +307,12 @@ public sealed class NumberRow : SettingRow
public double Maximum { get; }
public double Step { get; }
/// <summary>
/// Using the slider (dragged or focused) shows the preview's straighten grid (<c>Editor.IsStraightening</c>, driven
/// by the view through <see cref="SliderActivity"/>): the Camera step's Straighten.
/// </summary>
public bool ShowsGrid { get; init; }
public double Value
{
get => _value;
@@ -395,3 +402,85 @@ public sealed class InfoRow(string headerKey, string toolTipKey, Func<(string? V
protected override void Read() => (Value, NotApplicableReason) = read();
}
/// <summary>
/// A plain switch (no advice): the Camera step's Mirror and Flip. Each toggle is one edit, made by
/// <paramref name="toggle"/> with the new state (it may change more than one member, as <see cref="EditorSession.Orient"/> does).
/// </summary>
public sealed class SwitchRow : SettingRow
{
private readonly EditorSession _session;
private readonly Func<ProjectSettings, bool> _get;
private readonly Action<bool> _toggle;
private bool _isOn;
public SwitchRow(EditorSession session, string headerKey, string toolTipKey, Func<ProjectSettings, bool> get, Action<bool> toggle)
: base(headerKey, toolTipKey)
{
(_session, _get, _toggle) = (session, get, toggle);
Refresh();
}
public bool IsOn
{
get => _isOn;
set
{
if (!Set(ref _isOn, value) || IsRefreshing) return;
_toggle(value);
// A toggle the project did not take (read-only) springs back.
if (_get(_session.Project) != value) Refresh();
}
}
protected override void Read() => IsOn = _get(_session.Project);
}
/// <summary>An icon-only button of an <see cref="IconActionsRow"/>: its glyph (a resource key such as "Icon.RotateLeft"), name and tooltip.</summary>
public sealed class IconAction(string glyphKey, string nameKey, string toolTipKey, Action execute) : LocalizedViewModel
{
public string GlyphKey { get; } = glyphKey;
public IconData? Glyph => System.Windows.Application.Current?.TryFindResource(GlyphKey) as IconData;
/// <summary>The button's accessible name ("Rotate left").</summary>
public string Name => Loc.L(nameKey);
public string ToolTip => Loc.L(toolTipKey);
public ICommand Command { get; } = new RelayCommand(execute);
}
/// <summary>A label, a read-only value and icon-only buttons (the Camera step's Rotation: "90°", Rotate left, Rotate right).</summary>
public sealed class IconActionsRow : SettingRow
{
private readonly Func<string> _read;
private string _value = string.Empty;
public IconActionsRow(string headerKey, string toolTipKey, Func<string> value, IReadOnlyList<IconAction> actions)
: base(headerKey, toolTipKey)
{
(_read, Actions) = (value, actions);
Refresh();
}
public string Value { get => _value; private set => Set(ref _value, value); }
public IReadOnlyList<IconAction> Actions { get; }
protected override void Read() => Value = _read();
public override void Dispose()
{
foreach (var action in Actions) action.Dispose();
base.Dispose();
}
}
/// <summary>The start of a group of rows inside a step's column: a divider and the group's name (the Exposure step's Look).</summary>
public sealed class GroupRow(string headerKey, string toolTipKey) : SettingRow(headerKey, toolTipKey)
{
protected override void Read()
{
}
}
+50
View File
@@ -0,0 +1,50 @@
using System.Windows;
namespace Chronos.App.Editor;
/// <summary>
/// Whether the user is using a control (it holds the keyboard focus or the mouse capture: a slider dragged or focused),
/// for a binding to say so (<see cref="IsActiveProperty"/>, bound one way to the source): the Camera step's Straighten
/// shows the preview's grid while it is used (owner review 1, R6). <see cref="TracksProperty"/> starts the tracking.
/// </summary>
public static class SliderActivity
{
public static readonly DependencyProperty TracksProperty = DependencyProperty.RegisterAttached(
"Tracks", typeof(bool), typeof(SliderActivity), new PropertyMetadata(false, OnTracksChanged));
public static readonly DependencyProperty IsActiveProperty = DependencyProperty.RegisterAttached(
"IsActive", typeof(bool), typeof(SliderActivity), new FrameworkPropertyMetadata(false));
public static bool GetTracks(DependencyObject d) => (bool)d.GetValue(TracksProperty);
public static void SetTracks(DependencyObject d, bool value) => d.SetValue(TracksProperty, value);
public static bool GetIsActive(DependencyObject d) => (bool)d.GetValue(IsActiveProperty);
public static void SetIsActive(DependencyObject d, bool value) => d.SetValue(IsActiveProperty, value);
private static void OnTracksChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not FrameworkElement element) return;
element.IsKeyboardFocusWithinChanged -= OnChanged;
element.IsMouseCaptureWithinChanged -= OnChanged;
element.Unloaded -= OnUnloaded;
if (e.NewValue is not true) return;
element.IsKeyboardFocusWithinChanged += OnChanged;
element.IsMouseCaptureWithinChanged += OnChanged;
element.Unloaded += OnUnloaded;
Update(element);
}
private static void OnChanged(object sender, DependencyPropertyChangedEventArgs e) => Update((FrameworkElement)sender);
/// <summary>A control taken off screen (another step) is no longer being used.</summary>
private static void OnUnloaded(object sender, RoutedEventArgs e) => ((FrameworkElement)sender).SetCurrentValue(IsActiveProperty, false);
/// <summary>Set through <see cref="DependencyObject.SetCurrentValue"/>, so a binding on the property stays and receives it.</summary>
private static void Update(FrameworkElement element)
{
var active = element.IsKeyboardFocusWithin || element.IsMouseCaptureWithin;
if (GetIsActive(element) != active) element.SetCurrentValue(IsActiveProperty, active);
}
}
@@ -0,0 +1,293 @@
using System.Globalization;
using Chronos.App.Editor;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>
/// The Camera step's rows (owner review 1, R5/R6) and the Exposure step's Look group on an open session of the 96 × 64
/// synthetic sunset: the crop box locked to the aspect through Crop size, X and Y, the orientation controls, Straighten,
/// the look written only when it is not the identity, and every row's label and tooltip in English and Italian.
/// </summary>
[Serial]
public sealed class CameraTabTests
{
private static (EditorSession Session, FakeSequenceSource Source) Open(ProjectSettings? project = null)
{
var content = EditorFixture.Content(EditorFixture.Sunset, project);
var source = new FakeSequenceSource(EditorFixture.Sunset, content);
return (new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20)), source);
}
private static ProjectSettings WithAspect(string aspect, string? preset = null)
{
var project = new ProjectSettings();
project = project with { Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect) } };
return preset is null ? project : project with { Export = project.Export with { Preset = project.Export.Preset.WithManual(preset) } };
}
private static T Row<T>(IReadOnlyList<SettingRow> rows, string headerKey)
where T : SettingRow => (T)rows.Single(r => r.Header == Loc.L(headerKey));
private static void Refresh(IReadOnlyList<SettingRow> rows)
{
foreach (var row in rows) row.Refresh();
}
[Test]
public async Task CropSizeAndPlaceMoveTheBoxLockedToTheAspect()
{
var (session, _) = Open(WithAspect("9:16"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var size = Row<NumberRow>(rows, "Editor.Camera.CropSize");
var x = Row<NumberRow>(rows, "Editor.Camera.CropX");
var y = Row<NumberRow>(rows, "Editor.Camera.CropY");
Assert.Equal(1.0, size.Value, "no crop: the largest box");
Assert.Equal(0.0, x.Value);
Assert.True(x.IsApplicable, "a 9:16 box can move across a 3:2 frame");
Assert.False(y.IsApplicable, "but not up or down");
Assert.Equal(Loc.L("Tooltips.Editor.NotApplicable.NoSlack"), y.NotApplicableReason);
var ratio = session.CropLockRatio(session.Project);
x.Value = 1;
var box = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(1, box.Right, 1e-9, "Crop X +1 puts the box at the right edge");
Assert.Approximately(ratio, box.Width / box.Height, 1e-9, "locked to the aspect");
Refresh(rows);
size.Value = 0.5;
box = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(0.5, box.Height, 1e-9, "half the largest box");
Assert.Approximately(1, box.Right, 1e-9, "still at the right edge");
Assert.Approximately(ratio, box.Width / box.Height, 1e-9);
Refresh(rows);
Assert.True(y.IsApplicable, "a smaller box can move up and down");
Assert.Equal(1.0, x.Value);
Assert.Equal("+1.00", x.DisplayValue);
Assert.Equal("50 %", size.DisplayValue);
y.Value = -1;
Assert.Approximately(0, CropFrame.Of(session.Project.Camera.Crop).Y, 1e-9, "Crop Y −1 is the top");
Refresh(rows);
size.Value = 0.02;
Assert.Approximately(CropFrame.MinimumShare, CropFrame.Of(session.Project.Camera.Crop).Height, 1e-9, "never below a tenth of the largest box");
Assert.True(session.Project.Camera is { OffsetX: 0, OffsetY: 0 });
}
}
[Test]
public async Task TheWholeFrameAtItsOwnProportionsIsNoCrop()
{
var (session, _) = Open(WithAspect("source", "png-sequence"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var size = Row<NumberRow>(rows, "Editor.Camera.CropSize");
size.Value = 0.6;
Assert.NotNull(session.Project.Camera.Crop);
Refresh(rows);
size.Value = 1;
Assert.Null(session.Project.Camera.Crop, "the largest box is the whole view: nothing is stored");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat);
}
}
[Test]
public async Task ALegacyCropPlacedByOffsetsIsBakedInAtItsFirstEdit()
{
var legacy = WithAspect("1:1");
legacy = legacy with { Camera = legacy.Camera with { OffsetX = 1 } };
var (session, _) = Open(legacy);
await using (session)
{
var rows = CameraTab.FramingRows(session);
var before = CameraTab.LockedBox(session, session.Project);
Assert.Approximately(1, before.Right, 1e-9, "the render puts the square at the right");
Assert.Equal(1.0, Row<NumberRow>(rows, "Editor.Camera.CropX").Value, "the rows show it where it renders");
Row<NumberRow>(rows, "Editor.Camera.CropSize").Value = 0.8;
var after = CropFrame.Of(session.Project.Camera.Crop);
Assert.True(session.Project.Camera is { OffsetX: 0, OffsetY: 0 }, "the offsets are baked into the box");
Assert.Approximately(1, after.Right, 1e-9);
Assert.Approximately(0.8 * before.Height, after.Height, 1e-9);
}
}
[Test]
public async Task TheRotationButtonsTurnAndTheRowShowsTheStoredAngle()
{
var (session, _) = Open(WithAspect("16:9"));
await using (session)
{
var rows = CameraTab.FramingRows(session);
var rotation = Row<IconActionsRow>(rows, "Editor.Camera.Rotation");
Assert.Equal("0°", rotation.Value);
Assert.SequenceEqual([Loc.L("Editor.Camera.RotateLeft"), Loc.L("Editor.Camera.RotateRight")], rotation.Actions.Select(a => a.Name));
Assert.SequenceEqual(["Icon.RotateLeft", "Icon.RotateRight"], rotation.Actions.Select(a => a.GlyphKey));
rotation.Actions[1].Command.Execute(null);
Refresh(rows);
Assert.Equal("90°", rotation.Value);
rotation.Actions[0].Command.Execute(null);
rotation.Actions[0].Command.Execute(null);
Refresh(rows);
Assert.Equal("270°", rotation.Value);
Assert.Equal("9:16", session.Project.Camera.Aspect.Manual, "three quarter turns: portrait");
}
}
[Test]
public async Task MirrorAndFlipAreSwitchesThatMoveTheCropWithThePicture()
{
var project = WithAspect("16:9");
project = project with { Camera = project.Camera with { Crop = [0.1, 0.2, 0.3, 0.4] } };
var (session, _) = Open(project);
await using (session)
{
var rows = CameraTab.FramingRows(session);
var mirror = Row<SwitchRow>(rows, "Editor.Camera.Mirror");
var flip = Row<SwitchRow>(rows, "Editor.Camera.Flip");
Assert.False(mirror.IsOn);
mirror.IsOn = true;
Assert.True(session.Project.Camera.Mirror);
Assert.SequenceEqual([0.6, 0.2, 0.3, 0.4], session.Project.Camera.Crop!, "x becomes 1 − x − w");
flip.IsOn = true;
Assert.True(session.Project.Camera.Flip);
Assert.SequenceEqual([0.6, 0.4, 0.3, 0.4], session.Project.Camera.Crop!, "y becomes 1 − y − h");
Assert.True(session.Undo());
Refresh(rows);
Assert.False(flip.IsOn, "the switch follows undo");
Assert.True(mirror.IsOn);
}
}
[Test]
public async Task ASwitchTheProjectDoesNotTakeSpringsBack()
{
var (session, source) = Open();
await using (session)
{
var mirror = Row<SwitchRow>(CameraTab.FramingRows(session), "Editor.Camera.Mirror");
source.IsReadOnly = true;
mirror.IsOn = true;
Assert.False(mirror.IsOn);
Assert.False(session.Project.Camera.Mirror);
}
}
[Test]
public async Task StraightenStoresTenthsOfADegreeAndShowsTheGrid()
{
var (session, _) = Open();
await using (session)
{
var straighten = Row<NumberRow>(CameraTab.FramingRows(session), "Editor.Camera.Straighten");
Assert.True(straighten.ShowsGrid, "using it shows the preview's grid");
Assert.Equal((-15.0, 15.0), (straighten.Minimum, straighten.Maximum));
straighten.Value = -1.23;
Assert.Equal(-1.2, session.Project.Camera.Straighten);
Assert.Equal("−1.2°", straighten.DisplayValue);
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat, "a straighten needs format 2");
straighten.Value = 0.02;
Assert.Equal(0.0, session.Project.Camera.Straighten);
Assert.False(double.IsNegative(session.Project.Camera.Straighten), "never −0");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat, "level again: format 1");
Assert.True(CameraTab.FramingRows(session).OfType<NumberRow>().Count(r => r.ShowsGrid) == 1, "only Straighten");
}
}
[Test]
public async Task TheLookIsWrittenOnlyWhenAFilterIsChosen()
{
var (session, _) = Open();
await using (session)
{
var before = session.Project.ToJson();
var rows = ExposureTab.LookRows(session);
Assert.True(rows[0] is GroupRow, "the group starts with its name");
var filter = Row<ChoiceRow>(rows, "Editor.Look.Filter");
var strength = Row<NumberRow>(rows, "Editor.Look.Strength");
Assert.Equal("none", filter.Selected?.Value);
Assert.False(strength.IsApplicable, "no filter: Strength is n/a");
Assert.Equal(Loc.L("Tooltips.Editor.NotApplicable.NoLook"), strength.NotApplicableReason);
Assert.SequenceEqual(["None", "Mono", "Sepia", "Warm", "Cool", "Vivid", "Muted", "Fade"], filter.Options.Select(o => o.Label));
filter.Selected = filter.Options.Single(o => Equals(o.Value, "sepia"));
Assert.Equal(new LookSettings { Filter = "sepia" }.Filter, session.Project.Look?.Filter);
Assert.Null(session.Project.Look!.Strength, "100 % is the default");
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat);
Refresh(rows);
Assert.True(strength.IsApplicable);
Assert.Equal(1.0, strength.Value);
strength.Value = 0.6;
Assert.Equal(0.6, session.Project.Look!.Strength);
Assert.Equal("60 %", strength.DisplayValue);
strength.Value = 1;
Assert.Null(session.Project.Look!.Strength);
Refresh(rows);
filter.Selected = filter.Options.Single(o => Equals(o.Value, "none"));
Assert.Null(session.Project.Look, "the identity is no look");
Assert.Equal(ProjectSettings.BaseVersion, session.Project.RequiredFormat);
Assert.Equal(before, session.Project.ToJson(), "and the text is the one before the look");
}
}
[Test]
public void ALookOfANewerChronosKeepsWhatItDoesNotKnow()
{
var extra = ProjectSettings.FromJson("""{"look":{"filter":"warm","strength":0.4,"grain":0.2}}""");
var changed = ExposureTab.WithLook(extra, "cool", 0.4);
Assert.Equal("cool", changed.Look?.Filter);
Assert.Contains("\"grain\":0.2", changed.ToJson().Replace(" ", string.Empty, StringComparison.Ordinal));
}
[Test]
public async Task EveryRowHasATooltipAndALabelOfAtMostThreeWordsInEnglishAndItalian()
{
var (session, _) = Open(WithAspect("9:16"));
await using (session)
{
var missing = new List<string>();
void OnMissing(string key) => missing.Add(key);
Loc.MissingKey += OnMissing;
try
{
foreach (var culture in new[] { "en", "it" })
{
Loc.SetCulture(CultureInfo.GetCultureInfo(culture));
var rows = CameraTab.FramingRows(session).Concat(ExposureTab.LookRows(session)).ToList();
var labels = new List<string>();
foreach (var row in rows)
{
labels.Add(row.Header);
Assert.False(string.IsNullOrWhiteSpace(row.ToolTip), $"{culture}: {row.Header} has a tooltip");
Assert.NotEqual(row.Header, row.ToolTip, $"{culture}: the tooltip explains, it does not repeat the label");
if (row is IconActionsRow icons)
{
foreach (var action in icons.Actions)
{
labels.Add(action.Name);
Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{culture}: {action.Name} has a tooltip");
}
}
if (row is ChoiceRow choices) labels.AddRange(choices.Options.Select(o => o.Label));
}
labels.AddRange(new[] { "Editor.Camera.ResetFraming", "Editor.Export.OutputSize" }.Select(k => Loc.L(k)));
foreach (var key in new[] { "Tooltips.Editor.Camera.ResetFraming", "Tooltips.Editor.Camera.ResetFramingNone", "Tooltips.Editor.Export.OutputSize" })
Assert.False(string.IsNullOrWhiteSpace(Loc.L(key)), key);
foreach (var label in labels)
Assert.LessOrEqual(label.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"{culture}: \"{label}\" is at most three words");
}
}
finally
{
Loc.MissingKey -= OnMissing;
Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
}
Assert.Empty(missing);
}
}
}
@@ -206,6 +206,22 @@ public sealed class EditPathTests
"a crop of the whole frame is no crop");
}
[Test]
public void TheOrientationAndTheLookReadEdited()
{
var content = EditorFixture.Content(EditorFixture.Sunset);
var project = new ProjectSettings();
foreach (var (camera, what) in new[]
{
(new CameraSettings { Rotate = 90 }, "a quarter turn"), (new CameraSettings { Mirror = true }, "a mirror"),
(new CameraSettings { Flip = true }, "a flip"), (new CameraSettings { Straighten = -1.2 }, "a straighten"),
})
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Camera, content, project: project with { Camera = camera }).Text, what);
Assert.Equal(Loc.L("Editor.Step.Edited"), State(EditPath.Exposure, content, project: project with { Look = new LookSettings { Filter = "sepia" } }).Text,
"a look");
Assert.Equal(Loc.L("Common.Auto"), State(EditPath.Exposure, content, project: project with { Look = null }).Text, "no look");
}
[Test]
public void AMissingValueOfASettingThatDoesNotApplyAsksNothing()
{
@@ -3,6 +3,7 @@ using System.Text.Json;
using Chronos.App.Editor;
using Chronos.Core.Advice;
using Chronos.Core.Analysis;
using Chronos.Core.Imaging.Geometry;
using Chronos.Core.Model;
using Chronos.Core.Project;
using Chronos.Protocol;
@@ -416,4 +417,160 @@ public sealed class EditorSessionTests
Assert.Equal(2, session.Project.HeroFrame);
}
}
// ---- Orientation and framing (owner review 1, R5/R6) ----
/// <summary>A project with a manual aspect (the advice never decides it) and a crop.</summary>
private static ProjectSettings WithAspect(string aspect, double[]? crop = null)
{
var project = new ProjectSettings();
return project with { Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect), Crop = crop } };
}
[Test]
public async Task EachOrientationPressIsOneUndoStepAndTurnsTheCropWithThePicture()
{
var (session, _) = Open(WithAspect("16:9", [0.1, 0.2, 0.4, 0.3]));
await using (session)
{
Assert.True(session.Orient(OrientationOp.RotateRight));
Assert.Equal(90, session.Project.Camera.Rotate);
Assert.Equal("9:16", session.Project.Camera.Aspect.Manual, "the proportions turn with the picture");
Assert.SequenceEqual([0.5, 0.1, 0.3, 0.4], session.Project.Camera.Crop!, "the crop keeps the content");
Assert.True(session.Orient(OrientationOp.Mirror));
Assert.True(session.Project.Camera.Mirror);
Assert.SequenceEqual([0.2, 0.1, 0.3, 0.4], session.Project.Camera.Crop!, "mirror maps x to 1 − x − w");
Assert.True(session.Undo());
Assert.False(session.Project.Camera.Mirror, "one press, one step");
Assert.Equal(90, session.Project.Camera.Rotate);
Assert.True(session.Undo());
Assert.Equal(0, session.Project.Camera.Rotate);
Assert.SequenceEqual([0.1, 0.2, 0.4, 0.3], session.Project.Camera.Crop!);
}
}
[Test]
public async Task ATurnSeenThroughAMirrorTurnsThePictureTheWayTheUserPressed()
{
var (session, _) = Open(WithAspect("16:9"));
await using (session)
{
session.Orient(OrientationOp.RotateRight);
Assert.Equal(90, session.Project.Camera.Rotate, "clockwise as stored");
session.Orient(OrientationOp.Mirror);
session.Orient(OrientationOp.RotateRight);
Assert.Equal(0, session.Project.Camera.Rotate, "through one mirror, a clockwise press is an anticlockwise stored turn");
session.Orient(OrientationOp.Flip);
session.Orient(OrientationOp.RotateRight);
Assert.Equal(90, session.Project.Camera.Rotate, "mirror and flip together are a half turn: the sense is kept");
Assert.True(session.Project.Camera is { Mirror: true, Flip: true });
}
}
[Test]
public async Task FourRightTurnsGiveBackTheSameCanonicalText()
{
var keyed = WithAspect("16:9", [0.1, 0.2, 0.4, 0.3]);
keyed = keyed with { Camera = keyed.Camera with { Keyframes = [new CameraKey(4, 0.3, 0.6, 1.5, 2)], Straighten = 1.5 } };
var (session, _) = Open(keyed);
await using (session)
{
var before = session.Project.ToJson();
for (var i = 0; i < 4; i++) Assert.True(session.Orient(OrientationOp.RotateRight));
Assert.Equal(before, session.Project.ToJson());
Assert.Equal(ProjectSettings.CurrentVersion, session.Project.RequiredFormat, "a straighten needs format 2");
}
}
[Test]
public async Task AnAspectChangeRefitsALockedCropAroundItsCentre()
{
var (session, _) = Open(WithAspect("16:9"));
await using (session)
{
var ratio = session.CropLockRatio(session.Project);
var box = CropFrame.Clamp(new RectD(0.2, 0.2, 0.5, 0.5 / ratio), ratio);
Assert.True(session.Edit(p => p with { Camera = p.Camera with { Crop = CropFrame.ToCrop(box) } }));
Assert.True(session.Edit(p => EditorSettings.Aspect.WithManual(p, "9:16")));
var refitted = CropFrame.Of(session.Project.Camera.Crop);
Assert.Approximately(session.CropLockRatio(session.Project), refitted.Width / refitted.Height, 1e-9, "locked to the new proportions");
Assert.Approximately(box.CenterX, refitted.CenterX, 1e-9, "the same centre");
Assert.Approximately(box.CenterY, refitted.CenterY, 1e-9);
Assert.Approximately(box.Width * box.Height, refitted.Width * refitted.Height, 1e-9, "the same area");
Assert.True(session.Undo());
Assert.SequenceEqual(CropFrame.ToCrop(box)!, session.Project.Camera.Crop!, "the aspect and the refit are one step");
}
}
[Test]
public async Task ALegacyCropPlacedByOffsetsIsLeftForTheRenderToFit()
{
var legacy = WithAspect("16:9", [0, 0, 1, 0.8]);
legacy = legacy with { Camera = legacy.Camera with { OffsetX = 0.5 } };
var (session, _) = Open(legacy);
await using (session)
{
Assert.True(session.Edit(p => EditorSettings.Aspect.WithManual(p, "1:1")));
Assert.SequenceEqual([0.0, 0, 1, 0.8], session.Project.Camera.Crop!);
Assert.Equal(0.5, session.Project.Camera.OffsetX);
}
}
[Test]
public async Task ResetFramingClearsTheCropAndTheOrientationAndKeepsTheKeyframes()
{
var framed = WithAspect("9:16", [0.2, 0, 0.3, 1]);
var key = new CameraKey(3, 0.4, 0.5, 2, 0);
framed = framed with
{
Camera = framed.Camera with { OffsetX = 0.2, OffsetY = -0.1, Rotate = 270, Mirror = true, Flip = true, Straighten = -3.5, Keyframes = [key] },
Look = new LookSettings { Filter = "sepia" },
};
var (session, _) = Open(framed);
await using (session)
{
Assert.True(EditorSession.HasFraming(session.Project.Camera));
Assert.True(session.ResetFraming());
var camera = session.Project.Camera;
Assert.Null(camera.Crop);
Assert.True(camera is { OffsetX: 0, OffsetY: 0, Rotate: 0, Mirror: false, Flip: false, Straighten: 0 });
Assert.SequenceEqual([key], camera.Keyframes, "keyframes stay");
Assert.Equal("9:16", camera.Aspect.Manual, "the aspect is not framing");
Assert.Equal("sepia", session.Project.Look?.Filter, "nor the look");
Assert.False(EditorSession.HasFraming(camera));
Assert.False(session.ResetFraming(), "nothing left to clear");
Assert.True(session.Undo());
Assert.Equal(270, session.Project.Camera.Rotate, "one step");
}
}
[Test]
public async Task ASequencePresetKeepsTheOrientationAndTheLook()
{
var turned = new ProjectSettings() with { Look = new LookSettings { Filter = "mono", Strength = 0.5 } };
turned = turned with { Camera = turned.Camera with { Rotate = 90, Mirror = true, Straighten = 2 } };
var (session, _) = Open(turned);
await using (session)
{
Assert.True(session.ApplyPreset(session.Presets.First(p => p.Id == "social-vertical")));
Assert.True(session.Project.Camera is { Rotate: 90, Mirror: true, Straighten: 2 });
Assert.Equal("mono", session.Project.Look?.Filter);
Assert.Equal(0.5, session.Project.Look?.Strength);
}
}
[Test]
public async Task AReadOnlyProjectIsNeitherTurnedNorReset()
{
var (session, source) = Open(WithAspect("16:9", [0.1, 0.2, 0.4, 0.3]));
await using (session)
{
source.IsReadOnly = true;
Assert.False(session.Orient(OrientationOp.RotateLeft));
Assert.False(session.ResetFraming());
Assert.Equal(0, session.Project.Camera.Rotate);
Assert.NotNull(session.Project.Camera.Crop);
}
}
}
@@ -8,7 +8,7 @@ using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>Composed texts of the editor (the conflict prompt among them), crop margins and the waveform monitor.</summary>
/// <summary>Composed texts of the editor (the conflict prompt among them, the Camera step's values) and the waveform monitor.</summary>
public sealed class EditorTextTests
{
static EditorTextTests() => _ = EditorFixture.Sunset;
@@ -38,22 +38,15 @@ public sealed class EditorTextTests
}
[Test]
public void CropMarginsKeepAtLeastATenthOfTheFrame()
public void TheCameraRowsShowAnglesAndPlacementsAsTheMockupDoes()
{
Assert.SequenceEqual([0.0, 0, 0, 0], CropMargins.Of(null));
var crop = CropMargins.With(null, CropSide.Left, 0.2);
Assert.SequenceEqual([0.2, 0, 0.8, 1], crop!);
crop = CropMargins.With(crop, CropSide.Top, 0.6);
Assert.Approximately(CropMargins.MaxMargin, crop![1], 1e-12, "no margin beyond the maximum");
crop = CropMargins.With(crop, CropSide.Left, 0.45);
crop = CropMargins.With(crop, CropSide.Right, 0.45);
Assert.Approximately(CropMargins.MinSize, crop![2], 1e-12, "opposite margins leave a tenth of the width");
var margins = CropMargins.Of(crop);
Assert.Approximately(0.45, margins[0], 1e-12);
Assert.Approximately(0.45, margins[1], 1e-12);
Assert.Null(CropMargins.With(CropMargins.With(CropMargins.With(crop, CropSide.Left, 0), CropSide.Right, 0), CropSide.Top, 0),
"no margin left is the whole frame");
Assert.SequenceEqual([0.0, 0, 0, 0], CropMargins.Of([double.NaN, 0, 1, 1]), "an invalid crop is ignored, as the render does");
Assert.Equal("−1.2°", CameraTab.Degrees(-1.2), "a minus sign, one decimal");
Assert.Equal("15.0°", CameraTab.Degrees(15));
Assert.Equal("0°", CameraTab.Degrees(0), "level reads as a whole number");
Assert.Equal("0°", CameraTab.Degrees(-0.0), "never a negative zero");
Assert.Equal("+0.40", EditorText.Placement(0.4));
Assert.Equal("−0.60", EditorText.Placement(-0.6));
Assert.Equal("Centred", EditorText.Placement(0));
}
[Test]
@@ -1,6 +1,7 @@
using Chronos.App.Editor;
using Chronos.Core.Advice;
using Chronos.Core.Export;
using Chronos.Core.Localization;
using Chronos.Core.Project;
using Chronos.Core.Video;
using Chronos.Core.Video.Managed;
@@ -90,4 +91,57 @@ public sealed class ExportPlannerTests
Assert.Equal("Custom", plan.PresetName);
Assert.Equal(48, plan.Setup.Encoder.Settings.Width);
}
/// <summary>An H.264 encoder that takes at most <paramref name="maxWidth"/>×<paramref name="maxHeight"/> (either way round).</summary>
private sealed class H264Provider(int maxWidth, int maxHeight) : IVideoEncoderProvider
{
public string Name => "h264";
public IReadOnlyList<EncoderCapability> Capabilities { get; } = [new(VideoCodec.H264, "Test H.264", false, maxWidth, maxHeight, false)];
public bool CanEncode(EncodeSettings settings) => settings.Codec == VideoCodec.H264;
public IVideoEncoderSession Open(EncodeSettings settings) => throw new NotSupportedException("Planning never encodes.");
}
private static ProjectSettings FourKAt(string aspect)
{
var project = new ProjectSettings();
return project with
{
Camera = project.Camera with { Aspect = project.Camera.Aspect.WithManual(aspect) },
Export = project.Export with { Preset = project.Export.Preset.WithManual("4k-h264") },
};
}
[Test]
public void TheChosenProportionsWinAndThePresetKeepsItsName()
{
var planner = new ExportPlanner(Content, [new H264Provider(4096, 2304)], EncoderHost.Client);
var plan = planner.Plan(FourKAt("9:16"))!;
Assert.Equal((2160, 3840), plan.OutputSize, "4K at 9:16");
Assert.Equal((2160, 3840), plan.EncodedSize, "the encoder takes it turned");
Assert.False(plan.IsCapped);
Assert.Equal("2160 × 3840", ExportTab.OutputSizeOf(plan));
Assert.Equal(Loc.L("Tooltips.Editor.Export.OutputSize"), ExportTab.OutputSizeToolTipOf(plan));
Assert.Equal(Loc.L("Export.Preset.4kH264"), plan.PresetName, "the preset is not made Custom");
Assert.False(plan.Export.IsCustom);
Assert.Equal((3840, 2160), (plan.Export.Width, plan.Export.Height), "Width × Height stay the preset's box");
var workload = plan.Setup.Workload();
Assert.Equal((2160, 3840), (workload.Width, workload.Height), "the estimate is of the adapted size");
var source = planner.Plan(FourKAt("source"))!;
Assert.Equal((3840, 2160), source.OutputSize, "source keeps the preset's ratio");
}
[Test]
public void AnOutputTheEncoderShrinksIsMarkedCapped()
{
var plan = new ExportPlanner(Content, [new H264Provider(1920, 1080)], EncoderHost.Client).Plan(FourKAt("9:16"))!;
Assert.Equal((2160, 3840), plan.OutputSize);
Assert.Equal((1080, 1920), plan.EncodedSize);
Assert.True(plan.IsCapped);
Assert.Equal(Loc.L("Editor.Export.Capped", "1080 × 1920"), ExportTab.OutputSizeOf(plan));
Assert.Equal(Loc.L("Tooltips.Editor.Export.OutputCapped", "1080 × 1920"), ExportTab.OutputSizeToolTipOf(plan), "the largest size it takes, turned");
}
}