From 93d94fdc5ab74a20f1281ea1e9a4adb3cac13c16 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 25 Mar 2016 23:17:38 +0100 Subject: [PATCH] Added a selection for BrushCalculationModes (relative/absolute) --- CUE.NET.csproj | 1 + Devices/Keyboard/CorsairKeyboard.cs | 31 ++++++++++++++----- .../Keyboard/Enums/BrushCalculationMode.cs | 17 ++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 Devices/Keyboard/Enums/BrushCalculationMode.cs diff --git a/CUE.NET.csproj b/CUE.NET.csproj index b7d5900..d4cde53 100644 --- a/CUE.NET.csproj +++ b/CUE.NET.csproj @@ -52,6 +52,7 @@ + diff --git a/Devices/Keyboard/CorsairKeyboard.cs b/Devices/Keyboard/CorsairKeyboard.cs index 800a80d..c904629 100644 --- a/Devices/Keyboard/CorsairKeyboard.cs +++ b/Devices/Keyboard/CorsairKeyboard.cs @@ -105,6 +105,11 @@ namespace CUE.NET.Devices.Keyboard /// public int ZIndex { get; set; } = 0; + /// + /// Gets or sets the calculation mode used for the rectangle/points used for color-selection in brushes. + /// + public BrushCalculationMode BrushCalculationMode { get; set; } = BrushCalculationMode.Relative; + /// /// Gets a value indicating if the keyboard has an active effect to deal with or not. /// @@ -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); } diff --git a/Devices/Keyboard/Enums/BrushCalculationMode.cs b/Devices/Keyboard/Enums/BrushCalculationMode.cs new file mode 100644 index 0000000..26fec22 --- /dev/null +++ b/Devices/Keyboard/Enums/BrushCalculationMode.cs @@ -0,0 +1,17 @@ +namespace CUE.NET.Devices.Keyboard.Enums +{ + /// + /// Contains list of all brush calculation modes. + /// + public enum BrushCalculationMode + { + /// + /// The calculation rectangle for brushes will be the rectangle around the keygroup the brush is applied to. + /// + Relative, + /// + /// The calculation rectangle for brushes will always be the whole keyboard. + /// + Absolute + } +}