]> granicus.if.org Git - handbrake/commitdiff
WinGui: Refactor the Presets Picture Size handling to make it a bit clearer what...
authorsr55 <sr55.hb@outlook.com>
Sat, 25 May 2013 15:22:10 +0000 (15:22 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 25 May 2013 15:22:10 +0000 (15:22 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5512 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrake.ApplicationServices/Model/PresetPictureSettingsMode.cs
win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
win/CS/HandBrakeWPF/Properties/Resources.resx
win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs
win/CS/HandBrakeWPF/ViewModels/Interfaces/IAddPresetViewModel.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs
win/CS/HandBrakeWPF/Views/AddPresetView.xaml

index e670ccb7e17eee88216b2c3b64d8ba7364bc0b71..d6a84a617cfe591573272b9a6bfa0b533fbc46b3 100644 (file)
@@ -18,9 +18,11 @@ namespace HandBrake.ApplicationServices.Model
     {\r
         [Display(Name = "None")]\r
         None = 0,\r
-        [Display(Name = "Custom")]\r
+        [Display(Name = "Custom (Keep AR)")]\r
         Custom = 1,\r
-        [Display(Name = "Source Maximum")]\r
+        [Display(Name = "Current Source Max Size (Keep AR)")]\r
         SourceMaximum = 2,\r
+        [Display(Name = "No Limit (Keep AR)")]\r
+        NoLimit = 3,\r
     }\r
 }
\ No newline at end of file
index 1b2f1531a594e07da7da700a540a035f9e76abf5..bef7d703005f53253dc4e46fcc94220e48eb7529 100644 (file)
@@ -80,13 +80,13 @@ namespace HandBrakeWPF.Properties {
         }\r
         \r
         /// <summary>\r
-        ///   Looks up a localized string similar to You can optionally store a maximum resolution for encodes that use this preset. There are 3 modes:\r
+        ///   Looks up a localized string similar to You can optionally store a maximum resolution for encodes that use this preset. There are 4 modes:\r
         ///\r
-        ///None:  There is no maximum resolution for encodes using this preset. They will always use the source resolution minus any cropping that may be applied.\r
+        ///None:  There is no maximum resolution for encodes using this preset. When the preset is loaded, the current width, height and aspect ratio that you currently have set will be reloaded.\r
         ///\r
-        ///Custom: You can optionally set a Maximum width and height. When doing this an encode will be less than or equal to these values.\r
+        ///Custom: You can optionally set a Maximum width and Height. When doing this an encode will be less than or equal to these values. Keep Aspect Ratio will be automatically turned on.\r
         ///\r
-        ///Source Maximum:  Similar to custom, but the resolution of your current source is used as the Max width and Height values in [rest of string was truncated]&quot;;.\r
+        ///Source Maximum:  Similar to custom, but [rest of string was truncated]&quot;;.\r
         /// </summary>\r
         public static string AddPreset_PictureSizeMode {\r
             get {\r
index a1796ff59699d502e695580e66c4d67aa790e27f..180d0abc56cb7bb71640ad1bee87926a09623674 100644 (file)
@@ -292,13 +292,15 @@ So small increases in value will result in progressively larger increases in the
 Suggested values are: 18 to 20 for Standard Definition and 20 to 23 for High Definition.</value>\r
   </data>\r
   <data name="AddPreset_PictureSizeMode" xml:space="preserve">\r
-    <value>You can optionally store a maximum resolution for encodes that use this preset. There are 3 modes:\r
+    <value>You can optionally store a maximum resolution for encodes that use this preset. There are 4 modes:\r
 \r
-None:  There is no maximum resolution for encodes using this preset. They will always use the source resolution minus any cropping that may be applied.\r
+None:  There is no maximum resolution for encodes using this preset. When the preset is loaded, the current width, height and aspect ratio that you currently have set will be reloaded.\r
 \r
-Custom: You can optionally set a Maximum width and height. When doing this an encode will be less than or equal to these values.\r
+Custom: You can optionally set a Maximum width and Height. When doing this an encode will be less than or equal to these values. Keep Aspect Ratio will be automatically turned on.\r
 \r
-Source Maximum:  Similar to custom, but the resolution of your current source is used as the Max width and Height values instead.</value>\r
+Source Maximum:  Similar to custom, but the resolution of your current source is used as the Max width and Height values instead. Keep Aspect Ratio will be automatically turned on.\r
+\r
+No Limit: Always use the full source resolution for all sources keeping aspect ratio. This is the default behaviour.</value>\r
   </data>\r
   <data name="Advanced_EncoderOptions" xml:space="preserve">\r
     <value>The options passed to the x264 encoder. \r
index f4f496fcb24cc0112b2b6dc90518a3853bf2793c..488f58d74749609435ed0a32e71585fe5daa2dba 100644 (file)
@@ -13,6 +13,7 @@ namespace HandBrakeWPF.ViewModels
     using System.Windows;\r
 \r
     using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Parsing;\r
     using HandBrake.ApplicationServices.Services;\r
     using HandBrake.ApplicationServices.Services.Interfaces;\r
     using HandBrake.ApplicationServices.Utilities;\r
@@ -25,8 +26,6 @@ namespace HandBrakeWPF.ViewModels
     /// </summary>\r
     public class AddPresetViewModel : ViewModelBase, IAddPresetViewModel\r
     {\r
-        /* TODO this window is up for redesign. Quite a few nippy edge cases that can cause odd behaviour with importing presets. */\r
-\r
         /// <summary>\r
         /// Backing field for the Preset Service\r
         /// </summary>\r
@@ -47,6 +46,11 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>\r
         private bool showCustomInputs;\r
 \r
+        /// <summary>\r
+        /// The source.\r
+        /// </summary>\r
+        private Title selectedTitle;\r
+\r
         /// <summary>\r
         /// Initializes a new instance of the <see cref="AddPresetViewModel"/> class.\r
         /// </summary>\r
@@ -123,9 +127,10 @@ namespace HandBrakeWPF.ViewModels
         /// <param name="task">\r
         /// The Encode Task.\r
         /// </param>\r
-        public void Setup(EncodeTask task)\r
+        public void Setup(EncodeTask task, Title title)\r
         {\r
             this.Preset.Task = new EncodeTask(task);\r
+            this.selectedTitle = title;\r
         }\r
 \r
         /// <summary>\r
@@ -148,7 +153,7 @@ namespace HandBrakeWPF.ViewModels
                }\r
             }\r
 \r
-            if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum && (this.Preset.Task.Width == null || this.Preset.Task.Width == 0))\r
+            if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum && this.selectedTitle == null)\r
             {\r
                 this.errorService.ShowMessageBox("You must first scan a source to use the 'Source Maximum' Option.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);\r
                 return;\r
@@ -174,8 +179,8 @@ namespace HandBrakeWPF.ViewModels
 \r
             if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum)\r
             {\r
-                this.Preset.Task.MaxWidth = this.Preset.Task.Width;\r
-                this.Preset.Task.MaxHeight = this.Preset.Task.Height;\r
+                this.Preset.Task.MaxWidth = selectedTitle.Resolution.Width;\r
+                this.Preset.Task.MaxHeight = selectedTitle.Resolution.Height;\r
             }\r
 \r
             // Add the Preset\r
index 1d5342e0156ab4e16fcd8ba0c8fe7978a761ab93..ac0ec160fc7a0910d9473d3af05e49e6119dd9e8 100644 (file)
@@ -10,6 +10,7 @@
 namespace HandBrakeWPF.ViewModels.Interfaces\r
 {\r
     using HandBrake.ApplicationServices.Model;\r
+    using HandBrake.ApplicationServices.Parsing;\r
 \r
     /// <summary>\r
     /// The Add Preset View Model\r
@@ -22,6 +23,9 @@ namespace HandBrakeWPF.ViewModels.Interfaces
         /// <param name="task">\r
         /// The Encode Task.\r
         /// </param>\r
-        void Setup(EncodeTask task);\r
+        /// <param name="title">\r
+        /// The title.\r
+        /// </param>\r
+        void Setup(EncodeTask task, Title title);\r
     }\r
 }\r
index 02a2e88ebd97c874b25dfd32e137a7b3862012ed..fd25853370d598be02cbec9ffb4d5198e4dd6715 100644 (file)
@@ -1420,7 +1420,7 @@ namespace HandBrakeWPF.ViewModels
         public void PresetAdd()\r
         {\r
             IAddPresetViewModel presetViewModel = IoC.Get<IAddPresetViewModel>();\r
-            presetViewModel.Setup(this.CurrentTask);\r
+            presetViewModel.Setup(this.CurrentTask, this.SelectedTitle);\r
             this.WindowManager.ShowWindow(presetViewModel);\r
         }\r
 \r
index 1a6c90538505b1d54d938864f1655142be85c093..2684186921154f9ab89b49935331eec0f953163c 100644 (file)
@@ -601,59 +601,71 @@ namespace HandBrakeWPF.ViewModels
         {\r
             this.Task = task;\r
 \r
-            // TODO: These all need to be handled correctly.\r
+            // Anamorphic Mode\r
             this.SelectedAnamorphicMode = preset.Task.Anamorphic;\r
 \r
-            // Set the limits on the UI Controls.\r
-            this.MaxWidth = preset.Task.MaxWidth ?? this.sourceResolution.Width;\r
-            this.MaxHeight = preset.Task.MaxHeight ?? this.sourceResolution.Height;\r
-            this.Task.MaxWidth = preset.Task.MaxWidth;\r
-            this.Task.MaxHeight = preset.Task.MaxHeight;\r
-\r
-            // Setup the Width\r
-            if (preset.Task.MaxWidth.HasValue)\r
+            // Modulus\r
+            if (preset.Task.Modulus.HasValue)\r
             {\r
-                if (this.Width > preset.Task.MaxWidth)\r
-                {\r
-                    // Limit the Width to the Max Width\r
-                    this.Width = preset.Task.MaxWidth.Value; \r
-                }\r
-                else\r
-                {\r
-                    // Figure out the best width based on the preset and source\r
-                    this.Width = preset.Task.Width ?? this.GetModulusValue(this.getRes((this.sourceResolution.Width - this.CropLeft - this.CropRight), preset.Task.MaxWidth.Value));\r
-                }\r
+                this.SelectedModulus = preset.Task.Modulus;\r
             }\r
-            else\r
+\r
+            // Set the Maintain Aspect ratio.\r
+            this.MaintainAspectRatio = preset.Task.Anamorphic == Anamorphic.None && preset.Task.KeepDisplayAspect;\r
+\r
+            // Handle built-in presets.\r
+            if (preset.IsBuildIn)\r
             {\r
-                this.Width = preset.Task.Width ?? this.GetModulusValue((this.sourceResolution.Width - this.CropLeft - this.CropRight));\r
+                preset.PictureSettingsMode = PresetPictureSettingsMode.Custom;\r
             }\r
 \r
-            // Set the Maintain Aspect ratio. This will calculate Height for us now.\r
-            this.MaintainAspectRatio = preset.Task.Anamorphic == Anamorphic.None || preset.Task.KeepDisplayAspect;\r
-\r
-            // Set Height, but only if necessary.\r
-            if (preset.Task.MaxHeight.HasValue)\r
+            // Setup the Picture Sizes\r
+            switch (preset.PictureSettingsMode)\r
             {\r
-                if (this.Height > preset.Task.MaxHeight)\r
-                {\r
-                    // Limit the Height to the Max Height of the preset. Setting this will recalculate the width.\r
-                    this.Height = preset.Task.MaxHeight.Value;\r
-                }\r
-                else\r
-                {\r
-                    // Only calculate height if Maintain Aspect ratio is off.\r
-                    if (!this.MaintainAspectRatio)\r
+                default:\r
+                case PresetPictureSettingsMode.Custom:\r
+                case PresetPictureSettingsMode.SourceMaximum:\r
+                    this.MaintainAspectRatio = true;\r
+\r
+                    // Set the width, then check the height doesn't breach the max height and correct if necessary.\r
+                    int width = this.GetModulusValue(this.getRes((this.sourceResolution.Width - this.CropLeft - this.CropRight), preset.Task.MaxWidth));\r
+                    this.Width = width;\r
+\r
+                    // If we have a max height, make sure we havn't breached it.\r
+                    int height = this.GetModulusValue(this.getRes((this.sourceResolution.Height - this.CropTop - this.CropBottom), preset.Task.MaxHeight));\r
+                    if (preset.Task.MaxHeight.HasValue && this.Height > preset.Task.MaxHeight.Value)\r
                     {\r
-                        this.Height = preset.Task.Height ??\r
-                                      this.getRes(\r
-                                          (this.sourceResolution.Height - this.CropTop - this.CropBottom),\r
-                                          preset.Task.MaxHeight.Value);\r
+                        this.Height = height;\r
                     }\r
-                }\r
+\r
+                    this.MaxWidth = width;\r
+                    this.MaxHeight = height;\r
+                    break;\r
+                case PresetPictureSettingsMode.NoLimit:\r
+                    this.MaintainAspectRatio = true;\r
+                    this.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight);\r
+\r
+                    this.MaxWidth = this.sourceResolution.Width;\r
+                    this.MaxHeight = this.sourceResolution.Height;\r
+                    break;\r
+                case PresetPictureSettingsMode.None:\r
+\r
+                    if (preset.Task.Width.HasValue)\r
+                    {\r
+                        this.Width = this.GetModulusValue(preset.Task.Width.Value - this.CropLeft - this.CropRight);\r
+                    }\r
+\r
+                    if (!this.MaintainAspectRatio && preset.Task.Height.HasValue)\r
+                    {\r
+                        this.Height = this.GetModulusValue(preset.Task.Height.Value - this.CropTop - this.CropBottom);\r
+                    }\r
+\r
+                    this.MaxWidth = this.sourceResolution.Width;\r
+                    this.MaxHeight = this.sourceResolution.Height;\r
+                    break;\r
             }\r
 \r
-            // Anamorphic\r
+            // Custom Anamorphic\r
             if (preset.Task.Anamorphic == Anamorphic.Custom)\r
             {\r
                 this.DisplayWidth = preset.Task.DisplayWidth != null ? int.Parse(preset.Task.DisplayWidth.ToString()) : 0;\r
@@ -661,12 +673,6 @@ namespace HandBrakeWPF.ViewModels
                 this.ParHeight = preset.Task.PixelAspectY;\r
             }\r
 \r
-            // Modulus\r
-            if (preset.Task.Modulus.HasValue)\r
-            {\r
-                this.SelectedModulus = preset.Task.Modulus;\r
-            }\r
-\r
             // Cropping\r
             if (preset.Task.HasCropping)\r
             {\r
@@ -765,15 +771,14 @@ namespace HandBrakeWPF.ViewModels
                 }\r
 \r
                 // Set the Width, and Maintain Aspect ratio. That should calc the Height for us.\r
-                this.Width = this.MaxWidth;\r
-                this.MaintainAspectRatio = true;\r
+                this.Width = preset.Task.Width ?? this.MaxWidth;\r
 \r
                 // If our height is too large, let it downscale the width for us by setting the height to the lower value.\r
                 if (this.Height > this.MaxHeight)\r
                 {\r
                     this.Height = this.MaxHeight;\r
                 }\r
-       \r
+\r
                 if (this.SelectedAnamorphicMode == Anamorphic.Custom)\r
                 {\r
                     this.AnamorphicAdjust(); // Refresh the values\r
@@ -1145,9 +1150,9 @@ namespace HandBrakeWPF.ViewModels
         /// <returns>\r
         /// An Int\r
         /// </returns>\r
-        private int getRes(int value, int max)\r
+        private int getRes(int value, int? max)\r
         {\r
-            return value > max ? max : value;\r
+            return max.HasValue ? (value > max.Value ? max.Value : value) : value;\r
         }\r
 \r
         #endregion\r
index 3e7a3fd7b335ba8d0fa1ab518d106c3feae5d741..b49b439a685891ed13380a01e461604949cfac11 100644 (file)
@@ -88,7 +88,7 @@
                        Grid.Column="0"\r
                        Style="{StaticResource LongToolTipHolder}"\r
                        ToolTip="{x:Static Properties:Resources.AddPreset_PictureSizeMode}"\r
-                       Text="Picture Size:" />\r
+                       Text="Max Picture Size:" />\r
             <ComboBox Grid.Row="2"\r
                       Grid.Column="1"\r
                       Width="125"\r