diff --git a/Documentation/DeviceLayout.xsd b/Documentation/DeviceLayout.xsd index 8b708ee..00f1c04 100644 --- a/Documentation/DeviceLayout.xsd +++ b/Documentation/DeviceLayout.xsd @@ -12,19 +12,21 @@ + + - - - - - + + + + + diff --git a/RGB.NET.Core/Devices/Layout/DeviceLayout.cs b/RGB.NET.Core/Devices/Layout/DeviceLayout.cs index e522209..a8d2015 100644 --- a/RGB.NET.Core/Devices/Layout/DeviceLayout.cs +++ b/RGB.NET.Core/Devices/Layout/DeviceLayout.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Xml.Serialization; @@ -54,7 +55,8 @@ namespace RGB.NET.Core.Layout /// Gets or sets the of the . /// [XmlElement("Shape")] - public Shape Shape { get; set; } + [DefaultValue(Shape.Rectangle)] + public Shape Shape { get; set; } = Shape.Rectangle; /// /// Gets or sets the width of the . @@ -68,6 +70,20 @@ namespace RGB.NET.Core.Layout [XmlElement("Height")] public double Height { get; set; } + /// + /// Gets or sets the width of one 'unit' used for the calculation of led positions and sizes. + /// + [XmlElement("LedUnitWidth")] + [DefaultValue(19.0)] + public double LedUnitWidth { get; set; } = 19.0; + + /// + /// Gets or sets the height of one 'unit' used for the calculation of led positions and sizes. + /// + [XmlElement("LedUnitHeight")] + [DefaultValue(19.0)] + public double LedUnitHeight { get; set; } = 19.0; + /// /// Gets or sets a list of representing all the of the . /// @@ -91,7 +107,20 @@ namespace RGB.NET.Core.Layout { XmlSerializer serializer = new XmlSerializer(typeof(DeviceLayout)); using (StreamReader reader = new StreamReader(path)) - return serializer.Deserialize(reader) as DeviceLayout; + { + DeviceLayout layout = serializer.Deserialize(reader) as DeviceLayout; + if (layout?.Leds != null) + { + LedLayout lastLed = null; + foreach (LedLayout led in layout.Leds) + { + led.CalculateValues(layout, lastLed); + lastLed = led; + } + } + + return layout; + } } catch { diff --git a/RGB.NET.Core/Devices/Layout/LedLayout.cs b/RGB.NET.Core/Devices/Layout/LedLayout.cs index 5f46dcc..1b71e5b 100644 --- a/RGB.NET.Core/Devices/Layout/LedLayout.cs +++ b/RGB.NET.Core/Devices/Layout/LedLayout.cs @@ -1,4 +1,6 @@ using System; +using System.ComponentModel; +using System.Globalization; using System.Xml.Serialization; namespace RGB.NET.Core.Layout @@ -15,38 +17,145 @@ namespace RGB.NET.Core.Layout /// /// Gets or sets the Id of the . /// - [XmlElement("Id")] + [XmlAttribute("Id")] public string Id { get; set; } /// /// Gets or sets the of the . /// [XmlElement("Shape")] - public Shape Shape { get; set; } + [DefaultValue(Shape.Rectangle)] + public Shape Shape { get; set; } = Shape.Rectangle; + + /// + /// Gets or sets the descriptive x-position of the . + /// This property is for XML-serialization only and should not be directly accessed. + /// + [XmlElement("X")] + [DefaultValue("+")] + public string DescriptiveX { get; set; } = "+"; + + /// + /// Gets or sets the descriptive y-position of the . + /// This property is for XML-serialization only and should not be directly accessed. + /// + [XmlElement("Y")] + [DefaultValue("=")] + public string DescriptiveY { get; set; } = "="; + + /// + /// Gets or sets the descriptive width of the . + /// This property is for XML-serialization only and should not be directly accessed. + /// + [XmlElement("Width")] + [DefaultValue("1.0")] + public string DescriptiveWidth { get; set; } = "1.0"; + + /// + /// Gets or sets the descriptive height of the . + /// This property is for XML-serialization only and should not be directly accessed. + /// + [XmlElement("Height")] + [DefaultValue("1.0")] + public string DescriptiveHeight { get; set; } = "1.0"; /// /// Gets or sets the x-position of the . /// - [XmlElement("X")] - public double X { get; set; } + [XmlIgnore] + public double X { get; private set; } /// /// Gets or sets the y-position of the . /// - [XmlElement("Y")] - public double Y { get; set; } + [XmlIgnore] + public double Y { get; private set; } /// /// Gets or sets the width of the . /// - [XmlElement("Width")] - public double Width { get; set; } + [XmlIgnore] + public double Width { get; private set; } /// /// Gets or sets the height of the . /// - [XmlElement("Height")] - public double Height { get; set; } + [XmlIgnore] + public double Height { get; private set; } + + #endregion + + #region Methods + + /// + /// Calculates the position- and size-data from the respective descriptive values. + /// + /// The this belongs to. + /// The previously calculated. + public void CalculateValues(DeviceLayout device, LedLayout lastLed) + { + Width = GetSizeValue(DescriptiveWidth, device.LedUnitWidth); + Height = GetSizeValue(DescriptiveHeight, device.LedUnitHeight); + + X = GetLocationValue(DescriptiveX, lastLed?.X ?? 0, Width, lastLed?.Width ?? 0); + Y = GetLocationValue(DescriptiveY, lastLed?.Y ?? 0, Height, lastLed?.Height ?? 0); + } + + private double GetLocationValue(string value, double lastValue, double currentSize, double lastSize) + { + try + { + if (string.IsNullOrWhiteSpace(value)) return 0; + + value = value.Replace(" ", string.Empty); + + if (string.Equals(value, "=", StringComparison.Ordinal)) + return lastValue; + + if (string.Equals(value, "+", StringComparison.Ordinal)) + return lastValue + lastSize; + + if (value.StartsWith("+", StringComparison.Ordinal)) + return lastValue + lastSize + double.Parse(value.Substring(1), CultureInfo.InvariantCulture); + + if (string.Equals(value, "-", StringComparison.Ordinal)) + return lastValue - currentSize; + + if (value.StartsWith("-", StringComparison.Ordinal)) + return lastValue - currentSize - double.Parse(value.Substring(1), CultureInfo.InvariantCulture); + + if (string.Equals(value, "~", StringComparison.Ordinal)) + return (lastValue + lastSize) - currentSize; + + if (value.StartsWith("~", StringComparison.Ordinal)) + return (lastValue + lastSize) - currentSize - double.Parse(value.Substring(1), CultureInfo.InvariantCulture); + + return double.Parse(value, CultureInfo.InvariantCulture); + } + catch + { + return 0; + } + } + + private double GetSizeValue(string value, double unitSize) + { + try + { + if (string.IsNullOrWhiteSpace(value)) return 0; + + value = value.Replace(" ", string.Empty); + + if (value.EndsWith("mm", StringComparison.OrdinalIgnoreCase)) + return double.Parse(value.Substring(0, value.Length - 2), CultureInfo.InvariantCulture); + + return unitSize * double.Parse(value, CultureInfo.InvariantCulture); + } + catch + { + return 0; + } + } #endregion } diff --git a/RGB.NET.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGB/UK.xml b/RGB.NET.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGB/UK.xml index 8f50f84..c95053a 100644 --- a/RGB.NET.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGB/UK.xml +++ b/RGB.NET.Devices.Corsair/Layouts/Corsair/Keyboards/K95RGB/UK.xml @@ -1,1101 +1,359 @@ - + Corsair K95 RGB - Physical UK Physical UK-Layout of Corsairs K95 RGB (Logical: BE, CH, DE, ES, EU, FR, IT, ND, MEX, RU, UK, US_Int) Keyboard Key Corsair K95RGB - Rectangle 501 165 - - GraveAccentAndTilde - Rectangle - 70.5 - 50.5 - 14 - 14 - - - D1 - Rectangle - 89.5 - 50.5 - 14 - 14 - - - D2 - Rectangle - 108.5 - 50.5 - 14 - 14 - - - D3 - Rectangle - 127.5 - 50.5 - 14 - 14 - - - D4 - Rectangle - 146.5 - 50.5 - 14 - 14 - - - D5 - Rectangle - 165.5 - 50.5 - 14 - 14 - - - D6 - Rectangle - 184.5 - 50.5 - 14 - 14 - - - D7 - Rectangle - 203.5 - 50.5 - 14 - 14 - - - D8 - Rectangle - 222.5 - 50.5 - 14 - 14 - - - D9 - Rectangle - 241.5 - 50.5 - 14 - 14 - - - D0 - Rectangle - 260.5 - 50.5 - 14 - 14 - - - MinusAndUnderscore - Rectangle - 279.5 - 50.5 - 14 - 14 - - - EqualsAndPlus - Rectangle - 298.5 - 50.5 - 14 - 14 - - - - Q - Rectangle - 99 - 69.5 - 14 - 14 - - - W - Rectangle - 118 - 69.5 - 14 - 14 - - - E - Rectangle - 137 - 69.5 - 14 - 14 - - - R - Rectangle - 156 - 69.5 - 14 - 14 - - - T - Rectangle - 175 - 69.5 - 14 - 14 - - - Y - Rectangle - 194 - 69.5 - 14 - 14 - - - U - Rectangle - 213 - 69.5 - 14 - 14 - - - I - Rectangle - 232 - 69.5 - 14 - 14 - - - O - Rectangle - 250.75 - 69.5 - 14 - 14 - - - P - Rectangle - 269.75 - 69.5 - 14 - 14 - - - BracketLeft - Rectangle - 288.75 - 69.5 - 14 - 14 - - - BracketRight - Rectangle - 307.75 - 69.5 - 14 - 14 - - - - A - Rectangle - 103.75 - 88.25 - 14 - 14 - - - S - Rectangle - 122.75 - 88.25 - 14 - 14 - - - D - Rectangle - 141.75 - 88.25 - 14 - 14 - - - F - Rectangle - 160.5 - 88.25 - 14 - 14 - - - G - Rectangle - 179.5 - 88.25 - 14 - 14 - - - H - Rectangle - 198.5 - 88.25 - 14 - 14 - - - J - Rectangle - 217.5 - 88.25 - 14 - 14 - - - K - Rectangle - 236.5 - 88.25 - 14 - 14 - - - L - Rectangle - 255.5 - 88.25 - 14 - 14 - - - SemicolonAndColon - Rectangle - 274.5 - 88.25 - 14 - 14 - - - ApostropheAndDoubleQuote - Rectangle - 293.5 - 88.25 - 14 - 14 - - - NonUsTilde - Rectangle - 312.25 - 88.25 - 14 - 14 - - - - NonUsBackslash - Rectangle - 94.5 - 107 - 14 - 14 - - - Z - Rectangle - 113.5 - 107 - 14 - 14 - - - X - Rectangle - 132.5 - 107 - 14 - 14 - - - C - Rectangle - 151.5 - 107 - 14 - 14 - - - V - Rectangle - 170.25 - 107 - 14 - 14 - - - B - Rectangle - 189.25 - 107 - 14 - 14 - - - N - Rectangle - 208.25 - 107 - 14 - 14 - - - M - Rectangle - 227 - 107 - 14 - 14 - - - CommaAndLessThan - Rectangle - 246 - 107 - 14 - 14 - - - PeriodAndBiggerThan - Rectangle - 265 - 107 - 14 - 14 - - - SlashAndQuestionMark - Rectangle - 284 - 107 - 14 - 14 - - - - - Backspace - Rectangle - 317 - 50.5 - 33 - 14 - - - Tab - Rectangle - 70.5 - 69.5 - 23 - 14 - - - Enter - Rectangle - 330 - 69.5 - 20 - 32.75 - - - CapsLock - Rectangle - 70.5 - 88.25 - 28 - 14 - - - LeftShift - Rectangle - 70.5 - 107 - 20 - 14 - - - RightShift - Rectangle - 303 - 107 - 47 - 14 - - - LeftCtrl - Rectangle - 70.5 - 126 - 23 - 14 - - - LeftGui - Rectangle - 99 - 126 - 14 - 14 - - - LeftAlt - Rectangle - 118.5 - 126 - 18 - 14 - - - Space - Rectangle - 142 - 126 - 118 - 14 - - - RightAlt - Rectangle - 265 - 126 - 18 - 14 - - - RightGui - Rectangle - 288.5 - 126 - 14 - 14 - - - Application - Rectangle - 307.5 - 126 - 14 - 14 - - - RightCtrl - Rectangle - 326.5 - 126 - 23 - 14 - - - - - Escape - Rectangle - 70.5 - 29.5 - 14 - 14 - - - F1 - Rectangle - 102 - 29.5 - 14 - 14 - - - F2 - Rectangle - 121 - 29.5 - 14 - 14 - - - F3 - Rectangle - 140 - 29.5 - 14 - 14 - - - F4 - Rectangle - 159 - 29.5 - 14 - 14 - - - F5 - Rectangle - 190.5 - 29.5 - 14 - 14 - - - F6 - Rectangle - 209.5 - 29.5 - 14 - 14 - - - F7 - Rectangle - 228.5 - 29.5 - 14 - 14 - - - F8 - Rectangle - 247.5 - 29.5 - 14 - 14 - - - F9 - Rectangle - 279 - 29.5 - 14 - 14 - - - F10 - Rectangle - 298 - 29.5 - 14 - 14 - - - F11 - Rectangle - 317 - 29.5 - 14 - 14 - - - F12 - Rectangle - 336 - 29.5 - 14 - 14 - - - PrintScreen - Rectangle - 360 - 29.5 - 14 - 14 - - - ScrollLock - Rectangle - 379 - 29.5 - 14 - 14 - - - PauseBreak - Rectangle - 398 - 29.5 - 14 - 14 - - - Insert - Rectangle - 360 - 50.5 - 14 - 14 - - - Home - Rectangle - 379 - 50.5 - 14 - 14 - - - PageUp - Rectangle - 398 - 50.5 - 14 - 14 - - - Delete - Rectangle - 360 - 69.5 - 14 - 14 - - - End - Rectangle - 379 - 69.5 - 14 - 14 - - - PageDown - Rectangle - 398 - 69.5 - 14 - 14 - - - UpArrow - Rectangle - 379 - 107 - 14 - 14 - - - LeftArrow - Rectangle - 360 - 126 - 14 - 14 - - - DownArrow - Rectangle - 379 - 126 - 14 - 14 - - - RightArrow - Rectangle - 398 - 126 - 14 - 14 - - - - - NumLock - Rectangle - 422 - 50.5 - 14 - 14 - - - KeypadSlash - Rectangle - 441 - 50.5 - 14 - 14 - - - KeypadAsterisk - Rectangle - 460 - 50.5 - 14 - 14 - - - KeypadMinus - Rectangle - 479 - 50.5 - 14 - 14 - - - Keypad7 - Rectangle - 422 - 69.5 - 14 - 14 - - - Keypad8 - Rectangle - 441 - 69.5 - 14 - 14 - - - Keypad9 - Rectangle - 460 - 69.5 - 14 - 14 - - - KeypadPlus - Rectangle - 479 - 69.5 - 14 - 33 - - - Keypad4 - Rectangle - 422 - 88.25 - 14 - 14 - - - Keypad5 - Rectangle - 441 - 88.25 - 14 - 14 - - - Keypad6 - Rectangle - 460 - 88.25 - 14 - 14 - - - Keypad1 - Rectangle - 422 - 107 - 14 - 14 - - - Keypad2 - Rectangle - 441 - 107 - 14 - 14 - - - Keypad3 - Rectangle - 460 - 107 - 14 - 14 - - - KeypadEnter - Rectangle - 479 - 107 - 14 - 33 - - - Keypad0 - Rectangle - 422 - 126 - 33 - 14 - - - KeypadPeriodAndDelete - Rectangle - 460 - 126 - 14 - 14 - - - - - G1 - Rectangle - 9.5 - 29 - 14 - 14 - - - G2 - Rectangle - 27.5 - 29 - 14 - 14 - - - G3 - Rectangle - 45.5 - 29 - 14 - 14 - - - G4 - Rectangle - 9.5 - 47 - 14 - 14 - - - G5 - Rectangle - 27.5 - 47 - 14 - 14 - - - G6 - Rectangle - 45.5 - 47 - 14 - 14 - - - G7 - Rectangle - 9.5 - 69 - 14 - 14 - - - G8 - Rectangle - 27.5 - 69 - 14 - 14 - - - G9 - Rectangle - 45.5 - 69 - 14 - 14 - - - G10 - Rectangle - 9.5 - 87 - 14 - 14 - - - G11 - Rectangle - 27.5 - 87 - 14 - 14 - - - G12 - Rectangle - 45.5 - 87 - 14 - 14 - - - G13 - Rectangle - 9.5 - 109 - 14 - 14 - - - G14 - Rectangle - 27.5 - 109 - 14 - 14 - - - G15 - Rectangle - 45.5 - 109 - 14 - 14 - - - G16 - Rectangle - 9.5 - 127 - 14 - 14 - - - G17 - Rectangle - 27.5 - 127 - 14 - 14 - - - G18 - Rectangle - 45.5 - 127 - 14 - 14 - - - - - Mute - Rectangle - 439.5 - 6.5 - 17.5 - 11.5 - - - Stop - Rectangle - 421 - 29 - 17.5 - 11.5 - - - ScanPreviousTrack - Rectangle - 439.5 - 29 - 17.5 - 11.5 - - - PlayPause - Rectangle - 458 - 29 - 17.5 - 11.5 - - - ScanNextTrack - Rectangle - 476.5 - 29 - 17.5 - 11.5 - - - - - MR + + Circle - 73 - 7.5 - 9.5 - 9.5 + 72 + 6 + 12mm + 12mm - - M1 + Circle - 92 - 7.5 - 9.5 - 9.5 + 91.5 + 7 + 10mm + 10mm - - M2 + Circle - 111 - 7.5 - 9.5 - 9.5 + +9 + 10mm + 10mm - - M3 + Circle - 130 - 7.5 - 9.5 - 9.5 + +9 + 10mm + 10mm - - Brightness + + Circle - 362.5 - 7.5 - 9.5 - 9.5 + 362 + 10mm + 10mm - - WinLock + Circle - 381.5 - 7.5 - 9.5 - 9.5 + +9 + 10mm + 10mm + + + + 439 + 6 + 13mm + + + + + 68 + 28 + + + + +12.667 + + + + + + + +12.667 + + + + + + + +12.667 + + + + + + + +5 + + + + + + +5 + 14mm + + + 14mm + + + 14mm + + + 14mm + + + + + 68 + 49 + + + + + + + + + + + + + + + 2 + + + + +5 + + + + + + +5 + + + + + + + + 68 + + + 1.5 + + + + + + + + + + + + + + + 1.5 + 2 + + + + +5 + + + + + + +5 + + + + + 2 + + + + + 68 + ~ + 1.75 + + + + + + + + + + + + + + + + +90.75 + + + + + + + 68 + + + 1.25 + + + + + + + + + + + + + + 2.75 + + + + +24 + + + + +24 + + + + + 2 + + + + + 68 + ~ + 1.5 + + + + 1.25 + + + 6.5 + + + 1.25 + + + + + 1.5 + + + + +5 + + + + + + +5 + 2 + + + + + + 7 + 28 + 18mm + 18mm + + + 18mm + 18mm + + + 18mm + 18mm + + + 7 + + + 18mm + 18mm + + + 18mm + 18mm + + + 18mm + 18mm + + + + 7 + +4 + 18mm + 18mm + + + 18mm + 18mm + + + 18mm + 18mm + + + 7 + + + 18mm + 18mm + + + 18mm + 18mm + + + 18mm + 18mm + + + + 7 + +4 + 18mm + 18mm + + + 18mm + 18mm + + + 18mm + 18mm + + + 7 + + + 18mm + 18mm + + + 18mm + 18mm + + + 18mm + 18mm \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd b/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd new file mode 100644 index 0000000..00f1c04 --- /dev/null +++ b/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index c727a30..741971b 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -77,6 +77,9 @@ + + Designer +