1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Code cleanup

This commit is contained in:
Darth Affe 2016-09-10 18:06:07 +02:00
parent f8c537aaff
commit 8390c7da68
22 changed files with 146 additions and 116 deletions

View File

@ -1,5 +1,6 @@
// ReSharper disable VirtualMemberNeverOverriden.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable VirtualMemberNeverOverridden.Global
using System.Collections.Generic;
using System.Drawing;

View File

@ -1,4 +1,5 @@
// ReSharper disable UnusedMemberInSuper.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using System.Drawing;

View File

@ -1,5 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Drawing;

View File

@ -60,7 +60,7 @@
<Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" />
<Compile Include="Devices\Generic\LedUpateRequest.cs" />
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
<Compile Include="Effects\AbstractKeyGroupEffect.cs" />
<Compile Include="Effects\AbstractLedGroupEffect.cs" />
<Compile Include="Effects\AbstractBrushEffect.cs" />
<Compile Include="Effects\AbstractEffectTarget.cs" />
<Compile Include="Effects\IEffectTarget.cs" />

View File

@ -1,4 +1,5 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using System.Runtime.InteropServices;
@ -85,6 +86,7 @@ namespace CUE.NET
{
if (IsInitialized)
{
// ReSharper disable once SwitchStatementMissingSomeCases - everything else is true
switch (sdkType)
{
case CorsairDeviceType.Keyboard:

View File

@ -1,5 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMethodReturnValue.Global
// ReSharper disable VirtualMemberNeverOverridden.Global
using System;
using System.Collections;
@ -33,11 +34,6 @@ namespace CUE.NET.Devices.Generic
private Task _updateTask;
private DateTime _lastUpdate = DateTime.Now;
/// <summary>
/// Gets a list of attached ledgroups.
/// </summary>
protected LinkedList<ILedGroup> LedGroups { get; } = new LinkedList<ILedGroup>();
/// <summary>
/// Gets generic information provided by CUE for the device.
/// </summary>
@ -77,6 +73,11 @@ namespace CUE.NET.Devices.Generic
/// </summary>
public IEnumerable<CorsairLed> Leds => new ReadOnlyCollection<CorsairLed>(LedMapping.Values.ToList());
/// <summary>
/// Gets a list of attached ledgroups.
/// </summary>
protected LinkedList<ILedGroup> LedGroups { get; } = new LinkedList<ILedGroup>();
/// <summary>
/// Gets or sets the background brush of the keyboard.
/// </summary>
@ -174,6 +175,11 @@ namespace CUE.NET.Devices.Generic
#region Methods
#region Initialize
/// <summary>
/// Initializes the LEDs of the device.
/// </summary>
protected abstract void InitializeLeds();
/// <summary>
@ -184,16 +190,26 @@ namespace CUE.NET.Devices.Generic
/// <returns></returns>
protected CorsairLed InitializeLed(CorsairLedId ledId, RectangleF ledRectangle)
{
if (!LedMapping.ContainsKey(ledId))
{
CorsairLed led = new CorsairLed(ledId, ledRectangle);
LedMapping.Add(ledId, led);
return led;
}
if (LedMapping.ContainsKey(ledId)) return null;
return null;
CorsairLed led = new CorsairLed(ledId, ledRectangle);
LedMapping.Add(ledId, led);
return led;
}
/// <summary>
/// Resets all loaded LEDs back to default.
/// </summary>
internal void ResetLeds()
{
foreach (CorsairLed led in LedMapping.Values)
led.Reset();
}
#endregion
#region Update-Loop
/// <summary>
/// Checks if automatic updates should occur and starts/stops the update-loop if needed.
/// </summary>
@ -240,6 +256,10 @@ namespace CUE.NET.Devices.Generic
}
}
#endregion
#region Update
/// <summary>
/// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
/// </summary>
@ -276,41 +296,6 @@ namespace CUE.NET.Devices.Generic
protected virtual void DeviceUpdate()
{ }
/// <summary>
/// Attaches the given ledgroup.
/// </summary>
/// <param name="ledGroup">The ledgroup to attach.</param>
/// <returns><c>true</c> if the ledgroup could be attached; otherwise, <c>false</c>.</returns>
public bool AttachLedGroup(ILedGroup ledGroup)
{
lock (LedGroups)
{
if (ledGroup == null || LedGroups.Contains(ledGroup)) return false;
LedGroups.AddLast(ledGroup);
return true;
}
}
/// <summary>
/// Detaches the given ledgroup.
/// </summary>
/// <param name="ledGroup">The ledgroup to detached.</param>
/// <returns><c>true</c> if the ledgroup could be detached; otherwise, <c>false</c>.</returns>
public bool DetachLedGroup(ILedGroup ledGroup)
{
lock (LedGroups)
{
if (ledGroup == null) return false;
LinkedListNode<ILedGroup> node = LedGroups.Find(ledGroup);
if (node == null) return false;
LedGroups.Remove(node);
return true;
}
}
/// <summary>
/// Renders a ledgroup.
/// </summary>
@ -381,13 +366,43 @@ namespace CUE.NET.Devices.Generic
OnLedsUpdated(updateRequests);
}
#endregion
#region LedGroup
/// <summary>
/// Resets all loaded LEDs back to default.
/// Attaches the given ledgroup.
/// </summary>
internal void ResetLeds()
/// <param name="ledGroup">The ledgroup to attach.</param>
/// <returns><c>true</c> if the ledgroup could be attached; otherwise, <c>false</c>.</returns>
public bool AttachLedGroup(ILedGroup ledGroup)
{
foreach (CorsairLed led in LedMapping.Values)
led.Reset();
lock (LedGroups)
{
if (ledGroup == null || LedGroups.Contains(ledGroup)) return false;
LedGroups.AddLast(ledGroup);
return true;
}
}
/// <summary>
/// Detaches the given ledgroup.
/// </summary>
/// <param name="ledGroup">The ledgroup to detached.</param>
/// <returns><c>true</c> if the ledgroup could be detached; otherwise, <c>false</c>.</returns>
public bool DetachLedGroup(ILedGroup ledGroup)
{
lock (LedGroups)
{
if (ledGroup == null) return false;
LinkedListNode<ILedGroup> node = LedGroups.Find(ledGroup);
if (node == null) return false;
LedGroups.Remove(node);
return true;
}
}
/// <summary>
@ -399,32 +414,34 @@ namespace CUE.NET.Devices.Generic
return Leds;
}
#endregion
#region Effects
/// <summary>
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a keygroup instead.
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.
/// </summary>
public void UpdateEffects()
{
throw new NotSupportedException("Effects can't be applied directly to the device. Add it to the Brush or create a keygroup instead.");
throw new NotSupportedException("Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.");
}
/// <summary>
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a keygroup instead.
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.
/// </summary>
/// <param name="effect">The effect to add.</param>
public void AddEffect(IEffect<ILedGroup> effect)
{
throw new NotSupportedException("Effects can't be applied directly to the device. Add it to the Brush or create a keygroup instead.");
throw new NotSupportedException("Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.");
}
/// <summary>
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a keygroup instead.
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.
/// </summary>
/// <param name="effect">The effect to remove.</param>
public void RemoveEffect(IEffect<ILedGroup> effect)
{
throw new NotSupportedException("Effects can't be applied directly to the device. Add it to the Brush or create a keygroup instead.");
throw new NotSupportedException("Effects can't be applied directly to the device. Add it to the Brush or create a ledgroup instead.");
}
#endregion

View File

@ -1,4 +1,6 @@
namespace CUE.NET.Devices.Generic.Enums
// ReSharper disable InconsistentNaming
namespace CUE.NET.Devices.Generic.Enums
{
/// <summary>
/// Contains list of all LEDs available for all corsair devices.

View File

@ -1,6 +1,4 @@
using CUE.NET.Effects;
namespace CUE.NET.Devices.Generic.Enums
namespace CUE.NET.Devices.Generic.Enums
{
/// <summary>
/// Contains list of available update modes.
@ -8,12 +6,12 @@ namespace CUE.NET.Devices.Generic.Enums
public enum UpdateMode
{
/// <summary>
/// The device will not perform automatic updates. Updates will only occur if <see cref="CUE.NET.Devices.ICueDevice.Update" /> is called.
/// The device will not perform automatic updates. Updates will only occur if <see cref="ICueDevice.Update" /> is called.
/// </summary>
Manual,
/// <summary>
/// The device will perform automatic updates at the rate set in <see cref="CUE.NET.Devices.ICueDevice.UpdateFrequency" />.
/// The device will perform automatic updates at the rate set in <see cref="ICueDevice.UpdateFrequency" />.
/// </summary>
Continuous
}

View File

@ -4,7 +4,6 @@
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Headset.Enums;
namespace CUE.NET.Devices.Headset
@ -39,6 +38,9 @@ namespace CUE.NET.Devices.Headset
#region Methods
/// <summary>
/// Initializes the LEDs of the device.
/// </summary>
protected override void InitializeLeds()
{
InitializeLed(CorsairHeadsetLedId.LeftLogo, new RectangleF(0, 0, 1, 1));

View File

@ -4,18 +4,9 @@
// ReSharper disable UnusedMember.Global
using System;
using System.Collections;
using System.Collections.Generic;
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.Enums;
using CUE.NET.Effects;
using CUE.NET.Groups;
using CUE.NET.Helper;
using CUE.NET.Native;
namespace CUE.NET.Devices.Keyboard
@ -50,6 +41,9 @@ namespace CUE.NET.Devices.Keyboard
#region Methods
/// <summary>
/// Initializes the LEDs of the device.
/// </summary>
protected override void InitializeLeds()
{
_CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions));
@ -63,6 +57,7 @@ namespace CUE.NET.Devices.Keyboard
ptr = new IntPtr(ptr.ToInt64() + structSize);
}
}
#endregion
}
}

View File

@ -6,7 +6,7 @@
public enum BrushCalculationMode
{
/// <summary>
/// The calculation rectangle for brushes will be the rectangle around the keygroup the brush is applied to.
/// The calculation rectangle for brushes will be the rectangle around the ledgroup the brush is applied to.
/// </summary>
Relative,
/// <summary>

View File

@ -4,7 +4,6 @@
using System.Drawing;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Mouse.Enums;
using CUE.NET.Exceptions;
@ -40,6 +39,9 @@ namespace CUE.NET.Devices.Mouse
#region Methods
/// <summary>
/// Initializes the LEDs of the device.
/// </summary>
protected override void InitializeLeds()
{
switch (MouseDeviceInfo.PhysicalLayout)

View File

@ -3,9 +3,7 @@
// ReSharper disable UnusedMember.Global
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
@ -46,6 +44,9 @@ namespace CUE.NET.Devices.Mousemat
#region Methods
/// <summary>
/// Initializes the LEDs of the device.
/// </summary>
protected override void InitializeLeds()
{
int deviceCount = _CUESDK.CorsairGetDeviceCount();

View File

@ -14,7 +14,7 @@ namespace CUE.NET.Effects
where T : IEffectTarget<T>
{
#region Properties & Fields
private IList<EffectTimeContainer> _effectTimes = new List<EffectTimeContainer>();
/// <summary>
@ -68,11 +68,10 @@ namespace CUE.NET.Effects
/// <param name="effect">The effect to add.</param>
public void AddEffect(IEffect<T> effect)
{
if (_effectTimes.All(x => x.Effect != effect))
{
effect.OnAttach(EffectTarget);
_effectTimes.Add(new EffectTimeContainer(effect, -1));
}
if (_effectTimes.Any(x => x.Effect == effect)) return;
effect.OnAttach(EffectTarget);
_effectTimes.Add(new EffectTimeContainer(effect, -1));
}
/// <summary>
@ -82,11 +81,10 @@ namespace CUE.NET.Effects
public void RemoveEffect(IEffect<T> effect)
{
EffectTimeContainer effectTimeToRemove = _effectTimes.FirstOrDefault(x => x.Effect == effect);
if (effectTimeToRemove != null)
{
effect.OnDetach(EffectTarget);
_effectTimes.Remove(effectTimeToRemove);
}
if (effectTimeToRemove == null) return;
effect.OnDetach(EffectTarget);
_effectTimes.Remove(effectTimeToRemove);
}
#endregion

View File

@ -1,5 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedMember.Global
using CUE.NET.Groups;
@ -8,7 +9,7 @@ namespace CUE.NET.Effects
/// <summary>
/// Represents a basic effect targeting an <see cref="ILedGroup"/>.
/// </summary>
public abstract class AbstractKeyGroupEffect : IEffect<ILedGroup>
public abstract class AbstractLedGroupEffect : IEffect<ILedGroup>
{
#region Properties & Fields

View File

@ -1,5 +1,6 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedMemberInSuper.Global
// ReSharper disable UnusedParameter.Global
namespace CUE.NET.Effects
{

View File

@ -1,4 +1,6 @@
namespace CUE.NET.Effects
// ReSharper disable UnusedMember.Global
namespace CUE.NET.Effects
{
/// <summary>
/// Represents a basic effect-target.

View File

@ -8,7 +8,7 @@ using CUE.NET.Groups.Extensions;
namespace CUE.NET.Groups
{
/// <summary>
/// Represents a basic keygroup.
/// Represents a basic ledgroup.
/// </summary>
public abstract class AbstractLedGroup : AbstractEffectTarget<ILedGroup>, ILedGroup
{
@ -30,7 +30,7 @@ namespace CUE.NET.Groups
public IBrush Brush { get; set; }
/// <summary>
/// Gets or sets the z-index of this keygroup to allow ordering them before drawing. (lowest first) (default: 0)
/// Gets or sets the z-index of this ledgroup to allow ordering them before drawing. (lowest first) (default: 0)
/// </summary>
public int ZIndex { get; set; } = 0;

View File

@ -16,7 +16,7 @@ namespace CUE.NET.Groups.Extensions
/// </summary>
/// <param name="ledGroup">The <see cref="AbstractLedGroup" /> to convert.</param>
/// <returns>The converted <see cref="ListLedGroup" />.</returns>
public static ListLedGroup ToSimpleKeyGroup(this AbstractLedGroup ledGroup)
public static ListLedGroup ToSimpleLedGroup(this AbstractLedGroup ledGroup)
{
ListLedGroup simpleLedGroup = ledGroup as ListLedGroup;
if (simpleLedGroup == null)
@ -35,7 +35,7 @@ namespace CUE.NET.Groups.Extensions
/// <returns>The new <see cref="ListLedGroup" />.</returns>
public static ListLedGroup Exclude(this AbstractLedGroup ledGroup, params CorsairLedId[] ledIds)
{
ListLedGroup simpleLedGroup = ledGroup.ToSimpleKeyGroup();
ListLedGroup simpleLedGroup = ledGroup.ToSimpleLedGroup();
foreach (CorsairLedId ledId in ledIds)
simpleLedGroup.RemoveLed(ledId);
return simpleLedGroup;
@ -49,7 +49,7 @@ namespace CUE.NET.Groups.Extensions
/// <returns>The new <see cref="ListLedGroup" />.</returns>
public static ListLedGroup Exclude(this AbstractLedGroup ledGroup, params CorsairLed[] ledIds)
{
ListLedGroup simpleLedGroup = ledGroup.ToSimpleKeyGroup();
ListLedGroup simpleLedGroup = ledGroup.ToSimpleLedGroup();
foreach (CorsairLed led in ledIds)
simpleLedGroup.RemoveLed(led);
return simpleLedGroup;

View File

@ -16,7 +16,7 @@ namespace CUE.NET.Groups
IBrush Brush { get; set; }
/// <summary>
/// Gets or sets the z-index of this keygroup to allow ordering them before drawing. (lowest first) (default: 0)
/// Gets or sets the z-index of this ledgroup to allow ordering them before drawing. (lowest first) (default: 0)
/// </summary>
int ZIndex { get; set; }

View File

@ -126,10 +126,10 @@ namespace CUE.NET.Groups
/// <summary>
/// Adds the given LED(s) to the ledgroup.
/// </summary>
/// <param name="LEDs">The LED(s) to add.</param>
public void AddLed(params CorsairLed[] LEDs)
/// <param name="leds">The LED(s) to add.</param>
public void AddLed(params CorsairLed[] leds)
{
AddLeds(LEDs);
AddLeds(leds);
}
/// <summary>
@ -147,10 +147,11 @@ namespace CUE.NET.Groups
/// <param name="leds">The LEDs to add.</param>
public void AddLeds(IEnumerable<CorsairLed> leds)
{
if (leds != null)
foreach (CorsairLed led in leds)
if (led != null && !ContainsLed(led))
GroupLeds.Add(led);
if (leds == null) return;
foreach (CorsairLed led in leds)
if (led != null && !ContainsLed(led))
GroupLeds.Add(led);
}
/// <summary>
@ -159,9 +160,10 @@ namespace CUE.NET.Groups
/// <param name="ledIds">The IDs of the LEDs to add.</param>
public void AddLeds(IEnumerable<CorsairLedId> ledIds)
{
if (ledIds != null)
foreach (CorsairLedId ledId in ledIds)
AddLed(Device[ledId]);
if (ledIds == null) return;
foreach (CorsairLedId ledId in ledIds)
AddLed(Device[ledId]);
}
/// <summary>
@ -188,10 +190,11 @@ namespace CUE.NET.Groups
/// <param name="leds">The LEDs to remove.</param>
public void RemoveLeds(IEnumerable<CorsairLed> leds)
{
if (leds != null)
foreach (CorsairLed led in leds)
if (led != null)
GroupLeds.Remove(led);
if (leds == null) return;
foreach (CorsairLed led in leds)
if (led != null)
GroupLeds.Remove(led);
}
/// <summary>
@ -200,9 +203,10 @@ namespace CUE.NET.Groups
/// <param name="ledIds">The IDs of the LEDs to remove.</param>
public void RemoveLeds(IEnumerable<CorsairLedId> ledIds)
{
if (ledIds != null)
foreach (CorsairLedId ledId in ledIds)
RemoveLed(Device[ledId]);
if (ledIds == null) return;
foreach (CorsairLedId ledId in ledIds)
RemoveLed(Device[ledId]);
}
/// <summary>

View File

@ -1,7 +1,9 @@
using System;
// ReSharper disable UnusedMethodReturnValue.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Runtime.InteropServices;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Keyboard.Enums;
namespace CUE.NET.Native
{