]> granicus.if.org Git - handbrake/commitdiff
WinGui: Some further work in the background on the still preview feature.
authorsr55 <sr55.hb@outlook.com>
Fri, 6 Dec 2013 21:32:58 +0000 (21:32 +0000)
committersr55 <sr55.hb@outlook.com>
Fri, 6 Dec 2013 21:32:58 +0000 (21:32 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5922 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs
win/CS/HandBrakeWPF/ViewModels/StaticPreviewViewModel.cs
win/CS/HandBrakeWPF/Views/MainView.xaml
win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml

index 1069217832f294677f82ee5fa34c1016617eda3b..b3c73822bd2ea3fb09fc8b0a0fbc3ae99e1a65d2 100644 (file)
     <Compile Include="Factories\HBConfigurationFactory.cs" />\r
     <Compile Include="Services\Interfaces\IUserSettingService.cs" />\r
     <Compile Include="Services\UserSettingService.cs" />\r
+    <Compile Include="Utilities\DelayedActionProcessor.cs" />\r
     <Compile Include="ViewModels\CountdownAlertViewModel.cs" />\r
     <Compile Include="ViewModels\Interfaces\ICountdownAlertViewModel.cs" />\r
     <Compile Include="Controls\SourceSelection.xaml.cs">\r
diff --git a/win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs b/win/CS/HandBrakeWPF/Utilities/DelayedActionProcessor.cs
new file mode 100644 (file)
index 0000000..14d70c6
--- /dev/null
@@ -0,0 +1,73 @@
+// --------------------------------------------------------------------------------------------------------------------\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
index e3cb8afa18f312906901527b776ff0d4eb5289ef..c45299e8ee3448cba8d202574efbc2e6c642808b 100644 (file)
@@ -23,7 +23,7 @@ namespace HandBrakeWPF.ViewModels
     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
@@ -103,6 +103,11 @@ namespace HandBrakeWPF.ViewModels
         /// </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
@@ -157,6 +162,7 @@ namespace HandBrakeWPF.ViewModels
                 this.NotifyOfPropertyChange(() => this.CropBottom);\r
                 this.CropAdjust();\r
                 this.SetDisplaySize();\r
+                this.UpdatePreviewImage();\r
             }\r
         }\r
 \r
@@ -176,6 +182,7 @@ namespace HandBrakeWPF.ViewModels
                 this.NotifyOfPropertyChange(() => this.CropLeft);\r
                 this.CropAdjust();\r
                 this.SetDisplaySize();\r
+                this.UpdatePreviewImage();\r
             }\r
         }\r
 \r
@@ -195,6 +202,7 @@ namespace HandBrakeWPF.ViewModels
                 this.NotifyOfPropertyChange(() => this.CropRight);\r
                 this.CropAdjust();\r
                 this.SetDisplaySize();\r
+                this.UpdatePreviewImage();\r
             }\r
         }\r
 \r
@@ -214,6 +222,7 @@ namespace HandBrakeWPF.ViewModels
                 this.NotifyOfPropertyChange(() => this.CropTop);\r
                 this.CropAdjust();\r
                 this.SetDisplaySize();\r
+                this.UpdatePreviewImage();\r
             }\r
         }\r
 \r
@@ -253,6 +262,7 @@ namespace HandBrakeWPF.ViewModels
                     this.Task.DisplayWidth = value;\r
                     this.CustomAnamorphicAdjust();\r
                     this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+                    this.UpdatePreviewImage();\r
                 }\r
             }\r
         }\r
@@ -274,6 +284,7 @@ namespace HandBrakeWPF.ViewModels
                     this.Task.Height = value;\r
                     this.HeightAdjust();\r
                     this.NotifyOfPropertyChange(() => this.Height);\r
+                    this.UpdatePreviewImage();\r
                 }\r
             }\r
         }\r
@@ -327,6 +338,7 @@ namespace HandBrakeWPF.ViewModels
                 this.Task.KeepDisplayAspect = value;\r
                 this.WidthAdjust();\r
                 this.NotifyOfPropertyChange(() => this.MaintainAspectRatio);\r
+                this.UpdatePreviewImage();\r
             }\r
         }\r
 \r
@@ -358,6 +370,7 @@ namespace HandBrakeWPF.ViewModels
                     this.Task.PixelAspectY = value;\r
                     this.CustomAnamorphicAdjust();\r
                     this.NotifyOfPropertyChange(() => this.ParHeight);\r
+                    this.UpdatePreviewImage();\r
                 }\r
             }\r
         }\r
@@ -379,6 +392,7 @@ namespace HandBrakeWPF.ViewModels
                     this.Task.PixelAspectX = value;\r
                     this.CustomAnamorphicAdjust();\r
                     this.NotifyOfPropertyChange(() => this.ParWidth);\r
+                    this.UpdatePreviewImage();\r
                 }\r
             }\r
         }\r
@@ -400,6 +414,7 @@ namespace HandBrakeWPF.ViewModels
                     this.Task.Anamorphic = value;\r
                     this.AnamorphicAdjust();\r
                     this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);\r
+                    this.UpdatePreviewImage();\r
                 }\r
             }\r
         }\r
@@ -419,6 +434,7 @@ namespace HandBrakeWPF.ViewModels
                 this.Task.Modulus = value;\r
                 this.ModulusAdjust();\r
                 this.NotifyOfPropertyChange(() => this.SelectedModulus);\r
+                this.UpdatePreviewImage();\r
             }\r
         }\r
 \r
@@ -510,6 +526,7 @@ namespace HandBrakeWPF.ViewModels
                     this.Task.Width = value;\r
                     this.WidthAdjust();\r
                     this.NotifyOfPropertyChange(() => this.Width);\r
+                    this.UpdatePreviewImage();\r
                 }\r
             }\r
         }\r
@@ -768,7 +785,7 @@ namespace HandBrakeWPF.ViewModels
                     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
@@ -812,7 +829,7 @@ namespace HandBrakeWPF.ViewModels
             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
@@ -1176,6 +1193,28 @@ namespace HandBrakeWPF.ViewModels
             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
index d836f6d49800be2c5ea0ae52ed48420353ecdf4a..c4a26e0330a238272f997ff909e7a27bff703f27 100644 (file)
@@ -189,6 +189,12 @@ namespace HandBrakeWPF.ViewModels
             this.PreviewImage = image;\r
         }\r
 \r
+        protected override void OnActivate()\r
+        {\r
+            Console.Write("test");\r
+            base.OnActivate();\r
+        }\r
+\r
         /// <summary>\r
         ///     The update preview frame.\r
         /// </summary>\r
index 46fc614f0f317a865c55f15ca4a95f110aa44bdb..9c5a21f00f90fb97eff06a6e6119f03a65012642 100644 (file)
         \r
         <!-- Source Selection-->       \r
         <Controls:SourceSelection Grid.Row="1" Width="400" VerticalAlignment="Stretch" BorderThickness="1" BorderBrush="DarkGray"\r
-                                  Visibility="{Binding ShowSourceSelection, Converter={StaticResource boolToVisConverter}}"  />\r
+                                  Visibility="{Binding ShowSourceSelection, Converter={StaticResource boolToVisConverter}}" \r
+                                  Margin="0,10,0,10" />\r
         \r
         <!--  StatusPanel  -->\r
         <Controls:StatusPanel x:Name="loadingPanel"\r
index 629fa85a1e2f7228eaa8f67f183e45756298cbe0..2a5d136bc39054d629183ae4895ed8f615248ca3 100644 (file)
 \r
     <StackPanel Orientation="Horizontal" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">\r
 \r
+        <StackPanel.ContextMenu>\r
+            <ContextMenu>\r
+                <MenuItem Header="Show Still Preview (Experimental)" cal:Message.Attach="[Event Click] = [Action PreviewImage]" Visibility="Visible" />\r
+            </ContextMenu>\r
+        </StackPanel.ContextMenu>\r
+        \r
         <!-- Size Panel-->\r
         <StackPanel Name="SizePanel" Orientation="Vertical" >\r
             <Label Content="Size" FontWeight="Bold" />\r
 \r
             </Grid>\r
 \r
-\r
-            <Label Content="Preview" FontWeight="Bold" Margin="15,0,0,0"  Visibility="Collapsed"/>\r
-            <Button Content="Show Preview" cal:Message.Attach="[Event Click] = [Action PreviewImage]" Visibility="Collapsed" />\r
-\r
         </StackPanel>\r
     </StackPanel>\r
 </UserControl>\r