--- /dev/null
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="DelayedActionProcessor.cs" company="HandBrake Project (http://handbrake.fr)">\r
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+// An Action processor that supports queueing/delayed action processing.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Utilities\r
+{\r
+ using System;\r
+ using System.Timers;\r
+\r
+ /// <summary>\r
+ /// An Action processor that supports queueing/delayed action processing.\r
+ /// </summary>\r
+ public class DelayedActionProcessor\r
+ {\r
+ /// <summary>\r
+ /// The task.\r
+ /// </summary>\r
+ private Action task;\r
+\r
+ /// <summary>\r
+ /// The timer.\r
+ /// </summary>\r
+ private Timer timer;\r
+\r
+ /// <summary>\r
+ /// The set task.\r
+ /// </summary>\r
+ /// <param name="taskReset">\r
+ /// The task reset.\r
+ /// </param>\r
+ /// <param name="timems">\r
+ /// The timems.\r
+ /// </param>\r
+ public void PerformTask(Action taskReset, int timems)\r
+ {\r
+ if (timer != null)\r
+ {\r
+ timer.Stop();\r
+ timer.Close(); \r
+ }\r
+\r
+\r
+ timer = new Timer(timems) { AutoReset = true };\r
+ timer.Elapsed += this.timer_Elapsed;\r
+ task = taskReset;\r
+ timer.Stop();\r
+ timer.Start();\r
+ }\r
+\r
+ /// <summary>\r
+ /// The timer_ elapsed.\r
+ /// </summary>\r
+ /// <param name="sender">\r
+ /// The sender.\r
+ /// </param>\r
+ /// <param name="e">\r
+ /// The e.\r
+ /// </param>\r
+ private void timer_Elapsed(object sender, ElapsedEventArgs e)\r
+ {\r
+ if (task != null)\r
+ {\r
+ timer.Stop();\r
+ task(); \r
+ }\r
+ }\r
+ }\r
+}\r
using HandBrake.Interop.Model.Encoding;\r
\r
using HandBrakeWPF.Helpers;\r
- using HandBrakeWPF.Services.Interfaces;\r
+ using HandBrakeWPF.Utilities;\r
using HandBrakeWPF.ViewModels.Interfaces;\r
\r
using Size = System.Drawing.Size;\r
/// </summary>\r
private bool showKeepAr = true;\r
\r
+ /// <summary>\r
+ /// The delayed previewprocessor.\r
+ /// </summary>\r
+ private DelayedActionProcessor delayedPreviewprocessor = new DelayedActionProcessor();\r
+\r
#endregion\r
\r
#region Constructors and Destructors\r
this.NotifyOfPropertyChange(() => this.CropBottom);\r
this.CropAdjust();\r
this.SetDisplaySize();\r
+ this.UpdatePreviewImage();\r
}\r
}\r
\r
this.NotifyOfPropertyChange(() => this.CropLeft);\r
this.CropAdjust();\r
this.SetDisplaySize();\r
+ this.UpdatePreviewImage();\r
}\r
}\r
\r
this.NotifyOfPropertyChange(() => this.CropRight);\r
this.CropAdjust();\r
this.SetDisplaySize();\r
+ this.UpdatePreviewImage();\r
}\r
}\r
\r
this.NotifyOfPropertyChange(() => this.CropTop);\r
this.CropAdjust();\r
this.SetDisplaySize();\r
+ this.UpdatePreviewImage();\r
}\r
}\r
\r
this.Task.DisplayWidth = value;\r
this.CustomAnamorphicAdjust();\r
this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
}\r
this.Task.Height = value;\r
this.HeightAdjust();\r
this.NotifyOfPropertyChange(() => this.Height);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
}\r
this.Task.KeepDisplayAspect = value;\r
this.WidthAdjust();\r
this.NotifyOfPropertyChange(() => this.MaintainAspectRatio);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
\r
this.Task.PixelAspectY = value;\r
this.CustomAnamorphicAdjust();\r
this.NotifyOfPropertyChange(() => this.ParHeight);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
}\r
this.Task.PixelAspectX = value;\r
this.CustomAnamorphicAdjust();\r
this.NotifyOfPropertyChange(() => this.ParWidth);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
}\r
this.Task.Anamorphic = value;\r
this.AnamorphicAdjust();\r
this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
}\r
this.Task.Modulus = value;\r
this.ModulusAdjust();\r
this.NotifyOfPropertyChange(() => this.SelectedModulus);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
\r
this.Task.Width = value;\r
this.WidthAdjust();\r
this.NotifyOfPropertyChange(() => this.Width);\r
+ this.UpdatePreviewImage();\r
}\r
}\r
}\r
if (this.SelectedAnamorphicMode == Anamorphic.None)\r
{\r
this.Width = preset.Task.Width ?? (this.MaxWidth - this.CropLeft - this.CropRight);\r
- // Note: This will be auto-corrected in the property if it's too large.\r
+ // Note: This will be auto-corrected in the property if it's too large.\r
}\r
else\r
{\r
if (image != null)\r
{\r
this.StaticPreviewViewModel.PreviewFrame(image, this.Task);\r
- this.WindowManager.ShowDialog(this.StaticPreviewViewModel);\r
+ this.WindowManager.ShowWindow(this.StaticPreviewViewModel);\r
}\r
}\r
\r
return job;\r
}\r
\r
- #endregion\r
+ /// <summary>\r
+ /// Updates the preview after a period of time.\r
+ /// This gives the user the opertunity to make changes in quick sucession without the image refreshing instantly\r
+ /// and causing performance lag.\r
+ /// </summary>\r
+ private void UpdatePreviewImage()\r
+ {\r
+ if (delayedPreviewprocessor != null)\r
+ {\r
+ delayedPreviewprocessor.PerformTask(() =>\r
+ {\r
+ IScan scanService = IoC.Get<IScan>();\r
+ BitmapImage image = scanService.GetPreview(this.Task, 1);\r
+\r
+ if (image != null)\r
+ {\r
+ this.StaticPreviewViewModel.PreviewFrame(image, this.Task);\r
+ }\r
+ }, 800);\r
+ }\r
+ }\r
+\r
+ #endregion\r
}\r
}
\ No newline at end of file