Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 102 additions & 21 deletions src/ui/Features/Video/BurnIn/BurnInWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.Threading;
using Nikse.SubtitleEdit.Controls;
using Nikse.SubtitleEdit.Features.Main.Layout;
using Nikse.SubtitleEdit.Logic;
Expand All @@ -24,7 +25,7 @@ public BurnInWindow(BurnInViewModel vm)
UiUtil.InitializeWindow(this, GetType().Name);
Title = Se.Language.Video.BurnIn.Title;
SizeToContent = SizeToContent.WidthAndHeight;
CanResize = false;
CanResize = true;
vm.Window = this;
DataContext = vm;

Expand All @@ -38,6 +39,15 @@ public BurnInWindow(BurnInViewModel vm)
var videoInfoView = MakeVideoInfoView(vm);
var progressView = MakeProgressView(vm);

// Keep the left column (subtitle + video + target size) together and top-aligned so the
// extra vertical space goes to the preview instead of opening a gap between the boxes.
var leftPanel = new StackPanel
{
Orientation = Orientation.Vertical,
VerticalAlignment = VerticalAlignment.Top,
Children = { subtitleSettingsView, videoSettingsView, targetFileSizeView },
};

var buttonGenerate = new SplitButton
{
Content = Se.Language.General.Generate,
Expand Down Expand Up @@ -73,45 +83,116 @@ public BurnInWindow(BurnInViewModel vm)
UiUtil.MakeButtonCancel(vm.CancelCommand)
);

// The preview column grows in single mode; the batch column grows in batch mode
// (toggled in UpdateGrowAreas). The preview/batch row is a star row so the preview
// (single mode) and the batch list (batch mode) also grow vertically.
var previewColumn = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
var batchColumn = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) };

var grid = new Grid
{
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, // target file size + video info
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // cut
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, // preview + batch list
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // audio
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // video info
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // progress bar
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // buttons
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, // subtitle/video settings
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, // cut/preview/audio settings
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, // batch mode
previewColumn, // cut/preview/audio settings
batchColumn, // batch mode
},
Margin = UiUtil.MakeWindowMargin(),
Width = double.NaN,
HorizontalAlignment = HorizontalAlignment.Stretch,
};

grid.Add(subtitleSettingsView, 0, 0, 2, 1);
grid.Add(videoSettingsView, 2, 0);
grid.Add(leftPanel, 0, 0, 4, 1);
grid.Add(cutView, 0, 1);
grid.Add(previewView, 1, 1);
grid.Add(audioSettingsView, 2, 1);
grid.Add(batchView, 0, 3, 3, 1);
grid.Add(targetFileSizeView, 4, 0);
grid.Add(videoInfoView, 4, 1);
grid.Add(progressView, 5, 0, 1, 3);
grid.Add(buttonPanel, 6, 0, 1, 3);
grid.Add(videoInfoView, 3, 1);
grid.Add(batchView, 0, 2, 4, 1);
grid.Add(progressView, 4, 0, 1, 3);
grid.Add(buttonPanel, 5, 0, 1, 3);

Content = grid;

void UpdateGrowAreas()
{
// Steer extra space to whichever area is in use: the preview (single mode) or the batch list (batch mode).
previewColumn.Width = new GridLength(1, vm.IsBatchMode ? GridUnitType.Auto : GridUnitType.Star);
batchColumn.Width = new GridLength(1, vm.IsBatchMode ? GridUnitType.Star : GridUnitType.Auto);

// In batch mode the file list is the focus, so keep the preview small; in single mode let it grow.
var player = vm.VideoPlayerControl;
if (player == null)
{
return;
}

if (vm.IsBatchMode)
{
player.MinWidth = 0;
player.MinHeight = 0;
player.Width = 240;
player.Height = 135;
player.HorizontalAlignment = HorizontalAlignment.Left;
player.VerticalAlignment = VerticalAlignment.Top;
}
else
{
player.Width = double.NaN;
player.Height = double.NaN;
player.MinWidth = 480;
player.MinHeight = 270;
player.HorizontalAlignment = HorizontalAlignment.Stretch;
player.VerticalAlignment = VerticalAlignment.Stretch;
}
}

vm.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(vm.IsBatchMode))
{
UpdateGrowAreas();
LockMinimumToContentSize(); // batch mode needs more width; re-fit and re-lock the minimum
}
};
UpdateGrowAreas();

Activated += delegate { buttonOk.Focus(); }; // hack to make OnKeyDown work
Loaded += (_, _) => vm.Loaded();
KeyDown += (_, e) => vm.OnKeyDown(e);

Opened += (_, _) => LockMinimumToContentSize();
}

private void LockMinimumToContentSize()
{
// Re-fit the window to the current mode's content (single mode is narrower; batch mode
// needs more width for the file list), then lock that size in as the new minimum while
// still allowing the user to enlarge the window further.
MinWidth = 0;
MinHeight = 0;
SizeToContent = SizeToContent.WidthAndHeight;
Dispatcher.UIThread.Post(() =>
{
var width = ClientSize.Width;
var height = ClientSize.Height;
SizeToContent = SizeToContent.Manual;
if (width > 0 && height > 0)
{
MinWidth = width;
MinHeight = height;
Width = width;
Height = height;
}
}, DispatcherPriority.Loaded);
}

protected override void OnClosing(WindowClosingEventArgs e)
Expand Down Expand Up @@ -508,21 +589,21 @@ private static Border MakePreviewView(BurnInViewModel vm)
vm.VideoPlayerControl = InitVideoPlayer.MakeVideoPlayer();
vm.VideoPlayerControl.FullScreenIsVisible = true;
vm.VideoPlayerControl.FullScreenCommand = vm.PreviewFullScreenCommand;
vm.VideoPlayerControl.Width = 480;
vm.VideoPlayerControl.Height = 270;
vm.VideoPlayerControl.HorizontalAlignment = HorizontalAlignment.Left;
vm.VideoPlayerControl.VerticalAlignment = VerticalAlignment.Top;
vm.VideoPlayerControl.MinWidth = 480;
vm.VideoPlayerControl.MinHeight = 270;
vm.VideoPlayerControl.HorizontalAlignment = HorizontalAlignment.Stretch;
vm.VideoPlayerControl.VerticalAlignment = VerticalAlignment.Stretch;

var grid = new Grid
{
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, // video player grows
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
},
ColumnSpacing = 5,
RowSpacing = 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
using Nikse.SubtitleEdit.Controls;
using Nikse.SubtitleEdit.Features.Video.BurnIn;
using Nikse.SubtitleEdit.Logic;
Expand All @@ -22,14 +23,22 @@ public TransparentSubtitlesWindow(TransparentSubtitlesViewModel vm)
UiUtil.InitializeWindow(this, GetType().Name);
Title = Se.Language.Video.VideoTransparent.Title;
SizeToContent = SizeToContent.WidthAndHeight;
CanResize = false;
CanResize = true;

_vm = vm;
vm.Window = this;
DataContext = vm;

var subtitleSettingsView = MakeSubtitlesView(vm);
var videoSettingsView = MakeVideoSettingsView(vm);
// Keep the left column (subtitle + video settings) together and top-aligned so the extra
// vertical space goes to the preview instead of opening a gap between the two boxes.
var leftPanel = new StackPanel
{
Orientation = Orientation.Vertical,
VerticalAlignment = VerticalAlignment.Top,
Children = { subtitleSettingsView, videoSettingsView },
};
var cutView = MakeCutView(vm);
var previewView = MakePreviewView(vm);
var batchView = MakeBatchView(vm);
Expand Down Expand Up @@ -69,40 +78,86 @@ public TransparentSubtitlesWindow(TransparentSubtitlesViewModel vm)
UiUtil.MakeButtonCancel(vm.CancelCommand)
);

// The preview column grows in single mode; the batch column grows in batch mode
// (toggled in UpdateGrowAreas). The preview/batch row is a star row so the preview
// (single mode) and the batch list (batch mode) also grow vertically.
var previewColumn = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
var batchColumn = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) };

var grid = new Grid
{
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, // subtitle settings (lower) + preview
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // cut
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, // preview + batch list
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // video info
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // progress bar
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }, // buttons
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, // subtitle/video settings
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, // cut/preview/video info
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, // batch mode
previewColumn, // cut/preview/video info
batchColumn, // batch mode
},
Margin = UiUtil.MakeWindowMargin(),
Width = double.NaN,
HorizontalAlignment = HorizontalAlignment.Stretch,
};

grid.Add(subtitleSettingsView, 0, 0, 2, 1);
grid.Add(videoSettingsView, 2, 0);
grid.Add(leftPanel, 0, 0, 3, 1);
grid.Add(cutView, 0, 1);
grid.Add(previewView, 1, 1);
grid.Add(batchView, 0, 3, 3, 1);
grid.Add(videoInfoView, 2, 1);
grid.Add(progressView, 4, 0, 1, 3);
grid.Add(buttonPanel, 5, 0, 1, 3);
grid.Add(batchView, 0, 3, 3, 1);
grid.Add(progressView, 3, 0, 1, 3);
grid.Add(buttonPanel, 4, 0, 1, 3);

Content = grid;

void UpdateGrowAreas()
{
// Steer extra space to whichever area is in use: the preview (single mode) or the batch list (batch mode).
previewColumn.Width = new GridLength(1, vm.IsBatchMode ? GridUnitType.Auto : GridUnitType.Star);
batchColumn.Width = new GridLength(1, vm.IsBatchMode ? GridUnitType.Star : GridUnitType.Auto);
}

vm.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(vm.IsBatchMode))
{
UpdateGrowAreas();
LockMinimumToContentSize(); // batch mode needs more width; re-fit and re-lock the minimum
}
};
UpdateGrowAreas();

Activated += delegate { buttonOk.Focus(); }; // hack to make OnKeyDown work

Opened += (_, _) => LockMinimumToContentSize();
}

private void LockMinimumToContentSize()
{
// Re-fit the window to the current mode's content (single mode is narrower; batch mode
// needs more width for the file list), then lock that size in as the new minimum while
// still allowing the user to enlarge the window further.
MinWidth = 0;
MinHeight = 0;
SizeToContent = SizeToContent.WidthAndHeight;
Dispatcher.UIThread.Post(() =>
{
var width = ClientSize.Width;
var height = ClientSize.Height;
SizeToContent = SizeToContent.Manual;
if (width > 0 && height > 0)
{
MinWidth = width;
MinHeight = height;
Width = width;
Height = height;
}
}, DispatcherPriority.Loaded);
}

private static Border MakeSubtitlesView(TransparentSubtitlesViewModel vm)
Expand Down Expand Up @@ -420,7 +475,7 @@ private static Border MakePreviewView(TransparentSubtitlesViewModel vm)
VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Width = 300,
MinWidth = 300,
Height = double.NaN,
};

Expand All @@ -429,11 +484,11 @@ private static Border MakePreviewView(TransparentSubtitlesViewModel vm)
RowDefinitions =
{
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) },
new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, // preview grows
},
ColumnDefinitions =
{
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
},
ColumnSpacing = 5,
RowSpacing = 5,
Expand Down