diff --git a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj index 122ba525..72bdb306 100644 --- a/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj +++ b/src/Core_30/HandyControlDemo_Core_30/HandyControlDemo_Core30.csproj @@ -471,12 +471,6 @@ Resources\Img\cloud.png - - Resources\Img\f.png - - - Resources\Img\b.png - diff --git a/src/Core_30/HandyControl_Core_30/HandyControl_Core_30.csproj b/src/Core_30/HandyControl_Core_30/HandyControl_Core_30.csproj index 1cc60b14..d5a3a94b 100644 --- a/src/Core_30/HandyControl_Core_30/HandyControl_Core_30.csproj +++ b/src/Core_30/HandyControl_Core_30/HandyControl_Core_30.csproj @@ -76,9 +76,6 @@ Resources\Effects\GrayScaleEffect.ps - - Resources\Effects\MultiplyBlendEffect.ps - diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj index 8f01983d..50bbc0a2 100644 --- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj +++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj @@ -547,12 +547,6 @@ Resources\Img\cloud.png - - Resources\Img\f.png - - - Resources\Img\b.png - diff --git a/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj b/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj index 33712056..c593ae8c 100644 --- a/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj +++ b/src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj @@ -128,9 +128,6 @@ Resources\Effects\GrayScaleEffect.ps - - Resources\Effects\MultiplyBlendEffect.ps - diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj index b6cecb03..abe74897 100644 --- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj +++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj @@ -610,12 +610,6 @@ Resources\Img\cloud.png - - Resources\Img\f.png - - - Resources\Img\b.png - diff --git a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj index b0eec08e..9e873597 100644 --- a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj +++ b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj @@ -199,9 +199,6 @@ Resources\Effects\GrayScaleEffect.ps - - Resources\Effects\MultiplyBlendEffect.ps - diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Img/b.png b/src/Shared/HandyControlDemo_Shared/Resources/Img/b.png deleted file mode 100644 index a3cf8c17..00000000 Binary files a/src/Shared/HandyControlDemo_Shared/Resources/Img/b.png and /dev/null differ diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Img/f.png b/src/Shared/HandyControlDemo_Shared/Resources/Img/f.png deleted file mode 100644 index 99597c0c..00000000 Binary files a/src/Shared/HandyControlDemo_Shared/Resources/Img/f.png and /dev/null differ diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Tools/EffectsDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Tools/EffectsDemoCtl.xaml index 2bf916b7..649aef85 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Tools/EffectsDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Tools/EffectsDemoCtl.xaml @@ -25,371 +25,67 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index 6da6081b..8e5bce5f 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -68,8 +68,7 @@ - - + @@ -404,6 +403,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/src/Shared/HandyControl_Shared/Media/Effects/BlendEffect.cs b/src/Shared/HandyControl_Shared/Media/Effects/BlendEffect.cs deleted file mode 100644 index 744affcc..00000000 --- a/src/Shared/HandyControl_Shared/Media/Effects/BlendEffect.cs +++ /dev/null @@ -1,61 +0,0 @@ -//reference doc : https://docs.microsoft.com/en-us/windows/win32/direct2d/blend#blending-examples - -using System; -using System.Collections.Generic; -using System.Windows; -using System.Windows.Media; -using System.Windows.Media.Effects; - -namespace HandyControl.Media.Effects -{ - public class BlendEffect : ShaderEffect - { - private static readonly Dictionary ShaderDic; - - public static readonly DependencyProperty BackgroundProperty = RegisterPixelShaderSamplerProperty("Background", typeof(BlendEffect), 0); - - public static readonly DependencyProperty ForegroundProperty = RegisterPixelShaderSamplerProperty("Foreground", typeof(BlendEffect), 1); - - static BlendEffect() - { - ShaderDic = new Dictionary(); - } - - public BlendEffect() - { - if (!ShaderDic.ContainsKey(Mode)) - { - ShaderDic[Mode] = new PixelShader - { - UriSource = new Uri($"pack://application:,,,/HandyControl;component/Resources/Effects/{Mode.ToString()}BlendEffect.ps") - }; - } - - PixelShader = ShaderDic[Mode]; - - UpdateShaderValue(BackgroundProperty); - UpdateShaderValue(ForegroundProperty); - } - - public Brush Background - { - get => (Brush)GetValue(BackgroundProperty); - set => SetValue(BackgroundProperty, value); - } - - public Brush Foreground - { - get => (Brush)GetValue(ForegroundProperty); - set => SetValue(ForegroundProperty, value); - } - - public static readonly DependencyProperty ModeProperty = DependencyProperty.Register( - "Mode", typeof(BlendEffectMode), typeof(BlendEffect), new PropertyMetadata(default(BlendEffectMode), PixelShaderConstantCallback(0))); - - public BlendEffectMode Mode - { - get => (BlendEffectMode) GetValue(ModeProperty); - set => SetValue(ModeProperty, value); - } - } -} diff --git a/src/Shared/HandyControl_Shared/Media/Effects/BlendEffectBox.cs b/src/Shared/HandyControl_Shared/Media/Effects/BlendEffectBox.cs new file mode 100644 index 00000000..1a5b47db --- /dev/null +++ b/src/Shared/HandyControl_Shared/Media/Effects/BlendEffectBox.cs @@ -0,0 +1,116 @@ +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Markup; +using System.Windows.Media.Effects; + +namespace HandyControl.Media.Effects +{ + [DefaultProperty("Content")] + [ContentProperty("Content")] + public class BlendEffectBox : Control + { + private readonly ContentPresenter _effectBottomPresenter; + + private readonly ContentPresenter _effectTopPresenter; + + private bool _isInternalAction; + + public BlendEffectBox() + { + _effectTopPresenter = new ContentPresenter(); + ActualContent = _effectTopPresenter; + + _effectBottomPresenter = new ContentPresenter(); + _effectBottomPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding(ContentProperty.Name) + { + Source = this + }); + + var effects = new ObservableCollection(); + effects.CollectionChanged += OnEffectsChanged; + Effects = effects; + } + + private void OnEffectsChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (Effects == null || Effects.Count == 0) + { + ClearEffect(_effectTopPresenter); + return; + } + + if (_isInternalAction) return; + + _isInternalAction = true; + AddEffect(_effectTopPresenter, Effects.Count); + _isInternalAction = false; + } + + private void ClearEffect(ContentPresenter presenter) + { + if (presenter == null) return; + + if (ReferenceEquals(_effectBottomPresenter, presenter)) + { + _effectBottomPresenter.SetCurrentValue(EffectProperty, null); + return; + } + + presenter.SetCurrentValue(EffectProperty, null); + ClearEffect(presenter.Content as ContentPresenter); + } + + private void AddEffect(ContentPresenter presenter, int count) + { + var newCount = --count; + + if (newCount >= 0) + { + presenter.Effect = Effects[newCount]; + + var nextCount = --count; + if (nextCount >= 1) + { + var content = new ContentPresenter(); + presenter.Content = content; + AddEffect(content, newCount); + } + else if (nextCount >= 0) + { + _effectBottomPresenter.Effect = Effects[0]; + presenter.Content = _effectBottomPresenter; + } + else + { + presenter.Content = _effectBottomPresenter; + } + } + } + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] + [Bindable(true)] + public Collection Effects { get; } + + public static readonly DependencyProperty ContentProperty = DependencyProperty.Register( + "Content", typeof(FrameworkElement), typeof(BlendEffectBox), new PropertyMetadata(default(FrameworkElement))); + + public FrameworkElement Content + { + get => (FrameworkElement)GetValue(ContentProperty); + set => SetValue(ContentProperty, value); + } + + internal static readonly DependencyProperty ActualContentProperty = DependencyProperty.Register( + "ActualContent", typeof(FrameworkElement), typeof(BlendEffectBox), new PropertyMetadata(default(FrameworkElement))); + + internal FrameworkElement ActualContent + { + get => (FrameworkElement) GetValue(ActualContentProperty); + set => SetValue(ActualContentProperty, value); + } + } +} \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Media/Effects/BlendEffectMode.cs b/src/Shared/HandyControl_Shared/Media/Effects/BlendEffectMode.cs deleted file mode 100644 index 5c15ad70..00000000 --- a/src/Shared/HandyControl_Shared/Media/Effects/BlendEffectMode.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace HandyControl.Media.Effects -{ - public enum BlendEffectMode - { - Multiply, - Screen, - Darken, - Lighten, - Dissolve, - ColorBurn, - LinearBurn, - DarkerColor, - LighterColor, - ColorDodge, - LinearDodge, - Overlay, - SoftLight, - HardLight, - VividLight, - LinearLight, - PinLight, - HardMix, - Difference, - Exclusion, - Hue, - Saturation, - Color, - Luminosity, - Subtract, - Division - } -} diff --git a/src/Shared/HandyControl_Shared/Resources/Effects/MultiplyBlendEffect.fx b/src/Shared/HandyControl_Shared/Resources/Effects/MultiplyBlendEffect.fx deleted file mode 100644 index 5a83692b..00000000 --- a/src/Shared/HandyControl_Shared/Resources/Effects/MultiplyBlendEffect.fx +++ /dev/null @@ -1,15 +0,0 @@ -sampler2D background : register(s0); -sampler2D foreground : register(s1); - -float4 main(float2 uv : TEXCOORD) : COLOR -{ - float4 b = tex2D(background, uv); - float4 f = tex2D(foreground, uv); - float4 o = b; - - f.rgb *= f.a; - b.rgb *= b.a; - o.rgb = f.rgb * b.rgb + f.rgb * (1 - b.a) + b.rgb * (1 - f.a); - - return o; -} \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Resources/Effects/MultiplyBlendEffect.ps b/src/Shared/HandyControl_Shared/Resources/Effects/MultiplyBlendEffect.ps deleted file mode 100644 index c6b86762..00000000 Binary files a/src/Shared/HandyControl_Shared/Resources/Effects/MultiplyBlendEffect.ps and /dev/null differ diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/BlendEffectBox.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/BlendEffectBox.xaml new file mode 100644 index 00000000..e10faffb --- /dev/null +++ b/src/Shared/HandyControl_Shared/Themes/Styles/BlendEffectBox.xaml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Style.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Style.xaml index 6b0c7b0d..e7a0184c 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/Style.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Style.xaml @@ -84,6 +84,7 @@ + \ No newline at end of file