From 630090ac6fb8930f7c5b2edbe7f10af08bc5b2cb Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 18 Oct 2015 17:00:27 +0200 Subject: [PATCH] Refactored brushes, gradients, effects and the keyboard to uncouple them --- .../Brushes => Brushes}/AbstractBrush.cs | 2 +- .../Keyboard/Brushes => Brushes}/IBrush.cs | 2 +- .../LinearGradientBrush.cs | 4 +-- .../RadialGradientBrush.cs | 4 +-- .../Brushes => Brushes}/RandomColorBrush.cs | 2 +- .../Brushes => Brushes}/SolidColorBrush.cs | 2 +- CUE.NET.csproj | 30 +++++++++---------- Devices/Generic/Enums/UpdateMode.cs | 6 ++-- Devices/Keyboard/CorsairKeyboard.cs | 13 ++++++-- Devices/Keyboard/Keys/BaseKeyGroup.cs | 13 +++++++- Devices/Keyboard/Keys/IKeyGroup.cs | 9 +++++- .../Effects => Effects}/AbstractEffect.cs | 24 +++++---------- .../EffectTimeContainer.cs | 2 +- .../Effects => Effects}/FlashEffect.cs | 4 +-- .../Keyboard/Effects => Effects}/IEffect.cs | 14 ++++----- .../AbstractGradient.cs | 2 +- .../Gradient => Gradients}/GradientStop.cs | 2 +- .../Gradient => Gradients}/IGradient.cs | 2 +- .../Gradient => Gradients}/LinearGradient.cs | 2 +- .../Gradient => Gradients}/RainbowGradient.cs | 2 +- 20 files changed, 79 insertions(+), 62 deletions(-) rename {Devices/Keyboard/Brushes => Brushes}/AbstractBrush.cs (98%) rename {Devices/Keyboard/Brushes => Brushes}/IBrush.cs (95%) rename {Devices/Keyboard/Brushes => Brushes}/LinearGradientBrush.cs (97%) rename {Devices/Keyboard/Brushes => Brushes}/RadialGradientBrush.cs (97%) rename {Devices/Keyboard/Brushes => Brushes}/RandomColorBrush.cs (95%) rename {Devices/Keyboard/Brushes => Brushes}/SolidColorBrush.cs (96%) rename {Devices/Keyboard/Effects => Effects}/AbstractEffect.cs (71%) rename {Devices/Keyboard/Effects => Effects}/EffectTimeContainer.cs (96%) rename {Devices/Keyboard/Effects => Effects}/FlashEffect.cs (98%) rename {Devices/Keyboard/Effects => Effects}/IEffect.cs (83%) rename {Devices/Keyboard/Brushes/Gradient => Gradients}/AbstractGradient.cs (97%) rename {Devices/Keyboard/Brushes/Gradient => Gradients}/GradientStop.cs (95%) rename {Devices/Keyboard/Brushes/Gradient => Gradients}/IGradient.cs (89%) rename {Devices/Keyboard/Brushes/Gradient => Gradients}/LinearGradient.cs (97%) rename {Devices/Keyboard/Brushes/Gradient => Gradients}/RainbowGradient.cs (97%) diff --git a/Devices/Keyboard/Brushes/AbstractBrush.cs b/Brushes/AbstractBrush.cs similarity index 98% rename from Devices/Keyboard/Brushes/AbstractBrush.cs rename to Brushes/AbstractBrush.cs index 300fbc5..56d78ac 100644 --- a/Devices/Keyboard/Brushes/AbstractBrush.cs +++ b/Brushes/AbstractBrush.cs @@ -1,7 +1,7 @@ using System.Drawing; using CUE.NET.Helper; -namespace CUE.NET.Devices.Keyboard.Brushes +namespace CUE.NET.Brushes { /// /// Represents a basic brush. diff --git a/Devices/Keyboard/Brushes/IBrush.cs b/Brushes/IBrush.cs similarity index 95% rename from Devices/Keyboard/Brushes/IBrush.cs rename to Brushes/IBrush.cs index 4e3bf98..f441aca 100644 --- a/Devices/Keyboard/Brushes/IBrush.cs +++ b/Brushes/IBrush.cs @@ -1,6 +1,6 @@ using System.Drawing; -namespace CUE.NET.Devices.Keyboard.Brushes +namespace CUE.NET.Brushes { /// /// Represents a basic brush. diff --git a/Devices/Keyboard/Brushes/LinearGradientBrush.cs b/Brushes/LinearGradientBrush.cs similarity index 97% rename from Devices/Keyboard/Brushes/LinearGradientBrush.cs rename to Brushes/LinearGradientBrush.cs index a7bde7f..e3a851d 100644 --- a/Devices/Keyboard/Brushes/LinearGradientBrush.cs +++ b/Brushes/LinearGradientBrush.cs @@ -4,10 +4,10 @@ // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global using System.Drawing; -using CUE.NET.Devices.Keyboard.Brushes.Gradient; +using CUE.NET.Gradients; using CUE.NET.Helper; -namespace CUE.NET.Devices.Keyboard.Brushes +namespace CUE.NET.Brushes { /// /// Represents a brush drawing a linear gradient. diff --git a/Devices/Keyboard/Brushes/RadialGradientBrush.cs b/Brushes/RadialGradientBrush.cs similarity index 97% rename from Devices/Keyboard/Brushes/RadialGradientBrush.cs rename to Brushes/RadialGradientBrush.cs index b5a0225..0f614d8 100644 --- a/Devices/Keyboard/Brushes/RadialGradientBrush.cs +++ b/Brushes/RadialGradientBrush.cs @@ -3,10 +3,10 @@ using System; using System.Drawing; -using CUE.NET.Devices.Keyboard.Brushes.Gradient; +using CUE.NET.Gradients; using CUE.NET.Helper; -namespace CUE.NET.Devices.Keyboard.Brushes +namespace CUE.NET.Brushes { /// /// Represents a brush drawing a radial gradient around a center point. diff --git a/Devices/Keyboard/Brushes/RandomColorBrush.cs b/Brushes/RandomColorBrush.cs similarity index 95% rename from Devices/Keyboard/Brushes/RandomColorBrush.cs rename to Brushes/RandomColorBrush.cs index 09f4fc4..6a4c184 100644 --- a/Devices/Keyboard/Brushes/RandomColorBrush.cs +++ b/Brushes/RandomColorBrush.cs @@ -2,7 +2,7 @@ using System.Drawing; using CUE.NET.Helper; -namespace CUE.NET.Devices.Keyboard.Brushes +namespace CUE.NET.Brushes { //TODO DarthAffe 30.09.2015: Like this the brush seems kinda useless. Think about making it cool. diff --git a/Devices/Keyboard/Brushes/SolidColorBrush.cs b/Brushes/SolidColorBrush.cs similarity index 96% rename from Devices/Keyboard/Brushes/SolidColorBrush.cs rename to Brushes/SolidColorBrush.cs index 2a2c7a4..1ad65bd 100644 --- a/Devices/Keyboard/Brushes/SolidColorBrush.cs +++ b/Brushes/SolidColorBrush.cs @@ -3,7 +3,7 @@ using System.Drawing; -namespace CUE.NET.Devices.Keyboard.Brushes +namespace CUE.NET.Brushes { /// /// Represents a brush drawing only a single color. diff --git a/CUE.NET.csproj b/CUE.NET.csproj index 06f833a..47c2c85 100644 --- a/CUE.NET.csproj +++ b/CUE.NET.csproj @@ -46,20 +46,20 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -85,7 +85,7 @@ - + diff --git a/Devices/Generic/Enums/UpdateMode.cs b/Devices/Generic/Enums/UpdateMode.cs index c61c57d..6dc10a1 100644 --- a/Devices/Generic/Enums/UpdateMode.cs +++ b/Devices/Generic/Enums/UpdateMode.cs @@ -1,4 +1,6 @@ -namespace CUE.NET.Devices.Generic.Enums +using CUE.NET.Effects; + +namespace CUE.NET.Devices.Generic.Enums { /// /// Contains list of available update modes. @@ -12,7 +14,7 @@ /// /// The device will perform automatic updates at the rate set in - /// as long as an is attached. + /// as long as an is attached. /// AutoOnEffect, diff --git a/Devices/Keyboard/CorsairKeyboard.cs b/Devices/Keyboard/CorsairKeyboard.cs index 642c239..3b9a860 100644 --- a/Devices/Keyboard/CorsairKeyboard.cs +++ b/Devices/Keyboard/CorsairKeyboard.cs @@ -9,11 +9,11 @@ using System.Collections.ObjectModel; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; +using CUE.NET.Brushes; using CUE.NET.Devices.Generic; -using CUE.NET.Devices.Keyboard.Brushes; -using CUE.NET.Devices.Keyboard.Effects; using CUE.NET.Devices.Keyboard.Enums; using CUE.NET.Devices.Keyboard.Keys; +using CUE.NET.Effects; using CUE.NET.Helper; using CUE.NET.Native; @@ -188,7 +188,9 @@ namespace CUE.NET.Devices.Keyboard effect.TicksAtLastUpdate = currentTicks; effect.Effect.Update(deltaTime); - ApplyBrush((effect.Effect.KeyList ?? this).ToList(), effect.Effect.EffectBrush); + //TODO DarthAffe 18.10.2015: This is really dirty and might have a really negative performance impact - find a better solution. + IEnumerable keys = effect.Effect?.LedList?.Select(x => this.FirstOrDefault(y => y.Led == x)); + ApplyBrush((keys ?? this).ToList(), effect.Effect.EffectBrush); if (effect.Effect.IsDone) effectsToRemove.Add(effect.Effect); @@ -215,6 +217,11 @@ namespace CUE.NET.Devices.Keyboard catch (Exception ex) { ManageException(ex); } } + public IEnumerable GetLeds() + { + return this.Select(x => x.Led); + } + #endregion /// diff --git a/Devices/Keyboard/Keys/BaseKeyGroup.cs b/Devices/Keyboard/Keys/BaseKeyGroup.cs index b968e40..fa8874c 100644 --- a/Devices/Keyboard/Keys/BaseKeyGroup.cs +++ b/Devices/Keyboard/Keys/BaseKeyGroup.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using CUE.NET.Devices.Keyboard.Brushes; +using System.Linq; +using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; using CUE.NET.Devices.Keyboard.Extensions; namespace CUE.NET.Devices.Keyboard.Keys @@ -49,6 +51,15 @@ namespace CUE.NET.Devices.Keyboard.Keys this.Attach(); } + #endregion + + #region Methods + + public IEnumerable GetLeds() + { + return GetGroupKeys().Select(x => x.Led); + } + /// /// Gets a list containing the keys from this group. /// diff --git a/Devices/Keyboard/Keys/IKeyGroup.cs b/Devices/Keyboard/Keys/IKeyGroup.cs index ff23029..96ab7cf 100644 --- a/Devices/Keyboard/Keys/IKeyGroup.cs +++ b/Devices/Keyboard/Keys/IKeyGroup.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; -using CUE.NET.Devices.Keyboard.Brushes; +using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; namespace CUE.NET.Devices.Keyboard.Keys { @@ -19,5 +20,11 @@ namespace CUE.NET.Devices.Keyboard.Keys /// Gets or sets the z-index of this keygroup to allow ordering them before drawing. (lowest first) (default: 0) /// int ZIndex { get; set; } + + /// + /// Gets a list containing all LEDs of this group. + /// + /// The list containing all LEDs of this group. + IEnumerable GetLeds(); } } diff --git a/Devices/Keyboard/Effects/AbstractEffect.cs b/Effects/AbstractEffect.cs similarity index 71% rename from Devices/Keyboard/Effects/AbstractEffect.cs rename to Effects/AbstractEffect.cs index 51569e5..c3ea829 100644 --- a/Devices/Keyboard/Effects/AbstractEffect.cs +++ b/Effects/AbstractEffect.cs @@ -1,11 +1,10 @@ // ReSharper disable MemberCanBePrivate.Global using System.Collections.Generic; -using System.Linq; -using CUE.NET.Devices.Keyboard.Brushes; -using CUE.NET.Devices.Keyboard.Keys; +using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; -namespace CUE.NET.Devices.Keyboard.Effects +namespace CUE.NET.Effects { /// /// Represents a basic effect. @@ -15,9 +14,9 @@ namespace CUE.NET.Devices.Keyboard.Effects #region Properties & Fields /// - /// Gets or sets the list of keys to which the effect applies. + /// Gets or sets the list of LEDSs to which the effect applies. /// - public IEnumerable KeyList { get; protected set; } + public IEnumerable LedList { get; set; } /// /// Gets the brush which is drawn by the effect. @@ -38,15 +37,6 @@ namespace CUE.NET.Devices.Keyboard.Effects #region Methods - /// - /// Sets the list of keys to which the effect applies. - /// - /// - public void SetTarget(IKeyGroup keyGroup) - { - KeyList = keyGroup.Keys.ToList(); - } - /// /// Updates the effect. /// @@ -54,13 +44,13 @@ namespace CUE.NET.Devices.Keyboard.Effects public abstract void Update(float deltaTime); /// - /// Hook which is called when the effect is attached to a keyboard. + /// Hook which is called when the effect is attached to a device. /// public virtual void OnAttach() { } /// - /// Hook which is called when the effect is detached from a keyboard. + /// Hook which is called when the effect is detached from a device. /// public virtual void OnDetach() { } diff --git a/Devices/Keyboard/Effects/EffectTimeContainer.cs b/Effects/EffectTimeContainer.cs similarity index 96% rename from Devices/Keyboard/Effects/EffectTimeContainer.cs rename to Effects/EffectTimeContainer.cs index 9a2a963..3cb70b0 100644 --- a/Devices/Keyboard/Effects/EffectTimeContainer.cs +++ b/Effects/EffectTimeContainer.cs @@ -1,7 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global -namespace CUE.NET.Devices.Keyboard.Effects +namespace CUE.NET.Effects { /// /// Represents a wrapped effect with additional time information. diff --git a/Devices/Keyboard/Effects/FlashEffect.cs b/Effects/FlashEffect.cs similarity index 98% rename from Devices/Keyboard/Effects/FlashEffect.cs rename to Effects/FlashEffect.cs index 93d6a7d..7228bd6 100644 --- a/Devices/Keyboard/Effects/FlashEffect.cs +++ b/Effects/FlashEffect.cs @@ -3,9 +3,9 @@ using System; using System.Drawing; -using CUE.NET.Devices.Keyboard.Brushes; +using CUE.NET.Brushes; -namespace CUE.NET.Devices.Keyboard.Effects +namespace CUE.NET.Effects { /// /// Represents an effect which allows to flash an brush by modifying his opacity. diff --git a/Devices/Keyboard/Effects/IEffect.cs b/Effects/IEffect.cs similarity index 83% rename from Devices/Keyboard/Effects/IEffect.cs rename to Effects/IEffect.cs index 8cf4a6a..6e9ce35 100644 --- a/Devices/Keyboard/Effects/IEffect.cs +++ b/Effects/IEffect.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -using CUE.NET.Devices.Keyboard.Brushes; -using CUE.NET.Devices.Keyboard.Keys; +using CUE.NET.Brushes; +using CUE.NET.Devices.Generic; -namespace CUE.NET.Devices.Keyboard.Effects +namespace CUE.NET.Effects { /// /// Represents a basic effect. @@ -12,9 +12,9 @@ namespace CUE.NET.Devices.Keyboard.Effects #region Properties & Fields /// - /// Gets or sets the list of keys to which the effect applies. + /// Gets or sets the list of LEDs to which the effect applies. /// - IEnumerable KeyList { get; } + IEnumerable LedList { get; set; } /// /// Gets the brush which is drawn by the effect. @@ -42,12 +42,12 @@ namespace CUE.NET.Devices.Keyboard.Effects void Update(float deltaTime); /// - /// Hook which is called when the effect is attached to a keyboard. + /// Hook which is called when the effect is attached to a device. /// void OnAttach(); /// - /// Hook which is called when the effect is detached from a keyboard. + /// Hook which is called when the effect is detached from a device. /// void OnDetach(); diff --git a/Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs b/Gradients/AbstractGradient.cs similarity index 97% rename from Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs rename to Gradients/AbstractGradient.cs index f6e429b..7a48ad2 100644 --- a/Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs +++ b/Gradients/AbstractGradient.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; -namespace CUE.NET.Devices.Keyboard.Brushes.Gradient +namespace CUE.NET.Gradients { /// /// Represents a basic gradient. diff --git a/Devices/Keyboard/Brushes/Gradient/GradientStop.cs b/Gradients/GradientStop.cs similarity index 95% rename from Devices/Keyboard/Brushes/Gradient/GradientStop.cs rename to Gradients/GradientStop.cs index 06ade36..ae2c92a 100644 --- a/Devices/Keyboard/Brushes/Gradient/GradientStop.cs +++ b/Gradients/GradientStop.cs @@ -3,7 +3,7 @@ using System.Drawing; -namespace CUE.NET.Devices.Keyboard.Brushes.Gradient +namespace CUE.NET.Gradients { /// /// Represents a stop on a gradient. diff --git a/Devices/Keyboard/Brushes/Gradient/IGradient.cs b/Gradients/IGradient.cs similarity index 89% rename from Devices/Keyboard/Brushes/Gradient/IGradient.cs rename to Gradients/IGradient.cs index c30c8ec..275d9af 100644 --- a/Devices/Keyboard/Brushes/Gradient/IGradient.cs +++ b/Gradients/IGradient.cs @@ -1,6 +1,6 @@ using System.Drawing; -namespace CUE.NET.Devices.Keyboard.Brushes.Gradient +namespace CUE.NET.Gradients { /// /// Represents a basic gradient. diff --git a/Devices/Keyboard/Brushes/Gradient/LinearGradient.cs b/Gradients/LinearGradient.cs similarity index 97% rename from Devices/Keyboard/Brushes/Gradient/LinearGradient.cs rename to Gradients/LinearGradient.cs index 2057e01..f3ffd7a 100644 --- a/Devices/Keyboard/Brushes/Gradient/LinearGradient.cs +++ b/Gradients/LinearGradient.cs @@ -1,7 +1,7 @@ using System.Drawing; using System.Linq; -namespace CUE.NET.Devices.Keyboard.Brushes.Gradient +namespace CUE.NET.Gradients { /// /// Represents a linear interpolated gradient with n stops. diff --git a/Devices/Keyboard/Brushes/Gradient/RainbowGradient.cs b/Gradients/RainbowGradient.cs similarity index 97% rename from Devices/Keyboard/Brushes/Gradient/RainbowGradient.cs rename to Gradients/RainbowGradient.cs index dd86986..84ba9be 100644 --- a/Devices/Keyboard/Brushes/Gradient/RainbowGradient.cs +++ b/Gradients/RainbowGradient.cs @@ -3,7 +3,7 @@ using System.Drawing; using CUE.NET.Helper; -namespace CUE.NET.Devices.Keyboard.Brushes.Gradient +namespace CUE.NET.Gradients { /// /// Represents a rainbow gradient which circles through all color colors of the HUE-color-space.