1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Added a selection for BrushCalculationModes (relative/absolute)

This commit is contained in:
Darth Affe 2016-03-25 23:17:38 +01:00
parent 88ac78f19a
commit 93d94fdc5a
3 changed files with 41 additions and 8 deletions

View File

@ -52,6 +52,7 @@
<Compile Include="Devices\Generic\Enums\CorsairDeviceType.cs" />
<Compile Include="Devices\Generic\ExceptionEventArgs.cs" />
<Compile Include="Brushes\AbstractBrush.cs" />
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
<Compile Include="Gradients\AbstractGradient.cs" />
<Compile Include="Gradients\GradientStop.cs" />
<Compile Include="Gradients\IGradient.cs" />

View File

@ -105,6 +105,11 @@ namespace CUE.NET.Devices.Keyboard
/// </summary>
public int ZIndex { get; set; } = 0;
/// <summary>
/// Gets or sets the calculation mode used for the rectangle/points used for color-selection in brushes.
/// </summary>
public BrushCalculationMode BrushCalculationMode { get; set; } = BrushCalculationMode.Relative;
/// <summary>
/// Gets a value indicating if the keyboard has an active effect to deal with or not.
/// </summary>
@ -178,14 +183,24 @@ namespace CUE.NET.Devices.Keyboard
{
try
{
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));
//TODO DarthAffe 16.03.2016: Rework brushes and replace this workaround with a proper selection of absolute/relative calculations
float offsetX = -brushRectangle.X;
float offsetY = -brushRectangle.Y;
brushRectangle.X = 0;
brushRectangle.Y = 0;
foreach (CorsairKey key in keys)
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter(offsetX, offsetY));
switch (BrushCalculationMode)
{
case BrushCalculationMode.Relative:
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));
float offsetX = -brushRectangle.X;
float offsetY = -brushRectangle.Y;
brushRectangle.X = 0;
brushRectangle.Y = 0;
foreach (CorsairKey key in keys)
key.Led.Color = brush.GetColorAtPoint(KeyboardRectangle, key.KeyRectangle.GetCenter(offsetX, offsetY));
break;
case BrushCalculationMode.Absolute:
foreach (CorsairKey key in keys)
key.Led.Color = brush.GetColorAtPoint(KeyboardRectangle, key.KeyRectangle.GetCenter());
break;
default:
throw new ArgumentException();
}
}
// ReSharper disable once CatchAllClause
catch (Exception ex) { ManageException(ex); }

View File

@ -0,0 +1,17 @@
namespace CUE.NET.Devices.Keyboard.Enums
{
/// <summary>
/// Contains list of all brush calculation modes.
/// </summary>
public enum BrushCalculationMode
{
/// <summary>
/// The calculation rectangle for brushes will be the rectangle around the keygroup the brush is applied to.
/// </summary>
Relative,
/// <summary>
/// The calculation rectangle for brushes will always be the whole keyboard.
/// </summary>
Absolute
}
}