From 87737b6fe394bfb86bd277ccbe314bf11cf14374 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 6 Dec 2013 21:32:58 +0000 Subject: WinGui: Some further work in the background on the still preview feature. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5922 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../Utilities/DelayedActionProcessor.cs | 73 ++++++++++++++++++++++ .../ViewModels/PictureSettingsViewModel.cs | 47 ++++++++++++-- .../ViewModels/StaticPreviewViewModel.cs | 6 ++ win/CS/HandBrakeWPF/Views/MainView.xaml | 3 +- win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml | 10 +-- 6 files changed, 131 insertions(+), 9 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 106921783..b3c73822b 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -144,6 +144,7 @@ + diff --git a/win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs b/win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs new file mode 100644 index 000000000..14d70c691 --- /dev/null +++ b/win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs @@ -0,0 +1,73 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// An Action processor that supports queueing/delayed action processing. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Utilities +{ + using System; + using System.Timers; + + /// + /// An Action processor that supports queueing/delayed action processing. + /// + public class DelayedActionProcessor + { + /// + /// The task. + /// + private Action task; + + /// + /// The timer. + /// + private Timer timer; + + /// + /// The set task. + /// + /// + /// The task reset. + /// + /// + /// The timems. + /// + public void PerformTask(Action taskReset, int timems) + { + if (timer != null) + { + timer.Stop(); + timer.Close(); + } + + + timer = new Timer(timems) { AutoReset = true }; + timer.Elapsed += this.timer_Elapsed; + task = taskReset; + timer.Stop(); + timer.Start(); + } + + /// + /// The timer_ elapsed. + /// + /// + /// The sender. + /// + /// + /// The e. + /// + private void timer_Elapsed(object sender, ElapsedEventArgs e) + { + if (task != null) + { + timer.Stop(); + task(); + } + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index e3cb8afa1..c45299e8e 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -23,7 +23,7 @@ namespace HandBrakeWPF.ViewModels using HandBrake.Interop.Model.Encoding; using HandBrakeWPF.Helpers; - using HandBrakeWPF.Services.Interfaces; + using HandBrakeWPF.Utilities; using HandBrakeWPF.ViewModels.Interfaces; using Size = System.Drawing.Size; @@ -103,6 +103,11 @@ namespace HandBrakeWPF.ViewModels /// private bool showKeepAr = true; + /// + /// The delayed previewprocessor. + /// + private DelayedActionProcessor delayedPreviewprocessor = new DelayedActionProcessor(); + #endregion #region Constructors and Destructors @@ -157,6 +162,7 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.CropBottom); this.CropAdjust(); this.SetDisplaySize(); + this.UpdatePreviewImage(); } } @@ -176,6 +182,7 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.CropLeft); this.CropAdjust(); this.SetDisplaySize(); + this.UpdatePreviewImage(); } } @@ -195,6 +202,7 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.CropRight); this.CropAdjust(); this.SetDisplaySize(); + this.UpdatePreviewImage(); } } @@ -214,6 +222,7 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.CropTop); this.CropAdjust(); this.SetDisplaySize(); + this.UpdatePreviewImage(); } } @@ -253,6 +262,7 @@ namespace HandBrakeWPF.ViewModels this.Task.DisplayWidth = value; this.CustomAnamorphicAdjust(); this.NotifyOfPropertyChange(() => this.DisplayWidth); + this.UpdatePreviewImage(); } } } @@ -274,6 +284,7 @@ namespace HandBrakeWPF.ViewModels this.Task.Height = value; this.HeightAdjust(); this.NotifyOfPropertyChange(() => this.Height); + this.UpdatePreviewImage(); } } } @@ -327,6 +338,7 @@ namespace HandBrakeWPF.ViewModels this.Task.KeepDisplayAspect = value; this.WidthAdjust(); this.NotifyOfPropertyChange(() => this.MaintainAspectRatio); + this.UpdatePreviewImage(); } } @@ -358,6 +370,7 @@ namespace HandBrakeWPF.ViewModels this.Task.PixelAspectY = value; this.CustomAnamorphicAdjust(); this.NotifyOfPropertyChange(() => this.ParHeight); + this.UpdatePreviewImage(); } } } @@ -379,6 +392,7 @@ namespace HandBrakeWPF.ViewModels this.Task.PixelAspectX = value; this.CustomAnamorphicAdjust(); this.NotifyOfPropertyChange(() => this.ParWidth); + this.UpdatePreviewImage(); } } } @@ -400,6 +414,7 @@ namespace HandBrakeWPF.ViewModels this.Task.Anamorphic = value; this.AnamorphicAdjust(); this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode); + this.UpdatePreviewImage(); } } } @@ -419,6 +434,7 @@ namespace HandBrakeWPF.ViewModels this.Task.Modulus = value; this.ModulusAdjust(); this.NotifyOfPropertyChange(() => this.SelectedModulus); + this.UpdatePreviewImage(); } } @@ -510,6 +526,7 @@ namespace HandBrakeWPF.ViewModels this.Task.Width = value; this.WidthAdjust(); this.NotifyOfPropertyChange(() => this.Width); + this.UpdatePreviewImage(); } } } @@ -768,7 +785,7 @@ namespace HandBrakeWPF.ViewModels if (this.SelectedAnamorphicMode == Anamorphic.None) { this.Width = preset.Task.Width ?? (this.MaxWidth - this.CropLeft - this.CropRight); - // Note: This will be auto-corrected in the property if it's too large. + // Note: This will be auto-corrected in the property if it's too large. } else { @@ -812,7 +829,7 @@ namespace HandBrakeWPF.ViewModels if (image != null) { this.StaticPreviewViewModel.PreviewFrame(image, this.Task); - this.WindowManager.ShowDialog(this.StaticPreviewViewModel); + this.WindowManager.ShowWindow(this.StaticPreviewViewModel); } } @@ -1176,6 +1193,28 @@ namespace HandBrakeWPF.ViewModels return job; } - #endregion + /// + /// Updates the preview after a period of time. + /// This gives the user the opertunity to make changes in quick sucession without the image refreshing instantly + /// and causing performance lag. + /// + private void UpdatePreviewImage() + { + if (delayedPreviewprocessor != null) + { + delayedPreviewprocessor.PerformTask(() => + { + IScan scanService = IoC.Get(); + BitmapImage image = scanService.GetPreview(this.Task, 1); + + if (image != null) + { + this.StaticPreviewViewModel.PreviewFrame(image, this.Task); + } + }, 800); + } + } + + #endregion } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs index d836f6d49..c4a26e033 100644 --- a/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs @@ -189,6 +189,12 @@ namespace HandBrakeWPF.ViewModels this.PreviewImage = image; } + protected override void OnActivate() + { + Console.Write("test"); + base.OnActivate(); + } + /// /// The update preview frame. /// diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 46fc614f0..9c5a21f00 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -686,7 +686,8 @@ + Visibility="{Binding ShowSourceSelection, Converter={StaticResource boolToVisConverter}}" + Margin="0,10,0,10" /> + + + + + +