From 063446fa62266cea2d6a0487e8814bf5f2dba376 Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 2 Jan 2017 13:59:32 +0000 Subject: [PATCH] WinGui: Improve the SourceMax / Custom Picture Settings modes. Fixes a numer of edge causes and problems with this code #455 --- .../ViewModels/AddPresetViewModel.cs | 4 +- .../ViewModels/PictureSettingsViewModel.cs | 65 ++++++++++--------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs index 2facf2c66..52877f61f 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AddPresetViewModel.cs @@ -238,8 +238,8 @@ namespace HandBrakeWPF.ViewModels if (this.SelectedPictureSettingMode == PresetPictureSettingsMode.SourceMaximum) { - this.Preset.Task.MaxWidth = selectedTitle.Resolution.Width; - this.Preset.Task.MaxHeight = selectedTitle.Resolution.Height; + this.Preset.Task.MaxHeight = null; + this.Preset.Task.MaxWidth = null; } // Add the Preset diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index e4e8e0075..a428144c0 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -643,8 +643,8 @@ namespace HandBrakeWPF.ViewModels } // 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 height = this.GetModulusValue(this.GetRes((this.sourceResolution.Height - this.CropTop - this.CropBottom), preset.Task.MaxHeight)); + 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 backing fields to avoid triggering recalulation until both are set. this.Task.Width = width; @@ -663,6 +663,14 @@ namespace HandBrakeWPF.ViewModels this.MaxWidth = this.sourceResolution.Width; this.MaxHeight = this.sourceResolution.Height; this.SelectedAnamorphicMode = preset.Task.Anamorphic; + + 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); + } + break; } @@ -754,43 +762,42 @@ 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; + } + + // Set the W/H if (preset.PictureSettingsMode == PresetPictureSettingsMode.None) { - // We have no instructions, so simply set it to the source. 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 = true; } - else + 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 Max Width / Height available to the user controls. - 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; - } - // Set the Width, and Maintain Aspect ratio. That should calc the Height for us. - if (this.SelectedAnamorphicMode == Anamorphic.None) + this.Task.Width = this.GetModulusValue(this.MaxWidth - this.CropLeft - this.CropRight); + + if (this.SelectedAnamorphicMode != Anamorphic.Loose) { - this.Task.Width = preset.Task.Width ?? this.GetModulusValue(this.MaxWidth - this.CropLeft - this.CropRight); this.Task.Height = this.GetModulusValue(this.MaxHeight - this.CropTop - this.CropBottom); - // Note: This will be auto-corrected in the property if it's too large. - } - else - { - this.Task.Width = preset.Task.Width ?? this.MaxWidth; - - int cropHeight = this.Task.Cropping.Top + this.Task.Cropping.Bottom; - this.Task.Height = (preset.Task.Height ?? this.MaxHeight) - cropHeight; } - + // 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) { -- 2.40.0