]> granicus.if.org Git - handbrake/commitdiff
WinGui: Default the custom anamorphic values correctly. (Part 1 of Custom anamorphic...
authorsr55 <sr55.hb@outlook.com>
Sun, 18 Nov 2012 17:39:38 +0000 (17:39 +0000)
committersr55 <sr55.hb@outlook.com>
Sun, 18 Nov 2012 17:39:38 +0000 (17:39 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5070 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/ViewModels/PictureSettingsViewModel.cs

diff --git a/win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs b/win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs
new file mode 100644 (file)
index 0000000..3993ddb
--- /dev/null
@@ -0,0 +1,63 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="GrayscaleImage.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   Extend the Image Class to support a grayscale mode.\r
+//   Usage: local:AutoGreyableImage Source="Image.png"\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Helpers\r
+{\r
+    using System;\r
+    using System.Windows;\r
+    using System.Windows.Controls;\r
+    using System.Windows.Media;\r
+    using System.Windows.Media.Imaging;\r
+\r
+    /// <summary>\r
+    /// Extend the Image Class to support a grayscale mode.\r
+    /// </summary>\r
+    public class GrayscaleImage : Image\r
+    {\r
+        /// <summary>\r
+        /// Initializes static members of the <see cref="GrayscaleImage"/> class. \r
+        /// Usage: local:AutoGreyableImage Source="Image.png"\r
+        /// </summary>\r
+        static GrayscaleImage()\r
+        {\r
+            // Override the metadata of the IsEnabled property.\r
+            IsEnabledProperty.OverrideMetadata(typeof(GrayscaleImage), new FrameworkPropertyMetadata(true, IsEnabledPropertyChanged));\r
+        }\r
+\r
+        /// <summary>\r
+        /// The is enabled property changed.\r
+        /// When this changes, grayscale the image when false, leave with colour when true.\r
+        /// </summary>\r
+        /// <param name="source">\r
+        /// The source.\r
+        /// </param>\r
+        /// <param name="args">\r
+        /// The args.\r
+        /// </param>\r
+        private static void IsEnabledPropertyChanged(DependencyObject source, DependencyPropertyChangedEventArgs args)\r
+        {\r
+            var sourceImage = source as GrayscaleImage;\r
+            if (sourceImage != null)\r
+            {\r
+                if (!Convert.ToBoolean(args.NewValue))\r
+                {\r
+                    var bitmapImage = new BitmapImage(new Uri(sourceImage.Source.ToString()));\r
+                    sourceImage.Source = new FormatConvertedBitmap(bitmapImage, PixelFormats.Gray32Float, null, 0);\r
+                    sourceImage.OpacityMask = new ImageBrush(bitmapImage);\r
+                }\r
+                else\r
+                {\r
+                    sourceImage.Source = ((FormatConvertedBitmap)sourceImage.Source).Source;\r
+                    sourceImage.OpacityMask = null;\r
+                }\r
+            }\r
+        }\r
+    }\r
+}\r
index dbca8aa0a7c2edcd452958410625f535d05c2747..471c49de53b923376beb5be63ac1d92947b4cb25 100644 (file)
@@ -239,9 +239,12 @@ namespace HandBrakeWPF.ViewModels
 \r
             set\r
             {\r
-                this.Task.DisplayWidth = value;\r
-                this.CustomAnamorphicAdjust();\r
-                this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+                if (!object.Equals(this.Task.DisplayWidth, value))\r
+                {\r
+                    this.Task.DisplayWidth = value;\r
+                    this.CustomAnamorphicAdjust();\r
+                    this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+                }\r
             }\r
         }\r
 \r
@@ -257,9 +260,12 @@ namespace HandBrakeWPF.ViewModels
 \r
             set\r
             {\r
-                this.Task.Height = value;\r
-                this.HeightAdjust();\r
-                this.NotifyOfPropertyChange(() => this.Height);\r
+                if (!object.Equals(this.Task.Height, value))\r
+                {\r
+                    this.Task.Height = value;\r
+                    this.HeightAdjust();\r
+                    this.NotifyOfPropertyChange(() => this.Height);\r
+                }\r
             }\r
         }\r
 \r
@@ -338,9 +344,12 @@ namespace HandBrakeWPF.ViewModels
 \r
             set\r
             {\r
-                this.Task.PixelAspectY = value;\r
-                this.CustomAnamorphicAdjust();\r
-                this.NotifyOfPropertyChange(() => this.ParHeight);\r
+                if (!object.Equals(this.Task.PixelAspectY, value))\r
+                {\r
+                    this.Task.PixelAspectY = value;\r
+                    this.CustomAnamorphicAdjust();\r
+                    this.NotifyOfPropertyChange(() => this.ParHeight);\r
+                }\r
             }\r
         }\r
 \r
@@ -356,9 +365,12 @@ namespace HandBrakeWPF.ViewModels
 \r
             set\r
             {\r
-                this.Task.PixelAspectX = value;\r
-                this.CustomAnamorphicAdjust();\r
-                this.NotifyOfPropertyChange(() => this.ParWidth);\r
+                if (!object.Equals(this.Task.PixelAspectX, value))\r
+                {\r
+                    this.Task.PixelAspectX = value;\r
+                    this.CustomAnamorphicAdjust();\r
+                    this.NotifyOfPropertyChange(() => this.ParWidth);\r
+                }\r
             }\r
         }\r
 \r
@@ -481,9 +493,12 @@ namespace HandBrakeWPF.ViewModels
 \r
             set\r
             {\r
-                this.Task.Width = value;\r
-                this.WidthAdjust();\r
-                this.NotifyOfPropertyChange(() => this.Width);\r
+                if (!object.Equals(this.Task.Width, value))\r
+                {\r
+                    this.Task.Width = value;\r
+                    this.WidthAdjust();\r
+                    this.NotifyOfPropertyChange(() => this.Width);\r
+                }\r
             }\r
         }\r
 \r
@@ -665,9 +680,6 @@ namespace HandBrakeWPF.ViewModels
             this.NotifyOfPropertyChange(() => this.Height);\r
             this.NotifyOfPropertyChange(() => this.SelectedAnamorphicMode);\r
             this.NotifyOfPropertyChange(() => this.SelectedModulus);\r
-            this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
-            this.NotifyOfPropertyChange(() => this.ParHeight);\r
-            this.NotifyOfPropertyChange(() => this.ParWidth);\r
         }\r
 \r
         /// <summary>\r
@@ -795,8 +807,6 @@ namespace HandBrakeWPF.ViewModels
 \r
                     this.Width = 0;\r
                     this.Height = 0;\r
-                    this.NotifyOfPropertyChange(() => this.Width);\r
-                    this.NotifyOfPropertyChange(() => this.Height);\r
                     this.SetDisplaySize();\r
                     break;\r
 \r
@@ -805,11 +815,9 @@ namespace HandBrakeWPF.ViewModels
                     this.HeightControlEnabled = false;\r
                     this.ShowCustomAnamorphicControls = false;\r
                     this.ShowModulus = true;\r
-\r
                     this.Width = this.sourceResolution.Width;\r
                     this.Height = 0;\r
-                    this.NotifyOfPropertyChange(() => this.Width);\r
-                    this.NotifyOfPropertyChange(() => this.Height);\r
+\r
                     this.SetDisplaySize();\r
                     break;\r
 \r
@@ -820,16 +828,17 @@ namespace HandBrakeWPF.ViewModels
                     this.MaintainAspectRatio = true;\r
                     this.ShowModulus = true;\r
 \r
+                    // Ignore any of the users current settings and reset to source to make things easier.\r
                     this.Width = this.sourceResolution.Width;\r
-                    this.NotifyOfPropertyChange(() => this.Width);\r
-                    this.NotifyOfPropertyChange(() => this.Height);\r
+                    this.Height = this.sourceResolution.Height - this.CropTop - this.CropBottom;\r
 \r
-                    this.DisplayWidth = this.CalculateAnamorphicSizes().Width;\r
+                    // Set the Display Width and set the Par X/Y to the source values initially.      \r
                     this.ParWidth = this.sourceParValues.Width;\r
                     this.ParHeight = this.sourceParValues.Height;\r
-                    this.NotifyOfPropertyChange(() => this.ParHeight);\r
-                    this.NotifyOfPropertyChange(() => this.ParWidth);\r
-                    this.NotifyOfPropertyChange(() => this.DisplayWidth);\r
+                    if (this.ParHeight != 0)\r
+                    {\r
+                        this.DisplayWidth = (this.Width * this.ParWidth / this.ParHeight);\r
+                    }\r
 \r
                     this.SetDisplaySize();\r
                     break;\r
@@ -900,7 +909,6 @@ namespace HandBrakeWPF.ViewModels
                     return new Size((int)disWidthLoose, (int)calcHeight);\r
 \r
                 case Anamorphic.Custom:\r
-\r
                     // Get the User Interface Values\r
                     double uIdisplayWidth;\r
                     double.TryParse(this.DisplayWidth.ToString(CultureInfo.InvariantCulture), out uIdisplayWidth);\r