From 920821deee98b4129780f5abef611bcb6edd6570 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 9 Oct 2015 21:36:12 +0200 Subject: [PATCH] Refactored before merge --- Devices/Generic/CorsairLed.cs | 8 +++--- .../Brushes/Gradient/AbstractGradient.cs | 8 +++--- .../Keyboard/Brushes/Gradient/GradientStop.cs | 5 +++- .../Keyboard/Brushes/LinearGradientBrush.cs | 1 + .../Keyboard/Brushes/RadialGradientBrush.cs | 6 ++++- Devices/Keyboard/CorsairKeyboard.cs | 26 +++++++------------ Devices/Keyboard/Effects/AbstractEffect.cs | 4 ++- .../Keyboard/Effects/EffectTimeContainer.cs | 9 ++++--- Devices/Keyboard/Effects/FlashEffect.cs | 7 +++-- .../Keyboard/Extensions/KeyGroupExtension.cs | 5 +++- Devices/Keyboard/Keys/CorsairKey.cs | 5 +++- Devices/Keyboard/Keys/ListKeyGroup.cs | 4 ++- Devices/Keyboard/Keys/RectangleKeyGroup.cs | 5 +++- Helper/ColorHelper.cs | 3 +++ 14 files changed, 61 insertions(+), 35 deletions(-) diff --git a/Devices/Generic/CorsairLed.cs b/Devices/Generic/CorsairLed.cs index 930862d..c07dc18 100644 --- a/Devices/Generic/CorsairLed.cs +++ b/Devices/Generic/CorsairLed.cs @@ -1,4 +1,8 @@ -using System.Drawing; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global + +using System.Drawing; using CUE.NET.Helper; namespace CUE.NET.Devices.Generic @@ -28,8 +32,6 @@ namespace CUE.NET.Devices.Generic public bool IsLocked { get; set; } = false; - //TODO DarthAffe 19.09.2015: Add effects and stuff - #endregion #region Constructors diff --git a/Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs b/Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs index dfe056b..cb1bd64 100644 --- a/Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs +++ b/Devices/Keyboard/Brushes/Gradient/AbstractGradient.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +// ReSharper disable MemberCanBeProtected.Global + +using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -14,10 +16,10 @@ namespace CUE.NET.Devices.Keyboard.Brushes.Gradient #region Constructors - public AbstractGradient() + protected AbstractGradient() { } - public AbstractGradient(params GradientStop[] gradientStops) + protected AbstractGradient(params GradientStop[] gradientStops) { foreach (GradientStop gradientStop in gradientStops) GradientStops.Add(gradientStop); diff --git a/Devices/Keyboard/Brushes/Gradient/GradientStop.cs b/Devices/Keyboard/Brushes/Gradient/GradientStop.cs index 89bd03a..8ddd9db 100644 --- a/Devices/Keyboard/Brushes/Gradient/GradientStop.cs +++ b/Devices/Keyboard/Brushes/Gradient/GradientStop.cs @@ -1,4 +1,7 @@ -using System.Drawing; +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global +// ReSharper disable MemberCanBePrivate.Global + +using System.Drawing; namespace CUE.NET.Devices.Keyboard.Brushes.Gradient { diff --git a/Devices/Keyboard/Brushes/LinearGradientBrush.cs b/Devices/Keyboard/Brushes/LinearGradientBrush.cs index 729d969..741d4e6 100644 --- a/Devices/Keyboard/Brushes/LinearGradientBrush.cs +++ b/Devices/Keyboard/Brushes/LinearGradientBrush.cs @@ -1,6 +1,7 @@ // ReSharper disable CollectionNeverUpdated.Global // ReSharper disable MemberCanBePrivate.Global // ReSharper disable ReturnTypeCanBeEnumerable.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global using System.Drawing; using CUE.NET.Devices.Keyboard.Brushes.Gradient; diff --git a/Devices/Keyboard/Brushes/RadialGradientBrush.cs b/Devices/Keyboard/Brushes/RadialGradientBrush.cs index 57cca44..c284d0a 100644 --- a/Devices/Keyboard/Brushes/RadialGradientBrush.cs +++ b/Devices/Keyboard/Brushes/RadialGradientBrush.cs @@ -1,4 +1,7 @@ -using System; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global + +using System; using System.Drawing; using CUE.NET.Devices.Keyboard.Brushes.Gradient; using CUE.NET.Helper; @@ -39,6 +42,7 @@ namespace CUE.NET.Devices.Keyboard.Brushes PointF centerPoint = new PointF(rectangle.X + rectangle.Width * Center.X, rectangle.Y + rectangle.Height * Center.Y); // Calculate the distance to the farthest point from the center as reference (this has to be a corner) + // ReSharper disable once RedundantCast - never trust this ... float refDistance = (float)Math.Max(Math.Max(Math.Max(GradientHelper.CalculateDistance(rectangle.Location, centerPoint), GradientHelper.CalculateDistance(new PointF(rectangle.X + rectangle.Width, rectangle.Y), centerPoint)), GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)), diff --git a/Devices/Keyboard/CorsairKeyboard.cs b/Devices/Keyboard/CorsairKeyboard.cs index 1c5e7b9..806b88d 100644 --- a/Devices/Keyboard/CorsairKeyboard.cs +++ b/Devices/Keyboard/CorsairKeyboard.cs @@ -1,4 +1,8 @@ -using System; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global +// ReSharper disable UnusedMember.Global + +using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -28,26 +32,13 @@ namespace CUE.NET.Devices.Keyboard CorsairKey key; return _keys.TryGetValue(keyId, out key) ? key : null; } - private set { throw new NotSupportedException(); } } - public CorsairKey this[char key] - { - get { return this[_CUESDK.CorsairGetLedIdForKeyName(key)]; } - private set { throw new NotSupportedException(); } - } + public CorsairKey this[char key] => this[_CUESDK.CorsairGetLedIdForKeyName(key)]; - public CorsairKey this[PointF location] - { - get { return _keys.Values.FirstOrDefault(x => x.KeyRectangle.Contains(location)); } - private set { throw new NotSupportedException(); } - } + public CorsairKey this[PointF location] => _keys.Values.FirstOrDefault(x => x.KeyRectangle.Contains(location)); - public IEnumerable this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] - { - get { return _keys.Values.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, referenceRect) >= minOverlayPercentage); } - private set { throw new NotSupportedException(); } - } + public IEnumerable this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, referenceRect) >= minOverlayPercentage); #endregion @@ -142,6 +133,7 @@ namespace CUE.NET.Devices.Keyboard } } + // ReSharper disable once MemberCanBeMadeStatic.Local - idc private void ApplyBrush(ICollection keys, IBrush brush) { RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle)); diff --git a/Devices/Keyboard/Effects/AbstractEffect.cs b/Devices/Keyboard/Effects/AbstractEffect.cs index 3b9d0a9..25268b0 100644 --- a/Devices/Keyboard/Effects/AbstractEffect.cs +++ b/Devices/Keyboard/Effects/AbstractEffect.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +// ReSharper disable MemberCanBePrivate.Global + +using System.Collections.Generic; using System.Linq; using CUE.NET.Devices.Keyboard.Brushes; using CUE.NET.Devices.Keyboard.Keys; diff --git a/Devices/Keyboard/Effects/EffectTimeContainer.cs b/Devices/Keyboard/Effects/EffectTimeContainer.cs index 22dafca..ea32de4 100644 --- a/Devices/Keyboard/Effects/EffectTimeContainer.cs +++ b/Devices/Keyboard/Effects/EffectTimeContainer.cs @@ -1,4 +1,7 @@ -namespace CUE.NET.Devices.Keyboard.Effects +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global + +namespace CUE.NET.Devices.Keyboard.Effects { internal class EffectTimeContainer { @@ -14,8 +17,8 @@ internal EffectTimeContainer(IEffect effect, long ticksAtLastUpdate) { - Effect = effect; - TicksAtLastUpdate = ticksAtLastUpdate; + this.Effect = effect; + this.TicksAtLastUpdate = ticksAtLastUpdate; } #endregion diff --git a/Devices/Keyboard/Effects/FlashEffect.cs b/Devices/Keyboard/Effects/FlashEffect.cs index 5af00e7..3a538db 100644 --- a/Devices/Keyboard/Effects/FlashEffect.cs +++ b/Devices/Keyboard/Effects/FlashEffect.cs @@ -1,4 +1,7 @@ -using System; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global + +using System; using System.Drawing; using CUE.NET.Devices.Keyboard.Brushes; @@ -117,7 +120,7 @@ namespace CUE.NET.Devices.Keyboard.Effects Decay, Sustain, Release, - Pause, + Pause } } } diff --git a/Devices/Keyboard/Extensions/KeyGroupExtension.cs b/Devices/Keyboard/Extensions/KeyGroupExtension.cs index b68cc7d..73abff3 100644 --- a/Devices/Keyboard/Extensions/KeyGroupExtension.cs +++ b/Devices/Keyboard/Extensions/KeyGroupExtension.cs @@ -1,4 +1,6 @@ -using System.Linq; +// ReSharper disable MemberCanBePrivate.Global + +using System.Linq; using CUE.NET.Devices.Keyboard.Enums; using CUE.NET.Devices.Keyboard.Keys; @@ -33,6 +35,7 @@ namespace CUE.NET.Devices.Keyboard.Extensions return simpleKeyGroup; } + // ReSharper disable once UnusedMethodReturnValue.Global public static bool Attach(this BaseKeyGroup keyGroup) { return keyGroup.Keyboard?.AttachKeyGroup(keyGroup) ?? false; diff --git a/Devices/Keyboard/Keys/CorsairKey.cs b/Devices/Keyboard/Keys/CorsairKey.cs index 7a05530..aaa6705 100644 --- a/Devices/Keyboard/Keys/CorsairKey.cs +++ b/Devices/Keyboard/Keys/CorsairKey.cs @@ -1,4 +1,7 @@ -using System.Drawing; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +using System.Drawing; using CUE.NET.Devices.Generic; using CUE.NET.Devices.Keyboard.Enums; diff --git a/Devices/Keyboard/Keys/ListKeyGroup.cs b/Devices/Keyboard/Keys/ListKeyGroup.cs index bf158a6..5d95aae 100644 --- a/Devices/Keyboard/Keys/ListKeyGroup.cs +++ b/Devices/Keyboard/Keys/ListKeyGroup.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +// ReSharper disable MemberCanBePrivate.Global + +using System.Collections.Generic; using CUE.NET.Devices.Keyboard.Enums; namespace CUE.NET.Devices.Keyboard.Keys diff --git a/Devices/Keyboard/Keys/RectangleKeyGroup.cs b/Devices/Keyboard/Keys/RectangleKeyGroup.cs index 77db408..f29708f 100644 --- a/Devices/Keyboard/Keys/RectangleKeyGroup.cs +++ b/Devices/Keyboard/Keys/RectangleKeyGroup.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global + +using System.Collections.Generic; using System.Drawing; using System.Linq; using CUE.NET.Devices.Keyboard.Enums; diff --git a/Helper/ColorHelper.cs b/Helper/ColorHelper.cs index 8f3df61..b4cbc7e 100644 --- a/Helper/ColorHelper.cs +++ b/Helper/ColorHelper.cs @@ -36,6 +36,7 @@ namespace CUE.NET.Helper private static byte GetIntColorFromFloat(float f) { + // ReSharper disable once RedundantCast - never trust this ... float calcF = (float)Math.Max(0f, Math.Min(1f, f)); return (byte)(calcF.Equals(1f) ? 255 : calcF * 256f); } @@ -69,7 +70,9 @@ namespace CUE.NET.Helper int max = Math.Max(color.R, Math.Max(color.G, color.B)); int min = Math.Min(color.R, Math.Min(color.G, color.B)); + // ReSharper disable RedundantCast - never trust this ... return (max == 0) ? 0 : 1f - ((float)min / (float)max); + // ReSharper restore RedundantCast } public static float GetHSVValue(this Color color)