mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 00:58:31 +00:00
Implemented keyboard as key-group
This commit is contained in:
parent
35ff696d1c
commit
5d96a1ba11
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -12,7 +13,7 @@ using CUE.NET.Native;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard
|
||||
{
|
||||
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>
|
||||
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>, IKeyGroup
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
@ -43,6 +44,8 @@ namespace CUE.NET.Devices.Keyboard
|
||||
private set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public IEnumerable<CorsairKey> Keys => new ReadOnlyCollection<CorsairKey>(_keys.Values.ToList());
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
@ -60,6 +63,12 @@ namespace CUE.NET.Devices.Keyboard
|
||||
|
||||
#region Methods
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
foreach (CorsairKey key in this)
|
||||
key.Led.Color = color;
|
||||
}
|
||||
|
||||
private void InitializeKeys()
|
||||
{
|
||||
_CorsairLedPositions nativeLedPositions = (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions));
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
|
||||
namespace CUE.NET.Devices.Keyboard.Keys
|
||||
@ -9,7 +10,8 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
|
||||
protected CorsairKeyboard Keyboard { get; }
|
||||
|
||||
public IList<CorsairKey> Keys { get; } = new List<CorsairKey>();
|
||||
public IEnumerable<CorsairKey> Keys => new ReadOnlyCollection<CorsairKey>(GroupKeys);
|
||||
protected IList<CorsairKey> GroupKeys { get; } = new List<CorsairKey>();
|
||||
|
||||
#endregion
|
||||
|
||||
@ -26,15 +28,15 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
|
||||
public virtual void SetColor(Color color)
|
||||
{
|
||||
foreach (CorsairKey key in Keys)
|
||||
foreach (CorsairKey key in GroupKeys)
|
||||
key.Led.Color = color;
|
||||
}
|
||||
|
||||
public void MergeKeys(IKeyGroup groupToMerge)
|
||||
{
|
||||
foreach (CorsairKey key in groupToMerge.Keys)
|
||||
if (!Keys.Contains(key))
|
||||
Keys.Add(key);
|
||||
if (!GroupKeys.Contains(key))
|
||||
GroupKeys.Add(key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -5,11 +5,8 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
public interface IKeyGroup
|
||||
{
|
||||
//TODO DarthAffe 19.09.2015: This might be not needed/bad
|
||||
IList<CorsairKey> Keys { get; }
|
||||
IEnumerable<CorsairKey> Keys { get; }
|
||||
|
||||
void SetColor(Color color);
|
||||
|
||||
void MergeKeys(IKeyGroup groupToMerge);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
this.MinOverlayPercentage = minOverlayPercentage;
|
||||
|
||||
foreach (CorsairKey key in Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, requestedRectangle) >= minOverlayPercentage))
|
||||
Keys.Add(key);
|
||||
GroupKeys.Add(key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -31,7 +31,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
if (keys != null)
|
||||
foreach (CorsairKey key in keys)
|
||||
if (key != null && !ContainsKey(key))
|
||||
Keys.Add(key);
|
||||
GroupKeys.Add(key);
|
||||
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
if (keys != null)
|
||||
foreach (CorsairKey key in keys)
|
||||
if (key != null)
|
||||
Keys.Remove(key);
|
||||
GroupKeys.Remove(key);
|
||||
}
|
||||
|
||||
public void RemoveKey(params CorsairKeyboardKeyId[] keyIds)
|
||||
@ -59,7 +59,7 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
|
||||
public bool ContainsKey(CorsairKey key)
|
||||
{
|
||||
return key != null && Keys.Contains(key);
|
||||
return key != null && GroupKeys.Contains(key);
|
||||
}
|
||||
|
||||
public bool ContainsKey(CorsairKeyboardKeyId keyId)
|
||||
|
||||
@ -72,15 +72,14 @@ namespace SimpleDevTest
|
||||
Random random = new Random();
|
||||
|
||||
// Cover whole keyboard as Group to be able to reset (I'll fix this tomorrow)
|
||||
RectangleKeyGroup keyboardGroup = new RectangleKeyGroup(keyboard, keyboard.KeyboardRectangle, 0f);
|
||||
|
||||
// Flash whole keyboard three times to ... well ... just to make it happen
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
keyboardGroup.SetColor(Color.Aquamarine);
|
||||
keyboard.SetColor(Color.Aquamarine);
|
||||
keyboard.UpdateLeds();
|
||||
Thread.Sleep(160);
|
||||
keyboardGroup.SetColor(Color.Black);
|
||||
keyboard.SetColor(Color.Black);
|
||||
keyboard.UpdateLeds();
|
||||
Thread.Sleep(200);
|
||||
}
|
||||
@ -98,7 +97,7 @@ namespace SimpleDevTest
|
||||
else
|
||||
point.Location = Interpolate(point.Location, target, SPEED); // It would be better to calculate from the center of our rectangle but the easy way is enough here
|
||||
|
||||
keyboardGroup.SetColor(Color.Black);
|
||||
keyboard.SetColor(Color.Black);
|
||||
|
||||
IEnumerable<CorsairKey> keys = keyboard[point, 0.1f];
|
||||
if (keys != null)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user