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

Linear Gradient Brush

DarthAffe edited this page Jan 10, 2017 · 3 revisions

The LinearGradientBrush is one of the default brushes provided by CUE.NET.
It's used to draw a gradient as a "line" inside a rectangle.

You are able to define a start and an end-point (both are inter- or extrapolated if needed) and the gradient which should be drawn on the virtual line between this points by either providing them as constructor-parameters or using the StartPoint-, EndPoint- and Gradient-Properties.
If you don't set an gradient the brush will return transparent for every LED.

The Start- and End-Point is given as the percentage from the top left corner.
new PointF(0f, 0f) will be top left, new PointF(0,5f, 0,5f) in the center and new PointF(1f, 1f) in the bottom right.

If you want to create a background on your keyboard looking like this

you could use this code

GradientStop[] gradientStops =
{
    new GradientStop(0f, Color.Blue),
    new GradientStop(1f, Color.Red)
};
LinearGradient blueToRedGradient = new LinearGradient(gradientStops); // Gradient from blue to red
PointF startPoint = new PointF(0f, 1f); // Bottom left corner
PointF endPoint = new PointF(1f, 0f); // Top right corner
LinearGradientBrush linearBrush = new LinearGradientBrush(startPoint, endPoint, blueToRedGradient);
keyboard.Brush = linearBrush;