mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Added layout-functionality to corsair devices
This commit is contained in:
parent
cedd220789
commit
f83b08af5e
@ -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.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\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\targets\*.targets" target="build\net45\" />
|
||||
</files>
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
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.Core.Layout;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
@ -41,16 +44,49 @@ namespace RGB.NET.Devices.Corsair
|
||||
/// </summary>
|
||||
internal void Initialize()
|
||||
{
|
||||
InitializeLeds();
|
||||
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> of the device.
|
||||
/// Initializes the <see cref="Led"/> and <see cref="Size"/> of the device.
|
||||
/// </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 />
|
||||
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate)
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Core.Layout;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
@ -35,13 +39,14 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> of the headset.
|
||||
/// </summary>
|
||||
protected override void InitializeLeds()
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
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"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
@ -18,7 +20,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
internal CorsairHeadsetRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo 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
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
// 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.Native;
|
||||
@ -38,10 +40,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> of the keyboard.
|
||||
/// </summary>
|
||||
protected override void InitializeLeds()
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
_CorsairLedPositions nativeLedPositions =
|
||||
(_CorsairLedPositions)Marshal.PtrToStructure(_CUESDK.CorsairGetLedPositions(), typeof(_CorsairLedPositions));
|
||||
@ -57,6 +57,9 @@ 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.LogicalLayout.ToString().ToUpper()}.xml"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
@ -38,7 +40,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
this.PhysicalLayout = (CorsairPhysicalKeyboardLayout)nativeInfo.physicalLayout;
|
||||
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
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable UnusedMember.Global
|
||||
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Core.Exceptions;
|
||||
|
||||
@ -36,10 +38,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> of the mouse.
|
||||
/// </summary>
|
||||
protected override void InitializeLeds()
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
switch (MouseDeviceInfo.PhysicalLayout)
|
||||
{
|
||||
@ -64,6 +64,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
default:
|
||||
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
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
@ -29,7 +31,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
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
|
||||
|
||||
@ -3,7 +3,9 @@
|
||||
|
||||
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.Native;
|
||||
@ -40,10 +42,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="Led"/> of the mousemat.
|
||||
/// </summary>
|
||||
protected override void InitializeLeds()
|
||||
/// <inheritdoc />
|
||||
protected override void InitializeLayout()
|
||||
{
|
||||
_CorsairLedPositions nativeLedPositions =
|
||||
(_CorsairLedPositions)
|
||||
@ -64,6 +64,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.ledId))
|
||||
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"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RGB.NET.Devices.Corsair.Native;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
@ -18,7 +20,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
internal CorsairMousematRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo 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
|
||||
|
||||
@ -85,10 +85,14 @@
|
||||
<None Include="libs\x86\CUESDK_2015.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Images\Headsets\" />
|
||||
<Folder Include="Images\Keyboards\" />
|
||||
<Folder Include="Images\Mice\" />
|
||||
<Folder Include="Images\Mousemat\" />
|
||||
<Folder Include="Images\Corsair\Headsets\" />
|
||||
<Folder Include="Images\Corsair\Keyboards\" />
|
||||
<Folder Include="Images\Corsair\Mice\" />
|
||||
<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>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
<ItemGroup>
|
||||
<CueSDKFiles Condition="'$(MSBuildThisFileDirectory)' != '' And
|
||||
HasTrailingSlash('$(MSBuildThisFileDirectory)')"
|
||||
Include="$(MSBuildThisFileDirectory)libs\**\*.dll" />
|
||||
Include="$(MSBuildThisFileDirectory)libs\**\*.dll;$(MSBuildThisFileDirectory)resources\**\*.*" />
|
||||
|
||||
<AdditionalPublishFilex86 Include="$(MSBuildThisFileDirectory)libs\x86\*.dll">
|
||||
<Visible>False</Visible>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user