1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-13 09:08:34 +00:00

Refactored before merge

This commit is contained in:
Darth Affe 2015-10-09 21:36:12 +02:00
parent b977edf1da
commit 920821deee
14 changed files with 61 additions and 35 deletions

View File

@ -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; using CUE.NET.Helper;
namespace CUE.NET.Devices.Generic namespace CUE.NET.Devices.Generic
@ -28,8 +32,6 @@ namespace CUE.NET.Devices.Generic
public bool IsLocked { get; set; } = false; public bool IsLocked { get; set; } = false;
//TODO DarthAffe 19.09.2015: Add effects and stuff
#endregion #endregion
#region Constructors #region Constructors

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; // ReSharper disable MemberCanBeProtected.Global
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
@ -14,10 +16,10 @@ namespace CUE.NET.Devices.Keyboard.Brushes.Gradient
#region Constructors #region Constructors
public AbstractGradient() protected AbstractGradient()
{ } { }
public AbstractGradient(params GradientStop[] gradientStops) protected AbstractGradient(params GradientStop[] gradientStops)
{ {
foreach (GradientStop gradientStop in gradientStops) foreach (GradientStop gradientStop in gradientStops)
GradientStops.Add(gradientStop); GradientStops.Add(gradientStop);

View File

@ -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 namespace CUE.NET.Devices.Keyboard.Brushes.Gradient
{ {

View File

@ -1,6 +1,7 @@
// ReSharper disable CollectionNeverUpdated.Global // ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable ReturnTypeCanBeEnumerable.Global // ReSharper disable ReturnTypeCanBeEnumerable.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using System.Drawing; using System.Drawing;
using CUE.NET.Devices.Keyboard.Brushes.Gradient; using CUE.NET.Devices.Keyboard.Brushes.Gradient;

View File

@ -1,4 +1,7 @@
using System; // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using System;
using System.Drawing; using System.Drawing;
using CUE.NET.Devices.Keyboard.Brushes.Gradient; using CUE.NET.Devices.Keyboard.Brushes.Gradient;
using CUE.NET.Helper; 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); 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) // 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), 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.Width, rectangle.Y), centerPoint)),
GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)), GradientHelper.CalculateDistance(new PointF(rectangle.X, rectangle.Y + rectangle.Height), centerPoint)),

View File

@ -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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -28,26 +32,13 @@ namespace CUE.NET.Devices.Keyboard
CorsairKey key; CorsairKey key;
return _keys.TryGetValue(keyId, out key) ? key : null; return _keys.TryGetValue(keyId, out key) ? key : null;
} }
private set { throw new NotSupportedException(); }
} }
public CorsairKey this[char key] public CorsairKey this[char key] => this[_CUESDK.CorsairGetLedIdForKeyName(key)];
{
get { return this[_CUESDK.CorsairGetLedIdForKeyName(key)]; }
private set { throw new NotSupportedException(); }
}
public CorsairKey this[PointF location] public CorsairKey this[PointF location] => _keys.Values.FirstOrDefault(x => x.KeyRectangle.Contains(location));
{
get { return _keys.Values.FirstOrDefault(x => x.KeyRectangle.Contains(location)); }
private set { throw new NotSupportedException(); }
}
public IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] public IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, referenceRect) >= minOverlayPercentage);
{
get { return _keys.Values.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, referenceRect) >= minOverlayPercentage); }
private set { throw new NotSupportedException(); }
}
#endregion #endregion
@ -142,6 +133,7 @@ namespace CUE.NET.Devices.Keyboard
} }
} }
// ReSharper disable once MemberCanBeMadeStatic.Local - idc
private void ApplyBrush(ICollection<CorsairKey> keys, IBrush brush) private void ApplyBrush(ICollection<CorsairKey> keys, IBrush brush)
{ {
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle)); RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; // ReSharper disable MemberCanBePrivate.Global
using System.Collections.Generic;
using System.Linq; using System.Linq;
using CUE.NET.Devices.Keyboard.Brushes; using CUE.NET.Devices.Keyboard.Brushes;
using CUE.NET.Devices.Keyboard.Keys; using CUE.NET.Devices.Keyboard.Keys;

View File

@ -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 internal class EffectTimeContainer
{ {
@ -14,8 +17,8 @@
internal EffectTimeContainer(IEffect effect, long ticksAtLastUpdate) internal EffectTimeContainer(IEffect effect, long ticksAtLastUpdate)
{ {
Effect = effect; this.Effect = effect;
TicksAtLastUpdate = ticksAtLastUpdate; this.TicksAtLastUpdate = ticksAtLastUpdate;
} }
#endregion #endregion

View File

@ -1,4 +1,7 @@
using System; // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
using System;
using System.Drawing; using System.Drawing;
using CUE.NET.Devices.Keyboard.Brushes; using CUE.NET.Devices.Keyboard.Brushes;
@ -117,7 +120,7 @@ namespace CUE.NET.Devices.Keyboard.Effects
Decay, Decay,
Sustain, Sustain,
Release, Release,
Pause, Pause
} }
} }
} }

View File

@ -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.Enums;
using CUE.NET.Devices.Keyboard.Keys; using CUE.NET.Devices.Keyboard.Keys;
@ -33,6 +35,7 @@ namespace CUE.NET.Devices.Keyboard.Extensions
return simpleKeyGroup; return simpleKeyGroup;
} }
// ReSharper disable once UnusedMethodReturnValue.Global
public static bool Attach(this BaseKeyGroup keyGroup) public static bool Attach(this BaseKeyGroup keyGroup)
{ {
return keyGroup.Keyboard?.AttachKeyGroup(keyGroup) ?? false; return keyGroup.Keyboard?.AttachKeyGroup(keyGroup) ?? false;

View File

@ -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.Generic;
using CUE.NET.Devices.Keyboard.Enums; using CUE.NET.Devices.Keyboard.Enums;

View File

@ -1,4 +1,6 @@
using System.Collections.Generic; // ReSharper disable MemberCanBePrivate.Global
using System.Collections.Generic;
using CUE.NET.Devices.Keyboard.Enums; using CUE.NET.Devices.Keyboard.Enums;
namespace CUE.NET.Devices.Keyboard.Keys namespace CUE.NET.Devices.Keyboard.Keys

View File

@ -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.Drawing;
using System.Linq; using System.Linq;
using CUE.NET.Devices.Keyboard.Enums; using CUE.NET.Devices.Keyboard.Enums;

View File

@ -36,6 +36,7 @@ namespace CUE.NET.Helper
private static byte GetIntColorFromFloat(float f) private static byte GetIntColorFromFloat(float f)
{ {
// ReSharper disable once RedundantCast - never trust this ...
float calcF = (float)Math.Max(0f, Math.Min(1f, f)); float calcF = (float)Math.Max(0f, Math.Min(1f, f));
return (byte)(calcF.Equals(1f) ? 255 : calcF * 256f); 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 max = Math.Max(color.R, Math.Max(color.G, color.B));
int min = Math.Min(color.R, Math.Min(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); return (max == 0) ? 0 : 1f - ((float)min / (float)max);
// ReSharper restore RedundantCast
} }
public static float GetHSVValue(this Color color) public static float GetHSVValue(this Color color)