mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2026-11-11 21:16:24 +00:00
Improved the led update mechanism
This commit is contained in:
1 parent
61b712d026
commit
4e1a1d11bd
9 files changed
+112
-45
No files matched your search
@@ -51,6 +51,10 @@ namespace CUE.NET.Devices.Keyboard
|
||||
}
|
||||
|
||||
public IEnumerable<CorsairKey> Keys => new ReadOnlyCollection<CorsairKey>(_keys.Values.ToList());
|
||||
|
||||
public Color Color { get; set; } = Color.Transparent;
|
||||
|
||||
private readonly IList<IKeyGroup> _keyGroups = new List<IKeyGroup>();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -69,10 +73,38 @@ namespace CUE.NET.Devices.Keyboard
|
||||
|
||||
#region Methods
|
||||
|
||||
public void SetColor(Color color)
|
||||
public override void UpdateLeds(bool forceUpdate = false)
|
||||
{
|
||||
foreach (CorsairKey key in this)
|
||||
key.Led.Color = color;
|
||||
// Apply all KeyGroups first
|
||||
// Update only 'clean' leds, manual set should always override groups
|
||||
IEnumerable<CorsairKey> cleanKeys = this.Where(x => !x.Led.IsUpdated).ToList();
|
||||
|
||||
if (Color != Color.Transparent)
|
||||
foreach (CorsairKey key in cleanKeys)
|
||||
key.Led.Color = Color;
|
||||
|
||||
//TODO DarthAffe 20.09.2015: Add some sort of priority
|
||||
foreach (IKeyGroup keyGroup in _keyGroups)
|
||||
foreach (CorsairKey key in keyGroup.Keys.Where(key => cleanKeys.Contains(key)))
|
||||
key.Led.Color = keyGroup.Color;
|
||||
|
||||
// Perform 'real' update
|
||||
base.UpdateLeds(forceUpdate);
|
||||
}
|
||||
|
||||
public void AttachKeyGroup(IKeyGroup keyGroup)
|
||||
{
|
||||
if (keyGroup == null) return;
|
||||
|
||||
if (!_keyGroups.Contains(keyGroup))
|
||||
_keyGroups.Add(keyGroup);
|
||||
}
|
||||
|
||||
public void DetachKeyGroup(IKeyGroup keyGroup)
|
||||
{
|
||||
if (keyGroup == null) return;
|
||||
|
||||
_keyGroups.Remove(keyGroup);
|
||||
}
|
||||
|
||||
private void InitializeKeys()
|
||||
@@ -83,9 +115,11 @@ namespace CUE.NET.Devices.Keyboard
|
||||
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),
|
||||
CorsairLed led = GetLed((int)ledPosition.ledId);
|
||||
_keys.Add(ledPosition.ledId, new CorsairKey(ledPosition.ledId, led,
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,24 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
public IEnumerable<CorsairKey> Keys => new ReadOnlyCollection<CorsairKey>(GroupKeys);
|
||||
protected IList<CorsairKey> GroupKeys { get; } = new List<CorsairKey>();
|
||||
|
||||
public Color Color { get; set; } = Color.Transparent;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected BaseKeyGroup(CorsairKeyboard keyboard)
|
||||
protected BaseKeyGroup(CorsairKeyboard keyboard, bool autoAttach = true)
|
||||
{
|
||||
this.Keyboard = keyboard;
|
||||
|
||||
if (autoAttach)
|
||||
keyboard.AttachKeyGroup(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public virtual void SetColor(Color color)
|
||||
{
|
||||
foreach (CorsairKey key in GroupKeys)
|
||||
key.Led.Color = color;
|
||||
}
|
||||
|
||||
public void MergeKeys(IKeyGroup groupToMerge)
|
||||
{
|
||||
foreach (CorsairKey key in groupToMerge.Keys)
|
||||
|
||||
@@ -7,6 +7,6 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
{
|
||||
IEnumerable<CorsairKey> Keys { get; }
|
||||
|
||||
void SetColor(Color color);
|
||||
Color Color { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -16,20 +16,20 @@ namespace CUE.NET.Devices.Keyboard.Keys
|
||||
|
||||
#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, CorsairKeyboardKeyId fromKey, CorsairKeyboardKeyId toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: this(keyboard, keyboard[fromKey], keyboard[toKey], minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
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, CorsairKey fromKey, CorsairKey toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.KeyRectangle, toKey.KeyRectangle), minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, PointF fromPoint, PointF toPoint, float minOverlayPercentage = 0.5f)
|
||||
: this(keyboard, RectangleHelper.CreateRectangleFromPoints(fromPoint, toPoint), minOverlayPercentage)
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, PointF fromPoint, PointF toPoint, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: this(keyboard, RectangleHelper.CreateRectangleFromPoints(fromPoint, toPoint), minOverlayPercentage, autoAttach)
|
||||
{ }
|
||||
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, RectangleF requestedRectangle, float minOverlayPercentage = 0.5f)
|
||||
: base(keyboard)
|
||||
public RectangleKeyGroup(CorsairKeyboard keyboard, RectangleF requestedRectangle, float minOverlayPercentage = 0.5f, bool autoAttach = true)
|
||||
: base(keyboard, autoAttach)
|
||||
{
|
||||
this.RequestedRectangle = requestedRectangle;
|
||||
this.MinOverlayPercentage = minOverlayPercentage;
|
||||
|
||||
Reference in new issue
Block a user