mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 09:08:34 +00:00
Refactored the positionen to be stored in the LED
This commit is contained in:
parent
4b5263221a
commit
bfe51add66
@ -104,16 +104,21 @@ namespace CUE.NET.Devices.Generic
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the LED-Object with the specified id.
|
/// Initializes the LED-Object with the specified id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ledId">The LED-Id to look for.</param>
|
/// <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>
|
/// <returns></returns>
|
||||||
protected CorsairLed GetLed(int ledId)
|
protected CorsairLed InitializeLed(int ledId, RectangleF ledRectangle)
|
||||||
{
|
{
|
||||||
if (!Leds.ContainsKey(ledId))
|
if (!Leds.ContainsKey(ledId))
|
||||||
Leds.Add(ledId, new CorsairLed());
|
{
|
||||||
|
CorsairLed led = new CorsairLed(ledRectangle);
|
||||||
|
Leds.Add(ledId, led);
|
||||||
|
return led;
|
||||||
|
}
|
||||||
|
|
||||||
return Leds[ledId];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -169,7 +174,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
public void Update(bool flushLeds = false)
|
public void Update(bool flushLeds = false)
|
||||||
{
|
{
|
||||||
OnUpdating();
|
OnUpdating();
|
||||||
|
|
||||||
DeviceUpdate();
|
DeviceUpdate();
|
||||||
|
|
||||||
ICollection<LedUpateRequest> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();
|
ICollection<LedUpateRequest> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();
|
||||||
@ -186,7 +191,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// Performs device specific updates.
|
/// Performs device specific updates.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void DeviceUpdate();
|
protected abstract void DeviceUpdate();
|
||||||
|
|
||||||
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
|
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
|
||||||
{
|
{
|
||||||
updateRequests = updateRequests.Where(x => x.Color != Color.Transparent).ToList();
|
updateRequests = updateRequests.Where(x => x.Color != Color.Transparent).ToList();
|
||||||
|
|||||||
@ -13,6 +13,11 @@ namespace CUE.NET.Devices.Generic
|
|||||||
public class CorsairLed
|
public class CorsairLed
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a rectangle representing the physical location of the led.
|
||||||
|
/// </summary>
|
||||||
|
public RectangleF LedRectangle { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Indicates whether the LED has changed an internal state.
|
/// Indicates whether the LED has changed an internal state.
|
||||||
@ -55,7 +60,14 @@ namespace CUE.NET.Devices.Generic
|
|||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
internal CorsairLed() { }
|
/// <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)
|
||||||
|
{
|
||||||
|
this.LedRectangle = ledRectangle;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using CUE.NET.Devices.Generic;
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Headset.Enums;
|
using CUE.NET.Devices.Headset.Enums;
|
||||||
@ -67,8 +68,8 @@ namespace CUE.NET.Devices.Headset
|
|||||||
|
|
||||||
private void InitializeLeds()
|
private void InitializeLeds()
|
||||||
{
|
{
|
||||||
GetLed((int)CorsairHeadsetLedId.LeftLogo);
|
InitializeLed((int)CorsairHeadsetLedId.LeftLogo, new RectangleF(0, 0, 1, 1));
|
||||||
GetLed((int)CorsairHeadsetLedId.RightLogo);
|
InitializeLed((int)CorsairHeadsetLedId.RightLogo, new RectangleF(1, 0, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeviceUpdate()
|
protected override void DeviceUpdate()
|
||||||
|
|||||||
@ -64,7 +64,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">The point to get the key from.</param>
|
/// <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>
|
/// <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.KeyRectangle.Contains(location));
|
public CorsairKey this[PointF location] => _keys.Values.FirstOrDefault(x => x.Led.LedRectangle.Contains(location));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list of <see cref="CorsairKey" /> inside the given rectangle.
|
/// Gets a list of <see cref="CorsairKey" /> inside the given rectangle.
|
||||||
@ -72,7 +72,8 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
/// <param name="referenceRect">The rectangle to check.</param>
|
/// <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>
|
/// <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>
|
/// <returns></returns>
|
||||||
public IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, referenceRect) >= minOverlayPercentage);
|
public IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values
|
||||||
|
.Where(x => RectangleHelper.CalculateIntersectPercentage(x.Led.LedRectangle, referenceRect) >= minOverlayPercentage);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
this.KeyboardDeviceInfo = info;
|
this.KeyboardDeviceInfo = info;
|
||||||
|
|
||||||
InitializeKeys();
|
InitializeKeys();
|
||||||
KeyboardRectangle = RectangleHelper.CreateRectangleFromRectangles(this.Select(x => x.KeyRectangle));
|
KeyboardRectangle = RectangleHelper.CreateRectangleFromRectangles(this.Select(x => x.Led.LedRectangle));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -158,15 +159,15 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
switch (brush.BrushCalculationMode)
|
switch (brush.BrushCalculationMode)
|
||||||
{
|
{
|
||||||
case BrushCalculationMode.Relative:
|
case BrushCalculationMode.Relative:
|
||||||
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.KeyRectangle));
|
RectangleF brushRectangle = RectangleHelper.CreateRectangleFromRectangles(keys.Select(x => x.Led.LedRectangle));
|
||||||
float offsetX = -brushRectangle.X;
|
float offsetX = -brushRectangle.X;
|
||||||
float offsetY = -brushRectangle.Y;
|
float offsetY = -brushRectangle.Y;
|
||||||
brushRectangle.X = 0;
|
brushRectangle.X = 0;
|
||||||
brushRectangle.Y = 0;
|
brushRectangle.Y = 0;
|
||||||
brush.PerformRender(brushRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.KeyRectangle.GetCenter(offsetX, offsetY))));
|
brush.PerformRender(brushRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.Led.LedRectangle.GetCenter(offsetX, offsetY))));
|
||||||
break;
|
break;
|
||||||
case BrushCalculationMode.Absolute:
|
case BrushCalculationMode.Absolute:
|
||||||
brush.PerformRender(KeyboardRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.KeyRectangle.GetCenter())));
|
brush.PerformRender(KeyboardRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.Led.LedRectangle.GetCenter())));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
@ -181,7 +182,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
// ReSharper disable once CatchAllClause
|
// ReSharper disable once CatchAllClause
|
||||||
catch (Exception ex) { OnException(ex); }
|
catch (Exception ex) { OnException(ex); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list containing all LEDs of this group.
|
/// Gets a list containing all LEDs of this group.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -236,9 +237,8 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
|
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
|
||||||
{
|
{
|
||||||
_CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
|
_CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
|
||||||
CorsairLed led = GetLed((int)ledPosition.ledId);
|
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,
|
_keys.Add(ledPosition.ledId, new CorsairKey(ledPosition.ledId, led));
|
||||||
new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height)));
|
|
||||||
|
|
||||||
ptr = new IntPtr(ptr.ToInt64() + structSize);
|
ptr = new IntPtr(ptr.ToInt64() + structSize);
|
||||||
}
|
}
|
||||||
@ -273,7 +273,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEnumerable
|
#region IEnumerable
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -24,11 +24,6 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public CorsairLed Led { get; }
|
public CorsairLed Led { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a rectangle representing the physical location of the key.
|
|
||||||
/// </summary>
|
|
||||||
public RectangleF KeyRectangle { get; }
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
@ -38,12 +33,10 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="keyId">The key-ID of the key.</param>
|
/// <param name="keyId">The key-ID of the key.</param>
|
||||||
/// <param name="led">The LED of the key.</param>
|
/// <param name="led">The LED of the key.</param>
|
||||||
/// <param name="keyRectangle">The rectangle representing the physical location of the key.</param>
|
internal CorsairKey(CorsairKeyboardKeyId keyId, CorsairLed led)
|
||||||
internal CorsairKey(CorsairKeyboardKeyId keyId, CorsairLed led, RectangleF keyRectangle)
|
|
||||||
{
|
{
|
||||||
this.KeyId = keyId;
|
this.KeyId = keyId;
|
||||||
this.Led = led;
|
this.Led = led;
|
||||||
this.KeyRectangle = keyRectangle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -65,7 +65,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
|||||||
/// <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="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>
|
/// <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)
|
public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKey fromKey, CorsairKey toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||||
: this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.KeyRectangle, toKey.KeyRectangle), minOverlayPercentage, autoAttach)
|
: this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.Led.LedRectangle, toKey.Led.LedRectangle), minOverlayPercentage, autoAttach)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -104,7 +104,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
|||||||
/// <returns>The list containing the keys.</returns>
|
/// <returns>The list containing the keys.</returns>
|
||||||
protected override IList<CorsairKey> GetGroupKeys()
|
protected override IList<CorsairKey> GetGroupKeys()
|
||||||
{
|
{
|
||||||
return _keyCache ?? (_keyCache = Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, Rectangle) >= MinOverlayPercentage).ToList());
|
return _keyCache ?? (_keyCache = Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.Led.LedRectangle, Rectangle) >= MinOverlayPercentage).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using CUE.NET.Devices.Generic;
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Mouse.Enums;
|
using CUE.NET.Devices.Mouse.Enums;
|
||||||
@ -72,22 +73,22 @@ namespace CUE.NET.Devices.Mouse
|
|||||||
switch (MouseDeviceInfo.PhysicalLayout)
|
switch (MouseDeviceInfo.PhysicalLayout)
|
||||||
{
|
{
|
||||||
case CorsairPhysicalMouseLayout.Zones1:
|
case CorsairPhysicalMouseLayout.Zones1:
|
||||||
GetLed((int)CorsairMouseLedId.B1);
|
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||||
break;
|
break;
|
||||||
case CorsairPhysicalMouseLayout.Zones2:
|
case CorsairPhysicalMouseLayout.Zones2:
|
||||||
GetLed((int)CorsairMouseLedId.B1);
|
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||||
GetLed((int)CorsairMouseLedId.B2);
|
InitializeLed((int)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||||
break;
|
break;
|
||||||
case CorsairPhysicalMouseLayout.Zones3:
|
case CorsairPhysicalMouseLayout.Zones3:
|
||||||
GetLed((int)CorsairMouseLedId.B1);
|
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||||
GetLed((int)CorsairMouseLedId.B2);
|
InitializeLed((int)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||||
GetLed((int)CorsairMouseLedId.B3);
|
InitializeLed((int)CorsairMouseLedId.B3, new RectangleF(2, 0, 1, 1));
|
||||||
break;
|
break;
|
||||||
case CorsairPhysicalMouseLayout.Zones4:
|
case CorsairPhysicalMouseLayout.Zones4:
|
||||||
GetLed((int)CorsairMouseLedId.B1);
|
InitializeLed((int)CorsairMouseLedId.B1, new RectangleF(0, 0, 1, 1));
|
||||||
GetLed((int)CorsairMouseLedId.B2);
|
InitializeLed((int)CorsairMouseLedId.B2, new RectangleF(1, 0, 1, 1));
|
||||||
GetLed((int)CorsairMouseLedId.B3);
|
InitializeLed((int)CorsairMouseLedId.B3, new RectangleF(2, 0, 1, 1));
|
||||||
GetLed((int)CorsairMouseLedId.B4);
|
InitializeLed((int)CorsairMouseLedId.B4, new RectangleF(3, 0, 1, 1));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new WrapperException($"Can't initial mouse with layout '{MouseDeviceInfo.PhysicalLayout}'");
|
throw new WrapperException($"Can't initial mouse with layout '{MouseDeviceInfo.PhysicalLayout}'");
|
||||||
|
|||||||
@ -12,7 +12,6 @@ using System.Runtime.InteropServices;
|
|||||||
using CUE.NET.Devices.Generic;
|
using CUE.NET.Devices.Generic;
|
||||||
using CUE.NET.Devices.Generic.Enums;
|
using CUE.NET.Devices.Generic.Enums;
|
||||||
using CUE.NET.Devices.Mousemat.Enums;
|
using CUE.NET.Devices.Mousemat.Enums;
|
||||||
using CUE.NET.Effects;
|
|
||||||
using CUE.NET.Exceptions;
|
using CUE.NET.Exceptions;
|
||||||
using CUE.NET.Native;
|
using CUE.NET.Native;
|
||||||
|
|
||||||
@ -47,7 +46,7 @@ namespace CUE.NET.Devices.Mousemat
|
|||||||
/// Gets specific information provided by CUE for the mousemat.
|
/// Gets specific information provided by CUE for the mousemat.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CorsairMousematDeviceInfo MousematDeviceInfo { get; }
|
public CorsairMousematDeviceInfo MousematDeviceInfo { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a read-only collection containing all LEDs of the mousemat.
|
/// Gets a read-only collection containing all LEDs of the mousemat.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -105,8 +104,8 @@ namespace CUE.NET.Devices.Mousemat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort for easy iteration by clients
|
// Sort for easy iteration by clients
|
||||||
foreach (_CorsairLedPosition position in positions.OrderBy(p => p.ledId))
|
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId))
|
||||||
GetLed((int)position.ledId);
|
InitializeLed((int)ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void DeviceUpdate()
|
protected override void DeviceUpdate()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user