mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 13:06:24 +00:00
Refactored the positionen to be stored in the LED
This commit is contained in:
1 parent
4b5263221a
commit
bfe51add66
8 files changed
+56
-45
No files matched your search
@@ -64,7 +64,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.KeyRectangle.Contains(location));
|
||||
public 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,7 +72,8 @@ 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.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
|
||||
|
||||
@@ -120,7 +121,7 @@ namespace CUE.NET.Devices.Keyboard
|
||||
this.KeyboardDeviceInfo = info;
|
||||
|
||||
InitializeKeys();
|
||||
KeyboardRectangle = RectangleHelper.CreateRectangleFromRectangles(this.Select(x => x.KeyRectangle));
|
||||
KeyboardRectangle = RectangleHelper.CreateRectangleFromRectangles(this.Select(x => x.Led.LedRectangle));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -158,15 +159,15 @@ namespace CUE.NET.Devices.Keyboard
|
||||
switch (brush.BrushCalculationMode)
|
||||
{
|
||||
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 offsetY = -brushRectangle.Y;
|
||||
brushRectangle.X = 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;
|
||||
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;
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
@@ -181,7 +182,7 @@ namespace CUE.NET.Devices.Keyboard
|
||||
// ReSharper disable once CatchAllClause
|
||||
catch (Exception ex) { OnException(ex); }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list containing all LEDs of this group.
|
||||
/// </summary>
|
||||
@@ -236,9 +237,8 @@ namespace CUE.NET.Devices.Keyboard
|
||||
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
|
||||
{
|
||||
_CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
|
||||
CorsairLed led = GetLed((int)ledPosition.ledId);
|
||||
_keys.Add(ledPosition.ledId, new CorsairKey(ledPosition.ledId, led,
|
||||
new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height)));
|
||||
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));
|
||||
|
||||
ptr = new IntPtr(ptr.ToInt64() + structSize);
|
||||
}
|
||||
@@ -273,7 +273,7 @@ namespace CUE.NET.Devices.Keyboard
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -24,11 +24,6 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
/// </summary>
|
||||
public CorsairLed Led { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a rectangle representing the physical location of the key.
|
||||
/// </summary>
|
||||
public RectangleF KeyRectangle { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -38,12 +33,10 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
/// </summary>
|
||||
/// <param name="keyId">The key-ID 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, RectangleF keyRectangle)
|
||||
internal CorsairKey(CorsairKeyboardKeyId keyId, CorsairLed led)
|
||||
{
|
||||
this.KeyId = keyId;
|
||||
this.Led = led;
|
||||
this.KeyRectangle = keyRectangle;
|
||||
}
|
||||
|
||||
#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="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.KeyRectangle, toKey.KeyRectangle), minOverlayPercentage, autoAttach)
|
||||
: this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.Led.LedRectangle, toKey.Led.LedRectangle), minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
@@ -104,7 +104,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
/// <returns>The list containing the keys.</returns>
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user