Added rectangle KeyGroup

This commit is contained in:
DarthAffe committed 2015-09-19 20:22:40 +02:00
1 parent 64e0902046
commit 3e238adcc4
5 files changed
+109 -3

No files matched your search

+17 -2
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
@@ -9,7 +10,7 @@ using CUE.NET.Native;
namespace CUE.NET.Devices.Keyboard
{
public class CorsairKeyboard : AbstractCueDevice
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>
{
#region Properties & Fields
@@ -52,11 +53,25 @@ namespace CUE.NET.Devices.Keyboard
_CorsairLedPosition ledPosition = Marshal.PtrToStructure<_CorsairLedPosition>(ptr);
_keys.Add(ledPosition.ledId, new CorsairKey(ledPosition.ledId, GetLed((int)ledPosition.ledId),
//TODO DarthAffe 19.09.2015: Is something like RectangleD needed? I don't think so ...
new RectangleF((float)ledPosition.top, (float)ledPosition.left, (float)ledPosition.width, (float)ledPosition.height)));
new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height)));
ptr = new IntPtr(ptr.ToInt64() + structSize);
}
}
#region IEnumerable
public IEnumerator<CorsairKey> GetEnumerator()
{
return _keys.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#endregion
}
}
@@ -0,0 +1,47 @@
using System.Drawing;
using System.Linq;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Helper;
namespace CUE.NET.Devices.Keyboard.Keys
{
public class RectangleKeyGroup : BaseKeyGroup
{
#region Properties & Fields
public RectangleF RequestedRectangle { get; }
public float MinOverlayPercentage { get; }
#endregion
#region Constructors
public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKeyboardKeyId fromKey, CorsairKeyboardKeyId toKey, float minOverlayPercentage = 0.5f)
: this(keyboard, keyboard[fromKey], keyboard[toKey], minOverlayPercentage)
{ }
public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKey fromKey, CorsairKey toKey, float minOverlayPercentage = 0.5f)
: this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.KeyRectangle, toKey.KeyRectangle), minOverlayPercentage)
{ }
public RectangleKeyGroup(CorsairKeyboard keyboard, PointF fromPoint, PointF toPoint, float minOverlayPercentage = 0.5f)
: this(keyboard, RectangleHelper.CreateRectangleFromPoints(fromPoint, toPoint), minOverlayPercentage)
{ }
public RectangleKeyGroup(CorsairKeyboard keyboard, RectangleF requestedRectangle, float minOverlayPercentage = 0.5f)
: base(keyboard)
{
this.RequestedRectangle = requestedRectangle;
this.MinOverlayPercentage = minOverlayPercentage;
foreach (CorsairKey key in Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, requestedRectangle) >= minOverlayPercentage))
Keys.Add(key);
}
#endregion
#region Methods
#endregion
}
}