功能更新
This commit is contained in:
87
Melskin/Effects/BrightnessContrastEffect.cs
Normal file
87
Melskin/Effects/BrightnessContrastEffect.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System.Windows.Media.Effects;
|
||||
using Melskin.Appearance;
|
||||
|
||||
namespace Melskin.Effects;
|
||||
|
||||
/// <summary>
|
||||
/// 亮度对比度效果类。此效果用于调整图像或控件的亮度和对比度。
|
||||
/// 继承自ShaderEffect,使用像素着色器实现对输入源的亮度和对比度调节功能。
|
||||
/// </summary>
|
||||
public class BrightnessContrastEffect : ShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置作为效果输入的画刷。此属性定义了应用亮度对比度调整的基础图像或控件。
|
||||
/// 通过设置不同的画刷,可以改变效果作用的对象。
|
||||
/// </summary>
|
||||
public Brush Input
|
||||
{
|
||||
get => (Brush)GetValue(InputProperty);
|
||||
set => SetValue(InputProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置作为效果输入的画刷。此属性定义了应用亮度对比度调整的基础图像或控件。
|
||||
/// 通过设置不同的画刷,可以改变效果作用的对象。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty InputProperty
|
||||
= RegisterPixelShaderSamplerProperty("Input",
|
||||
typeof(BrightnessContrastEffect), 0);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置亮度效果的值。此属性允许用户调整应用到图像或控件上的亮度级别。
|
||||
/// 亮度值为0时,表示没有亮度调整;正值增加亮度,负值减少亮度。
|
||||
/// </summary>
|
||||
public double Brightness
|
||||
{
|
||||
get => (double)GetValue(BrightnessProperty);
|
||||
set => SetValue(BrightnessProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置亮度效果的值。此属性允许用户调整应用到图像或控件上的亮度级别。
|
||||
/// 亮度值为0时,表示没有亮度调整;正值增加亮度,负值减少亮度。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty BrightnessProperty =
|
||||
DependencyProperty.Register(nameof(Brightness), typeof(double),
|
||||
typeof(BrightnessContrastEffect),
|
||||
new PropertyMetadata(0.0, PixelShaderConstantCallback(0)));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置对比度效果的值。此属性允许用户调整应用到图像或控件上的对比度级别。
|
||||
/// 对比度值为0时,表示没有对比度调整;正值增加对比度,负值减少对比度。
|
||||
/// </summary>
|
||||
public double Contrast
|
||||
{
|
||||
get => (double)GetValue(ContrastProperty);
|
||||
set => SetValue(ContrastProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置对比度效果的值。此属性允许用户调整应用到图像或控件上的对比度级别。
|
||||
/// 对比度值为0时,表示没有对比度调整;正值增加对比度,负值减少对比度。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty ContrastProperty =
|
||||
DependencyProperty.Register(nameof(Contrast), typeof(double),
|
||||
typeof(BrightnessContrastEffect),
|
||||
new PropertyMetadata(0.0, PixelShaderConstantCallback(1)));
|
||||
|
||||
/// <summary>
|
||||
/// 亮度对比度效果类。此效果用于调整图像或控件的亮度和对比度。
|
||||
/// 继承自ShaderEffect,使用像素着色器实现对输入源的亮度和对比度调节功能。
|
||||
/// </summary>
|
||||
public BrightnessContrastEffect()
|
||||
{
|
||||
var shaderUri = $"pack://application:,,,/{ThemeManager.LibraryNamespace};component/Shaders/BrightnessContrastEffect.ps";
|
||||
PixelShader = new PixelShader()
|
||||
{
|
||||
UriSource = new Uri(shaderUri)
|
||||
};
|
||||
|
||||
UpdateShaderValue(InputProperty);
|
||||
UpdateShaderValue(BrightnessProperty);
|
||||
UpdateShaderValue(ContrastProperty);
|
||||
}
|
||||
|
||||
}
|
||||
149
Melskin/Effects/LightedSurfaceEffect.cs
Normal file
149
Melskin/Effects/LightedSurfaceEffect.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System.Windows.Media.Effects;
|
||||
using Melskin.Appearance;
|
||||
|
||||
namespace Melskin.Effects;
|
||||
|
||||
/// <summary>
|
||||
/// LightedSurfaceEffect 类用于创建一个光照表面的效果。它继承自 ShaderEffect,利用像素着色器来实现特定的视觉效果。
|
||||
/// 该效果能够根据鼠标位置、UI尺寸、光源大小、强度和颜色等参数动态改变表面的光照效果。
|
||||
/// </summary>
|
||||
public class LightedSurfaceEffect : ShaderEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// 输入属性,用于指定光照表面效果所应用的画刷。此属性允许设置一个Brush对象作为像素着色器的输入源,从而影响最终渲染的视觉效果。
|
||||
/// </summary>
|
||||
public Brush Input
|
||||
{
|
||||
get => (Brush)GetValue(InputProperty);
|
||||
set => SetValue(InputProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 输入属性的依赖属性标识符,用于定义画刷输入源。此属性允许设置一个Brush对象作为像素着色器的数据源,进而影响光照表面效果的视觉呈现。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty InputProperty
|
||||
= RegisterPixelShaderSamplerProperty("Input",
|
||||
typeof(LightedSurfaceEffect), 0);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标相对控件位置
|
||||
/// </summary>
|
||||
public Point MousePosition
|
||||
{
|
||||
get => (Point)GetValue(MousePositionProperty);
|
||||
set => SetValue(MousePositionProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于定义鼠标位置的依赖属性,该属性影响光照表面效果的位置计算。通过更改此属性的值,可以动态更新光照效果中鼠标位置相关的视觉表现。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty MousePositionProperty =
|
||||
DependencyProperty.Register(nameof(MousePosition),
|
||||
typeof(Point), typeof(LightedSurfaceEffect),
|
||||
new PropertyMetadata(new Point(100,20),
|
||||
PixelShaderConstantCallback(0)));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 控件的大小,表示为宽度和高度的点。
|
||||
/// </summary>
|
||||
public Point UiSize
|
||||
{
|
||||
get => (Point)GetValue(UiSizeProperty);
|
||||
set => SetValue(UiSizeProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UI尺寸属性,用于指定应用光照效果的控件大小。此属性影响光照效果在UI元素上的呈现方式。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty UiSizeProperty =
|
||||
DependencyProperty.Register(nameof(UiSize),
|
||||
typeof(Point), typeof(LightedSurfaceEffect),
|
||||
new PropertyMetadata(new Point(200,40),
|
||||
PixelShaderConstantCallback(1)));
|
||||
|
||||
/// <summary>
|
||||
/// 光照大小
|
||||
/// </summary>
|
||||
|
||||
public double LightSize
|
||||
{
|
||||
get => (double)GetValue(LightSizeProperty);
|
||||
set => SetValue(LightSizeProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 光源大小属性,用于控制光照效果中光源的尺寸。此属性影响光照覆盖范围,值越大则光照区域越广。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty LightSizeProperty =
|
||||
DependencyProperty.Register(nameof(LightSize),
|
||||
typeof(double), typeof(LightedSurfaceEffect),
|
||||
new PropertyMetadata(40.0,
|
||||
PixelShaderConstantCallback(2)));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 光照效果的强度
|
||||
/// </summary>
|
||||
public double Intensity
|
||||
{
|
||||
get => (double)GetValue(IntensityProperty);
|
||||
set => SetValue(IntensityProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 光照强度属性。此属性控制光照效果的强度,值越大表示光照越强。
|
||||
/// </summary>
|
||||
// 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)));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 光源颜色,用于定义光照效果的颜色。
|
||||
/// </summary>
|
||||
public Color LightColor
|
||||
{
|
||||
get => (Color)GetValue(LightColorProperty);
|
||||
set => SetValue(LightColorProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 光源颜色属性,用于定义光照效果的颜色。此属性影响光照在表面上的视觉呈现。
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty LightColorProperty =
|
||||
DependencyProperty.Register(nameof(LightColor),
|
||||
typeof(Color), typeof(LightedSurfaceEffect),
|
||||
new PropertyMetadata(Color.FromArgb(255,255,255,255),
|
||||
PixelShaderConstantCallback(4)));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// LightedSurfaceEffect 类用于创建一个光照表面的效果。它继承自 ShaderEffect,利用像素着色器来实现特定的视觉效果。
|
||||
/// 该效果能够根据鼠标位置、UI尺寸、光源大小、强度和颜色等参数动态改变表面的光照效果。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 通过设置不同的属性值可以控制光照效果的具体表现形式,包括光源的位置(MousePosition)、UI组件的尺寸(UiSize)、
|
||||
/// 光源的大小(LightSize)、光照强度(Intensity)以及光源的颜色(LightColor)。这些属性的变化会实时影响到呈现出来的光照效果,
|
||||
/// 使得用户界面更加生动和互动。
|
||||
/// </remarks>
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user