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

Added layout-functionality to corsair devices

This commit is contained in:
Darth Affe 2017-01-31 22:06:22 +01:00
parent cedd220789
commit f83b08af5e
12 changed files with 99 additions and 31 deletions

View File

@ -23,6 +23,8 @@
<file src="..\bin\RGB.NET.Devices.Corsair.pdb" target="lib\net45\RGB.NET.Devices.Corsair.pdb" /> <file src="..\bin\RGB.NET.Devices.Corsair.pdb" target="lib\net45\RGB.NET.Devices.Corsair.pdb" />
<file src="..\bin\RGB.NET.Devices.Corsair.xml" target="lib\net45\RGB.NET.Devices.Corsair.xml" /> <file src="..\bin\RGB.NET.Devices.Corsair.xml" target="lib\net45\RGB.NET.Devices.Corsair.xml" />
<file src="..\RGB.NET.Devices.Corsair\**\*.cs" target="src" exclude="..\RGB.NET.Devices.Corsair\obj\**\*.*" /> <file src="..\RGB.NET.Devices.Corsair\**\*.cs" target="src" exclude="..\RGB.NET.Devices.Corsair\obj\**\*.*" />
<file src="..\RGB.NET.Devices.Corsair\Images\**\*.*" target="build\net45\resources\Images\" />
<file src="..\RGB.NET.Devices.Corsair\Layouts\**\*.*" target="build\net45\resources\Layouts\" />
<file src="..\RGB.NET.Devices.Corsair\libs\**\*.*" target="build\net45\libs\" /> <file src="..\RGB.NET.Devices.Corsair\libs\**\*.*" target="build\net45\libs\" />
<file src="..\RGB.NET.Devices.Corsair\targets\*.targets" target="build\net45\" /> <file src="..\RGB.NET.Devices.Corsair\targets\*.targets" target="build\net45\" />
</files> </files>

View File

@ -1,8 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Core.Layout;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
@ -41,16 +44,49 @@ namespace RGB.NET.Devices.Corsair
/// </summary> /// </summary>
internal void Initialize() internal void Initialize()
{ {
InitializeLeds(); InitializeLayout();
if (InternalSize == null)
{
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle)); Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
} }
}
/// <summary> /// <summary>
/// Initializes the <see cref="Led"/> of the device. /// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
/// </summary> /// </summary>
protected abstract void InitializeLeds(); protected abstract void InitializeLayout();
/// <summary>
/// Applies the given layout.
/// </summary>
/// <param name="layoutPath">The file containing the layout.</param>
protected void ApplyLayoutFromFile(string layoutPath)
{
DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null)
{
InternalSize = new Size(layout.Width, layout.Height);
if (layout.Leds != null)
foreach (LedLayout layoutLed in layout.Leds)
{
CorsairLedIds ledId;
if (Enum.TryParse(layoutLed.Id, true, out ledId))
{
Led led;
if (LedMapping.TryGetValue(new CorsairLedId(this, ledId), out led))
{
led.LedRectangle.Location.X = layoutLed.X;
led.LedRectangle.Location.Y = layoutLed.Y;
led.LedRectangle.Size.Width = layoutLed.Width;
led.LedRectangle.Size.Height = layoutLed.Height;
}
}
}
}
}
/// <inheritdoc /> /// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)

View File

@ -1,7 +1,11 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.IO;
using System.Reflection;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Core.Layout;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
{ {
@ -35,13 +39,14 @@ namespace RGB.NET.Devices.Corsair
#region Methods #region Methods
/// <summary> /// <inheritdoc />
/// Initializes the <see cref="Led"/> of the headset. protected override void InitializeLayout()
/// </summary>
protected override void InitializeLeds()
{ {
InitializeLed(new CorsairLedId(this, CorsairLedIds.LeftLogo), new Rectangle(0, 0, 10, 10)); InitializeLed(new CorsairLedId(this, CorsairLedIds.LeftLogo), new Rectangle(0, 0, 10, 10));
InitializeLed(new CorsairLedId(this, CorsairLedIds.RightLogo), new Rectangle(10, 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"));
} }
#endregion #endregion

View File

@ -1,4 +1,6 @@
using System; using System;
using System.IO;
using System.Reflection;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
@ -18,7 +20,8 @@ namespace RGB.NET.Devices.Corsair
internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, Core.RGBDeviceType.Headset, nativeInfo) : base(deviceIndex, Core.RGBDeviceType.Headset, nativeInfo)
{ {
Image = new Uri($"pack://application:,,,/RGB.NET.Devices.Corsair;component/Images/Headsets/{Model.Replace(" ", string.Empty).ToUpper()}.png", UriKind.Absolute); Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Images\Corsair\Headsets\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Relative);
} }
#endregion #endregion

View File

@ -2,6 +2,8 @@
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System; using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
@ -38,10 +40,8 @@ namespace RGB.NET.Devices.Corsair
#region Methods #region Methods
/// <summary> /// <inheritdoc />
/// Initializes the <see cref="Led"/> of the keyboard. protected override void InitializeLayout()
/// </summary>
protected override void InitializeLeds()
{ {
_CorsairLedPositions nativeLedPositions = _CorsairLedPositions nativeLedPositions =
(_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions)); (_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions));
@ -57,6 +57,9 @@ namespace RGB.NET.Devices.Corsair
ptr = new IntPtr(ptr.ToInt64() + structSize); ptr = new IntPtr(ptr.ToInt64() + structSize);
} }
ApplyLayoutFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Layouts\Corsair\Keyboards\{KeyboardDeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}\{KeyboardDeviceInfo.LogicalLayout.ToString().ToUpper()}.xml"));
} }
#endregion #endregion

View File

@ -2,6 +2,8 @@
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System; using System;
using System.IO;
using System.Reflection;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
@ -38,7 +40,8 @@ namespace RGB.NET.Devices.Corsair
this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout; this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout; this.LogicalLayout = (CorsairLogicalKeyboardLayout)nativeInfo.logicalLayout;
Image = new Uri($"pack://application:,,,/RGB.NET.Devices.Corsair;component/Images/Keyboards/{Model.Replace(" ", string.Empty).ToUpper()}/{LogicalLayout.ToString().ToUpper()}.png", UriKind.Absolute); Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Images\Corsair\Keyboards\{Model.Replace(" ", string.Empty).ToUpper()}\{LogicalLayout.ToString().ToUpper()}.png"), UriKind.Absolute);
} }
#endregion #endregion

View File

@ -1,6 +1,8 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System.IO;
using System.Reflection;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Core.Exceptions; using RGB.NET.Core.Exceptions;
@ -36,10 +38,8 @@ namespace RGB.NET.Devices.Corsair
#region Methods #region Methods
/// <summary> /// <inheritdoc />
/// Initializes the <see cref="Led"/> of the mouse. protected override void InitializeLayout()
/// </summary>
protected override void InitializeLeds()
{ {
switch (MouseDeviceInfo.PhysicalLayout) switch (MouseDeviceInfo.PhysicalLayout)
{ {
@ -64,6 +64,9 @@ namespace RGB.NET.Devices.Corsair
default: default:
throw new RGBDeviceException($"Can't initial mouse with layout '{MouseDeviceInfo.PhysicalLayout}'"); 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"));
} }
#endregion #endregion

View File

@ -1,4 +1,6 @@
using System; using System;
using System.IO;
using System.Reflection;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
@ -29,7 +31,8 @@ namespace RGB.NET.Devices.Corsair
{ {
this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout; this.PhysicalLayout = (CorsairPhysicalMouseLayout)nativeInfo.physicalLayout;
Image = new Uri($"pack://application:,,,/RGB.NET.Devices.Corsair;component/Images/Mice/{Model.Replace(" ", string.Empty).ToUpper()}.png", UriKind.Absolute); Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Images\Corsair\Mice\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Relative);
} }
#endregion #endregion

View File

@ -3,7 +3,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
@ -40,10 +42,8 @@ namespace RGB.NET.Devices.Corsair
#region Methods #region Methods
/// <summary> /// <inheritdoc />
/// Initializes the <see cref="Led"/> of the mousemat. protected override void InitializeLayout()
/// </summary>
protected override void InitializeLeds()
{ {
_CorsairLedPositions nativeLedPositions = _CorsairLedPositions nativeLedPositions =
(_CorsairLedPositions) (_CorsairLedPositions)
@ -64,6 +64,9 @@ namespace RGB.NET.Devices.Corsair
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId)) foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId))
InitializeLed(new CorsairLedId(this, ledPosition.ledId), InitializeLed(new CorsairLedId(this, ledPosition.ledId),
new Rectangle(ledPosition.left, ledPosition.top, ledPosition.width, ledPosition.height)); 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"));
} }
#endregion #endregion

View File

@ -1,4 +1,6 @@
using System; using System;
using System.IO;
using System.Reflection;
using RGB.NET.Devices.Corsair.Native; using RGB.NET.Devices.Corsair.Native;
namespace RGB.NET.Devices.Corsair namespace RGB.NET.Devices.Corsair
@ -18,7 +20,8 @@ namespace RGB.NET.Devices.Corsair
internal CorsairMousematRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo) internal CorsairMousematRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo)
: base(deviceIndex, Core.RGBDeviceType.Mousemat, nativeInfo) : base(deviceIndex, Core.RGBDeviceType.Mousemat, nativeInfo)
{ {
Image = new Uri($"pack://application:,,,/RGB.NET.Devices.Corsair;component/Images/Mousemat/{Model.Replace(" ", string.Empty).ToUpper()}.png", UriKind.Absolute); Image = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
$@"Images\Corsair\Mousemat\{Model.Replace(" ", string.Empty).ToUpper()}.png"), UriKind.Relative);
} }
#endregion #endregion

View File

@ -85,10 +85,14 @@
<None Include="libs\x86\CUESDK_2015.dll" /> <None Include="libs\x86\CUESDK_2015.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Images\Headsets\" /> <Folder Include="Images\Corsair\Headsets\" />
<Folder Include="Images\Keyboards\" /> <Folder Include="Images\Corsair\Keyboards\" />
<Folder Include="Images\Mice\" /> <Folder Include="Images\Corsair\Mice\" />
<Folder Include="Images\Mousemat\" /> <Folder Include="Images\Corsair\Mousemat\" />
<Folder Include="Layouts\Corsair\Headsets\" />
<Folder Include="Layouts\Corsair\Keyboards\" />
<Folder Include="Layouts\Corsair\Mice\" />
<Folder Include="Layouts\Corsair\Mousemat\" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@ -14,7 +14,7 @@
<ItemGroup> <ItemGroup>
<CueSDKFiles Condition="'$(MSBuildThisFileDirectory)' != '' And <CueSDKFiles Condition="'$(MSBuildThisFileDirectory)' != '' And
HasTrailingSlash('$(MSBuildThisFileDirectory)')" HasTrailingSlash('$(MSBuildThisFileDirectory)')"
Include="$(MSBuildThisFileDirectory)libs\**\*.dll" /> Include="$(MSBuildThisFileDirectory)libs\**\*.dll;$(MSBuildThisFileDirectory)resources\**\*.*" />
<AdditionalPublishFilex86 Include="$(MSBuildThisFileDirectory)libs\x86\*.dll"> <AdditionalPublishFilex86 Include="$(MSBuildThisFileDirectory)libs\x86\*.dll">
<Visible>False</Visible> <Visible>False</Visible>