mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-10 20:46:24 +00:00
Added reactangle of keyboard, improved example
This commit is contained in:
1 parent
3e238adcc4
commit
f3d498afcf
2 files changed
+122
-4
No files matched your search
@@ -2,10 +2,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using CUE.NET.Devices.Generic;
|
||||
using CUE.NET.Devices.Keyboard.Enums;
|
||||
using CUE.NET.Devices.Keyboard.Keys;
|
||||
using CUE.NET.Helper;
|
||||
using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard
|
||||
@@ -16,6 +18,8 @@ namespace CUE.NET.Devices.Keyboard
|
||||
|
||||
public CorsairKeyboardDeviceInfo KeyboardDeviceInfo { get; }
|
||||
|
||||
public RectangleF KeyboardRectangle { get; private set; }
|
||||
|
||||
private Dictionary<CorsairKeyboardKeyId, CorsairKey> _keys = new Dictionary<CorsairKeyboardKeyId, CorsairKey>();
|
||||
public CorsairKey this[CorsairKeyboardKeyId keyId]
|
||||
{
|
||||
@@ -27,6 +31,18 @@ namespace CUE.NET.Devices.Keyboard
|
||||
private set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public CorsairKey this[PointF location]
|
||||
{
|
||||
get { return _keys.Values.FirstOrDefault(x => x.KeyRectangle.Contains(location)); }
|
||||
private set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f]
|
||||
{
|
||||
get { return _keys.Values.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, referenceRect) >= minOverlayPercentage); }
|
||||
private set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@@ -37,6 +53,7 @@ namespace CUE.NET.Devices.Keyboard
|
||||
this.KeyboardDeviceInfo = info;
|
||||
|
||||
InitializeKeys();
|
||||
CalculateKeyboardRectangle();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -58,6 +75,24 @@ namespace CUE.NET.Devices.Keyboard
|
||||
}
|
||||
}
|
||||
|
||||
private void CalculateKeyboardRectangle()
|
||||
{
|
||||
float posX = float.MaxValue;
|
||||
float posY = float.MaxValue;
|
||||
float posX2 = float.MinValue;
|
||||
float posY2 = float.MinValue;
|
||||
|
||||
foreach (CorsairKey key in this)
|
||||
{
|
||||
posX = Math.Min(posX, key.KeyRectangle.X);
|
||||
posY = Math.Min(posY, key.KeyRectangle.Y);
|
||||
posX2 = Math.Max(posX2, key.KeyRectangle.X + key.KeyRectangle.Width);
|
||||
posY2 = Math.Max(posY2, key.KeyRectangle.Y + key.KeyRectangle.Height);
|
||||
}
|
||||
|
||||
KeyboardRectangle = RectangleHelper.CreateRectangleFromPoints(new PointF(posX, posY), new PointF(posX2, posY2));
|
||||
}
|
||||
|
||||
#region IEnumerable
|
||||
|
||||
public IEnumerator<CorsairKey> GetEnumerator()
|
||||
|
||||
Reference in new issue
Block a user