mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 00:58:31 +00:00
78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using CUE.NET.Devices.Generic;
|
|
using CUE.NET.Devices.Keyboard.Enums;
|
|
using CUE.NET.Devices.Keyboard.Keys;
|
|
using CUE.NET.Native;
|
|
|
|
namespace CUE.NET.Devices.Keyboard
|
|
{
|
|
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>
|
|
{
|
|
#region Properties & Fields
|
|
|
|
public CorsairKeyboardDeviceInfo KeyboardDeviceInfo { get; }
|
|
|
|
private Dictionary<CorsairKeyboardKeyId, CorsairKey> _keys = new Dictionary<CorsairKeyboardKeyId, CorsairKey>();
|
|
public CorsairKey this[CorsairKeyboardKeyId keyId]
|
|
{
|
|
get
|
|
{
|
|
CorsairKey key;
|
|
return _keys.TryGetValue(keyId, out key) ? key : null;
|
|
}
|
|
private set { throw new NotSupportedException(); }
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructors
|
|
|
|
internal CorsairKeyboard(CorsairKeyboardDeviceInfo info)
|
|
: base(info)
|
|
{
|
|
this.KeyboardDeviceInfo = info;
|
|
|
|
InitializeKeys();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Methods
|
|
|
|
private void InitializeKeys()
|
|
{
|
|
_CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions));
|
|
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
|
|
IntPtr ptr = nativeLedPositions.pLedPosition;
|
|
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
|
|
{
|
|
_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.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
|
|
}
|
|
}
|