diff --git a/WpfExtended.Test/App.xaml b/WpfExtended.Test/App.xaml deleted file mode 100644 index 7034af2..0000000 --- a/WpfExtended.Test/App.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/WpfExtended.Test/App.xaml.cs b/WpfExtended.Test/App.xaml.cs deleted file mode 100644 index c762bf3..0000000 --- a/WpfExtended.Test/App.xaml.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Windows; - -namespace WpfExtended.Test -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} diff --git a/WpfExtended.Test/Controls/CaptionedImage.xaml b/WpfExtended.Test/Controls/CaptionedImage.xaml new file mode 100644 index 0000000..f5ed34f --- /dev/null +++ b/WpfExtended.Test/Controls/CaptionedImage.xaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/WpfExtended.Test/Controls/CaptionedImage.xaml.cs b/WpfExtended.Test/Controls/CaptionedImage.xaml.cs new file mode 100644 index 0000000..bb14eda --- /dev/null +++ b/WpfExtended.Test/Controls/CaptionedImage.xaml.cs @@ -0,0 +1,46 @@ +using System.Windows; +using System.Windows.Controls; +using System.Windows.Extensions; +using System.Windows.Media; +using System.Windows.Media.Effects; + +namespace WpfExtended.Tests.Controls +{ + /// + /// Interaction logic for CaptionedImage.xaml + /// + public partial class CaptionedImage : UserControl + { + public readonly static DependencyProperty ImageEffectProperty = + DependencyPropertyExtensions.Register(nameof(ImageEffect)); + + public readonly static DependencyProperty ImageSourceProperty = + DependencyPropertyExtensions.Register(nameof(ImageSource)); + + public readonly static DependencyProperty CaptionProperty = + DependencyPropertyExtensions.Register(nameof(Caption)); + + public Effect ImageEffect + { + get => this.GetTypedValue(ImageEffectProperty); + set => this.SetTypedValue(ImageEffectProperty, value); + } + + public ImageSource ImageSource + { + get => this.GetTypedValue(ImageSourceProperty); + set => this.SetTypedValue(ImageSourceProperty, value); + } + + public string Caption + { + get => this.GetTypedValue(CaptionProperty); + set => this.SetTypedValue(CaptionProperty, value); + } + + public CaptionedImage() + { + InitializeComponent(); + } + } +} diff --git a/WpfExtended.Test/Launcher.cs b/WpfExtended.Test/Launcher.cs new file mode 100644 index 0000000..76bcc0d --- /dev/null +++ b/WpfExtended.Test/Launcher.cs @@ -0,0 +1,27 @@ +using Slim; +using System; +using System.Windows.Extensions; +using WpfExtended.Test; + +namespace WpfExtended.Tests +{ + public class Launcher : ExtendedApplication + { + private static Launcher Instance { get; } = new Launcher(); + + [STAThread] + public static int Main() + { + return Instance.Run(); + } + + protected override bool HandleException(Exception e) + { + return false; + } + + protected override void RegisterServices(IServiceProducer serviceProducer) + { + } + } +} diff --git a/WpfExtended.Test/MainWindow.xaml b/WpfExtended.Test/MainWindow.xaml index 3074aa3..9b4dfc2 100644 --- a/WpfExtended.Test/MainWindow.xaml +++ b/WpfExtended.Test/MainWindow.xaml @@ -7,6 +7,8 @@ mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> - + + + diff --git a/WpfExtended.Test/MainWindow.xaml.cs b/WpfExtended.Test/MainWindow.xaml.cs index 896c245..2b26c6c 100644 --- a/WpfExtended.Test/MainWindow.xaml.cs +++ b/WpfExtended.Test/MainWindow.xaml.cs @@ -1,5 +1,13 @@ -using System.Windows; +using System; +using System.Extensions; +using System.IO; +using System.Windows; +using System.Windows.Extensions; using System.Windows.Media; +using System.Windows.Media.Effects; +using System.Windows.Media.Imaging; +using WpfExtended.Tests.Controls; +using WpfExtended.Tests.Utilities; namespace WpfExtended.Test { @@ -8,11 +16,39 @@ namespace WpfExtended.Test /// public partial class MainWindow : Window { - public static DependencyProperty ImageSourceProperty = - DependencyProperty.Register(nameof(ImageSource), typeof(ImageSource), typeof(MainWindow)); + public readonly static DependencyProperty ImageSourceProperty = + DependencyPropertyExtensions.Register(nameof(ImageSource)); + + public ImageSource ImageSource + { + get => this.GetTypedValue(ImageSourceProperty); + set => this.SetTypedValue(ImageSourceProperty, value); + } + public MainWindow() { InitializeComponent(); + this.ImageSource = new BitmapImage(new Uri(Path.GetFullPath("Images/Test.jpg"))); + this.BuildEffectsView(); + } + + private void BuildEffectsView() + { + foreach(var effectType in TypeCrawler.GetTypes()) + { + var effect = Activator.CreateInstance(effectType).As(); + var image = new CaptionedImage() + { + Width = 300, + Height = 300, + ImageSource = this.ImageSource, + Caption = effect.GetType().Name, + ImageEffect = effect, + BorderBrush = Brushes.LightGray, + BorderThickness = new Thickness(1) + }; + this.WrapPanel.Children.Add(image); + } } } } diff --git a/WpfExtended.Test/Utilities/TypeCrawler.cs b/WpfExtended.Test/Utilities/TypeCrawler.cs index 7d71a7d..d1800ee 100644 --- a/WpfExtended.Test/Utilities/TypeCrawler.cs +++ b/WpfExtended.Test/Utilities/TypeCrawler.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Windows.Media.Effects; namespace WpfExtended.Tests.Utilities { internal static class TypeCrawler { - public static IEnumerable GetEffectTypes() + public static IEnumerable GetTypes() { return AppDomain.CurrentDomain.GetAssemblies() .SelectMany(a => a.GetTypes() - .Where(t => t.IsAssignableTo(typeof(T)))); + .Where(t => t.IsAssignableTo(typeof(T))) + .Where(t => t.IsAbstract is false)); } } } diff --git a/WpfExtended.Test/WpfExtended.Tests.csproj b/WpfExtended.Test/WpfExtended.Tests.csproj index 6d01ce0..c402b2f 100644 --- a/WpfExtended.Test/WpfExtended.Tests.csproj +++ b/WpfExtended.Test/WpfExtended.Tests.csproj @@ -6,6 +6,14 @@ true + + + + + + + + PreserveNewest diff --git a/WpfExtended/Effects/BandedSwirl/BandedSwirlEffect.cs b/WpfExtended/Effects/BandedSwirl/BandedSwirl.cs similarity index 79% rename from WpfExtended/Effects/BandedSwirl/BandedSwirlEffect.cs rename to WpfExtended/Effects/BandedSwirl/BandedSwirl.cs index 4b5a471..8769a1c 100644 --- a/WpfExtended/Effects/BandedSwirl/BandedSwirlEffect.cs +++ b/WpfExtended/Effects/BandedSwirl/BandedSwirl.cs @@ -10,21 +10,21 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata; #endif - public class BandedSwirlEffect : ShaderEffect + public class BandedSwirl : ShaderEffect { - public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(BandedSwirlEffect), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); - public static readonly DependencyProperty SwirlStrengthProperty = DependencyProperty.Register("SwirlStrength", typeof(double), typeof(BandedSwirlEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty DistanceThresholdProperty = DependencyProperty.Register("DistanceThreshold", typeof(double), typeof(BandedSwirlEffect), new UIPropertyMetadata(0.2, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BandedSwirlEffect), 0); + public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(BandedSwirl), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); + public static readonly DependencyProperty SwirlStrengthProperty = DependencyProperty.Register("SwirlStrength", typeof(double), typeof(BandedSwirl), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty DistanceThresholdProperty = DependencyProperty.Register("DistanceThreshold", typeof(double), typeof(BandedSwirl), new UIPropertyMetadata(0.2, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BandedSwirl), 0); private readonly static PixelShader pixelShader; - static BandedSwirlEffect() + static BandedSwirl() { - pixelShader = PixelShaderUtility.LoadPixelShader("BandedSwirl/BandedSwirl.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public BandedSwirlEffect() + public BandedSwirl() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/Bloom/BloomEffect.cs b/WpfExtended/Effects/Bloom/Bloom.cs similarity index 82% rename from WpfExtended/Effects/Bloom/BloomEffect.cs rename to WpfExtended/Effects/Bloom/Bloom.cs index 0132622..18f5855 100644 --- a/WpfExtended/Effects/Bloom/BloomEffect.cs +++ b/WpfExtended/Effects/Bloom/Bloom.cs @@ -10,27 +10,27 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class BloomEffect : ShaderEffect + public class Bloom : ShaderEffect { public static readonly DependencyProperty InputProperty = - ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BloomEffect), 0); + ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Bloom), 0); public static readonly DependencyProperty BloomIntensityProperty = - DependencyProperty.Register("BloomIntensity", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(0))); + DependencyProperty.Register("BloomIntensity", typeof(double), typeof(Bloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(0))); public static readonly DependencyProperty BaseIntensityProperty = - DependencyProperty.Register("BaseIntensity", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); + DependencyProperty.Register("BaseIntensity", typeof(double), typeof(Bloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); public static readonly DependencyProperty BloomSaturationProperty = - DependencyProperty.Register("BloomSaturation", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(2))); + DependencyProperty.Register("BloomSaturation", typeof(double), typeof(Bloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(2))); public static readonly DependencyProperty BaseSaturationProperty = - DependencyProperty.Register("BaseSaturation", typeof(double), typeof(BloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(3))); + DependencyProperty.Register("BaseSaturation", typeof(double), typeof(Bloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(3))); private readonly static PixelShader pixelShader = new PixelShader(); - static BloomEffect() + static Bloom() { - pixelShader = PixelShaderUtility.LoadPixelShader("Bloom/Bloom.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public BloomEffect() + public Bloom() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/BrightExtract/BrightExtractEffect.cs b/WpfExtended/Effects/BrightExtract/BrightExtract.cs similarity index 80% rename from WpfExtended/Effects/BrightExtract/BrightExtractEffect.cs rename to WpfExtended/Effects/BrightExtract/BrightExtract.cs index 1ea248e..4ba8b1e 100644 --- a/WpfExtended/Effects/BrightExtract/BrightExtractEffect.cs +++ b/WpfExtended/Effects/BrightExtract/BrightExtract.cs @@ -10,21 +10,21 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class BrightExtractEffect : ShaderEffect + public class BrightExtract : ShaderEffect { public static readonly DependencyProperty InputProperty = - ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BrightExtractEffect), 0); + ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BrightExtract), 0); public static readonly DependencyProperty ThresholdProperty = - DependencyProperty.Register("Threshold", typeof(double), typeof(BrightExtractEffect), new UIPropertyMetadata(0.25, PixelShaderConstantCallback(0))); + DependencyProperty.Register("Threshold", typeof(double), typeof(BrightExtract), new UIPropertyMetadata(0.25, PixelShaderConstantCallback(0))); private readonly static PixelShader pixelShader = new PixelShader(); - static BrightExtractEffect() + static BrightExtract() { - pixelShader = PixelShaderUtility.LoadPixelShader("BrightExtract/BrightExtract.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public BrightExtractEffect() + public BrightExtract() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/InvertColor/InvertColorEffect.cs b/WpfExtended/Effects/ColorKeyAlpha/ColorKeyAlpha.cs similarity index 78% rename from WpfExtended/Effects/InvertColor/InvertColorEffect.cs rename to WpfExtended/Effects/ColorKeyAlpha/ColorKeyAlpha.cs index 5501ec8..ab267f3 100644 --- a/WpfExtended/Effects/InvertColor/InvertColorEffect.cs +++ b/WpfExtended/Effects/ColorKeyAlpha/ColorKeyAlpha.cs @@ -7,18 +7,18 @@ using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects { - public class InvertColorEffect : ShaderEffect + public class ColorKeyAlpha : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(InvertColorEffect), 0); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ColorKeyAlpha), 0); private readonly static PixelShader pixelShader; - static InvertColorEffect() + static ColorKeyAlpha() { - pixelShader = PixelShaderUtility.LoadPixelShader("InvertColor/InvertColor.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public InvertColorEffect() + public ColorKeyAlpha() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/ColorTone/ColorToneEffect.cs b/WpfExtended/Effects/ColorTone/ColorTone.cs similarity index 79% rename from WpfExtended/Effects/ColorTone/ColorToneEffect.cs rename to WpfExtended/Effects/ColorTone/ColorTone.cs index fb1640f..eff1981 100644 --- a/WpfExtended/Effects/ColorTone/ColorToneEffect.cs +++ b/WpfExtended/Effects/ColorTone/ColorTone.cs @@ -10,27 +10,27 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class ColorToneEffect : ShaderEffect + public class ColorTone : ShaderEffect { public static readonly DependencyProperty InputProperty = - ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ColorToneEffect), 0); + ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ColorTone), 0); public static readonly DependencyProperty DesaturationProperty = - DependencyProperty.Register("Desaturation", typeof(double), typeof(ColorToneEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(0))); + DependencyProperty.Register("Desaturation", typeof(double), typeof(ColorTone), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(0))); public static readonly DependencyProperty TonedProperty = - DependencyProperty.Register("Toned", typeof(double), typeof(ColorToneEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); + DependencyProperty.Register("Toned", typeof(double), typeof(ColorTone), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); public static readonly DependencyProperty LightColorProperty = - DependencyProperty.Register("LightColor", typeof(Color), typeof(ColorToneEffect), new UIPropertyMetadata(Color.FromArgb(255, 255, 229, 128), PixelShaderConstantCallback(2))); + DependencyProperty.Register("LightColor", typeof(Color), typeof(ColorTone), new UIPropertyMetadata(Color.FromArgb(255, 255, 229, 128), PixelShaderConstantCallback(2))); public static readonly DependencyProperty DarkColorProperty = - DependencyProperty.Register("DarkColor", typeof(Color), typeof(ColorToneEffect), new UIPropertyMetadata(Color.FromArgb(255, 51, 128, 0), PixelShaderConstantCallback(3))); + DependencyProperty.Register("DarkColor", typeof(Color), typeof(ColorTone), new UIPropertyMetadata(Color.FromArgb(255, 51, 128, 0), PixelShaderConstantCallback(3))); private readonly static PixelShader pixelShader = new PixelShader(); - static ColorToneEffect() + static ColorTone() { - pixelShader = PixelShaderUtility.LoadPixelShader("ColorTone/ColorTone.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public ColorToneEffect() + public ColorTone() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/ContrastAdjust/ContrastAdjustEffect.cs b/WpfExtended/Effects/ContrastAdjust/ContrastAdjust.cs similarity index 80% rename from WpfExtended/Effects/ContrastAdjust/ContrastAdjustEffect.cs rename to WpfExtended/Effects/ContrastAdjust/ContrastAdjust.cs index 3802b55..08c58a1 100644 --- a/WpfExtended/Effects/ContrastAdjust/ContrastAdjustEffect.cs +++ b/WpfExtended/Effects/ContrastAdjust/ContrastAdjust.cs @@ -10,20 +10,20 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class ContrastAdjustEffect : ShaderEffect + public class ContrastAdjust : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ContrastAdjustEffect), 0); - public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(ContrastAdjustEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(ContrastAdjustEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ContrastAdjust), 0); + public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(ContrastAdjust), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(ContrastAdjust), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); private readonly static PixelShader pixelShader = new PixelShader(); - static ContrastAdjustEffect() + static ContrastAdjust() { - pixelShader = PixelShaderUtility.LoadPixelShader("ContrastAdjust/ContrastAdjust.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public ContrastAdjustEffect() + public ContrastAdjust() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/DirectionalBlur/DirectionalBlurEffect.cs b/WpfExtended/Effects/DirectionalBlur/DirectionalBlur.cs similarity index 79% rename from WpfExtended/Effects/DirectionalBlur/DirectionalBlurEffect.cs rename to WpfExtended/Effects/DirectionalBlur/DirectionalBlur.cs index a9535a7..3bebff4 100644 --- a/WpfExtended/Effects/DirectionalBlur/DirectionalBlurEffect.cs +++ b/WpfExtended/Effects/DirectionalBlur/DirectionalBlur.cs @@ -10,20 +10,20 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class DirectionalBlurEffect : ShaderEffect + public class DirectionalBlur : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(DirectionalBlurEffect), 0); - public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DirectionalBlurEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty BlurAmountProperty = DependencyProperty.Register("BlurAmount", typeof(double), typeof(DirectionalBlurEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(DirectionalBlur), 0); + public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(DirectionalBlur), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty BlurAmountProperty = DependencyProperty.Register("BlurAmount", typeof(double), typeof(DirectionalBlur), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1))); private readonly static PixelShader pixelShader; - static DirectionalBlurEffect() + static DirectionalBlur() { - pixelShader = PixelShaderUtility.LoadPixelShader("DirectionalBlur/DirectionalBlur.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public DirectionalBlurEffect() + public DirectionalBlur() { this.PixelShader = pixelShader; UpdateShaderValue(InputProperty); diff --git a/WpfExtended/Effects/Embossed/EmbossedEffect.cs b/WpfExtended/Effects/Embossed/Embossed.cs similarity index 81% rename from WpfExtended/Effects/Embossed/EmbossedEffect.cs rename to WpfExtended/Effects/Embossed/Embossed.cs index cdc2639..73834c2 100644 --- a/WpfExtended/Effects/Embossed/EmbossedEffect.cs +++ b/WpfExtended/Effects/Embossed/Embossed.cs @@ -10,20 +10,20 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class EmbossedEffect : ShaderEffect + public class Embossed : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(EmbossedEffect), 0, SamplingMode.Bilinear); - public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(EmbossedEffect), new UIPropertyMetadata(15.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(EmbossedEffect), new UIPropertyMetadata(0.0001, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Embossed), 0, SamplingMode.Bilinear); + public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(Embossed), new UIPropertyMetadata(15.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(Embossed), new UIPropertyMetadata(0.0001, PixelShaderConstantCallback(1))); private readonly static PixelShader pixelShader = new PixelShader(); - static EmbossedEffect() + static Embossed() { - pixelShader = PixelShaderUtility.LoadPixelShader("Embossed/Embossed.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public EmbossedEffect() + public Embossed() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/Gloom/GloomEffect.cs b/WpfExtended/Effects/Gloom/Gloom.cs similarity index 82% rename from WpfExtended/Effects/Gloom/GloomEffect.cs rename to WpfExtended/Effects/Gloom/Gloom.cs index 4daa9f6..04e54c7 100644 --- a/WpfExtended/Effects/Gloom/GloomEffect.cs +++ b/WpfExtended/Effects/Gloom/Gloom.cs @@ -10,22 +10,22 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class GloomEffect : ShaderEffect + public class Gloom : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GloomEffect), 0); - public static readonly DependencyProperty GloomIntensityProperty = DependencyProperty.Register("GloomIntensity", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty BaseIntensityProperty = DependencyProperty.Register("BaseIntensity", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty GloomSaturationProperty = DependencyProperty.Register("GloomSaturation", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty BaseSaturationProperty = DependencyProperty.Register("BaseSaturation", typeof(double), typeof(GloomEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(3))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Gloom), 0); + public static readonly DependencyProperty GloomIntensityProperty = DependencyProperty.Register("GloomIntensity", typeof(double), typeof(Gloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty BaseIntensityProperty = DependencyProperty.Register("BaseIntensity", typeof(double), typeof(Gloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty GloomSaturationProperty = DependencyProperty.Register("GloomSaturation", typeof(double), typeof(Gloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty BaseSaturationProperty = DependencyProperty.Register("BaseSaturation", typeof(double), typeof(Gloom), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(3))); private readonly static PixelShader pixelShader = new PixelShader(); - static GloomEffect() + static Gloom() { - pixelShader = PixelShaderUtility.LoadPixelShader("Gloom/Gloom.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public GloomEffect() + public Gloom() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/GrowablePoissonDisk/GrowablePoissonDiskEffect.cs b/WpfExtended/Effects/GrowablePoissonDisk/GrowablePoissonDisk.cs similarity index 79% rename from WpfExtended/Effects/GrowablePoissonDisk/GrowablePoissonDiskEffect.cs rename to WpfExtended/Effects/GrowablePoissonDisk/GrowablePoissonDisk.cs index 2833e70..8e5b064 100644 --- a/WpfExtended/Effects/GrowablePoissonDisk/GrowablePoissonDiskEffect.cs +++ b/WpfExtended/Effects/GrowablePoissonDisk/GrowablePoissonDisk.cs @@ -10,21 +10,21 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class GrowablePoissonDiskEffect : ShaderEffect + public class GrowablePoissonDisk : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GrowablePoissonDiskEffect), 0); - public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(GrowablePoissonDiskEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(GrowablePoissonDiskEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(GrowablePoissonDiskEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GrowablePoissonDisk), 0); + public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(GrowablePoissonDisk), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(GrowablePoissonDisk), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty HeightProperty = DependencyProperty.Register("Height", typeof(double), typeof(GrowablePoissonDisk), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(2))); private readonly static PixelShader pixelShader = new PixelShader(); - static GrowablePoissonDiskEffect() + static GrowablePoissonDisk() { - pixelShader = PixelShaderUtility.LoadPixelShader("GrowablePoissonDisk/GrowablePoissonDisk.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public GrowablePoissonDiskEffect() + public GrowablePoissonDisk() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/ColorKeyAlpha/ColorKeyAlphaEffect.cs b/WpfExtended/Effects/InvertColor/InvertColor.cs similarity index 77% rename from WpfExtended/Effects/ColorKeyAlpha/ColorKeyAlphaEffect.cs rename to WpfExtended/Effects/InvertColor/InvertColor.cs index a0c6a58..f7c8afe 100644 --- a/WpfExtended/Effects/ColorKeyAlpha/ColorKeyAlphaEffect.cs +++ b/WpfExtended/Effects/InvertColor/InvertColor.cs @@ -7,18 +7,18 @@ using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects { - public class ColorKeyAlphaEffect : ShaderEffect + public class InvertColor : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ColorKeyAlphaEffect), 0); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(InvertColor), 0); private readonly static PixelShader pixelShader; - static ColorKeyAlphaEffect() + static InvertColor() { - pixelShader = PixelShaderUtility.LoadPixelShader("ColorKeyAlpha/ColorKeyAlpha.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public ColorKeyAlphaEffect() + public InvertColor() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/LightStreak/LightStreakEffect.cs b/WpfExtended/Effects/LightStreak/LightStreak.cs similarity index 81% rename from WpfExtended/Effects/LightStreak/LightStreakEffect.cs rename to WpfExtended/Effects/LightStreak/LightStreak.cs index 1366a5b..0f9a78d 100644 --- a/WpfExtended/Effects/LightStreak/LightStreakEffect.cs +++ b/WpfExtended/Effects/LightStreak/LightStreak.cs @@ -10,21 +10,21 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class LightStreakEffect : ShaderEffect + public class LightStreak : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(LightStreakEffect), 0); - public static readonly DependencyProperty BrightThresholdProperty = DependencyProperty.Register("BrightThreshold", typeof(double), typeof(LightStreakEffect), new UIPropertyMetadata(0.25, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register("Scale", typeof(double), typeof(LightStreakEffect), new UIPropertyMetadata(0.75, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty AttenuationProperty = DependencyProperty.Register("Attenuation", typeof(double), typeof(LightStreakEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(LightStreak), 0); + public static readonly DependencyProperty BrightThresholdProperty = DependencyProperty.Register("BrightThreshold", typeof(double), typeof(LightStreak), new UIPropertyMetadata(0.25, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register("Scale", typeof(double), typeof(LightStreak), new UIPropertyMetadata(0.75, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty AttenuationProperty = DependencyProperty.Register("Attenuation", typeof(double), typeof(LightStreak), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(2))); private readonly static PixelShader pixelShader = new PixelShader(); - static LightStreakEffect() + static LightStreak() { - pixelShader = PixelShaderUtility.LoadPixelShader("LightStreak/LightStreak.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public LightStreakEffect() + public LightStreak() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/Magnify/MagnifyEffect.cs b/WpfExtended/Effects/Magnify/Magnify.cs similarity index 90% rename from WpfExtended/Effects/Magnify/MagnifyEffect.cs rename to WpfExtended/Effects/Magnify/Magnify.cs index 4fe3ab5..5b9afc6 100644 --- a/WpfExtended/Effects/Magnify/MagnifyEffect.cs +++ b/WpfExtended/Effects/Magnify/Magnify.cs @@ -11,22 +11,22 @@ namespace System.Windows.Media.Extensions.Effects using UIPropertyMetadata = System.Windows.PropertyMetadata ; using Vector = System.Windows.Point ; #endif - public class MagnifyEffect : ShaderEffect + public class Magnify : ShaderEffect { - public static readonly DependencyProperty RadiiProperty = DependencyProperty.Register("Radii", typeof(Size), typeof(MagnifyEffect), new UIPropertyMetadata(new Size(0.2, 0.2), PixelShaderConstantCallback(0))); - public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(MagnifyEffect), new UIPropertyMetadata(new Point(0.25, 0.25), PixelShaderConstantCallback(1))); - public static readonly DependencyProperty ShrinkFactorProperty = DependencyProperty.Register("ShrinkFactor", typeof(double), typeof(MagnifyEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(MagnifyEffect), 0); + public static readonly DependencyProperty RadiiProperty = DependencyProperty.Register("Radii", typeof(Size), typeof(Magnify), new UIPropertyMetadata(new Size(0.2, 0.2), PixelShaderConstantCallback(0))); + public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(Magnify), new UIPropertyMetadata(new Point(0.25, 0.25), PixelShaderConstantCallback(1))); + public static readonly DependencyProperty ShrinkFactorProperty = DependencyProperty.Register("ShrinkFactor", typeof(double), typeof(Magnify), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Magnify), 0); private readonly static PixelShader pixelShader; private readonly MagnifyGeneralTransform generalTransform; - static MagnifyEffect() + static Magnify() { - pixelShader = PixelShaderUtility.LoadPixelShader("Magnify/Magnify.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public MagnifyEffect() + public Magnify() { this.PixelShader = pixelShader; @@ -70,10 +70,10 @@ namespace System.Windows.Media.Extensions.Effects private class MagnifyGeneralTransform : GeneralTransform { - private readonly MagnifyEffect effect; + private readonly Magnify effect; private bool thisIsInverse; private MagnifyGeneralTransform inverseTransform; - public MagnifyGeneralTransform(MagnifyEffect fx) + public MagnifyGeneralTransform(Magnify fx) { this.effect = fx; } diff --git a/WpfExtended/Effects/MonoChrome/MonochromeEffect.cs b/WpfExtended/Effects/Monochrome/Monochrome.cs similarity index 79% rename from WpfExtended/Effects/MonoChrome/MonochromeEffect.cs rename to WpfExtended/Effects/Monochrome/Monochrome.cs index 2f17244..ee0e225 100644 --- a/WpfExtended/Effects/MonoChrome/MonochromeEffect.cs +++ b/WpfExtended/Effects/Monochrome/Monochrome.cs @@ -10,18 +10,18 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class MonochromeEffect : ShaderEffect + public class Monochrome : ShaderEffect { - public static readonly DependencyProperty FilterColorProperty = DependencyProperty.Register("FilterColor", typeof(Color), typeof(MonochromeEffect), new UIPropertyMetadata(Colors.White, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(MonochromeEffect), 0); + public static readonly DependencyProperty FilterColorProperty = DependencyProperty.Register("FilterColor", typeof(Color), typeof(Monochrome), new UIPropertyMetadata(Colors.White, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Monochrome), 0); private readonly static PixelShader pixelShader; - static MonochromeEffect() + static Monochrome() { - pixelShader = PixelShaderUtility.LoadPixelShader("MonoChrome/Monochrome.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public MonochromeEffect() + public Monochrome() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/MotionBlur/MotionBlurEffect.cs b/WpfExtended/Effects/MotionBlur/MotionBlur.cs similarity index 85% rename from WpfExtended/Effects/MotionBlur/MotionBlurEffect.cs rename to WpfExtended/Effects/MotionBlur/MotionBlur.cs index eb1bbfc..7fe9cc2 100644 --- a/WpfExtended/Effects/MotionBlur/MotionBlurEffect.cs +++ b/WpfExtended/Effects/MotionBlur/MotionBlur.cs @@ -24,13 +24,13 @@ using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects { - public class MotionBlurEffect : ShaderEffect + public class MotionBlur : ShaderEffect { - public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty(nameof(Input), typeof(MotionBlurEffect), 0); + public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty(nameof(Input), typeof(MotionBlur), 0); public static readonly DependencyProperty BlurAngleProperty = - DependencyProperty.Register(nameof(BlurAngle), typeof(double), typeof(MotionBlurEffect), new UIPropertyMetadata(0d, PixelShaderConstantCallback(0))); + DependencyProperty.Register(nameof(BlurAngle), typeof(double), typeof(MotionBlur), new UIPropertyMetadata(0d, PixelShaderConstantCallback(0))); public static readonly DependencyProperty BlurMagnitudeProperty = - DependencyProperty.Register(nameof(BlurMagnitude), typeof(double), typeof(MotionBlurEffect), new UIPropertyMetadata(10d, PixelShaderConstantCallback(1))); + DependencyProperty.Register(nameof(BlurMagnitude), typeof(double), typeof(MotionBlur), new UIPropertyMetadata(10d, PixelShaderConstantCallback(1))); public Brush Input { @@ -48,9 +48,9 @@ namespace System.Windows.Media.Extensions.Effects set => SetValue(BlurMagnitudeProperty, value); } - public MotionBlurEffect() + public MotionBlur() { - PixelShader = PixelShaderUtility.LoadPixelShader("MotionBlur/MotionBlurEffect.ps"); + PixelShader = PixelShaderUtility.LoadPixelShader(); UpdateShaderValue(InputProperty); UpdateShaderValue(BlurAngleProperty); diff --git a/WpfExtended/Effects/MotionBlur/MotionBlurEffect.fx b/WpfExtended/Effects/MotionBlur/MotionBlur.fx similarity index 100% rename from WpfExtended/Effects/MotionBlur/MotionBlurEffect.fx rename to WpfExtended/Effects/MotionBlur/MotionBlur.fx diff --git a/WpfExtended/Effects/MotionBlur/MotionBlurEffect.ps b/WpfExtended/Effects/MotionBlur/MotionBlur.ps similarity index 100% rename from WpfExtended/Effects/MotionBlur/MotionBlurEffect.ps rename to WpfExtended/Effects/MotionBlur/MotionBlur.ps diff --git a/WpfExtended/Effects/Negative/NegativeEffect.cs b/WpfExtended/Effects/Negative/Negative.cs similarity index 89% rename from WpfExtended/Effects/Negative/NegativeEffect.cs rename to WpfExtended/Effects/Negative/Negative.cs index d033d67..674eae8 100644 --- a/WpfExtended/Effects/Negative/NegativeEffect.cs +++ b/WpfExtended/Effects/Negative/Negative.cs @@ -24,9 +24,9 @@ using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects { - public class NegativeEffect : ShaderEffect + public class Negative : ShaderEffect { - public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty(nameof(Input), typeof(NegativeEffect), 0); + public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty(nameof(Input), typeof(Negative), 0); public Brush Input { @@ -34,9 +34,9 @@ namespace System.Windows.Media.Extensions.Effects set => SetValue(InputProperty, value); } - public NegativeEffect() + public Negative() { - PixelShader = PixelShaderUtility.LoadPixelShader("Negative/NegativeEffect.ps"); + PixelShader = PixelShaderUtility.LoadPixelShader(); UpdateShaderValue(InputProperty); } } diff --git a/WpfExtended/Effects/Negative/NegativeEffect.fx b/WpfExtended/Effects/Negative/Negative.fx similarity index 100% rename from WpfExtended/Effects/Negative/NegativeEffect.fx rename to WpfExtended/Effects/Negative/Negative.fx diff --git a/WpfExtended/Effects/Negative/NegativeEffect.ps b/WpfExtended/Effects/Negative/Negative.ps similarity index 100% rename from WpfExtended/Effects/Negative/NegativeEffect.ps rename to WpfExtended/Effects/Negative/Negative.ps diff --git a/WpfExtended/Effects/Pinch/PinchEffect.cs b/WpfExtended/Effects/Pinch/Pinch.cs similarity index 83% rename from WpfExtended/Effects/Pinch/PinchEffect.cs rename to WpfExtended/Effects/Pinch/Pinch.cs index a987609..a57096d 100644 --- a/WpfExtended/Effects/Pinch/PinchEffect.cs +++ b/WpfExtended/Effects/Pinch/Pinch.cs @@ -10,21 +10,21 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class PinchEffect : ShaderEffect + public class Pinch : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(PinchEffect), 0); - public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.25, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(PinchEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Pinch), 0); + public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(Pinch), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(Pinch), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty RadiusProperty = DependencyProperty.Register("Radius", typeof(double), typeof(Pinch), new UIPropertyMetadata(0.25, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(Pinch), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3))); private readonly static PixelShader pixelShader = new PixelShader(); - static PinchEffect() + static Pinch() { - pixelShader = PixelShaderUtility.LoadPixelShader("Pinch/Pinch.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public PinchEffect() + public Pinch() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/PixelShaderUtility.cs b/WpfExtended/Effects/PixelShaderUtility.cs index 5001028..fc4aecf 100644 --- a/WpfExtended/Effects/PixelShaderUtility.cs +++ b/WpfExtended/Effects/PixelShaderUtility.cs @@ -20,7 +20,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -using System; +using System.IO; using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects @@ -37,15 +37,19 @@ namespace System.Windows.Media.Extensions.Effects .Name; } - public static PixelShader LoadPixelShader(string shaderFile) + public static PixelShader LoadPixelShader() + where T : ShaderEffect { - string uriString = $"pack://application:,,,/{AssemblyShortName};component/{shaderFile}"; - PixelShader pixelShader = new PixelShader - { - UriSource = new Uri(uriString) - }; - + var pixelShaderName = typeof(T).Name; + var resourceName = $"{AssemblyShortName}.Effects.{pixelShaderName}.{pixelShaderName}.ps"; + var pixelShader = new PixelShader(); + pixelShader.SetStreamSource(GetShaderStream(resourceName)); return pixelShader; } + + internal static Stream GetShaderStream(string name) + { + return typeof(PixelShaderUtility).Assembly.GetManifestResourceStream(name) ?? throw new InvalidOperationException($"Could not find shader resource for {name}"); + } } } \ No newline at end of file diff --git a/WpfExtended/Effects/Pixelate/PixelateEffect.cs b/WpfExtended/Effects/Pixelate/Pixelate.cs similarity index 81% rename from WpfExtended/Effects/Pixelate/PixelateEffect.cs rename to WpfExtended/Effects/Pixelate/Pixelate.cs index d2ba2be..db5118f 100644 --- a/WpfExtended/Effects/Pixelate/PixelateEffect.cs +++ b/WpfExtended/Effects/Pixelate/Pixelate.cs @@ -10,20 +10,20 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class PixelateEffect : ShaderEffect + public class Pixelate : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(PixelateEffect), 0); - public static readonly DependencyProperty HorizontalPixelCountsProperty = DependencyProperty.Register("HorizontalPixelCounts", typeof(double), typeof(PixelateEffect), new UIPropertyMetadata(80.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty VerticalPixelCountsProperty = DependencyProperty.Register("VerticalPixelCounts", typeof(double), typeof(PixelateEffect), new UIPropertyMetadata(80.0, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Pixelate), 0); + public static readonly DependencyProperty HorizontalPixelCountsProperty = DependencyProperty.Register("HorizontalPixelCounts", typeof(double), typeof(Pixelate), new UIPropertyMetadata(80.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty VerticalPixelCountsProperty = DependencyProperty.Register("VerticalPixelCounts", typeof(double), typeof(Pixelate), new UIPropertyMetadata(80.0, PixelShaderConstantCallback(1))); private readonly static PixelShader pixelShader = new PixelShader(); - static PixelateEffect() + static Pixelate() { - pixelShader = PixelShaderUtility.LoadPixelShader("Pixelate/Pixelate.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public PixelateEffect() + public Pixelate() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/Ripple/RippleEffect.cs b/WpfExtended/Effects/Ripple/Ripple.cs similarity index 81% rename from WpfExtended/Effects/Ripple/RippleEffect.cs rename to WpfExtended/Effects/Ripple/Ripple.cs index cbc2ce7..d7c0369 100644 --- a/WpfExtended/Effects/Ripple/RippleEffect.cs +++ b/WpfExtended/Effects/Ripple/Ripple.cs @@ -10,22 +10,22 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class RippleEffect : ShaderEffect + public class Ripple : ShaderEffect { - public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(RippleEffect), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); - public static readonly DependencyProperty AmplitudeProperty = DependencyProperty.Register("Amplitude", typeof(double), typeof(RippleEffect), new UIPropertyMetadata(0.1, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(RippleEffect), new UIPropertyMetadata(50.0, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(RippleEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3))); - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(RippleEffect), 0); + public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(Ripple), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); + public static readonly DependencyProperty AmplitudeProperty = DependencyProperty.Register("Amplitude", typeof(double), typeof(Ripple), new UIPropertyMetadata(0.1, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(Ripple), new UIPropertyMetadata(50.0, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(Ripple), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Ripple), 0); private static readonly PixelShader pixelShader; - static RippleEffect() + static Ripple() { - pixelShader = PixelShaderUtility.LoadPixelShader("Ripple/Ripple.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public RippleEffect() + public Ripple() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/Sharpen/SharpenEffect.cs b/WpfExtended/Effects/Sharpen/Sharpen.cs similarity index 83% rename from WpfExtended/Effects/Sharpen/SharpenEffect.cs rename to WpfExtended/Effects/Sharpen/Sharpen.cs index 0cf0c4b..34d000a 100644 --- a/WpfExtended/Effects/Sharpen/SharpenEffect.cs +++ b/WpfExtended/Effects/Sharpen/Sharpen.cs @@ -10,20 +10,20 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class SharpenEffect : ShaderEffect + public class Sharpen : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SharpenEffect), 0); - public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(SharpenEffect), new UIPropertyMetadata(15.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(SharpenEffect), new UIPropertyMetadata(0.0001, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Sharpen), 0); + public static readonly DependencyProperty AmountProperty = DependencyProperty.Register("Amount", typeof(double), typeof(Sharpen), new UIPropertyMetadata(15.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty WidthProperty = DependencyProperty.Register("Width", typeof(double), typeof(Sharpen), new UIPropertyMetadata(0.0001, PixelShaderConstantCallback(1))); private readonly static PixelShader pixelShader = new PixelShader(); - static SharpenEffect() + static Sharpen() { - pixelShader = PixelShaderUtility.LoadPixelShader("Sharpen/Sharpen.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public SharpenEffect() + public Sharpen() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/SmoothMagnify/SmoothMagnifyEffect.cs b/WpfExtended/Effects/SmoothMagnify/SmoothMagnify.cs similarity index 78% rename from WpfExtended/Effects/SmoothMagnify/SmoothMagnifyEffect.cs rename to WpfExtended/Effects/SmoothMagnify/SmoothMagnify.cs index ce2e90e..2c9068f 100644 --- a/WpfExtended/Effects/SmoothMagnify/SmoothMagnifyEffect.cs +++ b/WpfExtended/Effects/SmoothMagnify/SmoothMagnify.cs @@ -10,22 +10,22 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class SmoothMagnifyEffect : ShaderEffect + public class SmoothMagnify : ShaderEffect { - public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); - public static readonly DependencyProperty InnerRadiusProperty = DependencyProperty.Register("InnerRadius", typeof(double), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(.2, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty MagnificationProperty = DependencyProperty.Register("Magnification", typeof(double), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(2.0, PixelShaderConstantCallback(3))); - public static readonly DependencyProperty OuterRadiusProperty = DependencyProperty.Register("OuterRadius", typeof(double), typeof(SmoothMagnifyEffect), new UIPropertyMetadata(.27, PixelShaderConstantCallback(4))); - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SmoothMagnifyEffect), 0); + public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(SmoothMagnify), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); + public static readonly DependencyProperty InnerRadiusProperty = DependencyProperty.Register("InnerRadius", typeof(double), typeof(SmoothMagnify), new UIPropertyMetadata(.2, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty MagnificationProperty = DependencyProperty.Register("Magnification", typeof(double), typeof(SmoothMagnify), new UIPropertyMetadata(2.0, PixelShaderConstantCallback(3))); + public static readonly DependencyProperty OuterRadiusProperty = DependencyProperty.Register("OuterRadius", typeof(double), typeof(SmoothMagnify), new UIPropertyMetadata(.27, PixelShaderConstantCallback(4))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SmoothMagnify), 0); private readonly static PixelShader pixelShader; - static SmoothMagnifyEffect() + static SmoothMagnify() { - pixelShader = PixelShaderUtility.LoadPixelShader("SmoothMagnify/SmoothMagnify.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public SmoothMagnifyEffect() + public SmoothMagnify() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/Swirl/SwirlEffect.cs b/WpfExtended/Effects/Swirl/Swirl.cs similarity index 90% rename from WpfExtended/Effects/Swirl/SwirlEffect.cs rename to WpfExtended/Effects/Swirl/Swirl.cs index c8ae7f1..7adbbab 100644 --- a/WpfExtended/Effects/Swirl/SwirlEffect.cs +++ b/WpfExtended/Effects/Swirl/Swirl.cs @@ -11,22 +11,22 @@ namespace System.Windows.Media.Extensions.Effects using UIPropertyMetadata = System.Windows.PropertyMetadata ; using Vector = System.Windows.Point ; #endif - public class SwirlEffect : ShaderEffect + public class Swirl : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(SwirlEffect), 0); - public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(SwirlEffect), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); - public static readonly DependencyProperty SwirlStrengthProperty = DependencyProperty.Register("SwirlStrength", typeof(double), typeof(SwirlEffect), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty AngleFrequencyProperty = DependencyProperty.Register("AngleFrequency", typeof(Vector), typeof(SwirlEffect), new UIPropertyMetadata(new Vector(1, 1), PixelShaderConstantCallback(2))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(Swirl), 0); + public static readonly DependencyProperty CenterProperty = DependencyProperty.Register("Center", typeof(Point), typeof(Swirl), new UIPropertyMetadata(new Point(0.5, 0.5), PixelShaderConstantCallback(0))); + public static readonly DependencyProperty SwirlStrengthProperty = DependencyProperty.Register("SwirlStrength", typeof(double), typeof(Swirl), new UIPropertyMetadata(0.5, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty AngleFrequencyProperty = DependencyProperty.Register("AngleFrequency", typeof(Vector), typeof(Swirl), new UIPropertyMetadata(new Vector(1, 1), PixelShaderConstantCallback(2))); private readonly static PixelShader pixelShader; private readonly SwirlGeneralTransform generalTransform; - static SwirlEffect() + static Swirl() { - pixelShader = PixelShaderUtility.LoadPixelShader("SwirlEffect/SwirlEffect.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public SwirlEffect() + public Swirl() { this.PixelShader = pixelShader; @@ -68,10 +68,10 @@ namespace System.Windows.Media.Extensions.Effects } private class SwirlGeneralTransform : GeneralTransform { - private readonly SwirlEffect theEffect; + private readonly Swirl theEffect; private bool thisIsInverse; private SwirlGeneralTransform inverseTransform; - public SwirlGeneralTransform(SwirlEffect eff) + public SwirlGeneralTransform(Swirl eff) { this.theEffect = eff; } diff --git a/WpfExtended/Effects/ToneMapping/ToneMappingEffect.cs b/WpfExtended/Effects/ToneMapping/ToneMapping.cs similarity index 80% rename from WpfExtended/Effects/ToneMapping/ToneMappingEffect.cs rename to WpfExtended/Effects/ToneMapping/ToneMapping.cs index 095d6c0..2175c6c 100644 --- a/WpfExtended/Effects/ToneMapping/ToneMappingEffect.cs +++ b/WpfExtended/Effects/ToneMapping/ToneMapping.cs @@ -10,25 +10,25 @@ namespace System.Windows.Media.Extensions.Effects #if SILVERLIGHT using UIPropertyMetadata = System.Windows.PropertyMetadata ; #endif - public class ToneMappingEffect : ShaderEffect + public class ToneMapping : ShaderEffect { - public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ToneMappingEffect), 0); - public static readonly DependencyProperty ExposureProperty = DependencyProperty.Register("Exposure", typeof(double), typeof(ToneMappingEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0))); - public static readonly DependencyProperty DefogProperty = DependencyProperty.Register("Defog", typeof(double), typeof(ToneMappingEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1))); - public static readonly DependencyProperty GammaProperty = DependencyProperty.Register("Gamma", typeof(double), typeof(ToneMappingEffect), new UIPropertyMetadata(0.454545, PixelShaderConstantCallback(2))); - public static readonly DependencyProperty FogColorProperty = DependencyProperty.Register("FogColor", typeof(Color), typeof(ToneMappingEffect), new UIPropertyMetadata(Colors.White, PixelShaderConstantCallback(3))); - public static readonly DependencyProperty VignetteRadiusProperty = DependencyProperty.Register("VignetteRadius", typeof(double), typeof(ToneMappingEffect), new UIPropertyMetadata(0.35, PixelShaderConstantCallback(4))); - public static readonly DependencyProperty VignetteCenterProperty = DependencyProperty.Register("VignetteCenter", typeof(Point), typeof(ToneMappingEffect), new UIPropertyMetadata( new Point(0.5, 0.5), PixelShaderConstantCallback(5))); - public static readonly DependencyProperty BlueShiftProperty = DependencyProperty.Register("BlueShift", typeof(double), typeof(ToneMappingEffect), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(6))); + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ToneMapping), 0); + public static readonly DependencyProperty ExposureProperty = DependencyProperty.Register("Exposure", typeof(double), typeof(ToneMapping), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0))); + public static readonly DependencyProperty DefogProperty = DependencyProperty.Register("Defog", typeof(double), typeof(ToneMapping), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1))); + public static readonly DependencyProperty GammaProperty = DependencyProperty.Register("Gamma", typeof(double), typeof(ToneMapping), new UIPropertyMetadata(0.454545, PixelShaderConstantCallback(2))); + public static readonly DependencyProperty FogColorProperty = DependencyProperty.Register("FogColor", typeof(Color), typeof(ToneMapping), new UIPropertyMetadata(Colors.White, PixelShaderConstantCallback(3))); + public static readonly DependencyProperty VignetteRadiusProperty = DependencyProperty.Register("VignetteRadius", typeof(double), typeof(ToneMapping), new UIPropertyMetadata(0.35, PixelShaderConstantCallback(4))); + public static readonly DependencyProperty VignetteCenterProperty = DependencyProperty.Register("VignetteCenter", typeof(Point), typeof(ToneMapping), new UIPropertyMetadata( new Point(0.5, 0.5), PixelShaderConstantCallback(5))); + public static readonly DependencyProperty BlueShiftProperty = DependencyProperty.Register("BlueShift", typeof(double), typeof(ToneMapping), new UIPropertyMetadata(1.0, PixelShaderConstantCallback(6))); private readonly static PixelShader pixelShader; - static ToneMappingEffect() + static ToneMapping() { - pixelShader = PixelShaderUtility.LoadPixelShader("ToneMapping/ToneMapping.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); } - public ToneMappingEffect() + public ToneMapping() { this.PixelShader = pixelShader; diff --git a/WpfExtended/Effects/ToonShader/ToonShaderEffect.cs b/WpfExtended/Effects/ToonShader/ToonShader.cs similarity index 82% rename from WpfExtended/Effects/ToonShader/ToonShaderEffect.cs rename to WpfExtended/Effects/ToonShader/ToonShader.cs index 92ff493..9645cfb 100644 --- a/WpfExtended/Effects/ToonShader/ToonShaderEffect.cs +++ b/WpfExtended/Effects/ToonShader/ToonShader.cs @@ -7,16 +7,16 @@ using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects { - public class ToonShaderEffect : ShaderEffect + public class ToonShader : ShaderEffect { public static readonly DependencyProperty InputProperty = - ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ToonShaderEffect), 0); + ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ToonShader), 0); private static readonly PixelShader pixelShader; - static ToonShaderEffect() + static ToonShader() { - pixelShader = PixelShaderUtility.LoadPixelShader("ToonShader/ToonShader.ps"); + pixelShader = PixelShaderUtility.LoadPixelShader(); // Just saying hardware only for now since our drop of sw doesn't have sin/cos in // it, and thus we can't validate against that. @@ -26,7 +26,7 @@ namespace System.Windows.Media.Extensions.Effects #endif } - public ToonShaderEffect() + public ToonShader() { this.PixelShader = pixelShader; UpdateShaderValue(InputProperty); diff --git a/WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.cs b/WpfExtended/Effects/ZoomBlur/ZoomBlur.cs similarity index 85% rename from WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.cs rename to WpfExtended/Effects/ZoomBlur/ZoomBlur.cs index b6d1f87..5dabf7e 100644 --- a/WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.cs +++ b/WpfExtended/Effects/ZoomBlur/ZoomBlur.cs @@ -24,13 +24,13 @@ using System.Windows.Media.Effects; namespace System.Windows.Media.Extensions.Effects { - public class ZoomBlurEffect : ShaderEffect + public class ZoomBlur : ShaderEffect { - public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty(nameof(Input), typeof(ZoomBlurEffect), 0); + public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty(nameof(Input), typeof(ZoomBlur), 0); public static readonly DependencyProperty BlurCenterProperty = - DependencyProperty.Register(nameof(BlurCenter), typeof(Point), typeof(ZoomBlurEffect), new UIPropertyMetadata(new Point(0.5D, 0.5D), PixelShaderConstantCallback(0))); + DependencyProperty.Register(nameof(BlurCenter), typeof(Point), typeof(ZoomBlur), new UIPropertyMetadata(new Point(0.5D, 0.5D), PixelShaderConstantCallback(0))); public static readonly DependencyProperty BlurMagnitudeProperty = - DependencyProperty.Register(nameof(BlurMagnitude), typeof(double), typeof(ZoomBlurEffect), new UIPropertyMetadata(5D, PixelShaderConstantCallback(1))); + DependencyProperty.Register(nameof(BlurMagnitude), typeof(double), typeof(ZoomBlur), new UIPropertyMetadata(5D, PixelShaderConstantCallback(1))); public Brush Input { @@ -48,9 +48,9 @@ namespace System.Windows.Media.Extensions.Effects set => SetValue(BlurMagnitudeProperty, value); } - public ZoomBlurEffect() + public ZoomBlur() { - PixelShader = PixelShaderUtility.LoadPixelShader("ZoomBlur/ZoomBlurEffect.ps"); + PixelShader = PixelShaderUtility.LoadPixelShader(); UpdateShaderValue(InputProperty); UpdateShaderValue(BlurCenterProperty); diff --git a/WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.fx b/WpfExtended/Effects/ZoomBlur/ZoomBlur.fx similarity index 100% rename from WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.fx rename to WpfExtended/Effects/ZoomBlur/ZoomBlur.fx diff --git a/WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.ps b/WpfExtended/Effects/ZoomBlur/ZoomBlur.ps similarity index 100% rename from WpfExtended/Effects/ZoomBlur/ZoomBlurEffect.ps rename to WpfExtended/Effects/ZoomBlur/ZoomBlur.ps diff --git a/WpfExtended/Launch/ExtendedApplication.cs b/WpfExtended/Launch/ExtendedApplication.cs new file mode 100644 index 0000000..84d09f1 --- /dev/null +++ b/WpfExtended/Launch/ExtendedApplication.cs @@ -0,0 +1,75 @@ +using Slim; +using System.Extensions; +using System.Threading.Tasks; +using System.Windows.Navigation; + +namespace System.Windows.Extensions +{ + /// + /// Extended application class. + /// + /// Type of window to be launched after initialization. + public abstract class ExtendedApplication : Application + where T : Window + { + protected IServiceManager ServiceManager { get; } = new ServiceManager(); + + public ExtendedApplication() + { + this.RegisterInternals(); + } + + /// + /// Register services into the . + /// + /// + protected abstract void RegisterServices(IServiceProducer serviceProducer); + /// + /// Handle a caught exception. + /// + /// Exception to be handled. + /// True if exception is handled. Otherwise, return false. + protected abstract bool HandleException(Exception e); + + protected sealed override void OnStartup(StartupEventArgs e) + { + this.SetupExceptionHandling(); + this.RegisterServices(this.ServiceManager); + this.LaunchWindow(); + } + + private void LaunchWindow() + { + var window = this.ServiceManager.GetService(); + window.Show(); + } + private void RegisterInternals() + { + this.ServiceManager.RegisterServiceManager(); + this.ServiceManager.RegisterSingleton(); + } + private void SetupExceptionHandling() + { + this.DispatcherUnhandledException += (_, e) => + { + e.Handled = this.HandleException(e.Exception); + }; + + AppDomain.CurrentDomain.UnhandledException += (_, e) => + { + if (this.HandleException(e.ExceptionObject.As()) is false && e.IsTerminating is false) + { + throw e.ExceptionObject.As(); + } + }; + + TaskScheduler.UnobservedTaskException += (_, e) => + { + if (this.HandleException(e.Exception)) + { + e.SetObserved(); + } + }; + } + } +} diff --git a/WpfExtended/WpfExtended.csproj b/WpfExtended/WpfExtended.csproj index e8ff8a8..88a17e6 100644 --- a/WpfExtended/WpfExtended.csproj +++ b/WpfExtended/WpfExtended.csproj @@ -12,11 +12,72 @@ https://github.com/AlexMacocian/WpfExtended + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + True + + + + +