mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 13:06:24 +00:00
Code cleanup
This commit is contained in:
1 parent
f8c537aaff
commit
8390c7da68
22 files changed
+146
-116
No files matched your search
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user