summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels
diff options
context:
space:
mode:
authorsr55 <[email protected]>2013-05-25 15:22:10 +0000
committersr55 <[email protected]>2013-05-25 15:22:10 +0000
commitbe639f834ba19e1853d6c2844386478fb8c9a13c (patch)
treebbf8974965e23da167ded1906788b0fdc5bab43c /win/CS/HandBrakeWPF/ViewModels
parent3c4dcbe57e88d64eb9ff4e1186f7daf5793e02f2 (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/CS/HandBrakeWPF/ViewModels')
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs17
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/Interfaces/IAddPresetViewModel.cs6
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs2
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs109
4 files changed, 74 insertions, 60 deletions
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