add MultiplyBlendEffect

This commit is contained in:
NaBian committed 2020-02-21 23:56:42 +08:00
1 parent 24d323c09d
commit f6da5e1101
15 files changed
+502 -71

No files matched your search

@@ -0,0 +1,61 @@
//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<BlendEffectMode, PixelShader> 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<BlendEffectMode, PixelShader>();
}
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);
}
}
}
@@ -0,0 +1,32 @@
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
}
}