1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Added XML-Structure to represent device layouts.

This commit is contained in:
Darth Affe 2017-01-30 20:19:43 +01:00
parent dcaebd2b3b
commit 62626e91f2
7 changed files with 232 additions and 1 deletions

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xsd:element name="Device">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Name" type="xsd:string" />
<xsd:element name="Description" type="xsd:string" />
<xsd:element name="Type" type="xsd:string" />
<xsd:element name="Lighting" type="xsd:string" />
<xsd:element name="Vendor" type="xsd:string" />
<xsd:element name="Model" type="xsd:string" />
<xsd:element name="Shape" type="xsd:string" />
<xsd:element name="Width" type="xsd:double" />
<xsd:element name="Height" type="xsd:double" />
<xsd:element name="Leds">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="Led">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Id" type="xsd:string" />
<xsd:element name="Shape" type="xsd:string" />
<xsd:element name="X" type="xsd:double" />
<xsd:element name="Y" type="xsd:double" />
<xsd:element name="Width" type="xsd:double" />
<xsd:element name="Height" type="xsd:double" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xs:schema>

View File

@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace RGB.NET.Core.Layout
{
/// <summary>
/// Represents the serializable layout of a <see cref="IRGBDevice"/>.
/// </summary>
[Serializable]
[XmlRoot("Device")]
public class DeviceLayout
{
#region Properties & Fields
/// <summary>
/// Gets or sets the name of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Name")]
public string Name { get; set; }
/// <summary>
/// Gets or sets the description of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Description")]
public string Description { get; set; }
/// <summary>
/// Gets or sets the <see cref="RGBDeviceType"/> of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Type")]
public RGBDeviceType Type { get; set; }
/// <summary>
/// Gets or sets the <see cref="LayoutLighting"/> of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Lighting")]
public LayoutLighting Lighting { get; set; }
/// <summary>
/// Gets or sets the vendor of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Vendor")]
public string Vendor { get; set; }
/// <summary>
/// Gets or sets the model of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Model")]
public string Model { get; set; }
/// <summary>
/// Gets or sets the <see cref="LayoutShape"/> of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Shape")]
public LayoutShape Shape { get; set; }
/// <summary>
/// Gets or sets the width of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Width")]
public double Width { get; set; }
/// <summary>
/// Gets or sets the height of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlElement("Height")]
public double Height { get; set; }
/// <summary>
/// Gets or sets a list of <see cref="LedLayout"/> representing all the <see cref="Led"/> of the <see cref="DeviceLayout"/>.
/// </summary>
[XmlArray("Leds")]
public List<LedLayout> Leds { get; set; } = new List<LedLayout>();
#endregion
#region Methods
/// <summary>
/// Creates a new <see cref="DeviceLayout"/> from the given xml.
/// </summary>
/// <param name="path">The path to the xml file.</param>
/// <returns>The deserialized <see cref="DeviceLayout"/>.</returns>
public static DeviceLayout Load(string path)
{
if (!File.Exists(path)) return null;
try
{
XmlSerializer serializer = new XmlSerializer(typeof(DeviceLayout));
using (StreamReader reader = new StreamReader(path))
return serializer.Deserialize(reader) as DeviceLayout;
}
catch
{
return null;
}
}
#endregion
}
}

View File

@ -0,0 +1,18 @@
namespace RGB.NET.Core.Layout
{
/// <summary>
/// Contains a list of different lightning-modes used by <see cref="DeviceLayout"/>.
/// </summary>
public enum LayoutLighting
{
/// <summary>
/// The <see cref="IRGBDevice"/> supports per-key-lightning.
/// </summary>
Key = 0,
/// <summary>
/// The <see cref="IRGBDevice"/> supports per-keyboard-lightning.
/// </summary>
Keyboard = 1,
}
}

View File

@ -0,0 +1,16 @@
using System;
namespace RGB.NET.Core.Layout
{
/// <summary>
/// Contains a list of different shapes used by <see cref="DeviceLayout"/>.
/// </summary>
[Serializable]
public enum LayoutShape
{
/// <summary>
/// A simple rectangle.
/// </summary>
Rectangle = 0
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Xml.Serialization;
namespace RGB.NET.Core.Layout
{
/// <summary>
/// Represents the serializable layout of a <see cref="Led"/>.
/// </summary>
[Serializable]
[XmlType("Led")]
public class LedLayout
{
#region Properties & Fields
/// <summary>
/// Gets or sets the Id of the <see cref="LedLayout"/>.
/// </summary>
[XmlElement("Id")]
public string Id { get; set; }
/// <summary>
/// Gets or sets the <see cref="LayoutShape"/> of the <see cref="LedLayout"/>.
/// </summary>
[XmlElement("Shape")]
public LayoutShape Shape { get; set; }
/// <summary>
/// Gets or sets the x-position of the <see cref="LedLayout"/>.
/// </summary>
[XmlElement("X")]
public double X { get; set; }
/// <summary>
/// Gets or sets the y-position of the <see cref="LedLayout"/>.
/// </summary>
[XmlElement("Y")]
public double Y { get; set; }
/// <summary>
/// Gets or sets the width of the <see cref="LedLayout"/>.
/// </summary>
[XmlElement("Width")]
public double Width { get; set; }
/// <summary>
/// Gets or sets the height of the <see cref="LedLayout"/>.
/// </summary>
[XmlElement("Height")]
public double Height { get; set; }
#endregion
}
}

View File

@ -1,7 +1,7 @@
namespace RGB.NET.Core
{
/// <summary>
/// Contains list of different types of device.
/// Contains a list of different types of device.
/// </summary>
public enum RGBDeviceType
{

View File

@ -48,6 +48,10 @@
<Compile Include="Brushes\IBrush.cs" />
<Compile Include="ColorCorrection\IColorCorrection.cs" />
<Compile Include="Devices\AbstractRGBDevice.cs" />
<Compile Include="Devices\Layout\LayoutLighting.cs" />
<Compile Include="Devices\Layout\LayoutShape.cs" />
<Compile Include="Devices\Layout\LedLayout.cs" />
<Compile Include="Devices\Layout\DeviceLayout.cs" />
<Compile Include="Devices\RGBDeviceType.cs" />
<Compile Include="Devices\IRGBDeviceProvider.cs" />
<Compile Include="Devices\IRGBDeviceInfo.cs" />