diff --git a/Implementing-an-own-brush.md b/Implementing-an-own-brush.md index f2f4e84..330c6ef 100644 --- a/Implementing-an-own-brush.md +++ b/Implementing-an-own-brush.md @@ -1,20 +1,27 @@ -Implementing an own brush is quite easy. -All you need to do is implementing the _IBrush_-interface which looks like this: -```C# -public interface IBrush +Implementing an own brush is done by implementing the _[IBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/IBrush.cs)_-Interface, but since a lot of logic regarding effects and general configuration is the same for all brushes you should always start by deriving from _[AbstractBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/AbstractBrush.cs)_. + +> You should always start by deriving from **_[AbstractBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/AbstractBrush.cs)_**! If you don't do this you'll have to make sure to take care of the logic regarding effects and rendering. + +Starting here there are two ways to create your own logic. + +### The simple way +This should be the preferred way for almost every case since it's possible to achieve nearly everything without much effort. Every basic-brush shipped with CUE.NET is implemented this way. + +You start by simply deriving from _[AbstractBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/AbstractBrush.cs)_ and implementing the _GetColorAtPoint_-Method which should contain the logic your brush needs to decide which color goes where. +The easiest example here is the _[SolidColorBrush](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/SolidColorBrush.cs)_. It stores a color-property containing the color which is simply returned on every call to _GetColorAtPoint_, coloring the whole region in a single color. +```c# +public class SolidColorBrush : AbstractBrush { - float Brightness { get; set; } - float Opacity { get; set; } - Color GetColorAtPoint(RectangleF rectangle, PointF point); + public CorsairColor Color { get; set; } + + protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget) + { + return Color; + } } ``` -> **Since the _Brightness_ and _Opacity_ is something generic you should always derive from the [_AbstractBrush_-](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/AbstractBrush.cs)Class.** -> If you do this, you'll only have to implement the _GetColorAtPoint_-method. +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 the _GetColorAtPoint_-method you'll have to calculate and return the color of one specific point (representing a key) inside a rectangle (representing the keyboard or keygroup). Both, the point and the rectangle are given as parameters. - -> Before you return your calculated Color you should always call the _FinalizeColor_-method to apply the overall brightness and opacity. -> If you don't derive from the _AbstractBrush_-Class you'll have to to take care about this by yourself. - -If you need a reference on how the implementation might look, you can take the [_LinearGradientBrush_](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/LinearGradientBrush.cs), the [_RadialGradientBrush_](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/RadialGradientBrush.cs) or the [_SolidColorBrush_](https://github.com/DarthAffe/CUE.NET/blob/master/Brushes/SolidColorBrush.cs). \ No newline at end of file +### The advanced way \ No newline at end of file