mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 10:13:30 +00:00
Devices - Implemented device image loading
Devices - LED image loading WIP
This commit is contained in:
parent
e1121afdf9
commit
956ebd3313
@ -43,6 +43,7 @@
|
|||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties_005Ctypes/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayerproperties_005Ctypes/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayershapes/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Cprofile_005Clayershapes/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Csurface/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Csurface/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=models_005Csurface_005Clayout/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mvvm/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mvvm/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=placeholders/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=placeholders/@EntryIndexedValue">True</s:Boolean>
|
||||||
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins/@EntryIndexedValue">True</s:Boolean>
|
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=plugins/@EntryIndexedValue">True</s:Boolean>
|
||||||
|
|||||||
@ -32,7 +32,7 @@ namespace Artemis.Core
|
|||||||
GreenScale = 1;
|
GreenScale = 1;
|
||||||
BlueScale = 1;
|
BlueScale = 1;
|
||||||
IsEnabled = true;
|
IsEnabled = true;
|
||||||
|
|
||||||
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
||||||
|
|
||||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||||
@ -49,7 +49,7 @@ namespace Artemis.Core
|
|||||||
RgbDevice = rgbDevice;
|
RgbDevice = rgbDevice;
|
||||||
DeviceProvider = deviceProvider;
|
DeviceProvider = deviceProvider;
|
||||||
Surface = surface;
|
Surface = surface;
|
||||||
|
|
||||||
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
||||||
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
|
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
|
||||||
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
|
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
|
||||||
@ -95,13 +95,13 @@ namespace Artemis.Core
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a read only collection containing the LEDs of this device
|
/// Gets a read only collection containing the LEDs of this device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ReadOnlyCollection<ArtemisLed> Leds { get; }
|
public ReadOnlyCollection<ArtemisLed> Leds { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a dictionary containing all the LEDs of this device with their corresponding RGB.NET <see cref="LedId" /> as
|
/// Gets a dictionary containing all the LEDs of this device with their corresponding RGB.NET <see cref="LedId" /> as
|
||||||
/// key
|
/// key
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ReadOnlyDictionary<LedId, ArtemisLed> LedIds { get; }
|
public ReadOnlyDictionary<LedId, ArtemisLed> LedIds { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list of input identifiers associated with this device
|
/// Gets a list of input identifiers associated with this device
|
||||||
@ -225,6 +225,34 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the physical layout of the device e.g. ISO or ANSI.
|
||||||
|
/// <para>Only applicable to keyboards</para>
|
||||||
|
/// </summary>
|
||||||
|
public string? PhysicalLayout
|
||||||
|
{
|
||||||
|
get => DeviceEntity.PhysicalLayout;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
DeviceEntity.PhysicalLayout = value;
|
||||||
|
OnPropertyChanged(nameof(PhysicalLayout));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the logical layout of the device e.g. DE, UK or US.
|
||||||
|
/// <para>Only applicable to keyboards</para>
|
||||||
|
/// </summary>
|
||||||
|
public string? LogicalLayout
|
||||||
|
{
|
||||||
|
get => DeviceEntity.LogicalLayout;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
DeviceEntity.LogicalLayout = value;
|
||||||
|
OnPropertyChanged(nameof(LogicalLayout));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the layout of the device expanded with Artemis-specific data
|
/// Gets the layout of the device expanded with Artemis-specific data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -259,13 +287,58 @@ namespace Artemis.Core
|
|||||||
return artemisLed;
|
return artemisLed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generates the default layout file name of the device
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="includeExtension">If true, the .xml extension is added to the file name</param>
|
||||||
|
/// <returns>The resulting file name e.g. CORSAIR GLAIVE.xml or K95 RGB-ISO.xml</returns>
|
||||||
|
public string GetLayoutFileName(bool includeExtension = true)
|
||||||
|
{
|
||||||
|
// Take out invalid file name chars, may not be perfect but neither are you
|
||||||
|
string fileName = System.IO.Path.GetInvalidFileNameChars().Aggregate(RgbDevice.DeviceInfo.Model, (current, c) => current.Replace(c, '-'));
|
||||||
|
if (PhysicalLayout != null)
|
||||||
|
fileName = $"{fileName}-{PhysicalLayout.ToUpper()}";
|
||||||
|
if (includeExtension)
|
||||||
|
fileName = $"{fileName}.xml";
|
||||||
|
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Loads the best layout for this device, preferring user layouts and falling back to default layouts
|
||||||
|
/// </summary>
|
||||||
public void LoadBestLayout()
|
public void LoadBestLayout()
|
||||||
{
|
{
|
||||||
ArtemisLayout artemisLayout = DeviceProvider.LoadLayout(RgbDevice);
|
// If supported, detect the device layout so that we can load the correct one
|
||||||
if (artemisLayout.IsValid)
|
if (DeviceProvider.CanDetectLogicalLayout || DeviceProvider.CanDetectPhysicalLayout && RgbDevice is IKeyboard)
|
||||||
artemisLayout.DeviceLayout!.ApplyTo(RgbDevice);
|
DeviceProvider.DetectDeviceLayout(this);
|
||||||
|
|
||||||
Layout = artemisLayout;
|
// Look for a user layout
|
||||||
|
// ... here
|
||||||
|
|
||||||
|
// Try loading a device provider layout, if that comes back valid we use that
|
||||||
|
ArtemisLayout deviceProviderLayout = DeviceProvider.LoadLayout(this);
|
||||||
|
|
||||||
|
// Finally fall back to a default layout
|
||||||
|
// .. do it!
|
||||||
|
|
||||||
|
ApplyLayout(deviceProviderLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Applies the provided layout to the device
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="layout">The layout to apply</param>
|
||||||
|
public void ApplyLayout(ArtemisLayout layout)
|
||||||
|
{
|
||||||
|
if (layout.IsValid)
|
||||||
|
layout.RgbLayout!.ApplyTo(RgbDevice);
|
||||||
|
|
||||||
|
Layout = layout;
|
||||||
|
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||||
|
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||||
|
Layout.ApplyDevice(this);
|
||||||
|
Leds = Layout.Leds.Select(l => l.Led);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ApplyToEntity()
|
internal void ApplyToEntity()
|
||||||
|
|||||||
@ -1,57 +0,0 @@
|
|||||||
using System;
|
|
||||||
using RGB.NET.Layout;
|
|
||||||
|
|
||||||
namespace Artemis.Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Represents a device layout decorated with extra Artemis-specific data
|
|
||||||
/// </summary>
|
|
||||||
public class ArtemisLayout
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Creates a new instance of the <see cref="ArtemisLayout" /> class
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filePath">The path of the layout XML file</param>
|
|
||||||
public ArtemisLayout(string filePath)
|
|
||||||
{
|
|
||||||
FilePath = filePath;
|
|
||||||
DeviceLayout = DeviceLayout.Load(FilePath);
|
|
||||||
IsValid = DeviceLayout != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the file path the layout was (attempted to be) loaded from
|
|
||||||
/// </summary>
|
|
||||||
public string FilePath { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the RGB.NET device layout
|
|
||||||
/// </summary>
|
|
||||||
public DeviceLayout? DeviceLayout { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a boolean indicating whether a valid layout was loaded
|
|
||||||
/// </summary>
|
|
||||||
public bool IsValid { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the device this image is applied to
|
|
||||||
/// </summary>
|
|
||||||
public ArtemisDevice? Device { get; internal set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the physical layout of the device. Only applicable to keyboards
|
|
||||||
/// </summary>
|
|
||||||
public string? PhysicalLayout { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the logical layout of the device. Only applicable to keyboards
|
|
||||||
/// </summary>
|
|
||||||
public string? LogicalLayout { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the image of the device
|
|
||||||
/// </summary>
|
|
||||||
public Uri? Image { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
using RGB.NET.Core;
|
using System.Linq;
|
||||||
|
using RGB.NET.Core;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
@ -16,6 +17,9 @@ namespace Artemis.Core
|
|||||||
RgbLed = led;
|
RgbLed = led;
|
||||||
Device = device;
|
Device = device;
|
||||||
CalculateRectangles();
|
CalculateRectangles();
|
||||||
|
|
||||||
|
Layout = Device.Layout?.Leds.FirstOrDefault(l => l.RgbLayout.Id == led.Id.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -46,7 +50,7 @@ namespace Artemis.Core
|
|||||||
private set => SetAndNotify(ref _absoluteRectangle, value);
|
private set => SetAndNotify(ref _absoluteRectangle, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtemisLedLayout? Layout { get; set; }
|
public ArtemisLedLayout? Layout { get; }
|
||||||
|
|
||||||
internal void CalculateRectangles()
|
internal void CalculateRectangles()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace Artemis.Core
|
|
||||||
{
|
|
||||||
public class ArtemisLedLayout
|
|
||||||
{
|
|
||||||
public ArtemisLed Led { get; set; }
|
|
||||||
public Uri Image { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
85
src/Artemis.Core/Models/Surface/Layout/ArtemisLayout.cs
Normal file
85
src/Artemis.Core/Models/Surface/Layout/ArtemisLayout.cs
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using RGB.NET.Layout;
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a device layout decorated with extra Artemis-specific data
|
||||||
|
/// </summary>
|
||||||
|
public class ArtemisLayout
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a new instance of the <see cref="ArtemisLayout" /> class
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath">The path of the layout XML file</param>
|
||||||
|
public ArtemisLayout(string filePath)
|
||||||
|
{
|
||||||
|
FilePath = filePath;
|
||||||
|
Leds = new List<ArtemisLedLayout>();
|
||||||
|
|
||||||
|
DeviceLayout? deviceLayout = DeviceLayout.Load(FilePath, typeof(LayoutCustomDeviceData), typeof(LayoutCustomLedData));
|
||||||
|
if (deviceLayout != null)
|
||||||
|
{
|
||||||
|
RgbLayout = deviceLayout;
|
||||||
|
IsValid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RgbLayout = new DeviceLayout();
|
||||||
|
IsValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsValid)
|
||||||
|
Leds.AddRange(RgbLayout.Leds.Select(l => new ArtemisLedLayout(this, l)));
|
||||||
|
|
||||||
|
LayoutCustomDeviceData = (LayoutCustomDeviceData?) RgbLayout.CustomData ?? new LayoutCustomDeviceData();
|
||||||
|
ApplyCustomDeviceData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the file path the layout was (attempted to be) loaded from
|
||||||
|
/// </summary>
|
||||||
|
public string FilePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the RGB.NET device layout
|
||||||
|
/// </summary>
|
||||||
|
public DeviceLayout RgbLayout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the device this layout is applied to
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisDevice? Device { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a boolean indicating whether a valid layout was loaded
|
||||||
|
/// </summary>
|
||||||
|
public bool IsValid { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the image of the device
|
||||||
|
/// </summary>
|
||||||
|
public Uri? Image { get; set; }
|
||||||
|
|
||||||
|
public List<ArtemisLedLayout> Leds { get; }
|
||||||
|
|
||||||
|
internal LayoutCustomDeviceData LayoutCustomDeviceData { get; set; }
|
||||||
|
|
||||||
|
internal void ApplyDevice(ArtemisDevice artemisDevice)
|
||||||
|
{
|
||||||
|
Device = artemisDevice;
|
||||||
|
foreach (ArtemisLedLayout artemisLedLayout in Leds)
|
||||||
|
artemisLedLayout.ApplyDevice(Device);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyCustomDeviceData()
|
||||||
|
{
|
||||||
|
Uri layoutDirectory = new(Path.GetDirectoryName(FilePath)! + "\\", UriKind.Absolute);
|
||||||
|
if (LayoutCustomDeviceData.DeviceImage != null)
|
||||||
|
Image = new Uri(layoutDirectory, new Uri(LayoutCustomDeviceData.DeviceImage, UriKind.Relative));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
55
src/Artemis.Core/Models/Surface/Layout/ArtemisLedLayout.cs
Normal file
55
src/Artemis.Core/Models/Surface/Layout/ArtemisLedLayout.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using RGB.NET.Layout;
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
|
{
|
||||||
|
public class ArtemisLedLayout
|
||||||
|
{
|
||||||
|
internal ArtemisLedLayout(ArtemisLayout layout, ILedLayout led)
|
||||||
|
{
|
||||||
|
Layout = layout;
|
||||||
|
RgbLayout = led;
|
||||||
|
LayoutCustomLedData = (LayoutCustomLedData?) led.CustomData ?? new LayoutCustomLedData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArtemisLayout Layout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the RGB.NET LED Layout of this Artemis LED layout
|
||||||
|
/// </summary>
|
||||||
|
public ILedLayout RgbLayout { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the LED this layout is applied to
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisLed? Led { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the name of the logical layout this LED belongs to
|
||||||
|
/// </summary>
|
||||||
|
public string? LogicalName { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the image of the LED
|
||||||
|
/// </summary>
|
||||||
|
public Uri? Image { get; private set; }
|
||||||
|
|
||||||
|
internal LayoutCustomLedData LayoutCustomLedData { get; set; }
|
||||||
|
|
||||||
|
public void ApplyDevice(ArtemisDevice device)
|
||||||
|
{
|
||||||
|
Led = device.Leds.FirstOrDefault(d => d.RgbLed.Id.ToString() == RgbLayout.Id);
|
||||||
|
ApplyCustomLedData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyCustomLedData()
|
||||||
|
{
|
||||||
|
if (Led == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Uri layoutDirectory = new(Path.GetDirectoryName(Layout.FilePath)! + "\\", UriKind.Absolute);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
using System.Xml.Serialization;
|
||||||
|
#pragma warning disable 1591
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents extra Artemis-specific information stored in RGB.NET layouts
|
||||||
|
/// </summary>
|
||||||
|
[XmlRoot("CustomData")]
|
||||||
|
public class LayoutCustomDeviceData
|
||||||
|
{
|
||||||
|
[XmlElement("DeviceImage")]
|
||||||
|
public string? DeviceImage { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
#pragma warning disable 1591
|
||||||
|
|
||||||
|
namespace Artemis.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents extra Artemis-specific information stored in RGB.NET layouts
|
||||||
|
/// </summary>
|
||||||
|
[XmlRoot("CustomData")]
|
||||||
|
public class LayoutCustomLedData
|
||||||
|
{
|
||||||
|
[XmlArray("LogicalLayouts")]
|
||||||
|
public List<LayoutCustomLedDataLogicalLayout>? LogicalLayouts { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents extra Artemis-specific information stored in RGB.NET layouts
|
||||||
|
/// </summary>
|
||||||
|
[XmlType("LogicalLayout")]
|
||||||
|
public class LayoutCustomLedDataLogicalLayout
|
||||||
|
{
|
||||||
|
[XmlAttribute("Name")]
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
[XmlAttribute("Image")]
|
||||||
|
public string? Image { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
@ -35,12 +34,20 @@ namespace Artemis.Core.DeviceProviders
|
|||||||
public ILogger? Logger { get; set; }
|
public ILogger? Logger { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A boolean indicating whether this device provider detects the physical layout of connected keyboards
|
/// A boolean indicating whether this device provider detects the physical layout of connected keyboards.
|
||||||
|
/// <para>
|
||||||
|
/// Note: <see cref="DetectDeviceLayout" /> is only called when this or <see cref="CanDetectLogicalLayout" />
|
||||||
|
/// is <see langword="true" />.
|
||||||
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CanDetectPhysicalLayout { get; protected set; }
|
public bool CanDetectPhysicalLayout { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A boolean indicating whether this device provider detects the logical layout of connected keyboards
|
/// A boolean indicating whether this device provider detects the logical layout of connected keyboards
|
||||||
|
/// <para>
|
||||||
|
/// Note: <see cref="DetectDeviceLayout" /> is only called when this or <see cref="CanDetectPhysicalLayout" />
|
||||||
|
/// is <see langword="true" />.
|
||||||
|
/// </para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CanDetectLogicalLayout { get; protected set; }
|
public bool CanDetectLogicalLayout { get; protected set; }
|
||||||
|
|
||||||
@ -55,33 +62,27 @@ namespace Artemis.Core.DeviceProviders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rgbDevice">The device to load the layout for</param>
|
/// <param name="rgbDevice">The device to load the layout for</param>
|
||||||
/// <returns>The resulting Artemis layout</returns>
|
/// <returns>The resulting Artemis layout</returns>
|
||||||
public virtual ArtemisLayout LoadLayout(IRGBDevice rgbDevice)
|
public virtual ArtemisLayout LoadLayout(ArtemisDevice rgbDevice)
|
||||||
{
|
{
|
||||||
// Take out invalid file name chars, may not be perfect but neither are you
|
|
||||||
string model = Path.GetInvalidFileNameChars().Aggregate(rgbDevice.DeviceInfo.Model, (current, c) => current.Replace(c, '-'));
|
|
||||||
string layoutDir = Path.Combine(Plugin.Directory.FullName, "Layouts");
|
string layoutDir = Path.Combine(Plugin.Directory.FullName, "Layouts");
|
||||||
string filePath;
|
string filePath = Path.Combine(
|
||||||
// if (rgbDevice.DeviceInfo is IPhysicalLayoutDeviceInfo)
|
|
||||||
// {
|
|
||||||
// filePath = Path.Combine(
|
|
||||||
// layoutDir,
|
|
||||||
// rgbDevice.DeviceInfo.Manufacturer,
|
|
||||||
// rgbDevice.DeviceInfo.DeviceType.ToString(),
|
|
||||||
// model,
|
|
||||||
// keyboard.DeviceInfo.
|
|
||||||
// ) + ".xml";
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
filePath = Path.Combine(
|
|
||||||
layoutDir,
|
layoutDir,
|
||||||
rgbDevice.DeviceInfo.Manufacturer,
|
rgbDevice.RgbDevice.DeviceInfo.Manufacturer,
|
||||||
rgbDevice.DeviceInfo.DeviceType.ToString(),
|
rgbDevice.RgbDevice.DeviceInfo.DeviceType.ToString(),
|
||||||
model
|
rgbDevice.GetLayoutFileName()
|
||||||
) + ".xml";
|
);
|
||||||
// }
|
|
||||||
|
|
||||||
return new ArtemisLayout(filePath);
|
return new ArtemisLayout(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when a specific RGB device's logical and physical layout must be detected
|
||||||
|
/// <para>
|
||||||
|
/// Note: Only called when <see cref="CanDetectPhysicalLayout" /> or <see cref="CanDetectLogicalLayout" /> is <see langword="true" />.
|
||||||
|
/// </para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="rgbDevice">The device to detect the layout for, always a keyboard</param>
|
||||||
|
public virtual void DetectDeviceLayout(ArtemisDevice rgbDevice)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -20,6 +20,9 @@ namespace Artemis.Storage.Entities.Surface
|
|||||||
public double BlueScale { get; set; }
|
public double BlueScale { get; set; }
|
||||||
public bool IsEnabled { get; set; }
|
public bool IsEnabled { get; set; }
|
||||||
|
|
||||||
|
public string PhysicalLayout { get; set; }
|
||||||
|
public string LogicalLayout { get; set; }
|
||||||
|
|
||||||
public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; }
|
public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -235,8 +235,8 @@ namespace Artemis.UI.Shared
|
|||||||
UpdateTransform();
|
UpdateTransform();
|
||||||
|
|
||||||
// Load the device main image
|
// Load the device main image
|
||||||
// if (Device.RgbDevice.DeviceInfo?.Image?.AbsolutePath != null && File.Exists(Device.RgbDevice.DeviceInfo.Image.AbsolutePath))
|
if (Device.Layout?.Image != null && File.Exists(Device.Layout.Image.LocalPath))
|
||||||
// _deviceImage = new BitmapImage(Device.RgbDevice.DeviceInfo.Image);
|
_deviceImage = new BitmapImage(Device.Layout.Image);
|
||||||
|
|
||||||
// Create all the LEDs
|
// Create all the LEDs
|
||||||
foreach (ArtemisLed artemisLed in Device.Leds)
|
foreach (ArtemisLed artemisLed in Device.Leds)
|
||||||
|
|||||||
@ -11,6 +11,8 @@ namespace Artemis.UI.Shared
|
|||||||
{
|
{
|
||||||
internal class DeviceVisualizerLed
|
internal class DeviceVisualizerLed
|
||||||
{
|
{
|
||||||
|
private SolidColorBrush? _renderColorBrush;
|
||||||
|
|
||||||
public DeviceVisualizerLed(ArtemisLed led)
|
public DeviceVisualizerLed(ArtemisLed led)
|
||||||
{
|
{
|
||||||
Led = led;
|
Led = led;
|
||||||
@ -43,9 +45,9 @@ namespace Artemis.UI.Shared
|
|||||||
byte g = originalColor.GetG();
|
byte g = originalColor.GetG();
|
||||||
byte b = originalColor.GetB();
|
byte b = originalColor.GetB();
|
||||||
|
|
||||||
drawingContext.DrawRectangle(isDimmed
|
_renderColorBrush ??= new SolidColorBrush();
|
||||||
? new SolidColorBrush(Color.FromArgb(100, r, g, b))
|
_renderColorBrush.Color = isDimmed ? Color.FromArgb(100, r, g, b) : Color.FromRgb(r, g, b);
|
||||||
: new SolidColorBrush(Color.FromRgb(r, g, b)), null, LedRect);
|
drawingContext.DrawRectangle(_renderColorBrush, null, LedRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RenderImage(DrawingContext drawingContext)
|
public void RenderImage(DrawingContext drawingContext)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user