diff --git a/RGB.NET.Core/Devices/Layout/DeviceLayout.cs b/RGB.NET.Core/Devices/Layout/DeviceLayout.cs index a8d2015..2259ce2 100644 --- a/RGB.NET.Core/Devices/Layout/DeviceLayout.cs +++ b/RGB.NET.Core/Devices/Layout/DeviceLayout.cs @@ -90,6 +90,12 @@ namespace RGB.NET.Core.Layout [XmlArray("Leds")] public List Leds { get; set; } = new List(); + /// + /// Gets or sets a list of representing the layouts for the images of all the of the . + /// + [XmlArray("LedImageLayouts")] + public List LedImageLayouts { get; set; } = new List(); + #endregion #region Methods diff --git a/RGB.NET.Core/Devices/Layout/LedImage.cs b/RGB.NET.Core/Devices/Layout/LedImage.cs new file mode 100644 index 0000000..c76d95a --- /dev/null +++ b/RGB.NET.Core/Devices/Layout/LedImage.cs @@ -0,0 +1,25 @@ +using System; +using System.Xml.Serialization; + +namespace RGB.NET.Core.Layout +{ + /// + /// Represents the serializable image-data of a specific . + /// + [Serializable] + [XmlRoot("LedImage")] + public class LedImage + { + /// + /// Gets or sets the Id of the . + /// + [XmlAttribute("Id")] + public string Id { get; set; } + + /// + /// Gets or sets the image of the . + /// + [XmlAttribute("Image")] + public string Image { get; set; } + } +} diff --git a/RGB.NET.Core/Devices/Layout/LedImageLayout.cs b/RGB.NET.Core/Devices/Layout/LedImageLayout.cs new file mode 100644 index 0000000..2c3a491 --- /dev/null +++ b/RGB.NET.Core/Devices/Layout/LedImageLayout.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Xml.Serialization; + +namespace RGB.NET.Core.Layout +{ + /// + /// Represents the serializable collection of for a specific layout. + /// + [Serializable] + [XmlRoot("LedImageLayout")] + public class LedImageLayout + { + /// + /// Gets or sets the layout of the . + /// + [XmlAttribute("Layout")] + [DefaultValue(null)] + public string Layout { get; set; } + + /// + /// Gets or sets a list of representing the images of all the of the represented layout. + /// + [XmlArray("LedImages")] + public List LedImages { get; set; } = new List(); + } +} diff --git a/RGB.NET.Core/Leds/Led.cs b/RGB.NET.Core/Leds/Led.cs index 020cf5e..d4bac50 100644 --- a/RGB.NET.Core/Leds/Led.cs +++ b/RGB.NET.Core/Leds/Led.cs @@ -1,5 +1,6 @@ // ReSharper disable MemberCanBePrivate.Global +using System; using System.Diagnostics; namespace RGB.NET.Core @@ -90,6 +91,11 @@ namespace RGB.NET.Core set { SetProperty(ref _isLocked, value); } } + /// + /// Gets the URI of an image of the or null if there is no image. + /// + public Uri Image { get; set; } + #endregion #region Constructors diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index eef0e49..39e3b6f 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -48,6 +48,8 @@ + + diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index 3c63407..11c6cf3 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core; @@ -60,11 +61,15 @@ namespace RGB.NET.Devices.Corsair /// Applies the given layout. /// /// The file containing the layout. - protected void ApplyLayoutFromFile(string layoutPath) + /// The name of the layout used tp get the images of the leds. + /// The path images for this device are collected in. + protected void ApplyLayoutFromFile(string layoutPath, string imageLayout, string imageBasePath) { DeviceLayout layout = DeviceLayout.Load(layoutPath); if (layout != null) { + LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase)); + InternalSize = new Size(layout.Width, layout.Height); if (layout.Leds != null) @@ -82,6 +87,11 @@ namespace RGB.NET.Devices.Corsair led.LedRectangle.Size.Height = layoutLed.Height; led.Shape = layoutLed.Shape; + + LedImage image = ledImageLayout?.LedImages.FirstOrDefault(x => x.Id == layoutLed.Id); + led.Image = (!string.IsNullOrEmpty(image?.Image)) + ? new Uri(Path.Combine(imageBasePath, image.Image), UriKind.Absolute) + : new Uri(Path.Combine(imageBasePath, "Clean.png"), UriKind.Absolute); } } } diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs index a6d8ca5..e604c3f 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDevice.cs @@ -1,9 +1,8 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global -using System.IO; -using System.Reflection; using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Helper; namespace RGB.NET.Devices.Corsair { @@ -43,8 +42,8 @@ namespace RGB.NET.Devices.Corsair InitializeLed(new CorsairLedId(this, CorsairLedIds.LeftLogo), new Rectangle(0, 0, 10, 10)); InitializeLed(new CorsairLedId(this, CorsairLedIds.RightLogo), new Rectangle(10, 0, 10, 10)); - ApplyLayoutFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Layouts\Corsair\Headsets\{HeadsetDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml")); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Headsets\{HeadsetDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), + null, PathHelper.GetAbsolutePath(@"Images\Corsair\Headsets")); } #endregion diff --git a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs index 89bed5b..6925728 100644 --- a/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Headset/CorsairHeadsetRGBDeviceInfo.cs @@ -1,6 +1,5 @@ using System; -using System.IO; -using System.Reflection; +using RGB.NET.Devices.Corsair.Helper; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair @@ -20,8 +19,7 @@ namespace RGB.NET.Devices.Corsair internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) : base(deviceIndex, Core.RGBDeviceType.Headset, nativeInfo) { - Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Images\Corsair\Headsets\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Relative); + Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Headsets\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute); } #endregion diff --git a/RGB.NET.Devices.Corsair/Helper/PathHelper.cs b/RGB.NET.Devices.Corsair/Helper/PathHelper.cs new file mode 100644 index 0000000..0cbc5aa --- /dev/null +++ b/RGB.NET.Devices.Corsair/Helper/PathHelper.cs @@ -0,0 +1,24 @@ +using System.IO; +using System.Reflection; + +namespace RGB.NET.Devices.Corsair.Helper +{ + /// + /// Offers some helper-methods for file-path related things. + /// + public static class PathHelper + { + /// + /// Returns an absolute path created from an relative path relatvie to the location of the executung assembly. + /// + /// The relative path to convert. + /// The absolute path. + public static string GetAbsolutePath(string relativePath) + { + string assemblyLocation = Assembly.GetEntryAssembly()?.Location; + if (assemblyLocation == null) return relativePath; + + return Path.Combine(Path.GetDirectoryName(assemblyLocation), relativePath); + } + } +} diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs index b62192a..540f4e2 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDevice.cs @@ -2,10 +2,9 @@ // ReSharper disable UnusedMember.Global using System; -using System.IO; -using System.Reflection; using System.Runtime.InteropServices; using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Helper; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair @@ -58,8 +57,10 @@ namespace RGB.NET.Devices.Corsair ptr = new IntPtr(ptr.ToInt64() + structSize); } - ApplyLayoutFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Layouts\Corsair\Keyboards\{KeyboardDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}\{KeyboardDeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml")); + string model = KeyboardDeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath( + $@"Layouts\Corsair\Keyboards\{model}\{KeyboardDeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), + KeyboardDeviceInfo.LogicalLayout.ToString(), PathHelper.GetAbsolutePath($@"Images\Corsair\Keyboards\{model}")); } #endregion diff --git a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs index 6b0f616..f27c542 100644 --- a/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Keyboard/CorsairKeyboardRGBDeviceInfo.cs @@ -2,8 +2,7 @@ // ReSharper disable UnusedMember.Global using System; -using System.IO; -using System.Reflection; +using RGB.NET.Devices.Corsair.Helper; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair @@ -40,8 +39,8 @@ namespace RGB.NET.Devices.Corsair this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout; this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout; - Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Images\Corsair\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}\{LogicalLayout.ToString().ToUpper()}.png"), UriKind.Absolute); + string model = Model.Replace(" ", string.Empty).ToUpper(); + Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Keyboards\{model}\{model}.png"), UriKind.Absolute); } #endregion diff --git a/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd b/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd index 00f1c04..92690b3 100644 --- a/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd +++ b/RGB.NET.Devices.Corsair/Layouts/DeviceLayout.xsd @@ -32,7 +32,32 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs index 3328c1e..01a72cc 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs @@ -1,10 +1,9 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global -using System.IO; -using System.Reflection; using RGB.NET.Core; using RGB.NET.Core.Exceptions; +using RGB.NET.Devices.Corsair.Helper; namespace RGB.NET.Devices.Corsair { @@ -65,8 +64,8 @@ namespace RGB.NET.Devices.Corsair throw new RGBDeviceException($"Can't initial mouse with layout '{MouseDeviceInfo.PhysicalLayout}'"); } - ApplyLayoutFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Layouts\Corsair\String\{MouseDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml")); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Mice\{MouseDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), + null, PathHelper.GetAbsolutePath(@"Images\Corsair\Mice")); } #endregion diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs index 116ffff..e84964a 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDeviceInfo.cs @@ -1,6 +1,5 @@ using System; -using System.IO; -using System.Reflection; +using RGB.NET.Devices.Corsair.Helper; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair @@ -31,8 +30,7 @@ namespace RGB.NET.Devices.Corsair { this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout; - Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Images\Corsair\Mice\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Relative); + Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Mice\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute); } #endregion diff --git a/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDevice.cs b/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDevice.cs index 10dfe65..6f00342 100644 --- a/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDevice.cs @@ -3,11 +3,10 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Reflection; using System.Runtime.InteropServices; using RGB.NET.Core; +using RGB.NET.Devices.Corsair.Helper; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair @@ -65,8 +64,8 @@ namespace RGB.NET.Devices.Corsair InitializeLed(new CorsairLedId(this, ledPosition.ledId), new Rectangle(ledPosition.left, ledPosition.top, ledPosition.width, ledPosition.height)); - ApplyLayoutFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Layouts\Corsair\Mousemat\{MousematDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml")); + ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Mousemats\{MousematDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), + null, PathHelper.GetAbsolutePath(@"Images\Corsair\Mousemats")); } #endregion diff --git a/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDeviceInfo.cs index e9c6bd0..b78e2ad 100644 --- a/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair/Mousmat/CorsairMousematRGBDeviceInfo.cs @@ -1,6 +1,5 @@ using System; -using System.IO; -using System.Reflection; +using RGB.NET.Devices.Corsair.Helper; using RGB.NET.Devices.Corsair.Native; namespace RGB.NET.Devices.Corsair @@ -20,8 +19,7 @@ namespace RGB.NET.Devices.Corsair internal CorsairMousematRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) : base(deviceIndex, Core.RGBDeviceType.Mousemat, nativeInfo) { - Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), - $@"Images\Corsair\Mousemat\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Relative); + Image = new Uri(PathHelper.GetAbsolutePath($@"Images\Corsair\Mousemat\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Absolute); } #endregion diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index 741971b..92bf5f6 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -62,6 +62,7 @@ + @@ -90,10 +91,10 @@ - + - + diff --git a/RGB.NET.WPF/Styles/LedVisualizer.xaml b/RGB.NET.WPF/Styles/LedVisualizer.xaml index 5810dbf..ea212ee 100644 --- a/RGB.NET.WPF/Styles/LedVisualizer.xaml +++ b/RGB.NET.WPF/Styles/LedVisualizer.xaml @@ -7,20 +7,38 @@ - + + + + + + + - + + + + + + +