Layouts - Round LEDs and device size

Tray - Use dark icon for for light Windows theme
This commit is contained in:
Robert committed 2021-05-15 13:50:01 +02:00
1 parent 96c55e5c03
commit c7c78dfecc
5 files changed
+57 -40

No files matched your search

@@ -66,6 +66,44 @@ namespace Artemis.Core
/// </summary>
public LayoutCustomDeviceData LayoutCustomDeviceData { get; private set; } = null!;
/// <summary>
/// Applies the layout to the provided device
/// </summary>
public void ApplyTo(IRGBDevice device, bool createMissingLeds = false, bool removeExcessiveLeds = false)
{
device.Size = new Size(MathF.Round(RgbLayout.Width), MathF.Round(RgbLayout.Height));
device.DeviceInfo.LayoutMetadata = RgbLayout.CustomData;
HashSet<LedId> ledIds = new();
foreach (ILedLayout layoutLed in RgbLayout.Leds)
{
if (Enum.TryParse(layoutLed.Id, true, out LedId ledId))
{
ledIds.Add(ledId);
Led? led = device[ledId];
if (led == null && createMissingLeds)
led = device.AddLed(ledId, new Point(), new Size());
if (led != null)
{
led.Location = new Point(MathF.Round(layoutLed.X), MathF.Round(layoutLed.Y));
led.Size = new Size(MathF.Round(layoutLed.Width), MathF.Round(layoutLed.Height));
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
led.LayoutMetadata = layoutLed.CustomData;
}
}
}
if (removeExcessiveLeds)
{
List<LedId> ledsToRemove = device.Select(led => led.Id).Where(id => !ledIds.Contains(id)).ToList();
foreach (LedId led in ledsToRemove)
device.RemoveLed(led);
}
}
internal void ApplyDevice(ArtemisDevice artemisDevice)
{
Device = artemisDevice;
@@ -108,44 +146,6 @@ namespace Artemis.Core
else
Image = null;
}
/// <summary>
/// Applies the layout to the provided device
/// </summary>
public void ApplyTo(IRGBDevice device, bool createMissingLeds = false, bool removeExcessiveLeds = false)
{
device.Size = new Size(MathF.Round(RgbLayout.Width), MathF.Round(RgbLayout.Height));
device.DeviceInfo.LayoutMetadata = RgbLayout.CustomData;
HashSet<LedId> ledIds = new();
foreach (ILedLayout layoutLed in RgbLayout.Leds)
{
if (Enum.TryParse(layoutLed.Id, true, out LedId ledId))
{
ledIds.Add(ledId);
Led? led = device[ledId];
if ((led == null) && createMissingLeds)
led = device.AddLed(ledId, new Point(), new Size());
if (led != null)
{
led.Location = new Point(MathF.Round(layoutLed.X), MathF.Round(layoutLed.Y));
led.Size = new Size(MathF.Round(layoutLed.Width), MathF.Round(layoutLed.Height));
led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData;
led.LayoutMetadata = layoutLed.CustomData;
}
}
}
if (removeExcessiveLeds)
{
List<LedId> ledsToRemove = device.Select(led => led.Id).Where(id => !ledIds.Contains(id)).ToList();
foreach (LedId led in ledsToRemove)
device.RemoveLed(led);
}
}
}
/// <summary>