diff --git a/Implementing-an-own-brush.md b/Implementing-an-own-brush.md index 330c6ef..5c78870 100644 --- a/Implementing-an-own-brush.md +++ b/Implementing-an-own-brush.md @@ -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 \ No newline at end of file