diff --git a/Artemis/Artemis.sln b/Artemis/Artemis.sln index 9566a2c74..48cd72722 100644 --- a/Artemis/Artemis.sln +++ b/Artemis/Artemis.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.23107.0 +VisualStudioVersion = 14.0.24720.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis", "Artemis\Artemis.csproj", "{ED9997A2-E54C-4E9F-9350-62BE672C3ABE}" EndProject diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index d4dc18237..f02ab8248 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -2,41 +2,18 @@ - -
-
-
-
-
-
-
-
-
-
-
+ +
+
+
+
+
+
+
+
+
+
+
@@ -204,7 +181,7 @@ TypeWave - Razer BlackWidow Chroma + Corsair Gaming K95 RGB True @@ -217,6 +194,10 @@ + + + + diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 212859766..b24806b47 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -78,11 +78,15 @@ - ..\packages\Caliburn.Micro.Core.2.0.2\lib\net45\Caliburn.Micro.dll + ..\packages\Caliburn.Micro.Core.3.0.0-beta2\lib\net45\Caliburn.Micro.dll True - ..\packages\Caliburn.Micro.2.0.2\lib\net45\Caliburn.Micro.Platform.dll + ..\packages\Caliburn.Micro.3.0.0-beta2\lib\net45\Caliburn.Micro.Platform.dll + True + + + ..\packages\Caliburn.Micro.3.0.0-beta2\lib\net45\Caliburn.Micro.Platform.Core.dll True @@ -93,12 +97,12 @@ ..\packages\CUE.NET.1.0.0\lib\net45\CUE.NET.dll True - - ..\packages\log4net.2.0.4\lib\net45-full\log4net.dll + + ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll True - - ..\packages\MahApps.Metro.1.1.2.0\lib\net45\MahApps.Metro.dll + + ..\packages\MahApps.Metro.1.3.0-ALPHA017\lib\net45\MahApps.Metro.dll True @@ -113,8 +117,8 @@ ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll True - - ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll True @@ -128,7 +132,7 @@ - ..\packages\MahApps.Metro.1.1.2.0\lib\net45\System.Windows.Interactivity.dll + ..\packages\MahApps.Metro.1.3.0-ALPHA017\lib\net45\System.Windows.Interactivity.dll True @@ -147,28 +151,28 @@ - - ..\packages\Extended.Wpf.Toolkit.2.5\lib\net40\Xceed.Wpf.AvalonDock.dll + + ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.dll True - - ..\packages\Extended.Wpf.Toolkit.2.5\lib\net40\Xceed.Wpf.AvalonDock.Themes.Aero.dll + + ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.Themes.Aero.dll True - - ..\packages\Extended.Wpf.Toolkit.2.5\lib\net40\Xceed.Wpf.AvalonDock.Themes.Metro.dll + + ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.Themes.Metro.dll True - - ..\packages\Extended.Wpf.Toolkit.2.5\lib\net40\Xceed.Wpf.AvalonDock.Themes.VS2010.dll + + ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.AvalonDock.Themes.VS2010.dll True - - ..\packages\Extended.Wpf.Toolkit.2.5\lib\net40\Xceed.Wpf.DataGrid.dll + + ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.DataGrid.dll True - - ..\packages\Extended.Wpf.Toolkit.2.5\lib\net40\Xceed.Wpf.Toolkit.dll + + ..\packages\Extended.Wpf.Toolkit.2.6\lib\net40\Xceed.Wpf.Toolkit.dll True diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs index cd0c8b521..686076ab7 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs @@ -1,7 +1,10 @@ using System.Drawing; using CUE.NET; +using CUE.NET.Brushes; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Keyboard; +using CUE.NET.Devices.Keyboard.Keys; +using CUE.NET.Exceptions; namespace Artemis.KeyboardProviders.Corsair { @@ -14,27 +17,61 @@ namespace Artemis.KeyboardProviders.Corsair 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 (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(); } 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) { - // TODO: Resize bitmap to keyboard's size - //if (bitmap.Width > width || bitmap.Height > height) - // bitmap = ResizeImage(bitmap, width, height); - - // One way of doing this, not sure at all if it's any good - for (var y = 0; y < bitmap.Height - 1; y++) - for (var x = 0; x < bitmap.Width - 1; x++) - _keyboard[new PointF(x, y)].Led.Color = bitmap.GetPixel(x, y); - + var ledRectangles = new RectangleF[bitmap.Width, bitmap.Height]; + var ledGroups = new RectangleKeyGroup[bitmap.Width, bitmap.Height]; + //_keyboard.Brush = new SolidColorBrush(Color.Black); + for (var x = 0; x < bitmap.Width; x++) + { + for (var y = 0; y < bitmap.Height; y++) + { + ledRectangles[x, y] = + new RectangleF( + _keyboard.KeyboardRectangle.X* + (x*(_keyboard.KeyboardRectangle.Width/bitmap.Width/_keyboard.KeyboardRectangle.X)), + _keyboard.KeyboardRectangle.Y* + (y*(_keyboard.KeyboardRectangle.Height/bitmap.Height/_keyboard.KeyboardRectangle.Y)), + _keyboard.KeyboardRectangle.Width/bitmap.Width, + _keyboard.KeyboardRectangle.Height/bitmap.Height); + ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.1f) + { + Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) + }; + } + } _keyboard.Update(true); } } diff --git a/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs b/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs index b5b88c39b..b1f3dd154 100644 --- a/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs +++ b/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs @@ -16,12 +16,12 @@ namespace Artemis.KeyboardProviders /// Returns a bitmap matching the keyboard's dimensions /// /// - public Bitmap KeyboardBitmap() => new Bitmap(Height, Width); + public Bitmap KeyboardBitmap() => new Bitmap(Width, Height); /// /// Returns a bitmap matching the keyboard's dimensions using the provided scale /// /// - public Bitmap KeyboardBitmap(int scale) => new Bitmap(Height*scale, Width*scale); + public Bitmap KeyboardBitmap(int scale) => new Bitmap(Width*scale, Height*scale); } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs b/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs index 7fa77342e..5bc986d26 100644 --- a/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs +++ b/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs @@ -10,13 +10,13 @@ namespace Artemis.KeyboardProviders.Razer public BlackWidow() { Name = "Razer BlackWidow Chroma"; - Height = (int) Constants.MaxRows; - Width = (int) Constants.MaxColumns; } public override void Enable() { Chroma.Instance.Initialize(); + Height = (int)Constants.MaxRows; + Width = (int)Constants.MaxColumns; } public override void Disable() diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs index f13e3e262..1e1241a61 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs @@ -4,7 +4,6 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using Artemis.Models; -using Artemis.Utilities; using Artemis.Utilities.Audio; using Artemis.Utilities.Keyboard; using NAudio.CoreAudioApi; @@ -17,7 +16,6 @@ namespace Artemis.Modules.Effects.AudioVisualizer private const int FftLength = 2048; private readonly SampleAggregator _sampleAggregator = new SampleAggregator(FftLength); private bool _generating; - private bool _previousFromBottom; private IWaveIn _waveIn; public AudioVisualizerModel(MainModel mainModel, AudioVisualizerSettings settings) : base(mainModel) @@ -26,19 +24,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer Name = "Audiovisualizer"; DeviceIds = new List(); SpectrumData = new List(); - SoundRectangles = new List(); Scale = 4; - - // Fill list with device IDs - // Would rather just store a MMDevice object, but seems NAudio won't let me. - var deviceEnum = new MMDeviceEnumerator(); - var devices = deviceEnum.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active).ToList(); - foreach (var mmDevice in devices) - { - DeviceIds.Add(mmDevice.ID); - } - - SelectedDeviceId = DeviceIds.FirstOrDefault(); } public int Lines { get; set; } @@ -64,7 +50,29 @@ namespace Artemis.Modules.Effects.AudioVisualizer public override void Enable() { - Lines = MainModel.ActiveKeyboard.Width * Scale; + Lines = MainModel.ActiveKeyboard.Width; + + // TODO: Device selection + SelectedDeviceId = new MMDeviceEnumerator() + .EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active) + .FirstOrDefault()?.ID; + + SoundRectangles = new List(); + for (var i = 0; i < Lines; i++) + { + SoundRectangles.Add(new KeyboardRectangle( + MainModel.ActiveKeyboard, + 0, 0, new List + { + //ColorHelpers.MediaColorToDrawingColor(Settings.MainColor), + //ColorHelpers.MediaColorToDrawingColor(Settings.SecondaryColor) + Color.Red, + Color.Yellow, + Color.Green, + }, + LinearGradientMode.Vertical) {ContainedBrush = false}); + + } _sampleAggregator.FftCalculated += FftCalculated; _sampleAggregator.PerformFFT = true; @@ -79,72 +87,50 @@ namespace Artemis.Modules.Effects.AudioVisualizer if (SelectedDeviceId == null) return; - var deviceEnum = new MMDeviceEnumerator(); - var devices = deviceEnum.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active).ToList(); - var device = devices.FirstOrDefault(d => d.ID == SelectedDeviceId); + var device = new MMDeviceEnumerator() + .EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active) + .FirstOrDefault(d => d.ID == SelectedDeviceId); - if (device == null) + if (device == null || SpectrumData == null) return; // Start filling the model _generating = true; - if (SpectrumData == null) - { - _generating = false; - return; - } - - // Clear the rectangle cache on Bars settings change - if (SoundRectangles.Count != Settings.Bars) - SoundRectangles.Clear(); - if (Settings.FromBottom != _previousFromBottom) - SoundRectangles.Clear(); - _previousFromBottom = Settings.FromBottom; - // Parse spectrum data - for (var i = 0; i < Settings.Bars; i++) + for (var i = 0; i < Lines; i++) { int height; if (SpectrumData.Count - 1 < i || SpectrumData[i] == 0) height = 0; else - height = (int) (Math.Round(SpectrumData[i]/2.55)); - - if (SoundRectangles.Count <= i) - SoundRectangles.Add(new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 0, new List - { - ColorHelpers.MediaColorToDrawingColor(Settings.MainColor), - ColorHelpers.MediaColorToDrawingColor(Settings.SecondaryColor) - }, LinearGradientMode.Vertical)); + height = (int) Math.Round(SpectrumData[i]/2.55); // Apply Sensitivity setting height = height*Settings.Sensitivity; - if (height > SoundRectangles[i].Height) - SoundRectangles[i].Height = height; + var keyboardHeight = (int) Math.Round(((MainModel.ActiveKeyboard.Height/100.00)*height)*Scale); + if (keyboardHeight > SoundRectangles[i].Height) + SoundRectangles[i].Height = keyboardHeight; else SoundRectangles[i].Height = SoundRectangles[i].Height - Settings.FadeSpeed; // Apply Bars setting - SoundRectangles[i].X = (int) Math.Ceiling((double) Lines/Settings.Bars)*i; - SoundRectangles[i].Width = (int) Math.Ceiling((double) Lines/Settings.Bars); + SoundRectangles[i].X = i*Scale; + SoundRectangles[i].Width = Scale; if (Settings.FromBottom) - SoundRectangles[i].Y = (Scale*MainModel.ActiveKeyboard.Height) - SoundRectangles[i].Height; + SoundRectangles[i].Y = (MainModel.ActiveKeyboard.Height*Scale) - SoundRectangles[i].Height; } _generating = false; } public override Bitmap GenerateBitmap() { + if (SpectrumData == null) + return null; + // Lock the _spectrumData array while busy with it _generating = true; - if (SpectrumData == null) - { - _generating = false; - return null; - } - var bitmap = MainModel.ActiveKeyboard.KeyboardBitmap(Scale); using (var g = Graphics.FromImage(bitmap)) { diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml index 9c4e0fc28..32669c020 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml @@ -69,22 +69,6 @@ SmallChange="1" IsSnapToTickEnabled="True" /> - - - diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs index 15b9ca956..6808295c9 100644 --- a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs @@ -27,7 +27,7 @@ namespace Artemis.Modules.Effects.Debug public override void Enable() { - KeyboardRectangle = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 0, new List + KeyboardRectangle = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List { Color.Red, Color.OrangeRed, @@ -43,7 +43,7 @@ namespace Artemis.Modules.Effects.Debug { KeyboardRectangle.Height = Settings.Height; KeyboardRectangle.Width = Settings.Width; - //KeyboardRectangle.GradientMode = Settings.Type; + KeyboardRectangle.GradientMode = Settings.Type; KeyboardRectangle.Rotate = Settings.Rotate; } diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index f1071ba20..862a6bec2 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -42,9 +42,9 @@ namespace Artemis.Modules.Games.CounterStrike public override void Enable() { // TODO: Size stuff - AmmoRect = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 0, new List(), LinearGradientMode.Horizontal); - TeamRect = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 1 * Scale, new List(), LinearGradientMode.Horizontal); - EventRect = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 1 * Scale, new List(), LinearGradientMode.Horizontal); + AmmoRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List(), LinearGradientMode.Horizontal); + TeamRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 1 * Scale, new List(), LinearGradientMode.Horizontal); + EventRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 1 * Scale, new List(), LinearGradientMode.Horizontal); MainModel.GameStateWebServer.GameDataReceived += HandleGameData; } diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs index c7700c79a..6fb88fa44 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueModel.cs @@ -43,7 +43,7 @@ namespace Artemis.Modules.Games.RocketLeague public override void Enable() { - _boostRect = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 0, new List + _boostRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List { ColorHelpers.MediaColorToDrawingColor(_settings.MainColor), ColorHelpers.MediaColorToDrawingColor(_settings.SecondaryColor) diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs index d6d6dbb5e..c49593c5a 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3Model.cs @@ -38,7 +38,7 @@ namespace Artemis.Modules.Games.Witcher3 public override void Enable() { - _signRect = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 0, new List(), LinearGradientMode.Horizontal) + _signRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List(), LinearGradientMode.Horizontal) { Rotate = true, LoopSpeed = 0.5 diff --git a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs index 91a897118..54692b93a 100644 --- a/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs +++ b/Artemis/Artemis/Modules/Overlays/VolumeDisplay/VolumeDisplay.cs @@ -31,12 +31,12 @@ namespace Artemis.Modules.Overlays.VolumeDisplay public void Draw(Graphics g) { - var volumeRect = new KeyboardRectangle(MainModel.ActiveKeyboard, Scale, 0, 0, - new List + var volumeRect = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List { ColorHelpers.MediaColorToDrawingColor(Settings.MainColor), ColorHelpers.MediaColorToDrawingColor(Settings.SecondaryColor) - }, LinearGradientMode.Horizontal); + }, + LinearGradientMode.Horizontal); volumeRect.Draw(g); } } diff --git a/Artemis/Artemis/Settings/General.Designer.cs b/Artemis/Artemis/Settings/General.Designer.cs index 26087df61..3ec435f37 100644 --- a/Artemis/Artemis/Settings/General.Designer.cs +++ b/Artemis/Artemis/Settings/General.Designer.cs @@ -37,7 +37,7 @@ namespace Artemis.Settings { [global::System.Configuration.UserScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Razer BlackWidow Chroma")] + [global::System.Configuration.DefaultSettingValueAttribute("Corsair Gaming K95 RGB")] public string LastKeyboard { get { return ((string)(this["LastKeyboard"])); diff --git a/Artemis/Artemis/Settings/General.settings b/Artemis/Artemis/Settings/General.settings index c339986b0..1c3e60be8 100644 --- a/Artemis/Artemis/Settings/General.settings +++ b/Artemis/Artemis/Settings/General.settings @@ -1,14 +1,12 @@  - - + TypeWave - Razer BlackWidow Chroma + Corsair Gaming K95 RGB True diff --git a/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs b/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs index 6f5ecb18f..833cf82bc 100644 --- a/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs +++ b/Artemis/Artemis/Utilities/Keyboard/KeyboardRectangle.cs @@ -14,7 +14,6 @@ namespace Artemis.Utilities.Keyboard private readonly BackgroundWorker _blinkWorker = new BackgroundWorker {WorkerSupportsCancellation = true}; private readonly KeyboardProvider _keyboard; private int _blinkDelay; - private List _colors; private double _rotationProgress; /// @@ -22,57 +21,68 @@ namespace Artemis.Utilities.Keyboard /// By default, a rectangle is the entire keyboard's size. /// /// The keyboard this rectangle will be used for - /// The scale on which the rect should be rendered (Higher means smoother rotation) /// /// /// An array of colors the ColorBlend will use /// - public KeyboardRectangle(KeyboardProvider keyboard, int scale, int x, int y, List colors, + public KeyboardRectangle(KeyboardProvider keyboard, int x, int y, List colors, LinearGradientMode gradientMode) { _keyboard = keyboard; - Scale = scale; - X = x; - Y = y; - Width = keyboard.Width*Scale; - Height = keyboard.Height*Scale; - Colors = colors; - GradientMode = gradientMode; - - Opacity = 255; - Rotate = false; - LoopSpeed = 1; - Visible = true; - ContainedBrush = false; - _rotationProgress = 0; _blinkWorker.DoWork += BlinkWorker_DoWork; + + X = x; + Y = y; + Width = keyboard.Width; + Height = keyboard.Height; + Visible = true; + Opacity = 255; + + ContainedBrush = true; + Scale = 4; + GradientMode = gradientMode; + Rotate = false; + LoopSpeed = 1; + Colors = colors; } - public bool ContainedBrush { get; set; } - public int Scale { get; set; } - public byte Opacity { get; set; } public int X { get; set; } public int Y { get; set; } public int Width { get; set; } public int Height { get; set; } - public LinearGradientMode GradientMode { get; set; } - public bool Rotate { get; set; } - public double LoopSpeed { get; set; } public bool Visible { get; set; } + public byte Opacity { get; set; } // TODO: Remove - public List Colors - { - get { return _colors; } - set - { - _colors = value; + /// + /// Sets wether or not the colors should be contained within the rectangle, or span the entire keyboard. + /// + public bool ContainedBrush { get; set; } - // Make the list tilable so that we can loop it - _colors.AddRange(value); - _colors.Add(value.FirstOrDefault()); - } - } + /// + /// Used when ContainedBrush is set to false to make sure the colors span the entire keyboard on a higher scale. + /// + public int Scale { get; set; } + + /// + /// Determines what grientmode to use in the LinearGradientBrush. + /// + public LinearGradientMode GradientMode { get; set; } + + /// + /// Wether or not to rotate the colors over the brush. + /// + public bool Rotate { get; set; } + + /// + /// What speed to ratate the colors on. + /// + public double LoopSpeed { get; set; } + + /// + /// Colors used on the brush. + /// + public List Colors { get; set; } public void StartBlink(int delay) { @@ -130,24 +140,28 @@ namespace Artemis.Utilities.Keyboard private LinearGradientBrush CreateBrush() { var colorBlend = CreateColorBlend(); - var rect = ContainedBrush - ? new Rectangle((int) _rotationProgress, Y, Width, Height) - : new Rectangle((int) _rotationProgress, 0, _keyboard.Width*Scale, _keyboard.Height*Scale); + RectangleF rect; + if (Rotate) + rect = ContainedBrush + ? new Rectangle((int) _rotationProgress, Y, Width*2, Height*2) + : new Rectangle((int) _rotationProgress, 0, (_keyboard.Width*Scale)*2, (_keyboard.Height*Scale)*2); + else + rect = ContainedBrush + ? new Rectangle(X, Y, Width, Height) + : new Rectangle(0, 0, (_keyboard.Width*Scale), (_keyboard.Height*Scale)); - if (Colors.Count > 5) - return new LinearGradientBrush(rect, Colors[0], Colors[1], GradientMode) - { - InterpolationColors = colorBlend - }; - return Colors.Count > 1 - ? new LinearGradientBrush(rect, Colors[0], Colors[1], GradientMode) - : new LinearGradientBrush(rect, Colors[0], Colors[0], GradientMode); + return new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, GradientMode) + { + InterpolationColors = colorBlend + }; } private ColorBlend CreateColorBlend() { - var colorBlend = new ColorBlend {Colors = Colors.ToArray()}; + var colorBlend = Rotate + ? new ColorBlend {Colors = CreateTilebleColors(Colors).ToArray()} + : new ColorBlend {Colors = Colors.ToArray()}; // If needed, apply opacity to the colors in the blend if (Opacity < 255) @@ -155,9 +169,9 @@ namespace Artemis.Utilities.Keyboard colorBlend.Colors[i] = Color.FromArgb(Opacity, colorBlend.Colors[i]); // Devide the colors over the colorblend - var devider = (float) Colors.Count - 1; + var devider = (float) colorBlend.Colors.Length - 1; var positions = new List(); - for (var i = 0; i < Colors.Count; i++) + for (var i = 0; i < colorBlend.Colors.Length; i++) positions.Add(i/devider); // Apply the devided positions @@ -165,5 +179,16 @@ namespace Artemis.Utilities.Keyboard return colorBlend; } + + private List CreateTilebleColors(List sourceColors) + { + // Create a list using the original colors + var tilebleColors = new List(sourceColors); + // Add the original colors again + tilebleColors.AddRange(sourceColors); + // Add the first color, smoothing the transition + tilebleColors.Add(sourceColors.FirstOrDefault()); + return tilebleColors; + } } } \ No newline at end of file diff --git a/Artemis/Artemis/packages.config b/Artemis/Artemis/packages.config index 7137d3ff6..0f9b82309 100644 --- a/Artemis/Artemis/packages.config +++ b/Artemis/Artemis/packages.config @@ -1,16 +1,15 @@  - - - + + - - - + + + - + \ No newline at end of file diff --git a/README.md b/README.md index 13f2e1d38..7d82069da 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Support is planned for: * Dota 2 (Native Gamestate intergration) * Project CARS (Native memory sharing) -Currently the only supported keyboard is the Logitech G910 Orion Spark, but progress is being made to support Corsair and Razer as well. +Currently the only supported keyboards are the Logitech G910 Orion Spark and Corsair K95 RGB, but progress is being made to support Razer as well. For any keyboards/games/effects we'd love PRs!