summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Helpers
diff options
context:
space:
mode:
authorsr55 <[email protected]>2012-11-18 17:39:38 +0000
committersr55 <[email protected]>2012-11-18 17:39:38 +0000
commit88067c60586db1b7b7a1d9d33c9178eab602aa6a (patch)
treeba8dd211bc6bb276b4925a9cfc1d2b79df0420da /win/CS/HandBrakeWPF/Helpers
parent3ac2e5d661c132980f526ba13772798e012ab155 (diff)
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
Diffstat (limited to 'win/CS/HandBrakeWPF/Helpers')
-rw-r--r--win/CS/HandBrakeWPF/Helpers/GrayscaleImage.cs63
1 files changed, 63 insertions, 0 deletions
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 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="GrayscaleImage.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Extend the Image Class to support a grayscale mode.
+// Usage: local:AutoGreyableImage Source="Image.png"
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+ using System.Windows;
+ using System.Windows.Controls;
+ using System.Windows.Media;
+ using System.Windows.Media.Imaging;
+
+ /// <summary>
+ /// Extend the Image Class to support a grayscale mode.
+ /// </summary>
+ public class GrayscaleImage : Image
+ {
+ /// <summary>
+ /// Initializes static members of the <see cref="GrayscaleImage"/> class.
+ /// Usage: local:AutoGreyableImage Source="Image.png"
+ /// </summary>
+ static GrayscaleImage()
+ {
+ // Override the metadata of the IsEnabled property.
+ IsEnabledProperty.OverrideMetadata(typeof(GrayscaleImage), new FrameworkPropertyMetadata(true, IsEnabledPropertyChanged));
+ }
+
+ /// <summary>
+ /// The is enabled property changed.
+ /// When this changes, grayscale the image when false, leave with colour when true.
+ /// </summary>
+ /// <param name="source">
+ /// The source.
+ /// </param>
+ /// <param name="args">
+ /// The args.
+ /// </param>
+ 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;
+ }
+ }
+ }
+ }
+}