1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Updated Implementing an own brush (markdown)

DarthAffe 2017-01-15 11:37:19 +01:00
parent 212ad592fd
commit 14bf5d4f68

@ -22,6 +22,20 @@ public class SolidColorBrush : AbstractBrush
```
As you can see the _[SolidColorBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/SolidColorBrush.cs)_ doesn't care about what key or rectangle is rendered and therefore just ignores the passed parameters.
In most cases we want to draw something though, so we need to calculate our color from the given information. A good example here is the _[LinearGradientBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/LinearGradientBrush.cs)_
In most cases we want to draw something though, so we need to calculate our color from the given information. A good example here is the _[LinearGradientBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/LinearGradientBrush.cs)_.
```c#
protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{
if (Gradient == null) return CorsairColor.Transparent;
PointF startPoint = new PointF(StartPoint.X * rectangle.Width, StartPoint.Y * rectangle.Height);
PointF endPoint = new PointF(EndPoint.X * rectangle.Width, EndPoint.Y * rectangle.Height);
float offset = GradientHelper.CalculateLinearGradientOffset(startPoint, endPoint, renderTarget.Point);
return Gradient.GetColor(offset);
}
```
First it uses the size of the provided rectangle to calculate a start- and end-point for the gradient. After wards it using the Point (which reflects the center of the requested key) provided by the _[renderTarget](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/BrushRenderTarget.cs)_ to calculate the offset which is finally used to return the color on the gradient.
Note that you can not only get the point of the _[renderTarget](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/BrushRenderTarget.cs)_ but also the whole rectangle representing the key and the Id of the key.
### The advanced way