mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Provide BitmapBrush with the currently active surface
UI - Small style change to the confirmation dialog Surface - Add API to get an ArtemisLed by its corresponding RGB.NET LED Devices - Add API to get an ArtemisLed by its corresponding RGB.NET LED Devices - Add API to get an ArtemisLed by its corresponding RGB.NET LedId
This commit is contained in:
1 parent
5b0e1c91dd
commit
f05740a5f1
10 files changed
+182
-38
No files matched your search
@@ -14,7 +14,6 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public class ArtemisDevice : CorePropertyChanged
|
||||
{
|
||||
private ReadOnlyCollection<ArtemisLed> _leds;
|
||||
private SKPath? _renderPath;
|
||||
private SKRect _renderRectangle;
|
||||
|
||||
@@ -28,13 +27,14 @@ namespace Artemis.Core
|
||||
Rotation = 0;
|
||||
Scale = 1;
|
||||
ZIndex = 1;
|
||||
|
||||
|
||||
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
|
||||
LayoutPath = layoutPath;
|
||||
|
||||
|
||||
InputIdentifiers = new List<ArtemisDeviceInputIdentifier>();
|
||||
|
||||
_leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||
ApplyToEntity();
|
||||
CalculateRenderProperties();
|
||||
}
|
||||
@@ -45,7 +45,7 @@ namespace Artemis.Core
|
||||
RgbDevice = rgbDevice;
|
||||
DeviceProvider = deviceProvider;
|
||||
Surface = surface;
|
||||
|
||||
|
||||
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
|
||||
LayoutPath = layoutPath;
|
||||
|
||||
@@ -53,7 +53,8 @@ namespace Artemis.Core
|
||||
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
|
||||
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
|
||||
|
||||
_leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
Leds = rgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
|
||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,11 +93,13 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// Gets a read only collection containing the LEDs of this device
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<ArtemisLed> Leds
|
||||
{
|
||||
get => _leds;
|
||||
private set => SetAndNotify(ref _leds, value);
|
||||
}
|
||||
public ReadOnlyCollection<ArtemisLed> Leds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary containing all the LEDs of this device with their corresponding RGB.NET <see cref="LedId" /> as
|
||||
/// key
|
||||
/// </summary>
|
||||
public ReadOnlyDictionary<LedId, ArtemisLed> LedIds { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of input identifiers associated with this device
|
||||
@@ -182,16 +185,24 @@ namespace Artemis.Core
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the underlying RGB.NET device was updated
|
||||
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="Led" />
|
||||
/// </summary>
|
||||
public event EventHandler? DeviceUpdated;
|
||||
/// <param name="led">The RGB.NET <see cref="Led" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
|
||||
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
|
||||
public ArtemisLed? GetLed(Led led)
|
||||
{
|
||||
return GetLed(led.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="DeviceUpdated" /> event
|
||||
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="LedId" />
|
||||
/// </summary>
|
||||
protected virtual void OnDeviceUpdated()
|
||||
/// <param name="ledId">The RGB.NET <see cref="LedId" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
|
||||
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
|
||||
public ArtemisLed? GetLed(LedId ledId)
|
||||
{
|
||||
DeviceUpdated?.Invoke(this, EventArgs.Empty);
|
||||
LedIds.TryGetValue(ledId, out ArtemisLed? artemisLed);
|
||||
return artemisLed;
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
@@ -247,5 +258,22 @@ namespace Artemis.Core
|
||||
|
||||
RenderPath = path;
|
||||
}
|
||||
|
||||
#region Events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the underlying RGB.NET device was updated
|
||||
/// </summary>
|
||||
public event EventHandler? DeviceUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the <see cref="DeviceUpdated" /> event
|
||||
/// </summary>
|
||||
protected virtual void OnDeviceUpdated()
|
||||
{
|
||||
DeviceUpdated?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Surface;
|
||||
using RGB.NET.Core;
|
||||
@@ -11,7 +12,8 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public class ArtemisSurface : CorePropertyChanged
|
||||
{
|
||||
private List<ArtemisDevice> _devices;
|
||||
private List<ArtemisDevice> _devices = new List<ArtemisDevice>();
|
||||
private ReadOnlyDictionary<Led, ArtemisLed> _ledMap = new ReadOnlyDictionary<Led, ArtemisLed>(new Dictionary<Led, ArtemisLed>());
|
||||
private bool _isActive;
|
||||
private string _name;
|
||||
private double _scale;
|
||||
@@ -26,9 +28,6 @@ namespace Artemis.Core
|
||||
_scale = scale;
|
||||
_isActive = false;
|
||||
|
||||
// Devices are not populated here but as they are detected
|
||||
_devices = new List<ArtemisDevice>();
|
||||
|
||||
ApplyToEntity();
|
||||
}
|
||||
|
||||
@@ -41,9 +40,6 @@ namespace Artemis.Core
|
||||
_scale = scale;
|
||||
_name = surfaceEntity.Name;
|
||||
_isActive = surfaceEntity.IsActive;
|
||||
|
||||
// Devices are not populated here but as they are detected
|
||||
_devices = new List<ArtemisDevice>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,6 +83,16 @@ namespace Artemis.Core
|
||||
internal set => SetAndNotify(ref _devices, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary containing all <see cref="ArtemisLed" />s on the surface with their corresponding RGB.NET
|
||||
/// <see cref="Led" /> as key
|
||||
/// </summary>
|
||||
public ReadOnlyDictionary<Led, ArtemisLed> LedMap
|
||||
{
|
||||
get => _ledMap;
|
||||
private set => SetAndNotify(ref _ledMap, value);
|
||||
}
|
||||
|
||||
internal SurfaceEntity SurfaceEntity { get; set; }
|
||||
internal Guid EntityId { get; set; }
|
||||
|
||||
@@ -103,6 +109,24 @@ namespace Artemis.Core
|
||||
OnScaleChanged();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="Led" />
|
||||
/// </summary>
|
||||
/// <param name="led">The RGB.NET <see cref="Led" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
|
||||
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
|
||||
public ArtemisLed? GetArtemisLed(Led led)
|
||||
{
|
||||
LedMap.TryGetValue(led, out ArtemisLed? artemisLed);
|
||||
return artemisLed;
|
||||
}
|
||||
|
||||
internal void UpdateLedMap()
|
||||
{
|
||||
LedMap = new ReadOnlyDictionary<Led, ArtemisLed>(
|
||||
_devices.SelectMany(d => d.Leds.Select(al => new KeyValuePair<Led, ArtemisLed>(al.RgbLed, al))).ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
|
||||
);
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
SurfaceEntity.Id = EntityId;
|
||||
|
||||
Reference in new issue
Block a user