You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
209 lines
5.4 KiB
209 lines
5.4 KiB
using Colore.Data; |
|
using Colore.Effects.Keyboard; |
|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Xml.Linq; |
|
|
|
namespace ChromaController |
|
{ |
|
internal class ChromaEffectsReader |
|
{ |
|
public EffectRegion[] ReadFirstStatic(string filePath) |
|
{ |
|
XDocument root = XDocument.Load(filePath); |
|
IEnumerable<XElement> effectLayers = root.Descendants("EffectLayer").Where(x => x.Descendants("Effect").First().Value == "static"); |
|
return effectLayers.SelectMany(layer => layer.Descendants("EffectRegion").Select(region => |
|
{ |
|
return new EffectRegion( |
|
GetKeys(region), |
|
GetColor(region)); |
|
})).ToArray(); |
|
} |
|
|
|
private Key[] GetKeys(XElement region) |
|
{ |
|
IEnumerable<XElement> deviceCells = region.Descendants("DeviceCell"); |
|
List<RazerKey> keys = new List<RazerKey>(); |
|
foreach (XElement cell in deviceCells) |
|
{ |
|
int row = Convert.ToInt32(cell.Descendants("Row").First().Value); |
|
int column = Convert.ToInt32(cell.Descendants("Col").First().Value); |
|
keys.Add((RazerKey)column + row * 256); |
|
} |
|
return keys.Select(razerKey => (Key)Enum.Parse(typeof(Key), razerKey.ToString())).ToArray(); |
|
} |
|
|
|
private Color GetColor(XElement region) |
|
{ |
|
XElement rzColor = region.Descendants("RzColor").First(); |
|
int red = 0, green = 0, blue = 0; |
|
foreach (XElement element in rzColor.Descendants()) |
|
{ |
|
switch (element.Name.ToString()) |
|
{ |
|
case "Red": |
|
red = Convert.ToInt32(element.Value); |
|
break; |
|
|
|
case "Green": |
|
green = Convert.ToInt32(element.Value); |
|
break; |
|
|
|
case "Blue": |
|
blue = Convert.ToInt32(element.Value); |
|
break; |
|
|
|
default: |
|
throw new ArgumentException("Argument value not expected", "element"); |
|
} |
|
} |
|
return KeyEffect.GetColoreColor(red, green, blue); |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// Definition of almost all keyboard keys, with id's matching the Razer Synapse Grid. |
|
/// Keys not present on the US-International are not tested, and so commented out. If you need these, just test where they should be using a known ChromaEffects map. |
|
/// </summary> |
|
internal enum RazerKey |
|
{ |
|
Escape = 1, |
|
F1 = 4, |
|
F2 = 5, |
|
F3 = 6, |
|
F4 = 7, |
|
F5 = 8, |
|
F6 = 9, |
|
F7 = 10, |
|
F8 = 11, |
|
F9 = 12, |
|
F10 = 13, |
|
F11 = 14, |
|
F12 = 15, |
|
PrintScreen = 16, |
|
Scroll = 17, |
|
Pause = 18, |
|
|
|
//JpnYen = 21, |
|
//KorPipe = 21, |
|
|
|
Macro1 = 256, |
|
OemTilde = 257, |
|
D1 = 258, |
|
D2 = 259, |
|
D3 = 260, |
|
D4 = 261, |
|
D5 = 262, |
|
D6 = 263, |
|
D7 = 264, |
|
D8 = 265, |
|
D9 = 266, |
|
D0 = 267, |
|
OemMinus = 268, |
|
OemEquals = 269, |
|
Backspace = 270, |
|
Insert = 272, |
|
Home = 273, |
|
PageUp = 274, |
|
NumLock = 275, |
|
NumDivide = 276, |
|
NumMultiply = 277, |
|
NumSubtract = 278, |
|
Macro2 = 512, |
|
Tab = 513, |
|
Q = 514, |
|
W = 515, |
|
E = 516, |
|
R = 517, |
|
T = 518, |
|
Y = 519, |
|
U = 520, |
|
I = 521, |
|
O = 522, |
|
P = 523, |
|
OemLeftBracket = 524, |
|
OemRightBracket = 525, |
|
OemBackslash = 526, |
|
Delete = 528, |
|
End = 529, |
|
PageDown = 530, |
|
Num7 = 531, |
|
Num8 = 532, |
|
Num9 = 533, |
|
NumAdd = 534, |
|
Macro3 = 768, |
|
CapsLock = 770, |
|
A = 771, |
|
S = 772, |
|
D = 773, |
|
F = 774, |
|
G = 775, |
|
H = 776, |
|
J = 777, |
|
K = 778, |
|
L = 779, |
|
OemSemicolon = 780, |
|
OemApostrophe = 781, |
|
|
|
//EurPound = 782, |
|
//Kor2 = 782, |
|
|
|
Enter = 782, |
|
Num4 = 787, |
|
Num5 = 788, |
|
Num6 = 789, |
|
Macro4 = 1024, |
|
|
|
//EurBackslash = 1025, |
|
//Kor3 = 1025, |
|
|
|
LeftShift = 1026, |
|
Z = 1027, |
|
X = 1028, |
|
C = 1029, |
|
V = 1039, |
|
B = 1031, |
|
N = 1032, |
|
M = 1033, |
|
OemComma = 1034, |
|
OemPeriod = 1035, |
|
OemSlash = 1036, |
|
|
|
//JpnSlash = 1037, |
|
//Kor4 = 1037, |
|
|
|
RightShift = 1038, |
|
Up = 1041, |
|
Num1 = 1043, |
|
Num2 = 1044, |
|
Num3 = 1045, |
|
Macro5 = 1280, |
|
LeftControl = 1281, |
|
LeftWindows = 1282, |
|
LeftAlt = 1283, |
|
|
|
//Jpn3 = 1284, |
|
//Kor5 = 1284, |
|
|
|
Space = 1287, |
|
|
|
//Jpn4 = 1289, |
|
//Kor6 = 1289, |
|
//Jpn5 = 1290, |
|
//Kor7 = 1290, |
|
|
|
RightAlt = 1292, |
|
Function = 1293, |
|
RightMenu = 1294, |
|
RightControl = 1295, |
|
Left = 1296, |
|
Down = 1297, |
|
Right = 1298, |
|
Num0 = 1300, |
|
NumDecimal = 1301, |
|
NumEnter = 1302, |
|
Logo = 1548, |
|
Invalid = 65535 |
|
} |
|
} |