mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 04:56:44 +00:00
Refactored to do everything based on LEDs.
This will adapt the devices and reduces the importance of the "special case keyboard"
This commit is contained in:
1 parent
bfe51add66
commit
5a018d0743
24 files changed
+847
-894
No files matched your search
@@ -2,14 +2,21 @@
|
||||
// ReSharper disable UnusedMethodReturnValue.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 System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Generic.EventArgs;
|
||||
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.Generic
|
||||
@@ -21,6 +28,16 @@ namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private CancellationTokenSource _updateTokenSource;
|
||||
private CancellationToken _updateToken;
|
||||
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>
|
||||
@@ -45,15 +62,65 @@ namespace CUE.NET.Devices.Generic
|
||||
/// </summary>
|
||||
public float UpdateFrequency { get; set; } = 1f / 30f;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rectangle containing all LEDs of the device.
|
||||
/// </summary>
|
||||
public RectangleF DeviceRectangle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary containing all LEDs of the device.
|
||||
/// </summary>
|
||||
protected Dictionary<int, CorsairLed> Leds { get; } = new Dictionary<int, CorsairLed>();
|
||||
protected Dictionary<CorsairLedId, CorsairLed> LedMapping { get; } = new Dictionary<CorsairLedId, CorsairLed>();
|
||||
|
||||
private CancellationTokenSource _updateTokenSource;
|
||||
private CancellationToken _updateToken;
|
||||
private Task _updateTask;
|
||||
private DateTime _lastUpdate = DateTime.Now;
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing the LEDs of the device.
|
||||
/// </summary>
|
||||
public IEnumerable<CorsairLed> Leds => new ReadOnlyCollection<CorsairLed>(LedMapping.Values.ToList());
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the background brush of the keyboard.
|
||||
/// </summary>
|
||||
public IBrush Brush { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the z-index of the background brush of the keyboard.<br />
|
||||
/// This value has absolutely no effect.
|
||||
/// </summary>
|
||||
public int ZIndex { get; set; } = 0;
|
||||
|
||||
#region Indexers
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The ID of the LED to get.</param>
|
||||
/// <returns>The LED with the specified ID or null if no LED is found.</returns>
|
||||
public CorsairLed this[CorsairLedId ledId]
|
||||
{
|
||||
get
|
||||
{
|
||||
CorsairLed key;
|
||||
return LedMapping.TryGetValue(ledId, out key) ? key : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> at the given physical location.
|
||||
/// </summary>
|
||||
/// <param name="location">The point to get the location from.</param>
|
||||
/// <returns>The LED at the given point or null if no location is found.</returns>
|
||||
public CorsairLed this[PointF location] => LedMapping.Values.FirstOrDefault(x => x.LedRectangle.Contains(location));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="CorsairLed" /> inside the given rectangle.
|
||||
/// </summary>
|
||||
/// <param name="referenceRect">The rectangle to check.</param>
|
||||
/// <param name="minOverlayPercentage">The minimal percentage overlay a location must have with the <see cref="Rectangle" /> to be taken into the list.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<CorsairLed> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => LedMapping.Values
|
||||
.Where(x => RectangleHelper.CalculateIntersectPercentage(x.LedRectangle, referenceRect) >= minOverlayPercentage);
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -96,6 +163,10 @@ namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
this.DeviceInfo = info;
|
||||
|
||||
// ReSharper disable once VirtualMemberCallInConstructor - I know, but I need this ...
|
||||
InitializeLeds();
|
||||
DeviceRectangle = RectangleHelper.CreateRectangleFromRectangles(((IEnumerable<CorsairLed>)this).Select(x => x.LedRectangle));
|
||||
|
||||
CheckUpdateLoop();
|
||||
}
|
||||
|
||||
@@ -103,18 +174,20 @@ namespace CUE.NET.Devices.Generic
|
||||
|
||||
#region Methods
|
||||
|
||||
protected abstract void InitializeLeds();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the LED-Object with the specified id.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The LED-Id to initialize.</param>
|
||||
/// <param name="ledRectangle">The rectangle representing the position of the LED to initialize.</param>
|
||||
/// <returns></returns>
|
||||
protected CorsairLed InitializeLed(int ledId, RectangleF ledRectangle)
|
||||
protected CorsairLed InitializeLed(CorsairLedId ledId, RectangleF ledRectangle)
|
||||
{
|
||||
if (!Leds.ContainsKey(ledId))
|
||||
if (!LedMapping.ContainsKey(ledId))
|
||||
{
|
||||
CorsairLed led = new CorsairLed(ledRectangle);
|
||||
Leds.Add(ledId, led);
|
||||
CorsairLed led = new CorsairLed(ledId, ledRectangle);
|
||||
LedMapping.Add(ledId, led);
|
||||
return led;
|
||||
}
|
||||
|
||||
@@ -175,12 +248,22 @@ namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
OnUpdating();
|
||||
|
||||
// Update effects
|
||||
foreach (ILedGroup ledGroup in LedGroups)
|
||||
ledGroup.UpdateEffects();
|
||||
|
||||
// Render brushes
|
||||
Render(this);
|
||||
foreach (ILedGroup ledGroup in LedGroups.OrderBy(x => x.ZIndex))
|
||||
Render(ledGroup);
|
||||
|
||||
// Device-specific updates
|
||||
DeviceUpdate();
|
||||
|
||||
ICollection<LedUpateRequest> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();
|
||||
|
||||
foreach (CorsairLed led in Leds.Values)
|
||||
led.Update();
|
||||
// Send LEDs to SDK
|
||||
ICollection<LedUpateRequest> ledsToUpdate = (flushLeds ? LedMapping : LedMapping.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();
|
||||
foreach (LedUpateRequest updateRequest in ledsToUpdate)
|
||||
LedMapping[updateRequest.LedId].Update();
|
||||
|
||||
UpdateLeds(ledsToUpdate);
|
||||
|
||||
@@ -190,7 +273,82 @@ namespace CUE.NET.Devices.Generic
|
||||
/// <summary>
|
||||
/// Performs device specific updates.
|
||||
/// </summary>
|
||||
protected abstract void DeviceUpdate();
|
||||
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>
|
||||
/// <param name="ledGroup">The led group to render.</param>
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Local - idc
|
||||
protected virtual void Render(ILedGroup ledGroup)
|
||||
{
|
||||
IList<CorsairLed> leds = ledGroup.GetLeds().ToList();
|
||||
IBrush brush = ledGroup.Brush;
|
||||
|
||||
try
|
||||
{
|
||||
switch (brush.BrushCalculationMode)
|
||||
{
|
||||
case BrushCalculationMode.Relative:
|
||||
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(leds.Select(x => x.LedRectangle));
|
||||
float offsetX = -brushRectangle.X;
|
||||
float offsetY = -brushRectangle.Y;
|
||||
brushRectangle.X = 0;
|
||||
brushRectangle.Y = 0;
|
||||
brush.PerformRender(brushRectangle, leds.Select(x => new BrushRenderTarget(x.Id, x.LedRectangle.GetCenter(offsetX, offsetY))));
|
||||
break;
|
||||
case BrushCalculationMode.Absolute:
|
||||
brush.PerformRender(DeviceRectangle, leds.Select(x => new BrushRenderTarget(x.Id, x.LedRectangle.GetCenter())));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
brush.UpdateEffects();
|
||||
brush.PerformFinalize();
|
||||
|
||||
foreach (KeyValuePair<BrushRenderTarget, Color> renders in brush.RenderedTargets)
|
||||
this[renders.Key.LedId].Color = renders.Value;
|
||||
}
|
||||
// ReSharper disable once CatchAllClause
|
||||
catch (Exception ex) { OnException(ex); }
|
||||
}
|
||||
|
||||
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
|
||||
{
|
||||
@@ -207,7 +365,7 @@ namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
_CorsairLedColor color = new _CorsairLedColor
|
||||
{
|
||||
ledId = ledUpdateRequest.LedId,
|
||||
ledId = (int)ledUpdateRequest.LedId,
|
||||
r = ledUpdateRequest.Color.R,
|
||||
g = ledUpdateRequest.Color.G,
|
||||
b = ledUpdateRequest.Color.B
|
||||
@@ -228,10 +386,49 @@ namespace CUE.NET.Devices.Generic
|
||||
/// </summary>
|
||||
internal void ResetLeds()
|
||||
{
|
||||
foreach (CorsairLed led in Leds.Values)
|
||||
foreach (CorsairLed led in LedMapping.Values)
|
||||
led.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing all LEDs of this group.
|
||||
/// </summary>
|
||||
/// <returns>The list containing all LEDs of this group.</returns>
|
||||
public IEnumerable<CorsairLed> GetLeds()
|
||||
{
|
||||
return Leds;
|
||||
}
|
||||
|
||||
#region Effects
|
||||
|
||||
/// <summary>
|
||||
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a keygroup 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.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a keygroup 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.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NOT IMPLEMENTED: Effects can't be applied directly to the device. Add it to the Brush or create a keygroup 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.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region EventCaller
|
||||
|
||||
/// <summary>
|
||||
@@ -313,6 +510,28 @@ namespace CUE.NET.Devices.Generic
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all LEDs of the device.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all LEDs of the device.</returns>
|
||||
public IEnumerator<CorsairLed> GetEnumerator()
|
||||
{
|
||||
return LedMapping.Values.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all LEDs of the device.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all LEDs of the device.</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
|
||||
using System.Drawing;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Helper;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
@@ -13,7 +14,9 @@ namespace CUE.NET.Devices.Generic
|
||||
public class CorsairLed
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
|
||||
public CorsairLedId Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a rectangle representing the physical location of the led.
|
||||
/// </summary>
|
||||
@@ -24,11 +27,6 @@ namespace CUE.NET.Devices.Generic
|
||||
/// </summary>
|
||||
public bool IsDirty => RequestedColor != _color;
|
||||
|
||||
/// <summary>
|
||||
/// Indicate whether the Color of the LED was set since the last update.
|
||||
/// </summary>
|
||||
public bool IsUpdated { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Color the LED should be set to on the next update.
|
||||
/// </summary>
|
||||
@@ -36,7 +34,7 @@ namespace CUE.NET.Devices.Generic
|
||||
|
||||
private Color _color = Color.Transparent;
|
||||
/// <summary>
|
||||
/// Gets the current color of the LED. Sets the <see cref="RequestedColor" /> for the next update and mark the LED as <see cref="IsUpdated" />.
|
||||
/// Gets the current color of the LED. Sets the <see cref="RequestedColor" /> for the next update. />.
|
||||
/// </summary>
|
||||
public Color Color
|
||||
{
|
||||
@@ -44,10 +42,7 @@ namespace CUE.NET.Devices.Generic
|
||||
set
|
||||
{
|
||||
if (!IsLocked)
|
||||
{
|
||||
RequestedColor = RequestedColor.Blend(value);
|
||||
IsUpdated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +58,11 @@ namespace CUE.NET.Devices.Generic
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CorsairLed"/> class.
|
||||
/// </summary>
|
||||
/// <param name="ledRectangle">The rectangle representing the physical location of the led.</param>
|
||||
internal CorsairLed(RectangleF ledRectangle)
|
||||
/// <param name="id">The ID of the LED</param>
|
||||
/// <param name="ledRectangle">The rectangle representing the physical location of the LED.</param>
|
||||
internal CorsairLed(CorsairLedId id, RectangleF ledRectangle)
|
||||
{
|
||||
this.Id = id;
|
||||
this.LedRectangle = ledRectangle;
|
||||
}
|
||||
|
||||
@@ -79,7 +76,6 @@ namespace CUE.NET.Devices.Generic
|
||||
internal void Update()
|
||||
{
|
||||
_color = RequestedColor;
|
||||
IsUpdated = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -89,7 +85,6 @@ namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
_color = Color.Transparent;
|
||||
RequestedColor = Color.Transparent;
|
||||
IsUpdated = false;
|
||||
IsLocked = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
|
||||
using System.Drawing;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
|
||||
namespace CUE.NET.Devices.Generic
|
||||
{
|
||||
@@ -15,7 +16,7 @@ namespace CUE.NET.Devices.Generic
|
||||
/// <summary>
|
||||
/// Gets the id of the led to update.
|
||||
/// </summary>
|
||||
public int LedId { get; }
|
||||
public CorsairLedId LedId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the requested color of the led.
|
||||
@@ -31,7 +32,7 @@ namespace CUE.NET.Devices.Generic
|
||||
/// </summary>
|
||||
/// <param name="ledId">The id of the led to update.</param>
|
||||
/// <param name="color">The requested color of the led.</param>
|
||||
public LedUpateRequest(int ledId, Color color)
|
||||
public LedUpateRequest(CorsairLedId ledId, Color color)
|
||||
{
|
||||
this.LedId = ledId;
|
||||
this.Color = color;
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Headset.Enums;
|
||||
|
||||
namespace CUE.NET.Devices.Headset
|
||||
@@ -15,38 +12,15 @@ namespace CUE.NET.Devices.Headset
|
||||
/// <summary>
|
||||
/// Represents the SDK for a corsair headset.
|
||||
/// </summary>
|
||||
public class CorsairHeadset : AbstractCueDevice, IEnumerable<CorsairLed>
|
||||
public class CorsairHeadset : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The ID of the LED to get.</param>
|
||||
/// <returns>The LED with the specified ID.</returns>
|
||||
public CorsairLed this[CorsairHeadsetLedId ledId]
|
||||
{
|
||||
get
|
||||
{
|
||||
CorsairLed led;
|
||||
return base.Leds.TryGetValue((int)ledId, out led) ? led : null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets specific information provided by CUE for the headset.
|
||||
/// </summary>
|
||||
public CorsairHeadsetDeviceInfo HeadsetDeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing all LEDs of the headset.
|
||||
/// </summary>
|
||||
public new IEnumerable<CorsairLed> Leds => new ReadOnlyCollection<CorsairLed>(base.Leds.Values.ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -59,42 +33,18 @@ namespace CUE.NET.Devices.Headset
|
||||
: base(info)
|
||||
{
|
||||
this.HeadsetDeviceInfo = info;
|
||||
InitializeLeds();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLeds()
|
||||
protected override void InitializeLeds()
|
||||
{
|
||||
InitializeLed((int)CorsairHeadsetLedId.LeftLogo, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((int)CorsairHeadsetLedId.RightLogo, new RectangleF(1, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairHeadsetLedId.LeftLogo, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairHeadsetLedId.RightLogo, new RectangleF(1, 0, 1, 1));
|
||||
}
|
||||
|
||||
protected override void DeviceUpdate()
|
||||
{
|
||||
//DarthAffe 21.08.2016: Headsets can't own brushes or groups - nothing to do here for now
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all LEDs of the headset.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all LEDS of the headset.</returns>
|
||||
public IEnumerator<CorsairLed> GetEnumerator()
|
||||
{
|
||||
return Leds.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
+46
-1
@@ -1,8 +1,12 @@
|
||||
// ReSharper disable UnusedMemberInSuper.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Generic.EventArgs;
|
||||
using CUE.NET.Groups;
|
||||
|
||||
namespace CUE.NET.Devices
|
||||
{
|
||||
@@ -44,7 +48,7 @@ namespace CUE.NET.Devices
|
||||
/// <summary>
|
||||
/// Represents a generic cue device.
|
||||
/// </summary>
|
||||
public interface ICueDevice
|
||||
public interface ICueDevice : ILedGroup, IEnumerable<CorsairLed>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets generic information provided by CUE for the device.
|
||||
@@ -61,6 +65,38 @@ namespace CUE.NET.Devices
|
||||
/// </summary>
|
||||
float UpdateFrequency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rectangle containing all LEDs of the device.
|
||||
/// </summary>
|
||||
RectangleF DeviceRectangle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing the LEDs of the device.
|
||||
/// </summary>
|
||||
IEnumerable<CorsairLed> Leds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The ID of the LED to get.</param>
|
||||
/// <returns>The LED with the specified ID or null if no LED is found.</returns>
|
||||
CorsairLed this[CorsairLedId ledId] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> at the given physical location.
|
||||
/// </summary>
|
||||
/// <param name="location">The point to get the location from.</param>
|
||||
/// <returns>The LED at the given point or null if no location is found.</returns>
|
||||
CorsairLed this[PointF location] { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="CorsairLed" /> inside the given rectangle.
|
||||
/// </summary>
|
||||
/// <param name="referenceRect">The rectangle to check.</param>
|
||||
/// <param name="minOverlayPercentage">The minimal percentage overlay a location must have with the <see cref="Rectangle" /> to be taken into the list.</param>
|
||||
/// <returns></returns>
|
||||
IEnumerable<CorsairLed> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] { get; }
|
||||
|
||||
// ReSharper disable EventNeverSubscribedTo.Global
|
||||
|
||||
/// <summary>
|
||||
@@ -95,5 +131,14 @@ namespace CUE.NET.Devices
|
||||
/// </summary>
|
||||
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
||||
void Update(bool flushLeds = false);
|
||||
|
||||
bool AttachLedGroup(ILedGroup ledGroup);
|
||||
|
||||
/// <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>
|
||||
bool DetachLedGroup(ILedGroup ledGroup);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Keyboard.Enums;
|
||||
using CUE.NET.Devices.Keyboard.Keys;
|
||||
using CUE.NET.Effects;
|
||||
using CUE.NET.Groups;
|
||||
using CUE.NET.Helper;
|
||||
using CUE.NET.Native;
|
||||
|
||||
@@ -23,7 +24,7 @@ namespace CUE.NET.Devices.Keyboard
|
||||
/// <summary>
|
||||
/// Represents the SDK for a corsair keyboard.
|
||||
/// </summary>
|
||||
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>, IKeyGroup
|
||||
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@@ -64,7 +65,7 @@ namespace CUE.NET.Devices.Keyboard
|
||||
/// </summary>
|
||||
/// <param name="location">The point to get the key from.</param>
|
||||
/// <returns>The key at the given point or null if no key is found.</returns>
|
||||
public CorsairKey this[PointF location] => _keys.Values.FirstOrDefault(x => x.Led.LedRectangle.Contains(location));
|
||||
public new CorsairKey this[PointF location] => _keys.Values.FirstOrDefault(x => x.Led.LedRectangle.Contains(location));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of <see cref="CorsairKey" /> inside the given rectangle.
|
||||
@@ -72,13 +73,11 @@ namespace CUE.NET.Devices.Keyboard
|
||||
/// <param name="referenceRect">The rectangle to check.</param>
|
||||
/// <param name="minOverlayPercentage">The minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the list.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values
|
||||
public new IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values
|
||||
.Where(x => RectangleHelper.CalculateIntersectPercentage(x.Led.LedRectangle, referenceRect) >= minOverlayPercentage);
|
||||
|
||||
#endregion
|
||||
|
||||
private readonly LinkedList<IKeyGroup> _keyGroups = new LinkedList<IKeyGroup>();
|
||||
|
||||
private Dictionary<CorsairKeyboardKeyId, CorsairKey> _keys = new Dictionary<CorsairKeyboardKeyId, CorsairKey>();
|
||||
|
||||
/// <summary>
|
||||
@@ -91,22 +90,6 @@ namespace CUE.NET.Devices.Keyboard
|
||||
/// </summary>
|
||||
public CorsairKeyboardDeviceInfo KeyboardDeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rectangle containing all keys of the keyboard.
|
||||
/// </summary>
|
||||
public RectangleF KeyboardRectangle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the background brush of the keyboard.
|
||||
/// </summary>
|
||||
public IBrush Brush { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the z-index of the background brush of the keyboard.<br />
|
||||
/// This value has absolutely no effect.
|
||||
/// </summary>
|
||||
public int ZIndex { get; set; } = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -119,117 +102,13 @@ namespace CUE.NET.Devices.Keyboard
|
||||
: base(info)
|
||||
{
|
||||
this.KeyboardDeviceInfo = info;
|
||||
|
||||
InitializeKeys();
|
||||
KeyboardRectangle = RectangleHelper.CreateRectangleFromRectangles(this.Select(x => x.Led.LedRectangle));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region Update
|
||||
|
||||
/// <summary>
|
||||
/// Updates all brushes and groups on the keyboard.
|
||||
/// </summary>
|
||||
protected override void DeviceUpdate()
|
||||
{
|
||||
lock (_keyGroups)
|
||||
{
|
||||
foreach (IKeyGroup keyGroup in _keyGroups)
|
||||
keyGroup.UpdateEffects();
|
||||
}
|
||||
|
||||
if (Brush != null)
|
||||
ApplyBrush(this.ToList(), Brush);
|
||||
|
||||
lock (_keyGroups)
|
||||
{
|
||||
foreach (IKeyGroup keyGroup in _keyGroups.OrderBy(x => x.ZIndex))
|
||||
ApplyBrush(keyGroup.Keys.ToList(), keyGroup.Brush);
|
||||
}
|
||||
}
|
||||
|
||||
// ReSharper disable once MemberCanBeMadeStatic.Local - idc
|
||||
private void ApplyBrush(ICollection<CorsairKey> keys, IBrush brush)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (brush.BrushCalculationMode)
|
||||
{
|
||||
case BrushCalculationMode.Relative:
|
||||
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.Led.LedRectangle));
|
||||
float offsetX = -brushRectangle.X;
|
||||
float offsetY = -brushRectangle.Y;
|
||||
brushRectangle.X = 0;
|
||||
brushRectangle.Y = 0;
|
||||
brush.PerformRender(brushRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.Led.LedRectangle.GetCenter(offsetX, offsetY))));
|
||||
break;
|
||||
case BrushCalculationMode.Absolute:
|
||||
brush.PerformRender(KeyboardRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.Led.LedRectangle.GetCenter())));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
brush.UpdateEffects();
|
||||
brush.PerformFinalize();
|
||||
|
||||
foreach (KeyValuePair<BrushRenderTarget, Color> renders in brush.RenderedTargets)
|
||||
_keys[renders.Key.Key].Led.Color = renders.Value;
|
||||
}
|
||||
// ReSharper disable once CatchAllClause
|
||||
catch (Exception ex) { OnException(ex); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing all LEDs of this group.
|
||||
/// </summary>
|
||||
/// <returns>The list containing all LEDs of this group.</returns>
|
||||
public IEnumerable<CorsairLed> GetLeds()
|
||||
{
|
||||
return this.Select(x => x.Led);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the given keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The keygroup to attach.</param>
|
||||
/// <returns><c>true</c> if the keygroup could be attached; otherwise, <c>false</c>.</returns>
|
||||
public bool AttachKeyGroup(IKeyGroup keyGroup)
|
||||
{
|
||||
lock (_keyGroups)
|
||||
{
|
||||
if (keyGroup == null || _keyGroups.Contains(keyGroup)) return false;
|
||||
|
||||
_keyGroups.AddLast(keyGroup);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the given keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The keygroup to detached.</param>
|
||||
/// <returns><c>true</c> if the keygroup could be detached; otherwise, <c>false</c>.</returns>
|
||||
public bool DetachKeyGroup(IKeyGroup keyGroup)
|
||||
{
|
||||
lock (_keyGroups)
|
||||
{
|
||||
if (keyGroup == null) return false;
|
||||
|
||||
LinkedListNode<IKeyGroup> node = _keyGroups.Find(keyGroup);
|
||||
if (node == null) return false;
|
||||
|
||||
_keyGroups.Remove(node);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeKeys()
|
||||
protected override void InitializeLeds()
|
||||
{
|
||||
_CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions));
|
||||
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
|
||||
@@ -237,50 +116,20 @@ namespace CUE.NET.Devices.Keyboard
|
||||
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
|
||||
{
|
||||
_CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
|
||||
CorsairLed led = InitializeLed((int)ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
|
||||
_keys.Add(ledPosition.ledId, new CorsairKey(ledPosition.ledId, led));
|
||||
CorsairLed led = InitializeLed(ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
|
||||
_keys.Add((CorsairKeyboardKeyId)ledPosition.ledId, new CorsairKey((CorsairKeyboardKeyId)ledPosition.ledId, led));
|
||||
|
||||
ptr = new IntPtr(ptr.ToInt64() + structSize);
|
||||
}
|
||||
}
|
||||
|
||||
#region Effects
|
||||
|
||||
/// <summary>
|
||||
/// NOT IMPLEMENTED: Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.
|
||||
/// </summary>
|
||||
public void UpdateEffects()
|
||||
{
|
||||
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NOT IMPLEMENTED: Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.
|
||||
/// </summary>
|
||||
/// <param name="effect">The effect to add.</param>
|
||||
public void AddEffect(IEffect<IKeyGroup> effect)
|
||||
{
|
||||
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NOT IMPLEMENTED: Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.
|
||||
/// </summary>
|
||||
/// <param name="effect">The effect to remove.</param>
|
||||
public void RemoveEffect(IEffect<IKeyGroup> effect)
|
||||
{
|
||||
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all keys of the keyboard.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all keys of the keyboard.</returns>
|
||||
public IEnumerator<CorsairKey> GetEnumerator()
|
||||
public new IEnumerator<CorsairKey> GetEnumerator()
|
||||
{
|
||||
return _keys.Values.GetEnumerator();
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Linq;
|
||||
using CUE.NET.Devices.Keyboard.Enums;
|
||||
using CUE.NET.Devices.Keyboard.Keys;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Offers some extensions and helper-methods for keygroup related things.
|
||||
/// </summary>
|
||||
public static class KeyGroupExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the given <see cref="AbstractKeyGroup" /> to a <see cref="ListKeyGroup" />.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The <see cref="AbstractKeyGroup" /> to convert.</param>
|
||||
/// <returns>The converted <see cref="ListKeyGroup" />.</returns>
|
||||
public static ListKeyGroup ToSimpleKeyGroup(this AbstractKeyGroup keyGroup)
|
||||
{
|
||||
ListKeyGroup simpleKeyGroup = keyGroup as ListKeyGroup;
|
||||
if (simpleKeyGroup == null)
|
||||
{
|
||||
bool wasAttached = keyGroup.Detach();
|
||||
simpleKeyGroup = new ListKeyGroup(keyGroup.Keyboard, wasAttached, keyGroup.Keys.ToArray()) { Brush = keyGroup.Brush };
|
||||
}
|
||||
return simpleKeyGroup;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="ListKeyGroup" /> which contains all keys from the given keygroup excluding the specified ones.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The base keygroup.</param>
|
||||
/// <param name="keyIds">The ids of the keys to exclude.</param>
|
||||
/// <returns>The new <see cref="ListKeyGroup" />.</returns>
|
||||
public static ListKeyGroup Exclude(this AbstractKeyGroup keyGroup, params CorsairKeyboardKeyId[] keyIds)
|
||||
{
|
||||
ListKeyGroup simpleKeyGroup = keyGroup.ToSimpleKeyGroup();
|
||||
foreach (CorsairKeyboardKeyId keyId in keyIds)
|
||||
simpleKeyGroup.RemoveKey(keyId);
|
||||
return simpleKeyGroup;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="ListKeyGroup" /> which contains all keys from the given keygroup excluding the specified ones.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The base keygroup.</param>
|
||||
/// <param name="keyIds">The keys to exclude.</param>
|
||||
/// <returns>The new <see cref="ListKeyGroup" />.</returns>
|
||||
public static ListKeyGroup Exclude(this AbstractKeyGroup keyGroup, params CorsairKey[] keyIds)
|
||||
{
|
||||
ListKeyGroup simpleKeyGroup = keyGroup.ToSimpleKeyGroup();
|
||||
foreach (CorsairKey key in keyIds)
|
||||
simpleKeyGroup.RemoveKey(key);
|
||||
return simpleKeyGroup;
|
||||
}
|
||||
|
||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||
/// <summary>
|
||||
/// Attaches the given keygroup to the keyboard.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The keygroup to attach.</param>
|
||||
/// <returns><c>true</c> if the keygroup could be attached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Attach(this AbstractKeyGroup keyGroup)
|
||||
{
|
||||
return keyGroup.Keyboard?.AttachKeyGroup(keyGroup) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the given keygroup from the keyboard.
|
||||
/// </summary>
|
||||
/// <param name="keyGroup">The keygroup to attach.</param>
|
||||
/// <returns><c>true</c> if the keygroup could be detached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Detach(this AbstractKeyGroup keyGroup)
|
||||
{
|
||||
return keyGroup.Keyboard?.DetachKeyGroup(keyGroup) ?? false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Keyboard.Extensions;
|
||||
using CUE.NET.Effects;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a basic keygroup.
|
||||
/// </summary>
|
||||
public abstract class AbstractKeyGroup : AbstractEffectTarget<IKeyGroup>, IKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keyboard this keygroup belongs to.
|
||||
/// </summary>
|
||||
internal CorsairKeyboard Keyboard { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing the keys from this group.
|
||||
/// </summary>
|
||||
public IEnumerable<CorsairKey> Keys => new ReadOnlyCollection<CorsairKey>(GetGroupKeys());
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the brush which should be drawn over this group.
|
||||
/// </summary>
|
||||
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)
|
||||
/// </summary>
|
||||
public int ZIndex { get; set; } = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this group should be automatically attached or not.</param>
|
||||
protected AbstractKeyGroup(CorsairKeyboard keyboard, bool autoAttach = true)
|
||||
{
|
||||
this.Keyboard = keyboard;
|
||||
|
||||
if (autoAttach)
|
||||
this.Attach();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public IEnumerable<CorsairLed> GetLeds()
|
||||
{
|
||||
return GetGroupKeys().Select(x => x.Led);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing the keys from this group.
|
||||
/// </summary>
|
||||
/// <returns>The list containing the keys.</returns>
|
||||
protected abstract IList<CorsairKey> GetGroupKeys();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
using System.Drawing;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Keyboard.Enums;
|
||||
|
||||
@@ -40,5 +39,14 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static implicit operator CorsairLed(CorsairKey key)
|
||||
{
|
||||
return key.Led;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
// ReSharper disable UnusedMemberInSuper.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Collections.Generic;
|
||||
using CUE.NET.Brushes;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Effects;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
public interface IKeyGroup : IEffectTarget<IKeyGroup>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing the keys from this group.
|
||||
/// </summary>
|
||||
IEnumerable<CorsairKey> Keys { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the brush which should be drawn over this group.
|
||||
/// </summary>
|
||||
IBrush Brush { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the z-index of this keygroup to allow ordering them before drawing. (lowest first) (default: 0)
|
||||
/// </summary>
|
||||
int ZIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing all LEDs of this group.
|
||||
/// </summary>
|
||||
/// <returns>The list containing all LEDs of this group.</returns>
|
||||
IEnumerable<CorsairLed> GetLeds();
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Collections.Generic;
|
||||
using CUE.NET.Devices.Keyboard.Enums;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a keygroup containing arbitrary keys.
|
||||
/// </summary>
|
||||
public class ListKeyGroup : AbstractKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
protected override IKeyGroup EffectTarget => this;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list containing the keys of this keygroup.
|
||||
/// </summary>
|
||||
protected IList<CorsairKey> GroupKeys { get; } = new List<CorsairKey>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this keygroup should be automatically attached or not.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach = true)
|
||||
: base(keyboard, autoAttach)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="keys">The initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, params CorsairKey[] keys)
|
||||
: this(keyboard, true, keys)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="keys">The initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, IEnumerable<CorsairKey> keys)
|
||||
: this(keyboard, true, keys)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this keygroup should be automatically attached or not.</param>
|
||||
/// <param name="keys">The initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, IEnumerable<CorsairKey> keys)
|
||||
: base(keyboard, autoAttach)
|
||||
{
|
||||
AddKeys(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this keygroup should be automatically attached or not.</param>
|
||||
/// <param name="keys">The initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, params CorsairKey[] keys)
|
||||
: base(keyboard, autoAttach)
|
||||
{
|
||||
AddKeys(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="keys">The IDs of the initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, params CorsairKeyboardKeyId[] keys)
|
||||
: this(keyboard, true, keys)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="keys">The IDs of the initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, IEnumerable<CorsairKeyboardKeyId> keys)
|
||||
: this(keyboard, true, keys)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this keygroup should be automatically attached or not.</param>
|
||||
/// <param name="keys">The IDs of the initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, params CorsairKeyboardKeyId[] keys)
|
||||
: base(keyboard, autoAttach)
|
||||
{
|
||||
AddKeys(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ListKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="autoAttach">Specifies whether this keygroup should be automatically attached or not.</param>
|
||||
/// <param name="keys">The IDs of the initial keys of this keygroup.</param>
|
||||
public ListKeyGroup(CorsairKeyboard keyboard, bool autoAttach, IEnumerable<CorsairKeyboardKeyId> keys)
|
||||
: base(keyboard, autoAttach)
|
||||
{
|
||||
AddKeys(keys);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given key(s) to the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keys">The key(s) to add.</param>
|
||||
public void AddKey(params CorsairKey[] keys)
|
||||
{
|
||||
AddKeys(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given key(s) to the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyIds">The ID(s) of the key(s) to add.</param>
|
||||
public void AddKey(params CorsairKeyboardKeyId[] keyIds)
|
||||
{
|
||||
AddKeys(keyIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given keys to the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keys">The keys to add.</param>
|
||||
public void AddKeys(IEnumerable<CorsairKey> keys)
|
||||
{
|
||||
if (keys != null)
|
||||
foreach (CorsairKey key in keys)
|
||||
if (key != null && !ContainsKey(key))
|
||||
GroupKeys.Add(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given keys to the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyIds">The IDs of the keys to add.</param>
|
||||
public void AddKeys(IEnumerable<CorsairKeyboardKeyId> keyIds)
|
||||
{
|
||||
if (keyIds != null)
|
||||
foreach (CorsairKeyboardKeyId keyId in keyIds)
|
||||
AddKey(Keyboard[keyId]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given key(s) from the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keys">The key(s) to remove.</param>
|
||||
public void RemoveKey(params CorsairKey[] keys)
|
||||
{
|
||||
RemoveKeys(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given key(s) from the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyIds">The ID(s) of the key(s) to remove.</param>
|
||||
public void RemoveKey(params CorsairKeyboardKeyId[] keyIds)
|
||||
{
|
||||
RemoveKeys(keyIds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given keys from the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keys">The keys to remove.</param>
|
||||
public void RemoveKeys(IEnumerable<CorsairKey> keys)
|
||||
{
|
||||
if (keys != null)
|
||||
foreach (CorsairKey key in keys)
|
||||
if (key != null)
|
||||
GroupKeys.Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the given keys from the keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyIds">The IDs of the keys to remove.</param>
|
||||
public void RemoveKeys(IEnumerable<CorsairKeyboardKeyId> keyIds)
|
||||
{
|
||||
if (keyIds != null)
|
||||
foreach (CorsairKeyboardKeyId keyId in keyIds)
|
||||
RemoveKey(Keyboard[keyId]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given key is contained by this keygroup.
|
||||
/// </summary>
|
||||
/// <param name="key">The key which should be checked.</param>
|
||||
/// <returns><c>true</c> if the key is contained by this keygroup; otherwise, <c>false</c>.</returns>
|
||||
public bool ContainsKey(CorsairKey key)
|
||||
{
|
||||
return key != null && GroupKeys.Contains(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given key is contained by this keygroup.
|
||||
/// </summary>
|
||||
/// <param name="keyId">The ID of the key which should be checked.</param>
|
||||
/// <returns><c>true</c> if the key is contained by this keygroup; otherwise, <c>false</c>.</returns>
|
||||
public bool ContainsKey(CorsairKeyboardKeyId keyId)
|
||||
{
|
||||
return ContainsKey(Keyboard[keyId]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Merges the keys from the given keygroup in this keygroup.
|
||||
/// </summary>
|
||||
/// <param name="groupToMerge">The keygroup to merge.</param>
|
||||
public void MergeKeys(IKeyGroup groupToMerge)
|
||||
{
|
||||
foreach (CorsairKey key in groupToMerge.Keys)
|
||||
if (!GroupKeys.Contains(key))
|
||||
GroupKeys.Add(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing the keys from this group.
|
||||
/// </summary>
|
||||
/// <returns>The list containing the keys.</returns>
|
||||
protected override IList<CorsairKey> GetGroupKeys()
|
||||
{
|
||||
return GroupKeys;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using CUE.NET.Devices.Keyboard.Enums;
|
||||
using CUE.NET.Helper;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a keygroup containing keys which physically lay inside a rectangle.
|
||||
/// </summary>
|
||||
public class RectangleKeyGroup : AbstractKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
protected override IKeyGroup EffectTarget => this;
|
||||
|
||||
private IList<CorsairKey> _keyCache;
|
||||
|
||||
private RectangleF _rectangle;
|
||||
/// <summary>
|
||||
/// Gets or sets the rectangle the keys should be taken from.
|
||||
/// </summary>
|
||||
public RectangleF Rectangle
|
||||
{
|
||||
get { return _rectangle; }
|
||||
set
|
||||
{
|
||||
_rectangle = value;
|
||||
_keyCache = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the keygroup.
|
||||
/// </summary>
|
||||
public float MinOverlayPercentage { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RectangleKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="fromKey">They ID of the first key to calculate the rectangle of this keygroup from.</param>
|
||||
/// <param name="toKey">They ID of the second key to calculate the rectangle of this keygroup from.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the keygroup. (default: 0.5f)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this group should be automatically attached or not. (default: true)</param>
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKeyboardKeyId fromKey, CorsairKeyboardKeyId toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: this(keyboard, keyboard[fromKey], keyboard[toKey], minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RectangleKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="fromKey">They first key to calculate the rectangle of this keygroup from.</param>
|
||||
/// <param name="toKey">They second key to calculate the rectangle of this keygroup from.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the keygroup. (default: 0.5f)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this group should be automatically attached or not. (default: true)</param>
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKey fromKey, CorsairKey toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.Led.LedRectangle, toKey.Led.LedRectangle), minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RectangleKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="fromPoint">They first point to calculate the rectangle of this keygroup from.</param>
|
||||
/// <param name="toPoint">They second point to calculate the rectangle of this keygroup from.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the keygroup. (default: 0.5f)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this group should be automatically attached or not. (default: true)</param>
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, PointF fromPoint, PointF toPoint, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: this(keyboard, RectangleHelper.CreateRectangleFromPoints(fromPoint, toPoint), minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RectangleKeyGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="keyboard">The keyboard this keygroup belongs to.</param>
|
||||
/// <param name="rectangle">The rectangle of this keygroup.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the keygroup. (default: 0.5f)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this group should be automatically attached or not. (default: true)</param>
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, RectangleF rectangle, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: base(keyboard, autoAttach)
|
||||
{
|
||||
this.Rectangle = rectangle;
|
||||
this.MinOverlayPercentage = minOverlayPercentage;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing the keys from this group.
|
||||
/// </summary>
|
||||
/// <returns>The list containing the keys.</returns>
|
||||
protected override IList<CorsairKey> GetGroupKeys()
|
||||
{
|
||||
return _keyCache ?? (_keyCache = Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.Led.LedRectangle, Rectangle) >= MinOverlayPercentage).ToList());
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,9 @@
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Mouse.Enums;
|
||||
using CUE.NET.Exceptions;
|
||||
|
||||
@@ -16,38 +13,15 @@ namespace CUE.NET.Devices.Mouse
|
||||
/// <summary>
|
||||
/// Represents the SDK for a corsair mouse.
|
||||
/// </summary>
|
||||
public class CorsairMouse : AbstractCueDevice, IEnumerable<CorsairLed>
|
||||
public class CorsairMouse : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The ID of the LED to get.</param>
|
||||
/// <returns>The LED with the specified ID.</returns>
|
||||
public CorsairLed this[CorsairMouseLedId ledId]
|
||||
{
|
||||
get
|
||||
{
|
||||
CorsairLed led;
|
||||
return base.Leds.TryGetValue((int)ledId, out led) ? led : null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets specific information provided by CUE for the mouse.
|
||||
/// </summary>
|
||||
public CorsairMouseDeviceInfo MouseDeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing all LEDs of the mouse.
|
||||
/// </summary>
|
||||
public new IEnumerable<CorsairLed> Leds => new ReadOnlyCollection<CorsairLed>(base.Leds.Values.ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -60,64 +34,39 @@ namespace CUE.NET.Devices.Mouse
|
||||
: base(info)
|
||||
{
|
||||
this.MouseDeviceInfo = info;
|
||||
|
||||
InitializeLeds();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLeds()
|
||||
protected override void InitializeLeds()
|
||||
{
|
||||
switch (MouseDeviceInfo.PhysicalLayout)
|
||||
{
|
||||
case CorsairPhysicalMouseLayout.Zones1:
|
||||
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
break;
|
||||
case CorsairPhysicalMouseLayout.Zones2:
|
||||
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((int)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||
break;
|
||||
case CorsairPhysicalMouseLayout.Zones3:
|
||||
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((int)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||
InitializeLed((int)CorsairMouseLedId.B3, new RectangleF(2, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B3, new RectangleF(2, 0, 1, 1));
|
||||
break;
|
||||
case CorsairPhysicalMouseLayout.Zones4:
|
||||
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((int)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||
InitializeLed((int)CorsairMouseLedId.B3, new RectangleF(2, 0, 1, 1));
|
||||
InitializeLed((int)CorsairMouseLedId.B4, new RectangleF(3, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B3, new RectangleF(2, 0, 1, 1));
|
||||
InitializeLed((CorsairLedId)CorsairMouseLedId.B4, new RectangleF(3, 0, 1, 1));
|
||||
break;
|
||||
default:
|
||||
throw new WrapperException($"Can't initial mouse with layout '{MouseDeviceInfo.PhysicalLayout}'");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DeviceUpdate()
|
||||
{
|
||||
//DarthAffe 21.08.2016: Mice can't own brushes or groups - nothing to do here for now
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all LEDs of the mouse.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all LDS of the mouse.</returns>
|
||||
public IEnumerator<CorsairLed> GetEnumerator()
|
||||
{
|
||||
return Leds.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Generic.Enums;
|
||||
using CUE.NET.Devices.Mousemat.Enums;
|
||||
using CUE.NET.Exceptions;
|
||||
using CUE.NET.Native;
|
||||
|
||||
@@ -20,38 +19,15 @@ namespace CUE.NET.Devices.Mousemat
|
||||
/// <summary>
|
||||
/// Represents the SDK for a corsair mousemat.
|
||||
/// </summary>
|
||||
public class CorsairMousemat : AbstractCueDevice, IEnumerable<CorsairLed>
|
||||
public class CorsairMousemat : AbstractCueDevice
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="CorsairLed" /> with the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="ledId">The ID of the LED to get.</param>
|
||||
/// <returns>The LED with the specified ID.</returns>
|
||||
public CorsairLed this[CorsairMousematLedId ledId]
|
||||
{
|
||||
get
|
||||
{
|
||||
CorsairLed led;
|
||||
return base.Leds.TryGetValue((int)ledId, out led) ? led : null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets specific information provided by CUE for the mousemat.
|
||||
/// </summary>
|
||||
public CorsairMousematDeviceInfo MousematDeviceInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only collection containing all LEDs of the mousemat.
|
||||
/// </summary>
|
||||
public new IEnumerable<CorsairLed> Leds => new ReadOnlyCollection<CorsairLed>(base.Leds.Values.ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -64,14 +40,13 @@ namespace CUE.NET.Devices.Mousemat
|
||||
: base(info)
|
||||
{
|
||||
this.MousematDeviceInfo = info;
|
||||
InitializeLeds();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
private void InitializeLeds()
|
||||
protected override void InitializeLeds()
|
||||
{
|
||||
int deviceCount = _CUESDK.CorsairGetDeviceCount();
|
||||
|
||||
@@ -105,32 +80,9 @@ namespace CUE.NET.Devices.Mousemat
|
||||
|
||||
// Sort for easy iteration by clients
|
||||
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId))
|
||||
InitializeLed((int)ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
|
||||
InitializeLed(ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
|
||||
}
|
||||
|
||||
protected override void DeviceUpdate()
|
||||
{
|
||||
//TODO DarthAffe 10.09.2016: Implement
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all LEDs of the mousemat.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all LEDS of the mousemat.</returns>
|
||||
public IEnumerator<CorsairLed> GetEnumerator()
|
||||
{
|
||||
return Leds.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user