using System.Windows.Media.Effects; using Melskin.Appearance; namespace Melskin.Effects; /// /// LightedSurfaceEffect 类用于创建一个光照表面的效果。它继承自 ShaderEffect,利用像素着色器来实现特定的视觉效果。 /// 该效果能够根据鼠标位置、UI尺寸、光源大小、强度和颜色等参数动态改变表面的光照效果。 /// public class LightedSurfaceEffect : ShaderEffect { /// /// 输入属性,用于指定光照表面效果所应用的画刷。此属性允许设置一个Brush对象作为像素着色器的输入源,从而影响最终渲染的视觉效果。 /// public Brush Input { get => (Brush)GetValue(InputProperty); set => SetValue(InputProperty, value); } /// /// 输入属性的依赖属性标识符,用于定义画刷输入源。此属性允许设置一个Brush对象作为像素着色器的数据源,进而影响光照表面效果的视觉呈现。 /// public static readonly DependencyProperty InputProperty = RegisterPixelShaderSamplerProperty("Input", typeof(LightedSurfaceEffect), 0); /// /// 鼠标相对控件位置 /// public Point MousePosition { get => (Point)GetValue(MousePositionProperty); set => SetValue(MousePositionProperty, value); } /// /// 用于定义鼠标位置的依赖属性,该属性影响光照表面效果的位置计算。通过更改此属性的值,可以动态更新光照效果中鼠标位置相关的视觉表现。 /// public static readonly DependencyProperty MousePositionProperty = DependencyProperty.Register(nameof(MousePosition), typeof(Point), typeof(LightedSurfaceEffect), new PropertyMetadata(new Point(100,20), PixelShaderConstantCallback(0))); /// /// 控件的大小,表示为宽度和高度的点。 /// public Point UiSize { get => (Point)GetValue(UiSizeProperty); set => SetValue(UiSizeProperty, value); } /// /// UI尺寸属性,用于指定应用光照效果的控件大小。此属性影响光照效果在UI元素上的呈现方式。 /// public static readonly DependencyProperty UiSizeProperty = DependencyProperty.Register(nameof(UiSize), typeof(Point), typeof(LightedSurfaceEffect), new PropertyMetadata(new Point(200,40), PixelShaderConstantCallback(1))); /// /// 光照大小 /// public double LightSize { get => (double)GetValue(LightSizeProperty); set => SetValue(LightSizeProperty, value); } /// /// 光源大小属性,用于控制光照效果中光源的尺寸。此属性影响光照覆盖范围,值越大则光照区域越广。 /// public static readonly DependencyProperty LightSizeProperty = DependencyProperty.Register(nameof(LightSize), typeof(double), typeof(LightedSurfaceEffect), new PropertyMetadata(40.0, PixelShaderConstantCallback(2))); /// /// 光照效果的强度 /// public double Intensity { get => (double)GetValue(IntensityProperty); set => SetValue(IntensityProperty, value); } /// /// 光照强度属性。此属性控制光照效果的强度,值越大表示光照越强。 /// // Using a DependencyProperty as the backing store for Intensity. public static readonly DependencyProperty IntensityProperty = DependencyProperty.Register(nameof(Intensity), typeof(double), typeof(LightedSurfaceEffect), new PropertyMetadata(1.0, PixelShaderConstantCallback(3))); /// /// 光源颜色,用于定义光照效果的颜色。 /// public Color LightColor { get => (Color)GetValue(LightColorProperty); set => SetValue(LightColorProperty, value); } /// /// 光源颜色属性,用于定义光照效果的颜色。此属性影响光照在表面上的视觉呈现。 /// public static readonly DependencyProperty LightColorProperty = DependencyProperty.Register(nameof(LightColor), typeof(Color), typeof(LightedSurfaceEffect), new PropertyMetadata(Color.FromArgb(255,255,255,255), PixelShaderConstantCallback(4))); /// /// LightedSurfaceEffect 类用于创建一个光照表面的效果。它继承自 ShaderEffect,利用像素着色器来实现特定的视觉效果。 /// 该效果能够根据鼠标位置、UI尺寸、光源大小、强度和颜色等参数动态改变表面的光照效果。 /// /// /// 通过设置不同的属性值可以控制光照效果的具体表现形式,包括光源的位置(MousePosition)、UI组件的尺寸(UiSize)、 /// 光源的大小(LightSize)、光照强度(Intensity)以及光源的颜色(LightColor)。这些属性的变化会实时影响到呈现出来的光照效果, /// 使得用户界面更加生动和互动。 /// public LightedSurfaceEffect() { var shaderUri = $"pack://application:,,,/{ThemeManager.LibraryNamespace};component/Shaders/LightedSurfaceEffect.ps"; PixelShader = new PixelShader() { UriSource = new Uri(shaderUri) }; UpdateShaderValue(InputProperty); UpdateShaderValue(MousePositionProperty); UpdateShaderValue(UiSizeProperty); UpdateShaderValue(LightSizeProperty); UpdateShaderValue(LightColorProperty); UpdateShaderValue(IntensityProperty); } }