1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-13 09:08:34 +00:00

Updated Implementing an own brush (markdown)

DarthAffe 2017-01-15 12:09:47 +01:00
parent 14bf5d4f68
commit bd946b325b

@ -2,7 +2,9 @@ Implementing an own brush is done by implementing the _[IBrush](https://github.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.
Starting here there are two ways to create your own logic.
Starting here, there are two ways to create your own logic.
> No mather what way you choose, you should always take a look at the [CUE.NET.Helper-namespace](https://github.com/DarthAffe/CUE.NET/tree/master/Helper)! It contains a few helpers with quite some useful methods.
### 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.
@ -39,3 +41,20 @@ First it uses the size of the provided rectangle to calculate a start- and end-p
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
To understand what writing an advanced brush means, you need to know how brushes are processed.
In CUE.NET brushes perform two passes.
1. **The render-pass**
This is initiated by calling the _PerformRender_-Method. This method calculates the color for every requested LED by calling _GetColorAtPoint_ (we know that one from the simple way) for every single one and builds up a list of processed _BrushRenderTargets_.
2. **The finalize-pass**
This is initiated by calling the _PerformFinalize_-Method. This method is calling _FinalizeColor_ for every _BrushRenderTargets_ in the list created in the render-pass.
The _FinalizeColor_-Method applies brush-wide modifications (color-correction, brightness and opacity) to every processed color.
All four of this methods can be overwritten to hook deeper into that process.
> You should prefer to always call the base-method after your logic when overwriting one of the virtual methods if possible. If not you need to take care of doing logically the same as the original method or you might get unexpected behaviors.
An example of such an advanced brush can be found in the [ambilight-example](https://github.com/DarthAffe/CUE.NET/blob/master/Examples/Ambilight/Example_Ambilight_full/AbstractAmbilightBrush.cs).
It overwrites _PerformRender_ and _FinalizeColor_.
_PerformRender_ is used to create some data needed by every _GetcolorAtPointCall_ and is therefore calculated before the rendering for performance reasons. At the end the original render-sequence is initiated by the 'base.PerformRender'-call.
_FinalizeColor_ is overwritten to replace the original color-correction-logic with one that works better with the settings passed to the brush. This is a use-case-specific implementation to reduce overhead. The rest of the code is just a copy from the base-method since it should behave the same except the color-correction part.