From d97eb4f9a23dd8dd6019b0d3e2121294d8bb7dea Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 26 Jun 2020 21:30:37 +0100 Subject: WinGui: Experimental new Dimensions Tab Design. (Part 1 of Several). Adding the Resolution Limit on display and removing upscale limitations. (These will come back in some less restrictive than current form later) #2437 --- .../HandBrakeWPF/Converters/EnumComboConverter.cs | 16 -- .../Converters/Picture/ResolutionLimitConverter.cs | 49 +++++ .../Model/Picture/PictureSettingsResLimitModes.cs | 42 ++++ .../Model/Picture/PresetPictureSettingsMode.cs | 2 +- win/CS/HandBrakeWPF/Model/Picture/ResLimit.cs | 23 +++ .../HandBrakeWPF/Properties/Resources.Designer.cs | 90 +++++++++ win/CS/HandBrakeWPF/Properties/Resources.resx | 30 +++ .../Presets/Factories/JsonPresetFactory.cs | 4 +- .../HandBrakeWPF/Services/Presets/Model/Preset.cs | 123 +----------- .../HandBrakeWPF/Services/Presets/PresetService.cs | 166 +--------------- win/CS/HandBrakeWPF/Utilities/EnumHelper.cs | 17 ++ .../HandBrakeWPF/ViewModels/AddPresetViewModel.cs | 149 ++------------- .../ViewModels/PictureSettingsViewModel.cs | 211 +++++++++++---------- win/CS/HandBrakeWPF/Views/AddPresetView.xaml | 4 +- win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml | 130 +++++++------ 15 files changed, 451 insertions(+), 605 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Converters/Picture/ResolutionLimitConverter.cs create mode 100644 win/CS/HandBrakeWPF/Model/Picture/PictureSettingsResLimitModes.cs create mode 100644 win/CS/HandBrakeWPF/Model/Picture/ResLimit.cs (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index 20c833cdd..aeaf153f2 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -20,7 +20,6 @@ namespace HandBrakeWPF.Converters using HandBrakeWPF.Services.Queue.Model; using HandBrakeWPF.Utilities; using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat; - using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode; /// /// Enum Combo Converter @@ -40,11 +39,6 @@ namespace HandBrakeWPF.Converters return EnumHelper.GetEnumDisplayValues(typeof(VideoEncoder)); } - if (value is IEnumerable) - { - return EnumHelper.GetEnumDisplayValues(typeof(PresetPictureSettingsMode)); - } - if (value is IEnumerable) { return EnumHelper.GetEnumDisplayValues(typeof(Detelecine)); @@ -101,11 +95,6 @@ namespace HandBrakeWPF.Converters return EnumHelper.GetDisplay((VideoEncoder)value); } - if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) - { - return EnumHelper.GetDisplay((PresetPictureSettingsMode)value); - } - if (targetType == typeof(Detelecine) || value.GetType() == typeof(Detelecine)) { return EnumHelper.GetDisplay((Detelecine)value); @@ -176,11 +165,6 @@ namespace HandBrakeWPF.Converters return EnumHelper.GetValue(value.ToString()); } - if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) - { - return EnumHelper.GetValue(value.ToString()); - } - if (targetType == typeof(Denoise) || value.GetType() == typeof(Denoise)) { return EnumHelper.GetValue(value.ToString()); diff --git a/win/CS/HandBrakeWPF/Converters/Picture/ResolutionLimitConverter.cs b/win/CS/HandBrakeWPF/Converters/Picture/ResolutionLimitConverter.cs new file mode 100644 index 000000000..c54296294 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Picture/ResolutionLimitConverter.cs @@ -0,0 +1,49 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// + +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Picture +{ + using System; + using System.ComponentModel; + using System.Globalization; + using System.Linq; + using System.Windows.Data; + + using HandBrakeWPF.Model.Picture; + using HandBrakeWPF.Utilities; + + public class ResolutionLimitConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value.GetType() == typeof(BindingList)) + { + return + new BindingList( + EnumHelper.GetEnumDisplayValues(typeof(PictureSettingsResLimitModes)).ToList()); + } + + if (value != null && value.GetType() == typeof(PictureSettingsResLimitModes)) + { + return EnumHelper.GetDisplay((PictureSettingsResLimitModes)value); + } + + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + string name = value as string; + if (!string.IsNullOrEmpty(name)) + { + return EnumHelper.GetValue(name); + } + + return null; + } + } +} diff --git a/win/CS/HandBrakeWPF/Model/Picture/PictureSettingsResLimitModes.cs b/win/CS/HandBrakeWPF/Model/Picture/PictureSettingsResLimitModes.cs new file mode 100644 index 000000000..877550470 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/Picture/PictureSettingsResLimitModes.cs @@ -0,0 +1,42 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Model.Picture +{ + using HandBrake.Interop.Attributes; + + using HandBrakeWPF.Properties; + + public enum PictureSettingsResLimitModes + { + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_8K")] + [ResLimit(7680, 4320)] + Size8K, + + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_4K")] + [ResLimit(3840, 2160)] + Size4K, + + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_1080p")] + [ResLimit(1920, 1080)] + Size1080p, + + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_720p")] + [ResLimit(1280, 720)] + Size720p, + + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_576p")] + [ResLimit(720, 576)] + Size576p, + + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_480p")] + [ResLimit(720, 480)] + Size480p, + + [DisplayName(typeof(Resources), "PictureSettingsResLimitModes_custom")] + Custom, + } +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Model/Picture/PresetPictureSettingsMode.cs b/win/CS/HandBrakeWPF/Model/Picture/PresetPictureSettingsMode.cs index 517da08ee..d4d2845c8 100644 --- a/win/CS/HandBrakeWPF/Model/Picture/PresetPictureSettingsMode.cs +++ b/win/CS/HandBrakeWPF/Model/Picture/PresetPictureSettingsMode.cs @@ -16,7 +16,7 @@ namespace HandBrakeWPF.Model.Picture /// /// Picture Settings Mode when adding presets /// - public enum PresetPictureSettingsMode + public enum PresetPictureSettingsMode2 { [DisplayName(typeof(Resources), "PresetPictureSettingsMode_None")] None = 0, diff --git a/win/CS/HandBrakeWPF/Model/Picture/ResLimit.cs b/win/CS/HandBrakeWPF/Model/Picture/ResLimit.cs new file mode 100644 index 000000000..392b9d7a3 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/Picture/ResLimit.cs @@ -0,0 +1,23 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Model.Picture +{ + using System; + + public class ResLimit : Attribute + { + public ResLimit(int width, int height) + { + this.Width = width; + this.Height = height; + } + + public int Width { get; } + + public int Height { get; } + } +} diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 0213629cc..77aaed9cb 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -3853,6 +3853,69 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to 1080p HD. + /// + public static string PictureSettingsResLimitModes_1080p { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_1080p", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 480p NTSC SD. + /// + public static string PictureSettingsResLimitModes_480p { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_480p", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 2160p 4K Ultra HD. + /// + public static string PictureSettingsResLimitModes_4K { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_4K", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 576p PAL SD. + /// + public static string PictureSettingsResLimitModes_576p { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_576p", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 720p HD. + /// + public static string PictureSettingsResLimitModes_720p { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_720p", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to 4320p 8K Ultra HD. + /// + public static string PictureSettingsResLimitModes_8K { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_8K", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Custom. + /// + public static string PictureSettingsResLimitModes_custom { + get { + return ResourceManager.GetString("PictureSettingsResLimitModes_custom", resourceCulture); + } + } + /// /// Looks up a localized string similar to Anamorphic:. /// @@ -3943,6 +4006,24 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Max Height:. + /// + public static string PictureSettingsView_MaxHeight { + get { + return ResourceManager.GetString("PictureSettingsView_MaxHeight", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Max Width:. + /// + public static string PictureSettingsView_MaxWidth { + get { + return ResourceManager.GetString("PictureSettingsView_MaxWidth", resourceCulture); + } + } + /// /// Looks up a localized string similar to Modulus:. /// @@ -3997,6 +4078,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Resolution Limit:. + /// + public static string PictureSettingsView_ResLimit { + get { + return ResourceManager.GetString("PictureSettingsView_ResLimit", resourceCulture); + } + } + /// /// Looks up a localized string similar to Right. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index d869657b0..e75028c5b 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -2280,4 +2280,34 @@ Please choose a different preset. Forced + + 1080p HD + + + 480p NTSC SD + + + 2160p 4K Ultra HD + + + 576p PAL SD + + + 720p HD + + + 4320p 8K Ultra HD + + + Custom + + + Max Height: + + + Max Width: + + + Resolution Limit: + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index 94c66adb1..c6e35cb96 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -75,7 +75,7 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.Task.AlignAVStart = importedPreset.AlignAVStart; /* Picture Settings */ - preset.PictureSettingsMode = (PresetPictureSettingsMode)importedPreset.UsesPictureSettings; + // preset.PictureSettingsMode = (PresetPictureSettingsMode)importedPreset.UsesPictureSettings; preset.Task.MaxWidth = importedPreset.PictureWidth.HasValue && importedPreset.PictureWidth.Value > 0 ? importedPreset.PictureWidth.Value : (int?)null; preset.Task.MaxHeight = importedPreset.PictureHeight.HasValue && importedPreset.PictureHeight.Value > 0 ? importedPreset.PictureHeight.Value : (int?)null; preset.Task.Cropping = new Cropping(importedPreset.PictureTopCrop, importedPreset.PictureBottomCrop, importedPreset.PictureLeftCrop, importedPreset.PictureRightCrop); @@ -544,7 +544,7 @@ namespace HandBrakeWPF.Services.Presets.Factories preset.PresetDescription = export.Description; preset.PresetName = export.Name; preset.Type = export.IsBuildIn ? 0 : 1; - preset.UsesPictureSettings = (int)export.PictureSettingsMode; + // preset.UsesPictureSettings = (int)export.PictureSettingsMode; preset.Default = export.IsDefault; // Audio diff --git a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs index df21ccf9b..c67298c32 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Model/Preset.cs @@ -17,64 +17,32 @@ namespace HandBrakeWPF.Services.Presets.Model using HandBrakeWPF.Services.Presets.Interfaces; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; - using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode; - /// - /// A Preset for encoding with. - /// - public class Preset : PropertyChangedBase, IPresetObject // Delibery not + public class Preset : PropertyChangedBase, IPresetObject { - #region Constants and Fields - - /// - /// The is default. - /// private bool isDefault; private bool isSelected; - #endregion - - /// - /// Initializes a new instance of the class. - /// public Preset() { } - /// - /// Initializes a new instance of the class. - /// - /// - /// The preset. - /// public Preset(Preset preset) { this.Category = preset.Category; this.Description = preset.Description; this.IsBuildIn = preset.IsBuildIn; this.Name = preset.Name; - this.PictureSettingsMode = preset.PictureSettingsMode; this.Task = new EncodeTask(preset.Task); this.AudioTrackBehaviours = new AudioBehaviours(preset.AudioTrackBehaviours); this.SubtitleTrackBehaviours = new SubtitleBehaviours(preset.SubtitleTrackBehaviours); } - #region Properties - - /// - /// Gets or sets the category which the preset resides under - /// public string Category { get; set; } - /// - /// Gets or sets the Description for the preset - /// public string Description { get; set; } - /// - /// Reflects the visual state of this preset. - /// public bool IsExpanded { get; set; } public string DisplayValue @@ -88,10 +56,7 @@ namespace HandBrakeWPF.Services.Presets.Model public bool IsSelected { - get - { - return this.isSelected; - } + get => this.isSelected; set { this.isSelected = value; @@ -99,14 +64,8 @@ namespace HandBrakeWPF.Services.Presets.Model } } - /// - /// Gets or sets a value indicating whether this is a built in preset - /// public bool IsBuildIn { get; set; } - /// - /// Gets or sets a value indicating whether IsDefault. - /// public bool IsDefault { get @@ -120,125 +79,53 @@ namespace HandBrakeWPF.Services.Presets.Model } } - /// - /// Gets or sets the preset name - /// public string Name { get; set; } - /// - /// Gets or sets PictureSettingsMode. - /// Source Maximum, Custom or None - /// - public PresetPictureSettingsMode PictureSettingsMode { get; set; } - - /// - /// Gets or sets task. - /// public EncodeTask Task { get; set; } - /// - /// Gets or sets the audio track behaviours. - /// public AudioBehaviours AudioTrackBehaviours { get; set; } - /// - /// Gets or sets the subtitle track behaviours. - /// public SubtitleBehaviours SubtitleTrackBehaviours { get; set; } public bool IsPresetDisabled { get; set; } - #endregion - - #region Public Methods - - /// - /// Update this preset. - /// The given parameters should be copy-constructed. - /// - /// - /// The task. - /// - /// - /// The audio behaviours. - /// - /// - /// The subtitle behaviours. - /// public void Update(EncodeTask task, AudioBehaviours audioBehaviours, SubtitleBehaviours subtitleBehaviours) { - // Copy over Max Width / Height for the following picture settings modes. - if (this.PictureSettingsMode == PresetPictureSettingsMode.Custom - || this.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) - { - task.MaxWidth = this.Task.MaxWidth; - task.MaxHeight = this.Task.MaxHeight; - } - this.Task = task; this.AudioTrackBehaviours = new AudioBehaviours(audioBehaviours); this.SubtitleTrackBehaviours = new SubtitleBehaviours(subtitleBehaviours); } - /// - /// Override the ToString Method - /// - /// - /// The Preset Name - /// public override string ToString() { return this.Name; } - #endregion - - /// - /// The equals. - /// - /// - /// The obj. - /// - /// - /// The . - /// public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } + if (ReferenceEquals(this, obj)) { return true; } + if (obj.GetType() != this.GetType()) { return false; } + return Equals((Preset)obj); } - /// - /// The get hash code. - /// - /// - /// The . - /// public override int GetHashCode() { return (this.Name != null ? this.Name.GetHashCode() : 0); } - /// - /// The equals. - /// - /// - /// The other. - /// - /// - /// The . - /// protected bool Equals(Preset other) { return string.Equals(this.Name, other.Name); diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 9ee511ca8..c34ca617f 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -14,11 +14,9 @@ namespace HandBrakeWPF.Services.Presets using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; - using System.Diagnostics; using System.IO; using System.Linq; using System.Windows; - using System.Windows.Documents; using HandBrake.Interop.Interop; using HandBrake.Interop.Interop.Json.Presets; @@ -28,11 +26,9 @@ namespace HandBrakeWPF.Services.Presets using HandBrake.Interop.Utilities; using HandBrakeWPF.Factories; - using HandBrakeWPF.Model.Picture; using HandBrakeWPF.Properties; using HandBrakeWPF.Services.Encode.Model.Models; using HandBrakeWPF.Services.Interfaces; - using HandBrakeWPF.Services.Logging; using HandBrakeWPF.Services.Logging.Interfaces; using HandBrakeWPF.Services.Presets.Factories; using HandBrakeWPF.Services.Presets.Interfaces; @@ -44,9 +40,6 @@ namespace HandBrakeWPF.Services.Presets using GeneralApplicationException = HandBrakeWPF.Exceptions.GeneralApplicationException; using SystemInfo = HandBrake.Interop.Utilities.SystemInfo; - /// - /// The preset service manages HandBrake's presets - /// public class PresetService : IPresetService { public const int ForcePresetReset = 3; @@ -66,9 +59,6 @@ namespace HandBrakeWPF.Services.Presets this.userSettingService = userSettingService; } - /// - /// Gets a Collection of presets. - /// public ObservableCollection Presets { get @@ -77,9 +67,6 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// Gets the DefaultPreset. - /// public Preset DefaultPreset { get @@ -88,9 +75,6 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// The load. - /// public void Load() { // Load the presets from file @@ -102,20 +86,6 @@ namespace HandBrakeWPF.Services.Presets return this.Add(preset, false); } - /// - /// Add a new preset to the system. - /// Performs an Update if it already exists - /// - /// - /// A Preset to add - /// - /// - /// Prevents Saving of presets. - /// - /// - /// True if added, - /// False if name already exists - /// public bool Add(Preset preset, bool isLoading) { if (!this.CheckIfPresetExists(preset.Name)) @@ -155,12 +125,6 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// The import. - /// - /// - /// The filename. - /// public void Import(string filename) { if (!string.IsNullOrEmpty(filename)) @@ -236,18 +200,6 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// The export. - /// - /// - /// The filename. - /// - /// - /// The preset. - /// - /// - /// The configuration. - /// public void Export(string filename, Preset preset, HBConfiguration configuration) { // TODO Add support for multiple export @@ -255,19 +207,12 @@ namespace HandBrakeWPF.Services.Presets HandBrakePresetService.ExportPreset(filename, container); } - /// - /// Update a preset - /// - /// - /// The updated preset - /// public void Update(Preset update) { Preset preset; if (this.flatPresetDict.TryGetValue(update.Name, out preset)) { preset.Task = update.Task; - preset.PictureSettingsMode = update.PictureSettingsMode; preset.Category = update.Category; preset.Description = update.Description; preset.AudioTrackBehaviours = update.AudioTrackBehaviours; @@ -278,28 +223,12 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// Replace an existing preset with a modified one. - /// - /// - /// The existing. - /// - /// - /// The replacement. - /// public void Replace(Preset existing, Preset replacement) { this.Remove(existing); this.Add(replacement, false); } - /// - /// Remove a preset with a given name from either the built in or user preset list. - /// - /// - /// The Preset to remove - /// - /// True if successfully removed, false otherwise. public bool Remove(Preset preset) { if (preset == null || preset.IsDefault) @@ -331,12 +260,6 @@ namespace HandBrakeWPF.Services.Presets return true; } - /// - /// Remove a group of presets by category - /// - /// - /// The Category to remove - /// public void RemoveGroup(string categoryName) { PresetDisplayCategory category = this.presets.FirstOrDefault(p => p.Category == categoryName) as PresetDisplayCategory; @@ -365,12 +288,6 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// Set Default Preset - /// - /// - /// The name. - /// public void SetDefault(Preset preset) { // Set IsDefault false for everything. @@ -385,15 +302,6 @@ namespace HandBrakeWPF.Services.Presets this.SavePresetFiles(); } - /// - /// Get a Preset - /// - /// - /// The name of the preset to get - /// - /// - /// A Preset or null object - /// public Preset GetPreset(string name) { Preset preset; @@ -405,9 +313,6 @@ namespace HandBrakeWPF.Services.Presets return null; } - /// - /// Clear Built-in Presets - /// public void ClearBuiltIn() { List topLevel = new List(); @@ -463,18 +368,12 @@ namespace HandBrakeWPF.Services.Presets } } - /// - /// Clear all presets - /// public void ClearAll() { this.presets.Clear(); this.flatPresetList.Clear(); } - /// - /// Reads the CLI's CLI output format and load's them into the preset List Preset - /// public void UpdateBuiltInPresets() { // Clear the current built in Presets and now parse the temporary Presets file. @@ -507,15 +406,6 @@ namespace HandBrakeWPF.Services.Presets this.SavePresetFiles(); } - /// - /// Check if the preset "name" exists in either Presets or UserPresets lists. - /// - /// - /// Name of the preset - /// - /// - /// True if found - /// public bool CheckIfPresetExists(string name) { if (this.flatPresetDict.ContainsKey(name)) @@ -526,15 +416,6 @@ namespace HandBrakeWPF.Services.Presets return false; } - /// - /// Returns a value if the preset can be updated / resaved - /// - /// - /// The name. - /// - /// - /// True if it's not a built-in preset, false otherwise. - /// public bool CanUpdatePreset(string name) { Preset preset; @@ -546,10 +427,6 @@ namespace HandBrakeWPF.Services.Presets return true; } - /// - /// Set the selected preset - /// - /// The preset we want to select. public void SetSelected(Preset selectedPreset) { foreach (var item in this.flatPresetList) @@ -614,18 +491,6 @@ namespace HandBrakeWPF.Services.Presets return categoriesList; } - /// - /// Archive the presets file without deleting it. - /// - /// - /// The filename to archive - /// - /// - /// True will delete the current presets file. - /// - /// - /// The archived filename - /// private string ArchivePresetFile(string file, bool delete) { try @@ -661,9 +526,6 @@ namespace HandBrakeWPF.Services.Presets return "Sorry, the archiving failed."; } - /// - /// Load in the Built-in and User presets into the collection - /// private void LoadPresets() { // First clear the Presets arraylists @@ -758,13 +620,6 @@ namespace HandBrakeWPF.Services.Presets preset.IsBuildIn = hbpreset.Type == 0; preset.IsPresetDisabled = this.IsPresetDisabled(preset); - // IF we are using Source Max, Set the Max Width / Height values. - if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) - { - preset.Task.MaxWidth = preset.Task.Height; - preset.Task.MaxHeight = preset.Task.Width; - } - this.Add(preset, true); } } @@ -779,21 +634,11 @@ namespace HandBrakeWPF.Services.Presets preset.IsBuildIn = hbPreset.Type == 1; preset.IsPresetDisabled = this.IsPresetDisabled(preset); - // IF we are using Source Max, Set the Max Width / Height values. - if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) - { - preset.Task.MaxWidth = preset.Task.Height; - preset.Task.MaxHeight = preset.Task.Width; - } - this.Add(preset, true); } } } - /// - /// Update the preset files - /// private void SavePresetFiles() { try @@ -870,18 +715,9 @@ namespace HandBrakeWPF.Services.Presets private Preset ConvertHbPreset(HBPreset hbPreset) { - Preset preset = null; - - preset = JsonPresetFactory.ImportPreset(hbPreset); + Preset preset = JsonPresetFactory.ImportPreset(hbPreset); preset.Category = UserPresetCatgoryName; // TODO can we get this from the preset? - // IF we are using Source Max, Set the Max Width / Height values. - if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) - { - preset.Task.MaxWidth = preset.Task.Height; - preset.Task.MaxHeight = preset.Task.Width; - } - return preset; } diff --git a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs index ef8583917..fd19a1cf0 100644 --- a/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs +++ b/win/CS/HandBrakeWPF/Utilities/EnumHelper.cs @@ -143,6 +143,23 @@ namespace HandBrakeWPF.Utilities return string.Empty; } + public static T GetAttribute(TK value) where T : Attribute + { + if (value == null) + { + return null; + } + + FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); + if (fieldInfo != null) + { + T[] attributes = (T[])fieldInfo.GetCustomAttributes(typeof(T), false); + return (attributes.Length > 0) ? attributes[0] : null; + } + + return null; + } + /// /// Return a list of all the enum values. /// diff --git a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs index d2c5f9452..e7a9235fc 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs @@ -15,8 +15,6 @@ namespace HandBrakeWPF.ViewModels using Caliburn.Micro; - using HandBrake.Interop.Interop.Model.Encoding; - using HandBrakeWPF.Model.Audio; using HandBrakeWPF.Model.Subtitles; using HandBrakeWPF.Properties; @@ -25,12 +23,10 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.Services.Presets.Interfaces; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.Services.Scan.Model; - using HandBrakeWPF.Utilities; using HandBrakeWPF.ViewModels.Interfaces; using HandBrakeWPF.Views; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; - using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode; /// /// The Add Preset View Model @@ -40,15 +36,14 @@ namespace HandBrakeWPF.ViewModels private readonly IPresetService presetService; private readonly IErrorService errorService; private readonly IWindowManager windowManager; - private PresetPictureSettingsMode selectedPictureSettingMode; + private readonly PresetDisplayCategory addNewCategory = new PresetDisplayCategory(Resources.AddPresetView_AddNewCategory, true, null); + private bool showCustomInputs; - private Title selectedTitle; private IAudioDefaultsViewModel audioDefaultsViewModel; private ISubtitlesDefaultsViewModel subtitlesDefaultsViewModel; private PresetDisplayCategory selectedPresetCategory; - private readonly PresetDisplayCategory addNewCategory = new PresetDisplayCategory(Resources.AddPresetView_AddNewCategory, true, null); private bool canAddNewPresetCategory; /// @@ -70,40 +65,15 @@ namespace HandBrakeWPF.ViewModels this.windowManager = windowManager; this.Title = Resources.AddPresetView_AddPreset; this.Preset = new Preset { IsBuildIn = false, IsDefault = false, Category = PresetService.UserPresetCatgoryName }; - this.PictureSettingsModes = EnumHelper.GetEnumList(); this.PresetCategories = presetService.GetPresetCategories(true).Union(new List { addNewCategory }).ToList(); this.SelectedPresetCategory = this.PresetCategories.FirstOrDefault(n => n.Category == PresetService.UserPresetCatgoryName); } - /// - /// Gets the Preset - /// - public Preset Preset { get; private set; } - - /// - /// Gets or sets PictureSettingsModes. - /// - public IEnumerable PictureSettingsModes { get; set; } - - /// - /// Gets or sets CustomWidth. - /// - public int? CustomWidth { get; set; } + public Preset Preset { get; } - /// - /// Gets or sets CustomHeight. - /// - public int? CustomHeight { get; set; } - - /// - /// Gets or sets a value indicating whether ShowCustomInputs. - /// public bool ShowCustomInputs { - get - { - return this.showCustomInputs; - } + get => this.showCustomInputs; set { this.showCustomInputs = value; @@ -115,10 +85,7 @@ namespace HandBrakeWPF.ViewModels public PresetDisplayCategory SelectedPresetCategory { - get - { - return this.selectedPresetCategory; - } + get => this.selectedPresetCategory; set { this.selectedPresetCategory = value; @@ -138,10 +105,7 @@ namespace HandBrakeWPF.ViewModels public string PresetCategory { - get - { - return this.Preset.Category; - } + get => this.Preset.Category; set { this.Preset.Category = value; @@ -151,49 +115,19 @@ namespace HandBrakeWPF.ViewModels public bool CanAddNewPresetCategory { - get - { - return this.canAddNewPresetCategory; - } + get => this.canAddNewPresetCategory; set { - if (value == this.canAddNewPresetCategory) return; + if (value == this.canAddNewPresetCategory) + { + return; + } + this.canAddNewPresetCategory = value; this.NotifyOfPropertyChange(); } } - /// - /// Gets or sets SelectedPictureSettingMode. - /// - public PresetPictureSettingsMode SelectedPictureSettingMode - { - get - { - return this.selectedPictureSettingMode; - } - set - { - this.selectedPictureSettingMode = value; - this.ShowCustomInputs = value == PresetPictureSettingsMode.Custom; - } - } - - /// - /// Prepare the Preset window to create a Preset Object later. - /// - /// - /// The Encode Task. - /// - /// - /// The title. - /// - /// - /// The audio Behaviours. - /// - /// - /// The subtitle Behaviours. - /// public void Setup(EncodeTask task, Title title, AudioBehaviours audioBehaviours, SubtitleBehaviours subtitleBehaviours) { this.Preset.Task = new EncodeTask(task); @@ -205,28 +139,8 @@ namespace HandBrakeWPF.ViewModels this.subtitlesDefaultsViewModel = new SubtitlesDefaultsViewModel(); this.subtitlesDefaultsViewModel.SetupLanguages(subtitleBehaviours); - - this.selectedTitle = title; - - switch (task.Anamorphic) - { - default: - this.SelectedPictureSettingMode = PresetPictureSettingsMode.Custom; - if (title != null && title.Resolution != null) - { - this.CustomWidth = title.Resolution.Width; - this.CustomHeight = title.Resolution.Height; - } - break; - case Anamorphic.Automatic: - this.SelectedPictureSettingMode = PresetPictureSettingsMode.SourceMaximum; - break; - } } - /// - /// Add a Preset - /// public void Add() { if (string.IsNullOrEmpty(this.Preset.Name)) @@ -250,42 +164,7 @@ namespace HandBrakeWPF.ViewModels return; } } - - if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum && this.selectedTitle == null) - { - this.errorService.ShowMessageBox(Resources.AddPresetViewModel_YouMustFirstScanSource, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - if (this.CustomWidth == null && this.CustomHeight == null && this.SelectedPictureSettingMode == PresetPictureSettingsMode.Custom) - { - this.errorService.ShowMessageBox(Resources.AddPresetViewModel_CustomWidthHeightFieldsRequired, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - this.Preset.PictureSettingsMode = this.SelectedPictureSettingMode; - - // Setting W, H, MW and MH - if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.None) - { - this.Preset.Task.MaxHeight = null; - this.Preset.Task.MaxWidth = null; - } - - if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.Custom) - { - this.Preset.Task.MaxWidth = this.CustomWidth; - this.Preset.Task.MaxHeight = this.CustomHeight; - this.Preset.Task.Width = null; - this.Preset.Task.Height = null; - } - - if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum) - { - this.Preset.Task.MaxHeight = null; - this.Preset.Task.MaxWidth = null; - } - + // Add the Preset bool added = this.presetService.Add(this.Preset); if (!added) @@ -308,7 +187,7 @@ namespace HandBrakeWPF.ViewModels public void EditAudioDefaults() { this.audioDefaultsViewModel.ResetApplied(); - bool? result = this.windowManager.ShowDialog(this.audioDefaultsViewModel); + this.windowManager.ShowDialog(this.audioDefaultsViewModel); if (audioDefaultsViewModel.IsApplied) { this.Preset.AudioTrackBehaviours = this.audioDefaultsViewModel.AudioBehaviours.Clone(); diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index b6a1705d5..925d3e269 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -11,6 +11,7 @@ namespace HandBrakeWPF.ViewModels { using System; using System.Collections.Generic; + using System.ComponentModel; using System.Globalization; using HandBrake.Interop.Interop; @@ -19,6 +20,7 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.EventArgs; using HandBrakeWPF.Helpers; + using HandBrakeWPF.Model.Picture; using HandBrakeWPF.Properties; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.Services.Scan.Model; @@ -27,7 +29,6 @@ namespace HandBrakeWPF.ViewModels using HandBrakeWPF.ViewModels.Interfaces; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; - using PresetPictureSettingsMode = HandBrakeWPF.Model.Picture.PresetPictureSettingsMode; public class PictureSettingsViewModel : ViewModelBase, IPictureSettingsViewModel { @@ -48,6 +49,8 @@ namespace HandBrakeWPF.ViewModels private Title currentTitle; private Source scannedSource; + private PictureSettingsResLimitModes selectedPictureSettingsResLimitMode; + public PictureSettingsViewModel(IStaticPreviewViewModel staticPreviewViewModel) { this.StaticPreviewViewModel = staticPreviewViewModel; @@ -156,6 +159,7 @@ namespace HandBrakeWPF.ViewModels { this.maxHeight = value; this.NotifyOfPropertyChange(() => this.MaxHeight); + this.SetSelectedPictureSettingsResLimitMode(); } } @@ -166,6 +170,7 @@ namespace HandBrakeWPF.ViewModels { this.maxWidth = value; this.NotifyOfPropertyChange(() => this.MaxWidth); + this.SetSelectedPictureSettingsResLimitMode(); } } @@ -179,6 +184,57 @@ namespace HandBrakeWPF.ViewModels } } + public BindingList ResolutionLimitModes => new BindingList + { + PictureSettingsResLimitModes.Size8K, + PictureSettingsResLimitModes.Size4K, + PictureSettingsResLimitModes.Size1080p, + PictureSettingsResLimitModes.Size720p, + PictureSettingsResLimitModes.Size576p, + PictureSettingsResLimitModes.Size480p, + PictureSettingsResLimitModes.Custom, + }; + + public PictureSettingsResLimitModes SelectedPictureSettingsResLimitMode + { + get => this.selectedPictureSettingsResLimitMode; + set + { + if (value == this.selectedPictureSettingsResLimitMode) + { + return; + } + + this.selectedPictureSettingsResLimitMode = value; + this.NotifyOfPropertyChange(() => this.SelectedPictureSettingsResLimitMode); + + this.IsCustomMaxRes = value == PictureSettingsResLimitModes.Custom; + this.NotifyOfPropertyChange(() => this.IsCustomMaxRes); + + // Enforce the new limit + ResLimit limit = EnumHelper.GetAttribute(value); + if (limit != null) + { + this.maxWidth = limit.Width; + this.maxHeight = limit.Height; + this.NotifyOfPropertyChange(() => this.MaxWidth); + this.NotifyOfPropertyChange(() => this.Height); + + if (this.Width > this.MaxWidth) + { + this.Width = this.MaxWidth; + } + + if (this.Height > this.MaxWidth) + { + this.Height = this.MaxHeight; + } + } + } + } + + public bool IsCustomMaxRes { get; private set; } + /* Task Properties */ public int CropBottom @@ -370,12 +426,6 @@ namespace HandBrakeWPF.ViewModels { this.Task = task; - // Handle built-in presets. - if (preset.IsBuildIn) - { - preset.PictureSettingsMode = PresetPictureSettingsMode.Custom; - } - // Cropping if (preset.Task.HasCropping) { @@ -395,75 +445,41 @@ namespace HandBrakeWPF.ViewModels this.IsCustomCrop = false; } - // Padding + // Padding and Rotate Filters this.PaddingFilter.SetPreset(preset, task); this.RotateFlipFilter?.SetPreset(preset, task); - - // Setup the Picture Sizes - switch (preset.PictureSettingsMode) - { - default: - case PresetPictureSettingsMode.Custom: - case PresetPictureSettingsMode.SourceMaximum: - // Anamorphic Mode - this.SelectedAnamorphicMode = preset.Task.Anamorphic; - - // Modulus - if (preset.Task.Modulus.HasValue) - { - this.SelectedModulus = preset.Task.Modulus; - } - - // Set the Maintain Aspect ratio. - this.MaintainAspectRatio = preset.Task.KeepDisplayAspect; - - // Set the Maximum so libhb can correctly manage the size. - if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) - { - this.MaxWidth = this.sourceResolution.Width; - this.MaxHeight = this.sourceResolution.Height; - } - else - { - int presetWidth = preset.Task.MaxWidth ?? this.sourceResolution.Width; - int presetHeight = preset.Task.MaxHeight ?? this.sourceResolution.Height; + // Picture Sizes and Anamorphic + this.SelectedAnamorphicMode = preset.Task.Anamorphic; - this.MaxWidth = presetWidth <= this.sourceResolution.Width ? presetWidth : this.sourceResolution.Width; - this.MaxHeight = presetHeight <= this.sourceResolution.Height ? presetHeight : this.sourceResolution.Height; - } + // Modulus + if (preset.Task.Modulus.HasValue) + { + this.SelectedModulus = preset.Task.Modulus; + } - // 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), this.MaxWidth)); - int height = this.GetModulusValue(this.GetRes((this.sourceResolution.Height - this.CropTop - this.CropBottom), this.MaxHeight)); + // Set the Maintain Aspect ratio. + this.MaintainAspectRatio = preset.Task.KeepDisplayAspect; - // Set the backing fields to avoid triggering recalulation until both are set. - this.Task.Width = width; - this.Task.Height = height; + // Setup the Maximum Width / Height with sane 4K fallback. + this.MaxWidth = preset.Task.MaxWidth ?? 3840; + this.MaxHeight = preset.Task.MaxHeight ?? 2160; - // Trigger a Recalc - this.RecaulcatePictureSettingsProperties(ChangedPictureField.Width); + // 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), this.MaxWidth)); + int height = this.GetModulusValue(this.GetRes((this.sourceResolution.Height - this.CropTop - this.CropBottom), this.MaxHeight)); - // Update the UI - this.NotifyOfPropertyChange(() => this.Width); - this.NotifyOfPropertyChange(() => this.Height); + // Set the backing fields to avoid triggering re-calculation until both are set. + this.Task.Width = width; + this.Task.Height = height; - break; - case PresetPictureSettingsMode.None: - // Do Nothing except reset the Max Width/Height - this.MaxWidth = this.sourceResolution.Width; - this.MaxHeight = this.sourceResolution.Height; - this.SelectedAnamorphicMode = preset.Task.Anamorphic; + // Trigger a calculation + this.RecaulcatePictureSettingsProperties(ChangedPictureField.Width); - if (this.Width > this.MaxWidth) - { - // Trigger a Recalc - this.Task.Width = this.GetModulusValue(this.GetRes((this.sourceResolution.Width - this.CropLeft - this.CropRight), this.MaxWidth)); - this.RecaulcatePictureSettingsProperties(ChangedPictureField.Width); - } + // Update the UI + this.NotifyOfPropertyChange(() => this.Width); + this.NotifyOfPropertyChange(() => this.Height); - break; - } // Custom Anamorphic if (preset.Task.Anamorphic == Anamorphic.Custom) @@ -534,43 +550,15 @@ namespace HandBrakeWPF.ViewModels this.IsCustomCrop = true; } - // Set the Max Width / Height available to the user controls. - // Preset Max is null for None / SourceMax - this.MaxWidth = preset.Task.MaxWidth ?? this.sourceResolution.Width; - if (this.sourceResolution.Width < this.MaxWidth) - { - this.MaxWidth = this.sourceResolution.Width; - } - - this.MaxHeight = preset.Task.MaxHeight ?? this.sourceResolution.Height; - if (this.sourceResolution.Height < this.MaxHeight) - { - this.MaxHeight = this.sourceResolution.Height; - } + // Setup the Maximum Width / Height with sane 4K fallback. + this.MaxWidth = preset.Task.MaxWidth ?? 3840; + this.MaxHeight = preset.Task.MaxHeight ?? 2160; // Set the W/H - if (preset.PictureSettingsMode == PresetPictureSettingsMode.None) - { - this.Task.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight); - this.Task.Height = this.GetModulusValue(this.sourceResolution.Height - this.CropTop - this.CropBottom); - } - else if (preset.PictureSettingsMode == PresetPictureSettingsMode.SourceMaximum) - { - this.Task.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight); - this.Task.Height = this.GetModulusValue(this.sourceResolution.Height - this.CropTop - this.CropBottom); - this.MaintainAspectRatio = preset.Task.KeepDisplayAspect; - } - else - { - // Custom - // Set the Width, and Maintain Aspect ratio. That should calc the Height for us. - this.Task.Width = this.GetModulusValue(this.sourceResolution.Width - this.CropLeft - this.CropRight); - - if (this.SelectedAnamorphicMode != Anamorphic.Loose) - { - this.Task.Height = this.GetModulusValue(this.sourceResolution.Height - this.CropTop - this.CropBottom); - } - } + // Set the width, then check the height doesn't breach the max height and correct if necessary. + this.Task.Width = this.GetModulusValue(this.GetRes((this.sourceResolution.Width - this.CropLeft - this.CropRight), this.MaxWidth)); + this.Task.Height = this.GetModulusValue(this.GetRes((this.sourceResolution.Height - this.CropTop - this.CropBottom), this.MaxHeight)); + this.MaintainAspectRatio = preset.Task.KeepDisplayAspect; // Set Screen Controls this.SourceInfo = string.Format( @@ -627,9 +615,9 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.SelectedModulus); this.NotifyOfPropertyChange(() => this.MaintainAspectRatio); - // Default the Max Width / Height to 1080p format - this.MaxHeight = 1080; - this.MaxWidth = 1920; + // Default the Max Width / Height to 4K format + this.MaxHeight = 2160; + this.MaxWidth = 3480; } private PictureSize.PictureSettingsTitle GetPictureTitleInfo() @@ -834,6 +822,23 @@ namespace HandBrakeWPF.ViewModels { return max.HasValue ? (value > max.Value ? max.Value : value) : value; } + + private void SetSelectedPictureSettingsResLimitMode() + { + // Look for a matching resolution. + foreach (PictureSettingsResLimitModes limit in EnumHelper.GetEnumList()) + { + ResLimit resLimit = EnumHelper.GetAttribute(limit); + if (resLimit != null) + { + if (resLimit.Width == this.MaxWidth && resLimit.Height == this.MaxHeight) + { + this.SelectedPictureSettingsResLimitMode = limit; + return; + } + } + } + } } public enum ChangedPictureField diff --git a/win/CS/HandBrakeWPF/Views/AddPresetView.xaml b/win/CS/HandBrakeWPF/Views/AddPresetView.xaml index acfe9168c..2dd2b0c6d 100644 --- a/win/CS/HandBrakeWPF/Views/AddPresetView.xaml +++ b/win/CS/HandBrakeWPF/Views/AddPresetView.xaml @@ -84,7 +84,7 @@ - - + -->