1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00

Added Led-Images as layout-part

This commit is contained in:
Darth Affe 2017-02-11 09:39:03 +01:00
parent 6d48cae4b3
commit 256c6dea74
19 changed files with 184 additions and 51 deletions

View File

@ -90,6 +90,12 @@ namespace RGB.NET.Core.Layout
[XmlArray("Leds")]
public List<LedLayout> Leds { get; set; } = new List<LedLayout>();
/// <summary>
/// Gets or sets a list of <see cref="LedImageLayout"/> representing the layouts for the images of all the <see cref="Led"/> of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlArray("LedImageLayouts")]
public List<LedImageLayout> LedImageLayouts { get; set; } = new List<LedImageLayout>();
#endregion
#region Methods

View File

@ -0,0 +1,25 @@
using System;
using System.Xml.Serialization;
namespace RGB.NET.Core.Layout
{
/// <summary>
/// Represents the serializable image-data of a specific <see cref="Led"/>.
/// </summary>
[Serializable]
[XmlRoot("LedImage")]
public class LedImage
{
/// <summary>
/// Gets or sets the Id of the <see cref="LedImage"/>.
/// </summary>
[XmlAttribute("Id")]
public string Id { get; set; }
/// <summary>
/// Gets or sets the image of the <see cref="LedImage"/>.
/// </summary>
[XmlAttribute("Image")]
public string Image { get; set; }
}
}

View File

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
namespace RGB.NET.Core.Layout
{
/// <summary>
/// Represents the serializable collection of <see cref="LedImage"/> for a specific layout.
/// </summary>
[Serializable]
[XmlRoot("LedImageLayout")]
public class LedImageLayout
{
/// <summary>
/// Gets or sets the layout of the <see cref="LedImage"/>.
/// </summary>
[XmlAttribute("Layout")]
[DefaultValue(null)]
public string Layout { get; set; }
/// <summary>
/// Gets or sets a list of <see cref="LedImage"/> representing the images of all the <see cref="Led"/> of the represented layout.
/// </summary>
[XmlArray("LedImages")]
public List<LedImage> LedImages { get; set; } = new List<LedImage>();
}
}

View File

@ -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); }
}
/// <summary>
/// Gets the URI of an image of the <see cref="Led"/> or null if there is no image.
/// </summary>
public Uri Image { get; set; }
#endregion
#region Constructors

View File

@ -48,6 +48,8 @@
<Compile Include="Brushes\IBrush.cs" />
<Compile Include="ColorCorrection\IColorCorrection.cs" />
<Compile Include="Devices\AbstractRGBDevice.cs" />
<Compile Include="Devices\Layout\LedImage.cs" />
<Compile Include="Devices\Layout\LedImageLayout.cs" />
<Compile Include="Devices\RGBDeviceLighting.cs" />
<Compile Include="Positioning\Shape.cs" />
<Compile Include="Devices\Layout\LedLayout.cs" />

View File

@ -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.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
protected void ApplyLayoutFromFile(string layoutPath)
/// <param name="imageLayout">The name of the layout used tp get the images of the leds.</param>
/// <param name="imageBasePath">The path images for this device are collected in.</param>
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);
}
}
}

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,24 @@
using System.IO;
using System.Reflection;
namespace RGB.NET.Devices.Corsair.Helper
{
/// <summary>
/// Offers some helper-methods for file-path related things.
/// </summary>
public static class PathHelper
{
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath)
{
string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath;
return Path.Combine(Path.GetDirectoryName(assemblyLocation), relativePath);
}
}
}

View File

@ -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

View File

@ -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

View File

@ -32,7 +32,32 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:element name="LedImageLayouts">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="LedImageLayout">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="LedImages">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="LedImage">
<xsd:complexType>
<xsd:attribute name="Id" type="xsd:string" use="required" />
<xsd:attribute name="Image" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="Layout" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xs:schema>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -62,6 +62,7 @@
<Compile Include="Generic\CorsairRGBDevice.cs" />
<Compile Include="Headset\CorsairHeadsetRGBDevice.cs" />
<Compile Include="Headset\CorsairHeadsetRGBDeviceInfo.cs" />
<Compile Include="Helper\PathHelper.cs" />
<Compile Include="Keyboard\CorsairKeyboardRGBDevice.cs" />
<Compile Include="Keyboard\CorsairKeyboardRGBDeviceInfo.cs" />
<Compile Include="Mouse\CorsairMouseRGBDevice.cs" />
@ -90,10 +91,10 @@
<ItemGroup>
<Folder Include="Images\Corsair\Headsets\" />
<Folder Include="Images\Corsair\Mice\" />
<Folder Include="Images\Corsair\Mousemat\" />
<Folder Include="Images\Corsair\Mousemats\" />
<Folder Include="Layouts\Corsair\Headsets\" />
<Folder Include="Layouts\Corsair\Mice\" />
<Folder Include="Layouts\Corsair\Mousemat\" />
<Folder Include="Layouts\Corsair\Mousemats\" />
</ItemGroup>
<ItemGroup>
<Content Include="Images\Corsair\Keyboards\K70RGB\BE.png" />

View File

@ -7,20 +7,38 @@
<ControlTemplate x:Key="ControlTemplateLedRectangle"
TargetType="{x:Type controls:LedVisualizer}">
<Rectangle VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{TemplateBinding BorderThickness}"
Fill="{TemplateBinding Background}" />
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.Background>
<Rectangle VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Opacity="0.5"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"
Fill="{TemplateBinding Background}" />
</Border>
</ControlTemplate>
<ControlTemplate x:Key="ControlTemplateLedCircle"
TargetType="{x:Type controls:LedVisualizer}">
<Ellipse VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{TemplateBinding BorderThickness}"
Fill="{TemplateBinding Background}" />
<Border VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image, RelativeSource={RelativeSource TemplatedParent}}" />
</Border.Background>
<Ellipse VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Opacity="0.5"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="1"
Fill="{TemplateBinding Background}" />
</Border>
</ControlTemplate>
<Style x:Key="StyleLedVisualizer"
@ -30,17 +48,15 @@
<Setter Property="Canvas.Left" Value="{Binding Led.LedRectangle.Location.X, RelativeSource={RelativeSource Self}}" />
<Setter Property="Canvas.Top" Value="{Binding Led.LedRectangle.Location.Y, RelativeSource={RelativeSource Self}}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#202020" />
<Setter Property="BorderBrush" Value="#A8202020" />
<Setter Property="Background" Value="{Binding Led.Color, RelativeSource={RelativeSource Self},
Converter={StaticResource ConverterColorToSolidColorBrush}}" />
<Setter Property="Opacity" Value="0.66" />
<Setter Property="Template" Value="{StaticResource ControlTemplateLedRectangle}" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="#FFFFFF" />
<Setter Property="BorderBrush" Value="#A8FFFFFF" />
</Trigger>
<DataTrigger Binding="{Binding Led.Shape, RelativeSource={RelativeSource Self}}" Value="Circle">

View File

@ -2,7 +2,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:RGB.NET.WPF.Controls">
<Style x:Key="StyleRGBDeviceVisualizer"
TargetType="{x:Type controls:RGBDeviceVisualizer}">
<Setter Property="Width" Value="{Binding Device.Size.Width, RelativeSource={RelativeSource Self}}" />