mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 09:08:34 +00:00
Updated Implementing an own brush (markdown)
parent
2d7fcd4390
commit
212ad592fd
@ -1,20 +1,27 @@
|
|||||||
Implementing an own brush is quite easy.
|
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)_.
|
||||||
All you need to do is implementing the _IBrush_-interface which looks like this:
|
|
||||||
```C#
|
> 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.
|
||||||
public interface IBrush
|
|
||||||
|
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; }
|
public CorsairColor Color { get; set; }
|
||||||
float Opacity { get; set; }
|
|
||||||
Color GetColorAtPoint(RectangleF rectangle, PointF point);
|
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.**
|
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.
|
||||||
> If you do this, you'll only have to implement the _GetColorAtPoint_-method.
|
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.
|
### The advanced way
|
||||||
|
|
||||||
> 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).
|
|
||||||
Loading…
x
Reference in New Issue
Block a user