mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 04:56:44 +00:00
Implemented keyboard as key-group
This commit is contained in:
1 parent
35ff696d1c
commit
5d96a1ba11
6 files changed
+24
-17
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user