Added some extensions for KeyGroups

This commit is contained in:
DarthAffe committed 2015-09-20 17:08:10 +02:00
1 parent 4e1a1d11bd
commit ced6c299b0
6 files changed
+86 -30

No files matched your search

@@ -0,0 +1,46 @@
using System.Linq;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Devices.Keyboard.Keys;
namespace CUE.NET.Devices.Keyboard.Extensions
{
public static class KeyGroupExtension
{
public static SimpleKeyGroup ToSimpleKeyGroup(this BaseKeyGroup keyGroup)
{
SimpleKeyGroup simpleKeyGroup = keyGroup as SimpleKeyGroup;
if (simpleKeyGroup == null)
{
bool wasAttached = keyGroup.Detach();
simpleKeyGroup = new SimpleKeyGroup(keyGroup.Keyboard, wasAttached, keyGroup.Keys.ToArray()) { Color = keyGroup.Color };
}
return simpleKeyGroup;
}
public static SimpleKeyGroup Exclude(this BaseKeyGroup keyGroup, params CorsairKeyboardKeyId[] keyIds)
{
SimpleKeyGroup simpleKeyGroup = keyGroup.ToSimpleKeyGroup();
foreach (CorsairKeyboardKeyId keyId in keyIds)
simpleKeyGroup.RemoveKey(keyId);
return simpleKeyGroup;
}
public static SimpleKeyGroup Exclude(this BaseKeyGroup keyGroup, params CorsairKey[] keyIds)
{
SimpleKeyGroup simpleKeyGroup = keyGroup.ToSimpleKeyGroup();
foreach (CorsairKey key in keyIds)
simpleKeyGroup.RemoveKey(key);
return simpleKeyGroup;
}
public static bool Attach(this BaseKeyGroup keyGroup)
{
return keyGroup.Keyboard?.AttachKeyGroup(keyGroup) ?? false;
}
public static bool Detach(this BaseKeyGroup keyGroup)
{
return keyGroup.Keyboard?.DetachKeyGroup(keyGroup) ?? false;
}
}
}