From 37d4b31247d07fe28e719a77f680d6dff6a9c255 Mon Sep 17 00:00:00 2001 From: Logan Saso Date: Fri, 5 Feb 2016 00:16:35 -0800 Subject: [PATCH] Added color reset for pixels that shouldn't be lit. It seems like the resize in the bitmap constructor is not high quality, research is needed. --- .../Artemis/KeyboardProviders/Corsair/K95.cs | 106 +++++++++--------- 1 file changed, 56 insertions(+), 50 deletions(-) diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs index 08c899437..df000f39f 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs @@ -1,55 +1,61 @@ -using System.Drawing; -using CUE.NET; -using CUE.NET.Devices.Generic.Enums; -using CUE.NET.Devices.Keyboard; -using CUE.NET.Brushes; -using CUE.NET.Devices.Keyboard.Keys; - -namespace Artemis.KeyboardProviders.Corsair -{ - internal class K95 : KeyboardProvider - { - private CorsairKeyboard _keyboard; - - public K95() - { - Name = "Corsair Gaming K95 RGB"; - } - - /// - /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. - /// - public override void Enable() - { - try - { - CueSDK.Initialize(); - } - catch (CUE.NET.Exceptions.WrapperException){/*CUE is already initialized*/} - _keyboard = CueSDK.KeyboardSDK; - Height = (int)_keyboard.KeyboardRectangle.Height; - Width = (int)_keyboard.KeyboardRectangle.Width; - - _keyboard.UpdateMode = UpdateMode.Manual; - _keyboard.Brush = new SolidColorBrush(Color.Black); - _keyboard.Update(true); - } - - public override void Disable() - { - } - - /// - /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap size. - /// Does not reset the color each time. Uncomment line 48 for collor reset. - /// - /// - public override void DrawBitmap(Bitmap bitmap) +using System.Drawing; +using CUE.NET; +using CUE.NET.Devices.Generic.Enums; +using CUE.NET.Devices.Keyboard; +using CUE.NET.Brushes; +using CUE.NET.Devices.Keyboard.Keys; +using System; + +namespace Artemis.KeyboardProviders.Corsair +{ + internal class K95 : KeyboardProvider + { + private CorsairKeyboard _keyboard; + + public K95() { + Name = "Corsair Gaming K95 RGB"; + } + + /// + /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. + /// + public override void Enable() + { + try + { + CueSDK.Initialize(); + } + catch (CUE.NET.Exceptions.WrapperException){/*CUE is already initialized*/} + _keyboard = CueSDK.KeyboardSDK; + Height = (int)_keyboard.KeyboardRectangle.Height; + Width = (int)_keyboard.KeyboardRectangle.Width; + + // _keyboard.UpdateMode = UpdateMode.Manual; + _keyboard.Update(true); + } + + public override void Disable() + { + } + + /// + /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap size. + /// Does not reset the color each time. Uncomment line 48 for collor reset. + /// + /// + public override void DrawBitmap(Bitmap bitmap) + { + //bitmap = new Bitmap(@"C:\Users\Hazard\Desktop\1920x1080.png"); Bitmap resize = new Bitmap(bitmap, new Size((int)_keyboard.KeyboardRectangle.Width, (int)_keyboard.KeyboardRectangle.Height)); foreach (var item in _keyboard.Keys) { - item.Led.Color = resize.GetPixel((int)item.KeyRectangle.X, (int)item.KeyRectangle.Y); + Color pixelColor = resize.GetPixel((int)item.KeyRectangle.X, (int)item.KeyRectangle.Y); + if (pixelColor.Name == "0") + { + pixelColor = Color.Black; + } + item.Led.Color = pixelColor; } _keyboard.Update(); } @@ -74,6 +80,6 @@ namespace Artemis.KeyboardProviders.Corsair _keyboard.DetachKeyGroup(ledGroups[x, y]); } } - */ - } + */ + } } \ No newline at end of file