From: sr55 Date: Sun, 18 Nov 2012 17:39:38 +0000 (+0000) Subject: WinGui: Default the custom anamorphic values correctly. (Part 1 of Custom anamorphic... X-Git-Tag: 0.9.9~282 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88067c60586db1b7b7a1d9d33c9178eab602aa6a;p=handbrake WinGui: Default the custom anamorphic values correctly. (Part 1 of Custom anamorphic implementation) git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5070 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs b/win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs new file mode 100644 index 000000000..3993ddb40 --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs @@ -0,0 +1,63 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Extend the Image Class to support a grayscale mode. +// Usage: local:AutoGreyableImage Source="Image.png" +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Helpers +{ + using System; + using System.Windows; + using System.Windows.Controls; + using System.Windows.Media; + using System.Windows.Media.Imaging; + + /// + /// Extend the Image Class to support a grayscale mode. + /// + public class GrayscaleImage : Image + { + /// + /// Initializes static members of the class. + /// Usage: local:AutoGreyableImage Source="Image.png" + /// + static GrayscaleImage() + { + // Override the metadata of the IsEnabled property. + IsEnabledProperty.OverrideMetadata(typeof(GrayscaleImage), new FrameworkPropertyMetadata(true, IsEnabledPropertyChanged)); + } + + /// + /// The is enabled property changed. + /// When this changes, grayscale the image when false, leave with colour when true. + /// + /// + /// The source. + /// + /// + /// The args. + /// + private static void IsEnabledPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs args) + { + var sourceImage = source as GrayscaleImage; + if (sourceImage != null) + { + if (!Convert.ToBoolean(args.NewValue)) + { + var bitmapImage = new BitmapImage(new Uri(sourceImage.Source.ToString())); + sourceImage.Source = new FormatConvertedBitmap(bitmapImage, PixelFormats.Gray32Float, null, 0); + sourceImage.OpacityMask = new ImageBrush(bitmapImage); + } + else + { + sourceImage.Source = ((FormatConvertedBitmap)sourceImage.Source).Source; + sourceImage.OpacityMask = null; + } + } + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs index dbca8aa0a..471c49de5 100644 --- a/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs @@ -239,9 +239,12 @@ namespace HandBrakeWPF.ViewModels set { - this.Task.DisplayWidth = value; - this.CustomAnamorphicAdjust(); - this.NotifyOfPropertyChange(() => this.DisplayWidth); + if (!object.Equals(this.Task.DisplayWidth, value)) + { + this.Task.DisplayWidth = value; + this.CustomAnamorphicAdjust(); + this.NotifyOfPropertyChange(() => this.DisplayWidth); + } } } @@ -257,9 +260,12 @@ namespace HandBrakeWPF.ViewModels set { - this.Task.Height = value; - this.HeightAdjust(); - this.NotifyOfPropertyChange(() => this.Height); + if (!object.Equals(this.Task.Height, value)) + { + this.Task.Height = value; + this.HeightAdjust(); + this.NotifyOfPropertyChange(() => this.Height); + } } } @@ -338,9 +344,12 @@ namespace HandBrakeWPF.ViewModels set { - this.Task.PixelAspectY = value; - this.CustomAnamorphicAdjust(); - this.NotifyOfPropertyChange(() => this.ParHeight); + if (!object.Equals(this.Task.PixelAspectY, value)) + { + this.Task.PixelAspectY = value; + this.CustomAnamorphicAdjust(); + this.NotifyOfPropertyChange(() => this.ParHeight); + } } } @@ -356,9 +365,12 @@ namespace HandBrakeWPF.ViewModels set { - this.Task.PixelAspectX = value; - this.CustomAnamorphicAdjust(); - this.NotifyOfPropertyChange(() => this.ParWidth); + if (!object.Equals(this.Task.PixelAspectX, value)) + { + this.Task.PixelAspectX = value; + this.CustomAnamorphicAdjust(); + this.NotifyOfPropertyChange(() => this.ParWidth); + } } } @@ -481,9 +493,12 @@ namespace HandBrakeWPF.ViewModels set { - this.Task.Width = value; - this.WidthAdjust(); - this.NotifyOfPropertyChange(() => this.Width); + if (!object.Equals(this.Task.Width, value)) + { + this.Task.Width = value; + this.WidthAdjust(); + this.NotifyOfPropertyChange(() => this.Width); + } } } @@ -665,9 +680,6 @@ namespace HandBrakeWPF.ViewModels this.NotifyOfPropertyChange(() => this.Height); this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode); this.NotifyOfPropertyChange(() => this.SelectedModulus); - this.NotifyOfPropertyChange(() => this.DisplayWidth); - this.NotifyOfPropertyChange(() => this.ParHeight); - this.NotifyOfPropertyChange(() => this.ParWidth); } /// @@ -795,8 +807,6 @@ namespace HandBrakeWPF.ViewModels this.Width = 0; this.Height = 0; - this.NotifyOfPropertyChange(() => this.Width); - this.NotifyOfPropertyChange(() => this.Height); this.SetDisplaySize(); break; @@ -805,11 +815,9 @@ namespace HandBrakeWPF.ViewModels this.HeightControlEnabled = false; this.ShowCustomAnamorphicControls = false; this.ShowModulus = true; - this.Width = this.sourceResolution.Width; this.Height = 0; - this.NotifyOfPropertyChange(() => this.Width); - this.NotifyOfPropertyChange(() => this.Height); + this.SetDisplaySize(); break; @@ -820,16 +828,17 @@ namespace HandBrakeWPF.ViewModels this.MaintainAspectRatio = true; this.ShowModulus = true; + // Ignore any of the users current settings and reset to source to make things easier. this.Width = this.sourceResolution.Width; - this.NotifyOfPropertyChange(() => this.Width); - this.NotifyOfPropertyChange(() => this.Height); + this.Height = this.sourceResolution.Height - this.CropTop - this.CropBottom; - this.DisplayWidth = this.CalculateAnamorphicSizes().Width; + // 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; - this.NotifyOfPropertyChange(() => this.ParHeight); - this.NotifyOfPropertyChange(() => this.ParWidth); - this.NotifyOfPropertyChange(() => this.DisplayWidth); + if (this.ParHeight != 0) + { + this.DisplayWidth = (this.Width * this.ParWidth / this.ParHeight); + } this.SetDisplaySize(); break; @@ -900,7 +909,6 @@ namespace HandBrakeWPF.ViewModels return new Size((int)disWidthLoose, (int)calcHeight); case Anamorphic.Custom: - // Get the User Interface Values double uIdisplayWidth; double.TryParse(this.DisplayWidth.ToString(CultureInfo.InvariantCulture), out uIdisplayWidth);