diff options
author | sr55 <[email protected]> | 2013-05-25 15:22:10 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2013-05-25 15:22:10 +0000 |
commit | be639f834ba19e1853d6c2844386478fb8c9a13c (patch) | |
tree | bbf8974965e23da167ded1906788b0fdc5bab43c /win | |
parent | 3c4dcbe57e88d64eb9ff4e1186f7daf5793e02f2 (diff) |
WinGui: Refactor the Presets Picture Size handling to make it a bit clearer what's actually happening.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5512 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
8 files changed, 89 insertions, 71 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Model/PresetPictureSettingsMode.cs b/win/CS/HandBrake.ApplicationServices/Model/PresetPictureSettingsMode.cs index e670ccb7e..d6a84a617 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/PresetPictureSettingsMode.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/PresetPictureSettingsMode.cs @@ -18,9 +18,11 @@ namespace HandBrake.ApplicationServices.Model {
[Display(Name = "None")]
None = 0,
- [Display(Name = "Custom")]
+ [Display(Name = "Custom (Keep AR)")]
Custom = 1,
- [Display(Name = "Source Maximum")]
+ [Display(Name = "Current Source Max Size (Keep AR)")]
SourceMaximum = 2,
+ [Display(Name = "No Limit (Keep AR)")]
+ NoLimit = 3,
}
}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 1b2f1531a..bef7d7030 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -80,13 +80,13 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
- /// Looks up a localized string similar to You can optionally store a maximum resolution for encodes that use this preset. There are 3 modes:
+ /// Looks up a localized string similar to You can optionally store a maximum resolution for encodes that use this preset. There are 4 modes:
///
- ///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.
+ ///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.
///
- ///Custom: You can optionally set a Maximum width and height. When doing this an encode will be less than or equal to these values.
+ ///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.
///
- ///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]";.
+ ///Source Maximum: Similar to custom, but [rest of string was truncated]";.
/// </summary>
public static string AddPreset_PictureSizeMode {
get {
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index a1796ff59..180d0abc5 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -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>
</data>
<data name="AddPreset_PictureSizeMode" xml:space="preserve">
- <value>You can optionally store a maximum resolution for encodes that use this preset. There are 3 modes:
+ <value>You can optionally store a maximum resolution for encodes that use this preset. There are 4 modes:
-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.
+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.
-Custom: You can optionally set a Maximum width and height. When doing this an encode will be less than or equal to these values.
+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.
-Source Maximum: Similar to custom, but the resolution of your current source is used as the Max width and Height values instead.</value>
+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.
+
+No Limit: Always use the full source resolution for all sources keeping aspect ratio. This is the default behaviour.</value>
</data>
<data name="Advanced_EncoderOptions" xml:space="preserve">
<value>The options passed to the x264 encoder.
diff --git a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs index f4f496fcb..488f58d74 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs @@ -13,6 +13,7 @@ namespace HandBrakeWPF.ViewModels using System.Windows;
using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Parsing;
using HandBrake.ApplicationServices.Services;
using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.ApplicationServices.Utilities;
@@ -25,8 +26,6 @@ namespace HandBrakeWPF.ViewModels /// </summary>
public class AddPresetViewModel : ViewModelBase, IAddPresetViewModel
{
- /* TODO this window is up for redesign. Quite a few nippy edge cases that can cause odd behaviour with importing presets. */
-
/// <summary>
/// Backing field for the Preset Service
/// </summary>
@@ -48,6 +47,11 @@ namespace HandBrakeWPF.ViewModels private bool showCustomInputs;
/// <summary>
+ /// The source.
+ /// </summary>
+ private Title selectedTitle;
+
+ /// <summary>
/// Initializes a new instance of the <see cref="AddPresetViewModel"/> class.
/// </summary>
/// <param name="presetService">
@@ -123,9 +127,10 @@ namespace HandBrakeWPF.ViewModels /// <param name="task">
/// The Encode Task.
/// </param>
- public void Setup(EncodeTask task)
+ public void Setup(EncodeTask task, Title title)
{
this.Preset.Task = new EncodeTask(task);
+ this.selectedTitle = title;
}
/// <summary>
@@ -148,7 +153,7 @@ namespace HandBrakeWPF.ViewModels }
}
- if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum && (this.Preset.Task.Width == null || this.Preset.Task.Width == 0))
+ if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum && this.selectedTitle == null)
{
this.errorService.ShowMessageBox("You must first scan a source to use the 'Source Maximum' Option.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
@@ -174,8 +179,8 @@ namespace HandBrakeWPF.ViewModels if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum)
{
- this.Preset.Task.MaxWidth = this.Preset.Task.Width;
- this.Preset.Task.MaxHeight = this.Preset.Task.Height;
+ this.Preset.Task.MaxWidth = selectedTitle.Resolution.Width;
+ this.Preset.Task.MaxHeight = selectedTitle.Resolution.Height;
}
// Add the Preset
diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAddPresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAddPresetViewModel.cs index 1d5342e01..ac0ec160f 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAddPresetViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IAddPresetViewModel.cs @@ -10,6 +10,7 @@ namespace HandBrakeWPF.ViewModels.Interfaces
{
using HandBrake.ApplicationServices.Model;
+ using HandBrake.ApplicationServices.Parsing;
/// <summary>
/// The Add Preset View Model
@@ -22,6 +23,9 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// <param name="task">
/// The Encode Task.
/// </param>
- void Setup(EncodeTask task);
+ /// <param name="title">
+ /// The title.
+ /// </param>
+ void Setup(EncodeTask task, Title title);
}
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 02a2e88eb..fd2585337 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -1420,7 +1420,7 @@ namespace HandBrakeWPF.ViewModels public void PresetAdd()
{
IAddPresetViewModel presetViewModel = IoC.Get<IAddPresetViewModel>();
- presetViewModel.Setup(this.CurrentTask);
+ presetViewModel.Setup(this.CurrentTask, this.SelectedTitle);
this.WindowManager.ShowWindow(presetViewModel);
}
diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index 1a6c90538..268418692 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -601,59 +601,71 @@ namespace HandBrakeWPF.ViewModels {
this.Task = task;
- // TODO: These all need to be handled correctly.
+ // Anamorphic Mode
this.SelectedAnamorphicMode = preset.Task.Anamorphic;
- // Set the limits on the UI Controls.
- this.MaxWidth = preset.Task.MaxWidth ?? this.sourceResolution.Width;
- this.MaxHeight = preset.Task.MaxHeight ?? this.sourceResolution.Height;
- this.Task.MaxWidth = preset.Task.MaxWidth;
- this.Task.MaxHeight = preset.Task.MaxHeight;
-
- // Setup the Width
- if (preset.Task.MaxWidth.HasValue)
+ // Modulus
+ if (preset.Task.Modulus.HasValue)
{
- if (this.Width > preset.Task.MaxWidth)
- {
- // Limit the Width to the Max Width
- this.Width = preset.Task.MaxWidth.Value;
- }
- else
- {
- // Figure out the best width based on the preset and source
- this.Width = preset.Task.Width ?? this.GetModulusValue(this.getRes((this.sourceResolution.Width - this.CropLeft - this.CropRight), preset.Task.MaxWidth.Value));
- }
+ this.SelectedModulus = preset.Task.Modulus;
}
- else
+
+ // Set the Maintain Aspect ratio.
+ this.MaintainAspectRatio = preset.Task.Anamorphic == Anamorphic.None && preset.Task.KeepDisplayAspect;
+
+ // Handle built-in presets.
+ if (preset.IsBuildIn)
{
- this.Width = preset.Task.Width ?? this.GetModulusValue((this.sourceResolution.Width - this.CropLeft - this.CropRight));
+ preset.PictureSettingsMode = PresetPictureSettingsMode.Custom;
}
- // Set the Maintain Aspect ratio. This will calculate Height for us now.
- this.MaintainAspectRatio = preset.Task.Anamorphic == Anamorphic.None || preset.Task.KeepDisplayAspect;
-
- // Set Height, but only if necessary.
- if (preset.Task.MaxHeight.HasValue)
+ // Setup the Picture Sizes
+ switch (preset.PictureSettingsMode)
{
- if (this.Height > preset.Task.MaxHeight)
- {
- // Limit the Height to the Max Height of the preset. Setting this will recalculate the width.
- this.Height = preset.Task.MaxHeight.Value;
- }
- else
- {
- // Only calculate height if Maintain Aspect ratio is off.
- if (!this.MaintainAspectRatio)
+ default:
+ case PresetPictureSettingsMode.Custom:
+ case PresetPictureSettingsMode.SourceMaximum:
+ this.MaintainAspectRatio = true;
+
+ // Set the width, then check the height doesn't breach the max height and correct if necessary.
+ int width = this.GetModulusValue(this.getRes((this.sourceResolution.Width - this.CropLeft - this.CropRight), preset.Task.MaxWidth));
+ this.Width = width;
+
+ // If we have a max height, make sure we havn't breached it.
+ int height = this.GetModulusValue(this.getRes((this.sourceResolution.Height - this.CropTop - this.CropBottom), preset.Task.MaxHeight));
+ if (preset.Task.MaxHeight.HasValue && this.Height > preset.Task.MaxHeight.Value)
{
- this.Height = preset.Task.Height ??
- this.getRes(
- (this.sourceResolution.Height - this.CropTop - this.CropBottom),
- preset.Task.MaxHeight.Value);
+ this.Height = height;
}
- }
+
+ this.MaxWidth = width;
+ this.MaxHeight = height;
+ break;
+ case PresetPictureSettingsMode.NoLimit:
+ this.MaintainAspectRatio = true;
+ this.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight);
+
+ this.MaxWidth = this.sourceResolution.Width;
+ this.MaxHeight = this.sourceResolution.Height;
+ break;
+ case PresetPictureSettingsMode.None:
+
+ if (preset.Task.Width.HasValue)
+ {
+ this.Width = this.GetModulusValue(preset.Task.Width.Value - this.CropLeft - this.CropRight);
+ }
+
+ if (!this.MaintainAspectRatio && preset.Task.Height.HasValue)
+ {
+ this.Height = this.GetModulusValue(preset.Task.Height.Value - this.CropTop - this.CropBottom);
+ }
+
+ this.MaxWidth = this.sourceResolution.Width;
+ this.MaxHeight = this.sourceResolution.Height;
+ break;
}
- // Anamorphic
+ // Custom Anamorphic
if (preset.Task.Anamorphic == Anamorphic.Custom)
{
this.DisplayWidth = preset.Task.DisplayWidth != null ? int.Parse(preset.Task.DisplayWidth.ToString()) : 0;
@@ -661,12 +673,6 @@ namespace HandBrakeWPF.ViewModels this.ParHeight = preset.Task.PixelAspectY;
}
- // Modulus
- if (preset.Task.Modulus.HasValue)
- {
- this.SelectedModulus = preset.Task.Modulus;
- }
-
// Cropping
if (preset.Task.HasCropping)
{
@@ -765,15 +771,14 @@ namespace HandBrakeWPF.ViewModels }
// Set the Width, and Maintain Aspect ratio. That should calc the Height for us.
- this.Width = this.MaxWidth;
- this.MaintainAspectRatio = true;
+ this.Width = preset.Task.Width ?? this.MaxWidth;
// If our height is too large, let it downscale the width for us by setting the height to the lower value.
if (this.Height > this.MaxHeight)
{
this.Height = this.MaxHeight;
}
-
+
if (this.SelectedAnamorphicMode == Anamorphic.Custom)
{
this.AnamorphicAdjust(); // Refresh the values
@@ -1145,9 +1150,9 @@ namespace HandBrakeWPF.ViewModels /// <returns>
/// An Int
/// </returns>
- private int getRes(int value, int max)
+ private int getRes(int value, int? max)
{
- return value > max ? max : value;
+ return max.HasValue ? (value > max.Value ? max.Value : value) : value;
}
#endregion
diff --git a/win/CS/HandBrakeWPF/Views/AddPresetView.xaml b/win/CS/HandBrakeWPF/Views/AddPresetView.xaml index 3e7a3fd7b..b49b439a6 100644 --- a/win/CS/HandBrakeWPF/Views/AddPresetView.xaml +++ b/win/CS/HandBrakeWPF/Views/AddPresetView.xaml @@ -88,7 +88,7 @@ Grid.Column="0"
Style="{StaticResource LongToolTipHolder}"
ToolTip="{x:Static Properties:Resources.AddPreset_PictureSizeMode}"
- Text="Picture Size:" />
+ Text="Max Picture Size:" />
<ComboBox Grid.Row="2"
Grid.Column="1"
Width="125"
|