更新
This commit is contained in:
206
WPFDark/Controls/Effects/HsvWheelBackgroundEffect.cs
Normal file
206
WPFDark/Controls/Effects/HsvWheelBackgroundEffect.cs
Normal file
@@ -0,0 +1,206 @@
|
||||
using WPFDark.Internals;
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Effects;
|
||||
|
||||
using System.Windows.Media.Media3D;
|
||||
namespace WPFDark.Controls.Effects
|
||||
{
|
||||
internal class HsvWheelBackgroundEffect : ShaderEffect
|
||||
{
|
||||
static HsvWheelBackgroundEffect()
|
||||
{
|
||||
_PixelShader = new PixelShader
|
||||
{
|
||||
UriSource = new Uri($"pack://application:,,,/{ThemeManager.LibraryNamespace};component/Controls/Effects/HsvWheelBackgroundEffect.ps")
|
||||
};
|
||||
|
||||
_PixelShader.Freeze();
|
||||
}
|
||||
|
||||
// ReSharper disable once InconsistentNaming
|
||||
private static readonly PixelShader _PixelShader;
|
||||
|
||||
internal HsvWheelBackgroundEffect()
|
||||
{
|
||||
PixelShader = _PixelShader;
|
||||
UpdateShaderValue(ValueProperty);
|
||||
UpdateShaderValue(AspectRatioCorrectionXProperty);
|
||||
UpdateShaderValue(AspectRatioCorrectionYProperty);
|
||||
UpdateShaderValue(BorderColorProperty);
|
||||
UpdateShaderValue(IsEnabledProperty);
|
||||
UpdateShaderValue(DisableColorProperty);
|
||||
}
|
||||
|
||||
#region Value
|
||||
|
||||
public double Value
|
||||
{
|
||||
get => value;
|
||||
set
|
||||
{
|
||||
if (NumberHelper.AreClose(value, this.value) == false)
|
||||
SetValue(ValueProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double value;
|
||||
|
||||
public static readonly DependencyProperty ValueProperty =
|
||||
DependencyProperty.Register(nameof(Value), typeof(double), typeof(HsvWheelBackgroundEffect),
|
||||
new PropertyMetadata(
|
||||
0.0,
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (HsvWheelBackgroundEffect)s;
|
||||
self.value = (double)e.NewValue;
|
||||
|
||||
PixelShaderConstantCallback(0)(s, e);
|
||||
}));
|
||||
|
||||
#endregion
|
||||
|
||||
#region AspectRatioCorrectionX
|
||||
|
||||
public double AspectRatioCorrectionX
|
||||
{
|
||||
get => _AspectRatioCorrectionX;
|
||||
set
|
||||
{
|
||||
if (NumberHelper.AreClose(value, _AspectRatioCorrectionX) == false)
|
||||
SetValue(AspectRatioCorrectionXProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _AspectRatioCorrectionX = 1;
|
||||
|
||||
public static readonly DependencyProperty AspectRatioCorrectionXProperty =
|
||||
DependencyProperty.Register(nameof(AspectRatioCorrectionX), typeof(double),
|
||||
typeof(HsvWheelBackgroundEffect),
|
||||
new PropertyMetadata(
|
||||
1.0,
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (HsvWheelBackgroundEffect)s;
|
||||
self._AspectRatioCorrectionX = (double)e.NewValue;
|
||||
|
||||
PixelShaderConstantCallback(1)(s, e);
|
||||
}));
|
||||
|
||||
#endregion
|
||||
|
||||
#region AspectRatioCorrectionY
|
||||
|
||||
public double AspectRatioCorrectionY
|
||||
{
|
||||
get => _AspectRatioCorrectionY;
|
||||
set
|
||||
{
|
||||
if (NumberHelper.AreClose(value, _AspectRatioCorrectionY) == false)
|
||||
SetValue(AspectRatioCorrectionYProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private double _AspectRatioCorrectionY = 1;
|
||||
|
||||
public static readonly DependencyProperty AspectRatioCorrectionYProperty =
|
||||
DependencyProperty.Register(nameof(AspectRatioCorrectionY), typeof(double),
|
||||
typeof(HsvWheelBackgroundEffect),
|
||||
new PropertyMetadata(
|
||||
1.0,
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (HsvWheelBackgroundEffect)s;
|
||||
self._AspectRatioCorrectionY = (double)e.NewValue;
|
||||
|
||||
PixelShaderConstantCallback(2)(s, e);
|
||||
}));
|
||||
|
||||
#endregion
|
||||
|
||||
#region BorderColor
|
||||
|
||||
public Point3D BorderColor
|
||||
{
|
||||
get => borderColor;
|
||||
set
|
||||
{
|
||||
if (value != borderColor)
|
||||
SetValue(BorderColorProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Point3D borderColor = new Point3D(1.0, 0.0, 0.0);
|
||||
|
||||
public static readonly DependencyProperty BorderColorProperty =
|
||||
DependencyProperty.Register(nameof(BorderColor), typeof(Point3D), typeof(HsvWheelBackgroundEffect),
|
||||
new PropertyMetadata(
|
||||
new Point3D(1.0, 0.0, 0.0),
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (HsvWheelBackgroundEffect)s;
|
||||
self.borderColor = (Point3D)e.NewValue;
|
||||
|
||||
PixelShaderConstantCallback(3)(s, e);
|
||||
}));
|
||||
|
||||
#endregion
|
||||
|
||||
#region IsEnabled
|
||||
|
||||
public float IsEnabled
|
||||
{
|
||||
get => isEnabled;
|
||||
set
|
||||
{
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
if (value != isEnabled)
|
||||
SetValue(IsEnabledProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private float isEnabled = 1.0f;
|
||||
|
||||
public static readonly DependencyProperty IsEnabledProperty =
|
||||
DependencyProperty.Register(nameof(IsEnabled), typeof(float), typeof(HsvWheelBackgroundEffect),
|
||||
new PropertyMetadata(
|
||||
1.0f,
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (HsvWheelBackgroundEffect)s;
|
||||
self.isEnabled = (float)e.NewValue;
|
||||
|
||||
PixelShaderConstantCallback(6)(s, e);
|
||||
}));
|
||||
|
||||
#endregion
|
||||
|
||||
#region DisableColor
|
||||
|
||||
public Point3D DisableColor
|
||||
{
|
||||
get => disableColor;
|
||||
set
|
||||
{
|
||||
if (value != disableColor)
|
||||
SetValue(DisableColorProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Point3D disableColor = new(1.0, 0.0, 0.0);
|
||||
|
||||
public static readonly DependencyProperty DisableColorProperty =
|
||||
DependencyProperty.Register(nameof(DisableColor), typeof(Point3D), typeof(HsvWheelBackgroundEffect),
|
||||
new PropertyMetadata(
|
||||
new Point3D(1.0, 0.0, 0.0),
|
||||
(s, e) =>
|
||||
{
|
||||
var self = (HsvWheelBackgroundEffect)s;
|
||||
self.disableColor = (Point3D)e.NewValue;
|
||||
|
||||
PixelShaderConstantCallback(7)(s, e);
|
||||
}));
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user