Skip to content
This repository has been archived by the owner on Aug 6, 2021. It is now read-only.

Implementing an own brush

DarthAffe edited this page Jan 15, 2017 · 6 revisions

Implementing an own brush is done by implementing the IBrush-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.

You should always start by deriving from AbstractBrush! 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 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. 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.

public class SolidColorBrush : AbstractBrush
{
    public CorsairColor Color { get; set; }

    protected override CorsairColor GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
    {
        return Color;
    }
}

As you can see the SolidColorBrush 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

The advanced way