mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 04:56:44 +00:00
Added RadialGradientBrush
This commit is contained in:
1 parent
f7b8fe130c
commit
70f8a54a38
3 files changed
+64
-2
No files matched your search
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using CUE.NET.Devices.Keyboard.Brushes.Gradient;
|
||||
using CUE.NET.Helper;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Brushes
|
||||
{
|
||||
public class RadialGradientBrush : AbstractBrush
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public PointF Center { get; set; } = new PointF(0.5f, 0.5f);
|
||||
public IGradient Gradient { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public RadialGradientBrush()
|
||||
{ }
|
||||
|
||||
public RadialGradientBrush(IGradient gradient)
|
||||
{
|
||||
this.Gradient = gradient;
|
||||
}
|
||||
|
||||
public RadialGradientBrush(PointF center, IGradient gradient)
|
||||
{
|
||||
this.Center = center;
|
||||
this.Gradient = gradient;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override Color GetColorAtPoint(RectangleF rectangle, PointF point)
|
||||
{
|
||||
PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y);
|
||||
|
||||
// Calculate the distance to the farthest point from the center as reference (this has to be a corner)
|
||||
float refDistance = (float)Math.Max(Math.Max(Math.Max(GradientHelper.CalculateDistance(rectangle.Location, centerPoint),
|
||||
GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y), centerPoint)),
|
||||
GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)),
|
||||
GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), centerPoint));
|
||||
|
||||
float distance = GradientHelper.CalculateDistance(point, centerPoint);
|
||||
float offset = distance / refDistance;
|
||||
return FinalizeColor(Gradient.GetColor(offset));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user