From 6e4d106cb1f0f4c24451efb90e352e40f7da8d06 Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 29 Mar 2021 21:08:12 +0100 Subject: WinGui: Implement the Pad filter in the UI. (For testing - Note, summary, preview and preset support is not implemented yet.) --- win/CS/HandBrakeWPF/Model/Filters/PadColour.cs | 27 ++++ win/CS/HandBrakeWPF/Model/Filters/PaddingFilter.cs | 6 +- win/CS/HandBrakeWPF/Model/Filters/PaddingMode.cs | 18 +-- .../HandBrakeWPF/Properties/Resources.Designer.cs | 48 +++++- win/CS/HandBrakeWPF/Properties/Resources.resx | 24 ++- .../Properties/ResourcesTooltips.Designer.cs | 9 ++ .../HandBrakeWPF/Properties/ResourcesTooltips.resx | 3 + .../Services/Encode/Factories/EncodeTaskFactory.cs | 14 +- .../ViewModelItems/Filters/PadFilter.cs | 175 +++++++++++++++------ win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml | 30 ++-- 10 files changed, 267 insertions(+), 87 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Model/Filters/PadColour.cs (limited to 'win/CS/HandBrakeWPF') diff --git a/win/CS/HandBrakeWPF/Model/Filters/PadColour.cs b/win/CS/HandBrakeWPF/Model/Filters/PadColour.cs new file mode 100644 index 000000000..dcecfb836 --- /dev/null +++ b/win/CS/HandBrakeWPF/Model/Filters/PadColour.cs @@ -0,0 +1,27 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// 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.Filters +{ + using HandBrake.Interop.Attributes; + + using HandBrakeWPF.Properties; + + public enum PadColour + { + [DisplayName(typeof(Resources), "PadColour_Black")] + [ShortName("black")] + Black = 0, + + [DisplayName(typeof(Resources), "PadColour_White")] + [ShortName("white")] + White, + + [DisplayName(typeof(Resources), "PadColour_Custom")] + [ShortName("custom")] + Custom, + } +} \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Model/Filters/PaddingFilter.cs b/win/CS/HandBrakeWPF/Model/Filters/PaddingFilter.cs index 03b0e660a..60f5758bb 100644 --- a/win/CS/HandBrakeWPF/Model/Filters/PaddingFilter.cs +++ b/win/CS/HandBrakeWPF/Model/Filters/PaddingFilter.cs @@ -1,5 +1,5 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // @@ -18,5 +18,9 @@ namespace HandBrakeWPF.Model.Filters public int X { get; set; } public int Y { get; set; } + + public int W { get; set; } + + public int H { get; set; } } } diff --git a/win/CS/HandBrakeWPF/Model/Filters/PaddingMode.cs b/win/CS/HandBrakeWPF/Model/Filters/PaddingMode.cs index 63323c4bb..e0a930ce6 100644 --- a/win/CS/HandBrakeWPF/Model/Filters/PaddingMode.cs +++ b/win/CS/HandBrakeWPF/Model/Filters/PaddingMode.cs @@ -19,17 +19,17 @@ namespace HandBrakeWPF.Model.Filters [ShortName("none")] None = 0, - [DisplayName(typeof(Resources), "PaddingMode_Fill")] - [ShortName("fill")] - FirstMatch, + //[DisplayName(typeof(Resources), "PaddingMode_Fill")] + //[ShortName("fill")] + //FirstMatch, - [DisplayName(typeof(Resources), "PaddingMode_Width")] - [ShortName("width")] - Width, + //[DisplayName(typeof(Resources), "PaddingMode_Width")] + //[ShortName("width")] + //Width, - [DisplayName(typeof(Resources), "PaddingMode_Height")] - [ShortName("height")] - Height, + //[DisplayName(typeof(Resources), "PaddingMode_Height")] + //[ShortName("height")] + //Height, [DisplayName(typeof(Resources), "PaddingMode_Custom")] [ShortName("custom")] diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 4019b1bc9..8dfcbb1e4 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -2821,7 +2821,7 @@ namespace HandBrakeWPF.Properties { /// /// Looks up a localized string similar to Please be aware that HandBrake is no longer supported on any version of Windows 7 or Windows 8. /// - ///While you can continue using the applicaiton at your own risk, please be aware that certain freatures are non-functional and there may be other unknown issues. There is no support available when these issues occur. + ///While you can continue using the application at your own risk, please be aware that certain features are non-functional and there may be other unknown issues. There is no support available when these issues occur. /// ///Support for Windows 7 and 8 was deprecated in the 1.3 series. This means there will be no further updates to correct issues on these platforms. /// @@ -4022,6 +4022,33 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to Black. + /// + public static string PadColour_Black { + get { + return ResourceManager.GetString("PadColour_Black", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Custom. + /// + public static string PadColour_Custom { + get { + return ResourceManager.GetString("PadColour_Custom", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to White. + /// + public static string PadColour_White { + get { + return ResourceManager.GetString("PadColour_White", resourceCulture); + } + } + /// /// Looks up a localized string similar to Custom (Not Limited). /// @@ -4032,7 +4059,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Fill (pad to resolution limit). + /// Looks up a localized string similar to Fill (Surround). /// public static string PaddingMode_Fill { get { @@ -4041,7 +4068,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Height (pad up to res limit). + /// Looks up a localized string similar to Height (Pillarbox). /// public static string PaddingMode_Height { get { @@ -4059,7 +4086,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Width (pad up to res limit). + /// Looks up a localized string similar to Width (Letterbox). /// public static string PaddingMode_Width { get { @@ -4176,7 +4203,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Borders. + /// Looks up a localized string similar to Borders:. /// public static string PictureSettingsView_Borders { get { @@ -4293,7 +4320,7 @@ namespace HandBrakeWPF.Properties { } /// - /// Looks up a localized string similar to Padding Colour:. + /// Looks up a localized string similar to Colour:. /// public static string PictureSettingsView_PaddingColour { get { @@ -4301,6 +4328,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to RGB Value:. + /// + public static string PictureSettingsView_PaddingCustomColour { + get { + return ResourceManager.GetString("PictureSettingsView_PaddingCustomColour", resourceCulture); + } + } + /// /// Looks up a localized string similar to PAR:. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 77733c8ef..47de39e99 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -2234,25 +2234,25 @@ Please choose a different preset. Custom (Not Limited) - Fill (pad to resolution limit) + Fill (Surround) - Height (pad up to res limit) + Height (Pillarbox) None - Width (pad up to res limit) + Width (Letterbox) Padding: - Padding Colour: + Colour: - Borders + Borders: Resolution and Scaling: @@ -2469,4 +2469,16 @@ Support for Windows 7 and 8 was deprecated in the 1.3 series. This means there w This warning will display only twice. - + + Black + + + Custom + + + White + + + RGB Value: + + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs index 01a4f44a8..aadfdc2dc 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs @@ -591,6 +591,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to This field can accept RGB values such as: "0xFF0000" or colour names such as "red". For a full list of named colours, see the padding filter documentation. . + /// + public static string PictureSettingsView_PaddingCustomColourTooltip { + get { + return ResourceManager.GetString("PictureSettingsView_PaddingCustomColourTooltip", resourceCulture); + } + } + /// /// Looks up a localized string similar to Pixel aspect defines the shape of the pixels. ///A 1:1 ratio defines a square pixel. Other values define rectangular shapes. diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx index cfc83b6c5..2bb780509 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx @@ -471,4 +471,7 @@ When disabled, it will use the path in the destination box on the main window if Chroma Smooth Filter + + This field can accept RGB values such as: "0xFF0000" or colour names such as "red". For a full list of named colours, see the padding filter documentation. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs index a5e8d26e8..dee655e15 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeTaskFactory.cs @@ -472,8 +472,18 @@ namespace HandBrakeWPF.Services.Encode.Factories // Padding Filter if (job.Padding.Enabled) - { - string padSettings = string.Format("width={0}:height={1}:color={2}:x={3}:y={4}", job.Width, job.Height, job.Padding.Color, job.Padding.X, job.Padding.Y); + { + // Calculate the new Width / Height + int? width = job.Width; + int? height = job.Height; + if (job.Padding.Enabled) + { + width = width + job.Padding.W; + height = height + job.Padding.H; + } + + // Setup the filter. + string padSettings = string.Format("width={0}:height={1}:color={2}:x={3}:y={4}", width, height, job.Padding.Color, job.Padding.X, job.Padding.Y); string unparsedPadSettingsJson = HandBrakeFilterHelpers.GenerateFilterSettingJson((int)hb_filter_ids.HB_FILTER_PAD, null, null, padSettings); if (!string.IsNullOrEmpty(unparsedPadSettingsJson)) { diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/PadFilter.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/PadFilter.cs index 3dc966b0f..5b268c2c0 100644 --- a/win/CS/HandBrakeWPF/ViewModelItems/Filters/PadFilter.cs +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/PadFilter.cs @@ -1,27 +1,17 @@ // -------------------------------------------------------------------------------------------------------------------- -// +// // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // -// -// Defines the DeblockFilter type. -// // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModelItems.Filters { using System.Collections.Generic; - using System.ComponentModel; - using System.Globalization; - using System.Linq; using Caliburn.Micro; - using HandBrake.Interop.Interop; - using HandBrake.Interop.Interop.HbLib; - using HandBrakeWPF.Model.Filters; using HandBrakeWPF.Services.Encode.Model; - using HandBrakeWPF.Services.Encode.Model.Models; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.Services.Scan.Model; using HandBrakeWPF.Utilities; @@ -31,6 +21,12 @@ namespace HandBrakeWPF.ViewModelItems.Filters public class PadFilter : PropertyChangedBase { private readonly Action triggerTabChanged; + private int top, bottom, left, right; + private EncodeTask currentTask; + private PaddingMode mode; + private PadColour colour; + + private string customColour; public PadFilter(EncodeTask currentTask, Action triggerTabChanged) { @@ -38,71 +34,134 @@ namespace HandBrakeWPF.ViewModelItems.Filters this.CurrentTask = currentTask; } - public EncodeTask CurrentTask { get; private set; } + public EncodeTask CurrentTask + { + get => this.currentTask; + private set => this.currentTask = value; + } public IEnumerable PaddingModes => EnumHelper.GetEnumList(); - public PaddingMode Mode { get; set; } + public PaddingMode Mode + { + get => this.mode; + set + { + this.mode = value; + this.IsCustomPaddingEnabled = false; + + switch (value) + { + case PaddingMode.Custom: + this.currentTask.Padding.Enabled = true; + IsCustomPaddingEnabled = true; + break; + case PaddingMode.None: + default: + this.currentTask.Padding.Enabled = false; + break; + } + + this.NotifyOfPropertyChange(() => this.IsCustomPaddingEnabled); + this.NotifyOfPropertyChange(() => this.IsCustomColourVisible); + } + } + + public bool IsCustomPaddingEnabled { get; set; } - public IEnumerable PaddingColours { get; } = new List() { "Black", "White", "Custom" }; + public IEnumerable PaddingColours => EnumHelper.GetEnumList(); - public int X + public PadColour Colour { get { - return this.CurrentTask.Padding.X; + return colour; } set { - this.CurrentTask.Padding.X = value; - this.NotifyOfPropertyChange(() => this.X); + this.colour = value; + this.SetColour(); + this.NotifyOfPropertyChange(() => this.Colour); + this.NotifyOfPropertyChange(() => this.IsCustomColourVisible); this.triggerTabChanged(); } } - public int Y + public string CustomColour { - get + get => this.customColour; + set { - return this.CurrentTask.Padding.Y; + this.customColour = value; + this.SetColour(); + this.NotifyOfPropertyChange(() => this.CustomColour); } + } + + public bool IsCustomColourVisible => this.IsCustomPaddingEnabled && this.Colour == PadColour.Custom; + + public int Top + { + get => this.top; set { - this.CurrentTask.Padding.Y = value; - this.NotifyOfPropertyChange(() => this.Y); + this.top = value; + this.CalculatePosition(); + this.NotifyOfPropertyChange(() => this.Top); this.triggerTabChanged(); } } - public string Colour + public int Bottom { - get + get => this.bottom; + + set { - return this.CurrentTask.Padding.Color; + this.bottom = value; + this.CalculatePosition(); + this.NotifyOfPropertyChange(() => this.Bottom); + this.triggerTabChanged(); } + } + + public int Left + { + get => this.left; set { - this.CurrentTask.Padding.Color = value; - this.NotifyOfPropertyChange(() => this.Colour); + this.left = value; + this.CalculatePosition(); + this.NotifyOfPropertyChange(() => this.Left); this.triggerTabChanged(); } } - - public void SetPreset(Preset preset, EncodeTask task) + + public int Right { - this.CurrentTask = task; + get => this.right; - if (preset == null) + set { - return; + this.right = value; + this.CalculatePosition(); + this.NotifyOfPropertyChange(() => this.Right); + this.triggerTabChanged(); } - - this.NotifyOfPropertyChange(() => this.X); - this.NotifyOfPropertyChange(() => this.Y); - this.NotifyOfPropertyChange(() => this.Colour); + } + + private void CalculatePosition() + { + // Figure the X,Y coordinate + this.CurrentTask.Padding.X = this.Left; + this.CurrentTask.Padding.Y = this.Top; + + // Calculate the total padding + this.currentTask.Padding.W = this.Left + this.Right; + this.currentTask.Padding.H = this.Top + this.Bottom; } public void UpdateTask(EncodeTask task) @@ -117,27 +176,43 @@ namespace HandBrakeWPF.ViewModelItems.Filters return false; } - if (preset.Task.Padding.X != this.X) - { - return false; - } + return true; + } - if (preset.Task.Padding.Y != this.Y) - { - return false; - } + public void SetSource(Source source, Title title, Preset preset, EncodeTask task) + { + this.CurrentTask = task; + } - if (preset.Task.Padding.Color != this.Colour) + private void SetColour() + { + switch (this.Colour) { - return false; + case PadColour.Black: + this.CurrentTask.Padding.Color = "black"; + break; + case PadColour.White: + this.CurrentTask.Padding.Color = "white"; + break; + case PadColour.Custom: + this.CurrentTask.Padding.Color = CustomColour?.Trim().ToLower(); + break; + default: + this.CurrentTask.Padding.Color = "black"; + break; } - - return true; } - public void SetSource(Source source, Title title, Preset preset, EncodeTask task) + public void SetPreset(Preset preset, EncodeTask task) { this.CurrentTask = task; + + if (preset == null) + { + return; + } + + this.NotifyOfPropertyChange(() => this.Colour); } } } diff --git a/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml b/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml index 8fba7bbdc..4a0f26a77 100644 --- a/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml +++ b/win/CS/HandBrakeWPF/Views/PictureSettingsView.xaml @@ -214,7 +214,7 @@ - + + + + -- cgit v1.2.3