summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrakeWPF/ViewModels')
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs850
1 files changed, 357 insertions, 493 deletions
diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs
index 1bcc43c36..7d8bdd51b 100644
--- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs
@@ -12,14 +12,9 @@ namespace HandBrakeWPF.ViewModels
using System;
using System.Collections.Generic;
using System.Globalization;
- using System.Windows;
- using System.Windows.Media.Imaging;
-
- using Caliburn.Micro;
using HandBrake.ApplicationServices.Model;
using HandBrake.ApplicationServices.Parsing;
- using HandBrake.ApplicationServices.Services.Interfaces;
using HandBrake.Interop.Model;
using HandBrake.Interop.Model.Encoding;
@@ -109,6 +104,11 @@ namespace HandBrakeWPF.ViewModels
/// </summary>
private DelayedActionProcessor delayedPreviewprocessor = new DelayedActionProcessor();
+ /// <summary>
+ /// The current title.
+ /// </summary>
+ private Title currentTitle;
+
#endregion
#region Constructors and Destructors
@@ -119,12 +119,7 @@ namespace HandBrakeWPF.ViewModels
public PictureSettingsViewModel()
{
this.Task = new EncodeTask();
- this.SelectedModulus = 16;
- this.MaintainAspectRatio = true;
-
- // Default the Max Width / Height to 1080p format
- this.MaxHeight = 1080;
- this.MaxWidth = 1920;
+ this.Init();
}
#endregion
@@ -148,369 +143,314 @@ namespace HandBrakeWPF.ViewModels
}
/// <summary>
- /// Gets or sets CropBottom.
+ /// Gets or sets DisplaySize.
/// </summary>
- public int CropBottom
+ public string DisplaySize
{
get
{
- return this.Task.Cropping.Bottom;
+ return this.displaySize;
}
set
{
- this.Task.Cropping.Bottom = value;
- this.NotifyOfPropertyChange(() => this.CropBottom);
- this.CropAdjust();
- this.SetDisplaySize();
- this.UpdatePreviewImage();
+ this.displaySize = value;
+ this.NotifyOfPropertyChange(() => this.DisplaySize);
}
}
/// <summary>
- /// Gets or sets CropLeft.
+ /// Gets or sets a value indicating whether HeightControlEnabled.
/// </summary>
- public int CropLeft
+ public bool HeightControlEnabled
{
get
{
- return this.Task.Cropping.Left;
+ return this.heightControlEnabled;
}
set
{
- this.Task.Cropping.Left = value;
- this.NotifyOfPropertyChange(() => this.CropLeft);
- this.CropAdjust();
- this.SetDisplaySize();
- this.UpdatePreviewImage();
+ this.heightControlEnabled = value;
+ this.NotifyOfPropertyChange(() => this.HeightControlEnabled);
}
}
/// <summary>
- /// Gets or sets CropRight.
+ /// Gets ModulusValues.
/// </summary>
- public int CropRight
+ public IEnumerable<int> ModulusValues
{
get
{
- return this.Task.Cropping.Right;
- }
-
- set
- {
- this.Task.Cropping.Right = value;
- this.NotifyOfPropertyChange(() => this.CropRight);
- this.CropAdjust();
- this.SetDisplaySize();
- this.UpdatePreviewImage();
+ return new List<int> { 16, 8, 4, 2 };
}
}
/// <summary>
- /// Gets or sets CropTop.
+ /// Gets or sets a value indicating whether ShowCustomAnamorphicControls.
/// </summary>
- public int CropTop
+ public bool ShowCustomAnamorphicControls
{
get
{
- return this.Task.Cropping.Top;
+ return this.showCustomAnamorphicControls;
}
set
{
- this.Task.Cropping.Top = value;
- this.NotifyOfPropertyChange(() => this.CropTop);
- this.CropAdjust();
- this.SetDisplaySize();
- this.UpdatePreviewImage();
+ this.showCustomAnamorphicControls = value;
+ this.NotifyOfPropertyChange(() => this.ShowCustomAnamorphicControls);
}
}
/// <summary>
- /// Gets or sets DisplaySize.
+ /// Gets or sets SourceInfo.
/// </summary>
- public string DisplaySize
+ public string SourceInfo
{
get
{
- return this.displaySize;
+ return this.sourceInfo;
}
set
{
- this.displaySize = value;
- this.NotifyOfPropertyChange(() => this.DisplaySize);
+ this.sourceInfo = value;
+ this.NotifyOfPropertyChange(() => this.SourceInfo);
}
}
/// <summary>
- /// Gets or sets DisplayWidth.
+ /// Gets or sets Task.
/// </summary>
- public int DisplayWidth
- {
- get
- {
- return this.Task.DisplayWidth.HasValue
- ? int.Parse(Math.Round(this.Task.DisplayWidth.Value, 0).ToString(CultureInfo.InvariantCulture))
- : 0;
- }
-
- set
- {
- if (!object.Equals(this.Task.DisplayWidth, value))
- {
- this.Task.DisplayWidth = value;
- this.CustomAnamorphicAdjust();
- this.NotifyOfPropertyChange(() => this.DisplayWidth);
- this.UpdatePreviewImage();
- }
- }
- }
+ public EncodeTask Task { get; set; }
/// <summary>
- /// Gets or sets Height.
+ /// Gets or sets a value indicating whether WidthControlEnabled.
/// </summary>
- public int Height
+ public bool WidthControlEnabled
{
get
{
- return this.Task.Height.HasValue ? this.Task.Height.Value : 0;
+ return this.widthControlEnabled;
}
set
{
- if (!object.Equals(this.Task.Height, value))
- {
- this.Task.Height = value;
- this.HeightAdjust();
- this.NotifyOfPropertyChange(() => this.Height);
- this.UpdatePreviewImage();
- }
+ this.widthControlEnabled = value;
+ this.NotifyOfPropertyChange(() => this.WidthControlEnabled);
}
}
/// <summary>
- /// Gets or sets a value indicating whether HeightControlEnabled.
+ /// Gets or sets a value indicating whether ShowModulus.
/// </summary>
- public bool HeightControlEnabled
+ public bool ShowModulus
{
get
{
- return this.heightControlEnabled;
+ return this.showModulus;
}
-
set
{
- this.heightControlEnabled = value;
- this.NotifyOfPropertyChange(() => this.HeightControlEnabled);
+ this.showModulus = value;
+ this.NotifyOfPropertyChange(() => this.ShowModulus);
}
}
/// <summary>
- /// Gets or sets a value indicating whether IsCustomCrop.
+ /// Gets or sets a value indicating whether ShowDisplaySize.
/// </summary>
- public bool IsCustomCrop
+ public bool ShowDisplaySize
{
get
{
- return this.Task.HasCropping;
+ return this.showDisplaySize;
}
-
set
{
- this.Task.HasCropping = value;
- this.NotifyOfPropertyChange(() => this.IsCustomCrop);
+ this.showDisplaySize = value;
+ this.NotifyOfPropertyChange(() => this.ShowDisplaySize);
}
}
/// <summary>
- /// Gets or sets a value indicating whether MaintainAspectRatio.
+ /// Gets or sets MaxHeight.
/// </summary>
- public bool MaintainAspectRatio
+ public int MaxHeight
{
get
{
- return this.Task.KeepDisplayAspect;
+ return this.maxHeight;
}
-
set
{
- this.Task.KeepDisplayAspect = value;
- this.WidthAdjust();
- this.NotifyOfPropertyChange(() => this.MaintainAspectRatio);
- this.UpdatePreviewImage();
+ this.maxHeight = value;
+ this.NotifyOfPropertyChange(() => this.MaxHeight);
}
}
/// <summary>
- /// Gets ModulusValues.
+ /// Gets or sets MinHeight.
/// </summary>
- public IEnumerable<int> ModulusValues
+ public int MaxWidth
{
get
{
- return new List<int> { 16, 8, 4, 2 };
+ return this.maxWidth;
+ }
+ set
+ {
+ this.maxWidth = value;
+ this.NotifyOfPropertyChange(() => this.MaxWidth);
}
}
/// <summary>
- /// Gets or sets ParHeight.
+ /// Gets or sets a value indicating whether show keep ar.
/// </summary>
- public int ParHeight
+ public bool ShowKeepAR
{
get
{
- return this.Task.PixelAspectY;
+ return this.showKeepAr;
}
-
set
{
- if (!object.Equals(this.Task.PixelAspectY, value))
- {
- this.Task.PixelAspectY = value;
- this.CustomAnamorphicAdjust();
- this.NotifyOfPropertyChange(() => this.ParHeight);
- this.UpdatePreviewImage();
- }
+ this.showKeepAr = value;
+ this.NotifyOfPropertyChange(() => this.ShowKeepAR);
}
}
/// <summary>
- /// Gets or sets ParWidth.
+ /// Gets a value indicating whether is picture preview enabled.
/// </summary>
- public int ParWidth
+ public bool IsPicturePreviewEnabled
{
get
{
- return this.Task.PixelAspectX;
- }
-
- set
- {
- if (!object.Equals(this.Task.PixelAspectX, value))
- {
- this.Task.PixelAspectX = value;
- this.CustomAnamorphicAdjust();
- this.NotifyOfPropertyChange(() => this.ParWidth);
- this.UpdatePreviewImage();
- }
+ return this.UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableStaticPreview);
}
}
+ #endregion
+
+ #region Task Properties
+
/// <summary>
- /// Gets or sets SelectedAnamorphicMode.
+ /// Gets or sets CropBottom.
/// </summary>
- public Anamorphic SelectedAnamorphicMode
+ public int CropBottom
{
get
{
- return this.Task.Anamorphic;
+ return this.Task.Cropping.Bottom;
}
set
{
- if (!object.Equals(this.SelectedAnamorphicMode, value))
- {
- this.Task.Anamorphic = value;
- this.AnamorphicAdjust();
- this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);
- this.UpdatePreviewImage();
- }
+ this.Task.Cropping.Bottom = value;
+ this.NotifyOfPropertyChange(() => this.CropBottom);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Crop);
}
}
/// <summary>
- /// Gets or sets SelectedModulus.
+ /// Gets or sets CropLeft.
/// </summary>
- public int? SelectedModulus
+ public int CropLeft
{
get
{
- return this.Task.Modulus;
+ return this.Task.Cropping.Left;
}
set
{
- this.Task.Modulus = value;
- this.ModulusAdjust();
- this.NotifyOfPropertyChange(() => this.SelectedModulus);
- this.UpdatePreviewImage();
+ this.Task.Cropping.Left = value;
+ this.NotifyOfPropertyChange(() => this.CropLeft);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Crop);
}
}
/// <summary>
- /// Gets or sets a value indicating whether ShowCustomAnamorphicControls.
+ /// Gets or sets CropRight.
/// </summary>
- public bool ShowCustomAnamorphicControls
+ public int CropRight
{
get
{
- return this.showCustomAnamorphicControls;
+ return this.Task.Cropping.Right;
}
set
{
- this.showCustomAnamorphicControls = value;
- this.NotifyOfPropertyChange(() => this.ShowCustomAnamorphicControls);
+ this.Task.Cropping.Right = value;
+ this.NotifyOfPropertyChange(() => this.CropRight);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Crop);
}
}
/// <summary>
- /// Gets or sets a value indicating whether ShowModulus.
+ /// Gets or sets CropTop.
/// </summary>
- public bool ShowModulus
+ public int CropTop
{
get
{
- return this.showModulus;
+ return this.Task.Cropping.Top;
}
+
set
{
- this.showModulus = value;
- this.NotifyOfPropertyChange(() => this.ShowModulus);
+ this.Task.Cropping.Top = value;
+ this.NotifyOfPropertyChange(() => this.CropTop);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Crop);
}
}
/// <summary>
- /// Gets or sets a value indicating whether ShowDisplaySize.
+ /// Gets or sets a value indicating whether IsCustomCrop.
/// </summary>
- public bool ShowDisplaySize
+ public bool IsCustomCrop
{
get
{
- return this.showDisplaySize;
+ return this.Task.HasCropping;
}
+
set
{
- this.showDisplaySize = value;
- this.NotifyOfPropertyChange(() => this.ShowDisplaySize);
+ this.Task.HasCropping = value;
+ this.NotifyOfPropertyChange(() => this.IsCustomCrop);
}
}
/// <summary>
- /// Gets or sets SourceInfo.
+ /// Gets or sets DisplayWidth.
/// </summary>
- public string SourceInfo
+ public int DisplayWidth
{
get
{
- return this.sourceInfo;
+ return this.Task.DisplayWidth.HasValue
+ ? int.Parse(Math.Round(this.Task.DisplayWidth.Value, 0).ToString(CultureInfo.InvariantCulture))
+ : 0;
}
set
{
- this.sourceInfo = value;
- this.NotifyOfPropertyChange(() => this.SourceInfo);
+ if (!object.Equals(this.Task.DisplayWidth, value))
+ {
+ this.Task.DisplayWidth = value;
+ this.NotifyOfPropertyChange(() => this.DisplayWidth);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.DisplayWidth);
+ }
}
}
/// <summary>
- /// Gets or sets Task.
- /// </summary>
- public EncodeTask Task { get; set; }
-
- /// <summary>
/// Gets or sets Width.
/// </summary>
public int Width
@@ -525,100 +465,129 @@ namespace HandBrakeWPF.ViewModels
if (!object.Equals(this.Task.Width, value))
{
this.Task.Width = value;
- this.WidthAdjust();
this.NotifyOfPropertyChange(() => this.Width);
- this.UpdatePreviewImage();
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Width);
}
}
}
/// <summary>
- /// Gets or sets a value indicating whether WidthControlEnabled.
+ /// Gets or sets Height.
/// </summary>
- public bool WidthControlEnabled
+ public int Height
{
get
{
- return this.widthControlEnabled;
+ return this.Task.Height.HasValue ? this.Task.Height.Value : 0;
}
set
{
- this.widthControlEnabled = value;
- this.NotifyOfPropertyChange(() => this.WidthControlEnabled);
+ if (!object.Equals(this.Task.Height, value))
+ {
+ this.Task.Height = value;
+ this.NotifyOfPropertyChange(() => this.Height);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Height);
+ }
}
}
/// <summary>
- /// Gets or sets MaxHeight.
+ /// Gets or sets a value indicating whether MaintainAspectRatio.
/// </summary>
- public int MaxHeight
+ public bool MaintainAspectRatio
{
get
{
- return this.maxHeight;
+ return this.Task.KeepDisplayAspect;
}
+
set
{
- this.maxHeight = value;
- this.NotifyOfPropertyChange(() => this.MaxHeight);
+ this.Task.KeepDisplayAspect = value;
+ this.NotifyOfPropertyChange(() => this.MaintainAspectRatio);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.MaintainAspectRatio);
}
}
/// <summary>
- /// Gets or sets MinHeight.
+ /// Gets or sets ParHeight.
/// </summary>
- public int MaxWidth
+ public int ParHeight
{
get
{
- return this.maxWidth;
+ return this.Task.PixelAspectY;
}
+
set
{
- this.maxWidth = value;
- this.NotifyOfPropertyChange(() => this.MaxWidth);
+ if (!object.Equals(this.Task.PixelAspectY, value))
+ {
+ this.Task.PixelAspectY = value;
+ this.NotifyOfPropertyChange(() => this.ParHeight);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.ParH);
+ }
}
}
/// <summary>
- /// Gets SourceAspect.
+ /// Gets or sets ParWidth.
/// </summary>
- private Size SourceAspect
+ public int ParWidth
{
get
{
- // display aspect = (width * par_width) / (height * par_height)
- return new Size(
- (this.sourceParValues.Width * this.sourceResolution.Width),
- (this.sourceParValues.Height * this.sourceResolution.Height));
+ return this.Task.PixelAspectX;
+ }
+
+ set
+ {
+ if (!object.Equals(this.Task.PixelAspectX, value))
+ {
+ this.Task.PixelAspectX = value;
+ this.NotifyOfPropertyChange(() => this.ParWidth);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.ParW);
+ }
}
}
/// <summary>
- /// Gets or sets a value indicating whether show keep ar.
+ /// Gets or sets SelectedAnamorphicMode.
/// </summary>
- public bool ShowKeepAR
+ public Anamorphic SelectedAnamorphicMode
{
get
{
- return this.showKeepAr;
+ return this.Task.Anamorphic;
}
+
set
{
- this.showKeepAr = value;
- this.NotifyOfPropertyChange(() => this.ShowKeepAR);
+ if (!object.Equals(this.SelectedAnamorphicMode, value))
+ {
+ this.Task.Anamorphic = value;
+ this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Anamorphic);
+ }
}
}
/// <summary>
- /// Gets a value indicating whether is picture preview enabled.
+ /// Gets or sets SelectedModulus.
/// </summary>
- public bool IsPicturePreviewEnabled
+ public int? SelectedModulus
{
get
{
- return this.UserSettingService.GetUserSetting<bool>(UserSettingConstants.EnableStaticPreview);
+ return this.Task.Modulus;
+ }
+
+ set
+ {
+ this.Task.Modulus = value;
+ this.NotifyOfPropertyChange(() => this.SelectedModulus);
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Modulus);
}
}
@@ -665,11 +634,11 @@ namespace HandBrakeWPF.ViewModels
this.MaintainAspectRatio = preset.Task.KeepDisplayAspect;
// 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));
+ 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));
+ 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 = height;
@@ -740,6 +709,7 @@ namespace HandBrakeWPF.ViewModels
/// </param>
public void SetSource(Title title, Preset preset, EncodeTask task)
{
+ this.currentTitle = title;
this.Task = task;
if (title != null)
@@ -751,25 +721,25 @@ namespace HandBrakeWPF.ViewModels
// Update the cropping values, preffering those in the presets.
if (!preset.Task.HasCropping)
{
- this.CropTop = title.AutoCropDimensions.Top;
- this.CropBottom = title.AutoCropDimensions.Bottom;
- this.CropLeft = title.AutoCropDimensions.Left;
- this.CropRight = title.AutoCropDimensions.Right;
+ this.Task.Cropping.Top = title.AutoCropDimensions.Top;
+ this.Task.Cropping.Bottom = title.AutoCropDimensions.Bottom;
+ this.Task.Cropping.Left = title.AutoCropDimensions.Left;
+ this.Task.Cropping.Right = title.AutoCropDimensions.Right;
this.IsCustomCrop = false;
}
else
{
- this.CropLeft = preset.Task.Cropping.Left;
- this.CropRight = preset.Task.Cropping.Right;
- this.CropTop = preset.Task.Cropping.Top;
- this.CropBottom = preset.Task.Cropping.Bottom;
+ this.Task.Cropping.Left = preset.Task.Cropping.Left;
+ this.Task.Cropping.Right = preset.Task.Cropping.Right;
+ this.Task.Cropping.Top = preset.Task.Cropping.Top;
+ this.Task.Cropping.Bottom = preset.Task.Cropping.Bottom;
this.IsCustomCrop = true;
}
if (preset.PictureSettingsMode == PresetPictureSettingsMode.None)
{
// We have no instructions, so simply set it to the source.
- this.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight);
+ this.Task.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight);
this.MaintainAspectRatio = true;
}
else
@@ -796,23 +766,18 @@ namespace HandBrakeWPF.ViewModels
// Set the Width, and Maintain Aspect ratio. That should calc the Height for us.
if (this.SelectedAnamorphicMode == Anamorphic.None)
{
- this.Width = preset.Task.Width ?? (this.MaxWidth - this.CropLeft - this.CropRight);
+ this.Task.Width = preset.Task.Width ?? (this.MaxWidth - this.CropLeft - this.CropRight);
// Note: This will be auto-corrected in the property if it's too large.
}
else
{
- this.Width = preset.Task.Width ?? this.MaxWidth;
+ this.Task.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.MaintainAspectRatio && this.Height > this.MaxHeight)
{
- this.Height = this.MaxHeight;
- }
-
- if (this.SelectedAnamorphicMode == Anamorphic.Custom)
- {
- this.AnamorphicAdjust(); // Refresh the values
+ this.Task.Height = this.MaxHeight;
}
}
@@ -824,6 +789,8 @@ namespace HandBrakeWPF.ViewModels
title.AspectRatio,
title.ParVal.Width,
title.ParVal.Height);
+
+ this.RecaulcatePictureSettingsProperties(ChangedPictureField.Width);
}
this.NotifyOfPropertyChange(() => this.Task);
@@ -848,35 +815,171 @@ namespace HandBrakeWPF.ViewModels
#region Methods
/// <summary>
- /// The crop adjust.
+ /// The init.
+ /// </summary>
+ private void Init()
+ {
+ this.Task.Modulus = 16;
+ this.Task.KeepDisplayAspect = true;
+
+ this.NotifyOfPropertyChange(() => this.SelectedModulus);
+ this.NotifyOfPropertyChange(() => this.MaintainAspectRatio);
+
+ // Default the Max Width / Height to 1080p format
+ this.MaxHeight = 1080;
+ this.MaxWidth = 1920;
+ }
+
+ /// <summary>
+ /// The get picture title info.
/// </summary>
- private void CropAdjust()
+ /// <returns>
+ /// The <see cref="PictureSize.PictureSettingsTitle"/>.
+ /// </returns>
+ private PictureSize.PictureSettingsTitle GetPictureTitleInfo()
{
- PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size(this.GetPictureSettings(), this.GetPictureTitleInfo());
+ PictureSize.PictureSettingsTitle title = new PictureSize.PictureSettingsTitle
+ {
+ Width = this.sourceResolution.Width,
+ Height = this.sourceResolution.Height,
+ ParW = this.sourceParValues.Width,
+ ParH = this.sourceParValues.Height,
+ Aspect = 0 // TODO
+ };
+
+ return title;
+ }
+
+ /// <summary>
+ /// The get picture settings.
+ /// </summary>
+ /// <returns>
+ /// The <see cref="PictureSize.PictureSettingsJob"/>.
+ /// </returns>
+ private PictureSize.PictureSettingsJob GetPictureSettings()
+ {
+ PictureSize.PictureSettingsJob job = new PictureSize.PictureSettingsJob
+ {
+ Width = this.Width,
+ Height = this.Height,
+ ItuPar = false,
+ Modulus = this.SelectedModulus,
+ ParW = this.ParWidth,
+ ParH = this.ParHeight,
+ MaxWidth = this.MaxWidth,
+ MaxHeight = this.MaxHeight,
+ KeepDisplayAspect = this.MaintainAspectRatio,
+ AnamorphicMode = this.SelectedAnamorphicMode,
+ DarWidth = 0,
+ DarHeight = 0,
+ Crop = new Cropping(this.CropTop, this.CropBottom, this.CropLeft, this.CropRight),
+ };
+
+ if (this.SelectedAnamorphicMode == Anamorphic.Loose)
+ {
+ job.ParW = sourceParValues.Width;
+ job.ParH = sourceParValues.Height;
+ }
+
+ return job;
+ }
+
+ /// <summary>
+ /// Recalculate the picture settings when the user changes a particular field defined in the ChangedPictureField enum.
+ /// The properties in this class are dumb. They simply call this method if there is a change.
+ /// It is the job of this method to update all affected private fields and raise change notifications.
+ /// </summary>
+ /// <param name="changedField">
+ /// The changed field.
+ /// </param>
+ private void RecaulcatePictureSettingsProperties(ChangedPictureField changedField)
+ {
+ // Sanity Check
+ if (this.currentTitle == null)
+ {
+ return;
+ }
+
+ // Step 1, Update what controls are visibile.
+ this.UpdateVisibileControls();
+
+ // Step 2, Set sensible defaults
+ if (changedField == ChangedPictureField.Anamorphic && (this.SelectedAnamorphicMode == Anamorphic.None || this.SelectedAnamorphicMode == Anamorphic.Loose))
+ {
+ this.Task.Width = this.sourceResolution.Width > this.MaxWidth
+ ? this.MaxWidth
+ : this.sourceResolution.Width;
+ this.Task.KeepDisplayAspect = true;
+ }
+
+ // Choose which setting to keep.
+ PictureSize.KeepSetting setting = PictureSize.KeepSetting.HB_KEEP_WIDTH;
+ switch (changedField)
+ {
+ case ChangedPictureField.Width:
+ setting = PictureSize.KeepSetting.HB_KEEP_WIDTH;
+ break;
+ case ChangedPictureField.Height:
+ setting = PictureSize.KeepSetting.HB_KEEP_HEIGHT;
+ break;
+ }
+
+ // Step 2, For the changed field, call hb_set_anamorphic_size and process the results.
+ PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size2(this.GetPictureSettings(), this.GetPictureTitleInfo(), setting);
+
switch (this.SelectedAnamorphicMode)
{
case Anamorphic.None:
- // this.Width = result.OutputWidth;
- // this.Height = result.OutputHeight;
+ this.Task.Width = result.OutputWidth;
+ this.Task.Height = result.OutputHeight;
break;
case Anamorphic.Strict:
+ this.Task.Width = 0;
+ this.Task.Height = 0;
+ break;
case Anamorphic.Loose:
+ this.Task.Width = result.OutputWidth;
+ this.Task.Height = 0;
+ break;
case Anamorphic.Custom:
- double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);
- this.DisplaySize = this.sourceResolution.IsEmpty
- ? string.Empty
- : string.Format("Storage: {0}x{1}, Display: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight);
+ this.Task.Width = result.OutputWidth;
+ this.Task.Height = result.OutputHeight;
break;
}
+
+ // Step 3, Set the display width label to indicate the output.
+ double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);
+ this.DisplaySize = this.sourceResolution.IsEmpty
+ ? string.Empty
+ : string.Format("Storage: {0}x{1}, Display: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight);
+
+ // Step 4, Force an update on all the UI elements.
+ this.NotifyOfPropertyChange(() => this.Width);
+ this.NotifyOfPropertyChange(() => this.Height);
+ this.NotifyOfPropertyChange(() => this.ParWidth);
+ this.NotifyOfPropertyChange(() => this.ParHeight);
+ this.NotifyOfPropertyChange(() => this.CropTop);
+ this.NotifyOfPropertyChange(() => this.CropBottom);
+ this.NotifyOfPropertyChange(() => this.CropLeft);
+ this.NotifyOfPropertyChange(() => this.CropRight);
+ this.NotifyOfPropertyChange(() => this.SelectedModulus);
+ this.NotifyOfPropertyChange(() => this.MaintainAspectRatio);
+
+ // Step 5, Update the Preview
+ if (delayedPreviewprocessor != null && this.Task != null && this.StaticPreviewViewModel != null && this.StaticPreviewViewModel.IsOpen)
+ {
+ delayedPreviewprocessor.PerformTask(() => this.StaticPreviewViewModel.UpdatePreviewFrame(this.Task), 800);
+ }
}
/// <summary>
- /// Adjust other values after the user has altered the anamorphic.
+ /// The update visibile controls.
/// </summary>
- private void AnamorphicAdjust()
+ private void UpdateVisibileControls()
{
this.ShowDisplaySize = true;
this.ShowKeepAR = true;
+
switch (this.SelectedAnamorphicMode)
{
case Anamorphic.None:
@@ -886,32 +989,13 @@ namespace HandBrakeWPF.ViewModels
this.ShowModulus = true;
this.ShowDisplaySize = true;
this.ShowKeepAR = true;
- this.SelectedModulus = 16; // Reset
- if (this.Width == 0)
- {
- this.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight);
- }
-
- if (!this.MaintainAspectRatio && this.Height == 0)
- {
- this.Height = this.GetModulusValue(this.sourceResolution.Height - this.CropTop - this.CropBottom);
- }
-
- this.MaintainAspectRatio = true;
-
- this.SetDisplaySize();
break;
case Anamorphic.Strict:
this.WidthControlEnabled = false;
this.HeightControlEnabled = false;
this.ShowCustomAnamorphicControls = false;
this.ShowModulus = false;
- this.SelectedModulus = 16; // Reset
this.ShowKeepAR = false;
-
- this.Width = 0;
- this.Height = 0;
- this.SetDisplaySize();
break;
case Anamorphic.Loose:
@@ -919,59 +1003,21 @@ namespace HandBrakeWPF.ViewModels
this.HeightControlEnabled = false;
this.ShowCustomAnamorphicControls = false;
this.ShowModulus = true;
-
- // Reset to the source size.
- this.Width = this.sourceResolution.Width;
- this.Height = 0; // this.sourceResolution.Height - this.CropTop - this.CropBottom;
this.ShowKeepAR = false;
-
- this.SetDisplaySize();
break;
case Anamorphic.Custom:
this.WidthControlEnabled = true;
this.HeightControlEnabled = true;
this.ShowCustomAnamorphicControls = true;
- this.MaintainAspectRatio = false; // TODO Fix when implementing custom
this.ShowModulus = true;
- this.ShowDisplaySize = false; // Disabled for Custom until we implement it properly. TODO
+ this.ShowDisplaySize = false;
this.ShowKeepAR = false;
-
- // Ignore any of the users current settings and reset to source to make things easier.
- this.Width = this.sourceResolution.Width;
- this.Height = this.sourceResolution.Height - this.CropTop - this.CropBottom;
-
- // Set the Display Width and set the Par X/Y to the source values initially.
- this.ParWidth = this.sourceParValues.Width;
- this.ParHeight = this.sourceParValues.Height;
- if (this.ParHeight != 0)
- {
- this.DisplayWidth = (this.Width * this.ParWidth / this.ParHeight);
- }
-
- // this.SetDisplaySize();
break;
}
}
/// <summary>
- /// Adjust other values after the user has altered one of the custom anamorphic settings
- /// </summary>
- private void CustomAnamorphicAdjust()
- {
- if (this.SelectedAnamorphicMode == Anamorphic.Custom)
- {
- if (this.MaintainAspectRatio && this.DisplayWidth != 0)
- {
- this.ParWidth = this.DisplayWidth;
- this.ParHeight = this.Width;
- }
-
- this.SetDisplaySize();
- }
- }
-
- /// <summary>
/// For a given value, correct so that it matches the users currently selected modulus value
/// </summary>
/// <param name="value">
@@ -1002,139 +1048,8 @@ namespace HandBrakeWPF.ViewModels
}
/// <summary>
- /// Adjust other values after the user has altered the height
- /// </summary>
- private void HeightAdjust()
- {
- if (this.sourceResolution == new Size(0, 0))
- {
- return;
- }
-
- if (this.Height > this.sourceResolution.Height)
- {
- this.Task.Height = this.sourceResolution.Height;
- this.NotifyOfPropertyChange(() => this.Task.Height);
- }
-
- switch (this.SelectedAnamorphicMode)
- {
- case Anamorphic.None:
- if (this.MaintainAspectRatio)
- {
- double cropWidth = this.sourceResolution.Width - this.CropLeft - this.CropRight;
- double cropHeight = this.sourceResolution.Height - this.CropTop - this.CropBottom;
-
- double newWidth = ((double)this.Height * this.sourceResolution.Height * this.SourceAspect.Width *
- cropWidth) /
- ((double)this.sourceResolution.Width * this.SourceAspect.Height * cropHeight);
-
- this.Task.Width = this.GetModulusValue(newWidth);
- this.NotifyOfPropertyChange(() => this.Task.Width);
- }
-
- break;
- case Anamorphic.Custom:
- this.SetDisplaySize();
- break;
- }
- }
-
- /// <summary>
- /// Adjust other values after the user has altered the modulus
- /// </summary>
- private void ModulusAdjust()
- {
- this.WidthAdjust();
- }
-
- /// <summary>
- /// Set the display size text
- /// </summary>
- private void SetDisplaySize()
- {
- /*
- * Handle Anamorphic Display
- */
- if (this.SelectedAnamorphicMode != Anamorphic.None)
- {
- PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size(this.GetPictureSettings(), this.GetPictureTitleInfo());
- double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0);
-
- this.DisplaySize = this.sourceResolution.IsEmpty
- ? string.Format(Properties.Resources.PictureSettings_OutputResolution, "None")
- : string.Format("Output: {0}x{1}, Anamorphic: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight);
- }
- else
- {
- this.DisplaySize = this.sourceResolution.IsEmpty
- ? string.Empty
- : string.Format("Output: {0}x{1}", this.Width, this.Height);
- }
- }
-
- /// <summary>
- /// Adjust other values after the user has altered the width
+ /// The get res.
/// </summary>
- private void WidthAdjust()
- {
- if (this.Width > this.sourceResolution.Width)
- {
- this.Task.Width = this.sourceResolution.Width;
- this.NotifyOfPropertyChange(() => this.Task.Width);
- }
-
- switch (this.SelectedAnamorphicMode)
- {
- case Anamorphic.None:
- if (this.MaintainAspectRatio)
- {
- double cropWidth = this.sourceResolution.Width - this.CropLeft - this.CropRight;
- double cropHeight = this.sourceResolution.Height - this.CropTop - this.CropBottom;
-
- if (this.SourceAspect.Width == 0 && this.SourceAspect.Height == 0)
- {
- break;
- }
-
- double newHeight = ((double)this.Width * this.sourceResolution.Width * this.SourceAspect.Height *
- cropHeight) /
- ((double)this.sourceResolution.Height * this.SourceAspect.Width * cropWidth);
-
- this.Task.Height = this.GetModulusValue(newHeight);
- this.NotifyOfPropertyChange(() => this.Height);
- }
- this.SetDisplaySize();
- break;
- case Anamorphic.Strict:
- this.Task.Width = 0;
- this.Task.Height = 0;
-
- this.NotifyOfPropertyChange(() => this.Width);
- this.NotifyOfPropertyChange(() => this.Height);
- this.SetDisplaySize();
- break;
- case Anamorphic.Loose:
- this.Task.Height = 0;
- this.NotifyOfPropertyChange(() => this.Width);
- this.NotifyOfPropertyChange(() => this.Height);
- this.SetDisplaySize();
- break;
- case Anamorphic.Custom:
- if (this.MaintainAspectRatio)
- {
- this.ParWidth = this.DisplayWidth;
- this.ParHeight = this.Width;
- }
-
- this.SetDisplaySize();
- break;
- }
- }
-
- /// <summary>
- /// Quick function to get the max resolution value
- /// </summary>
/// <param name="value">
/// The value.
/// </param>
@@ -1142,80 +1057,29 @@ namespace HandBrakeWPF.ViewModels
/// The max.
/// </param>
/// <returns>
- /// An Int
+ /// The <see cref="int"/>.
/// </returns>
- private int getRes(int value, int? max)
+ private int GetRes(int value, int? max)
{
return max.HasValue ? (value > max.Value ? max.Value : value) : value;
}
- /// <summary>
- /// The get picture title info.
- /// </summary>
- /// <returns>
- /// The <see cref="PictureSize.PictureSettingsTitle"/>.
- /// </returns>
- private PictureSize.PictureSettingsTitle GetPictureTitleInfo()
- {
- PictureSize.PictureSettingsTitle title = new PictureSize.PictureSettingsTitle
- {
- Width = this.sourceResolution.Width,
- Height = this.sourceResolution.Height,
- ParW = this.sourceParValues.Width,
- ParH = this.sourceParValues.Height,
- Aspect = 0 // TODO
- };
-
- return title;
- }
-
- /// <summary>
- /// The get picture settings.
- /// </summary>
- /// <returns>
- /// The <see cref="PictureSize.PictureSettingsJob"/>.
- /// </returns>
- private PictureSize.PictureSettingsJob GetPictureSettings()
- {
- PictureSize.PictureSettingsJob job = new PictureSize.PictureSettingsJob
- {
- Width = this.Width,
- Height = this.Height,
- ItuPar = false,
- Modulus = this.SelectedModulus,
- ParW = this.ParWidth,
- ParH = this.ParHeight,
- MaxWidth = this.MaxWidth,
- MaxHeight = this.MaxHeight,
- KeepDisplayAspect = this.MaintainAspectRatio,
- AnamorphicMode = this.SelectedAnamorphicMode,
- DarWidth = 0,
- DarHeight = 0,
- Crop = new Cropping(this.CropTop, this.CropBottom, this.CropLeft, this.CropRight),
- };
-
- if (this.SelectedAnamorphicMode == Anamorphic.Loose)
- {
- job.ParW = sourceParValues.Width;
- job.ParH = sourceParValues.Height;
- }
-
- return job;
- }
-
- /// <summary>
- /// Updates the preview after a period of time.
- /// This gives the user the opertunity to make changes in quick sucession without the image refreshing instantly
- /// and causing performance lag.
- /// </summary>
- private void UpdatePreviewImage()
- {
- if (delayedPreviewprocessor != null && this.Task != null && this.StaticPreviewViewModel != null && this.StaticPreviewViewModel.IsOpen)
- {
- delayedPreviewprocessor.PerformTask(() => this.StaticPreviewViewModel.UpdatePreviewFrame(this.Task), 800);
- }
- }
-
#endregion
}
+
+ /// <summary>
+ /// The changed picture field.
+ /// </summary>
+ enum ChangedPictureField
+ {
+ Width,
+ Height,
+ ParW,
+ ParH,
+ DisplayWidth,
+ Crop,
+ Anamorphic,
+ MaintainAspectRatio,
+ Modulus
+ }
} \ No newline at end of file