mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Undo device changes
This commit is contained in:
parent
ccd79de67c
commit
41c1458b5a
@ -15,17 +15,11 @@ namespace Artemis.Core;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ArtemisDevice : CorePropertyChanged
|
public class ArtemisDevice : CorePropertyChanged
|
||||||
{
|
{
|
||||||
private readonly List<OriginalLed> _originalLeds;
|
|
||||||
private readonly Size _originalSize;
|
|
||||||
private SKPath? _path;
|
private SKPath? _path;
|
||||||
private SKRect _rectangle;
|
private SKRect _rectangle;
|
||||||
|
|
||||||
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider)
|
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider)
|
||||||
{
|
{
|
||||||
_originalLeds = new List<OriginalLed>(rgbDevice.Select(l => new OriginalLed(l)));
|
|
||||||
Rectangle ledRectangle = new(rgbDevice.Select(x => x.Boundary));
|
|
||||||
_originalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
|
||||||
|
|
||||||
Identifier = rgbDevice.GetDeviceIdentifier();
|
Identifier = rgbDevice.GetDeviceIdentifier();
|
||||||
DeviceEntity = new DeviceEntity();
|
DeviceEntity = new DeviceEntity();
|
||||||
RgbDevice = rgbDevice;
|
RgbDevice = rgbDevice;
|
||||||
@ -54,10 +48,6 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
|
|
||||||
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, DeviceEntity deviceEntity)
|
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, DeviceEntity deviceEntity)
|
||||||
{
|
{
|
||||||
_originalLeds = new List<OriginalLed>(rgbDevice.Select(l => new OriginalLed(l)));
|
|
||||||
Rectangle ledRectangle = new(rgbDevice.Select(x => x.Boundary));
|
|
||||||
_originalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
|
||||||
|
|
||||||
Identifier = rgbDevice.GetDeviceIdentifier();
|
Identifier = rgbDevice.GetDeviceIdentifier();
|
||||||
DeviceEntity = deviceEntity;
|
DeviceEntity = deviceEntity;
|
||||||
RgbDevice = rgbDevice;
|
RgbDevice = rgbDevice;
|
||||||
@ -359,7 +349,7 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
return mappedLed;
|
return mappedLed;
|
||||||
return artemisLed;
|
return artemisLed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the most preferred device layout for this device.
|
/// Returns the most preferred device layout for this device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -461,16 +451,6 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
/// </param>
|
/// </param>
|
||||||
internal void ApplyLayout(ArtemisLayout? layout, bool createMissingLeds, bool removeExcessiveLeds)
|
internal void ApplyLayout(ArtemisLayout? layout, bool createMissingLeds, bool removeExcessiveLeds)
|
||||||
{
|
{
|
||||||
if (layout == null)
|
|
||||||
{
|
|
||||||
ClearLayout();
|
|
||||||
UpdateLeds();
|
|
||||||
|
|
||||||
CalculateRenderProperties();
|
|
||||||
OnDeviceUpdated();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createMissingLeds && !DeviceProvider.CreateMissingLedsSupported)
|
if (createMissingLeds && !DeviceProvider.CreateMissingLedsSupported)
|
||||||
throw new ArtemisCoreException($"Cannot apply layout with {nameof(createMissingLeds)} " +
|
throw new ArtemisCoreException($"Cannot apply layout with {nameof(createMissingLeds)} " +
|
||||||
"set to true because the device provider does not support it");
|
"set to true because the device provider does not support it");
|
||||||
@ -478,33 +458,18 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
throw new ArtemisCoreException($"Cannot apply layout with {nameof(removeExcessiveLeds)} " +
|
throw new ArtemisCoreException($"Cannot apply layout with {nameof(removeExcessiveLeds)} " +
|
||||||
"set to true because the device provider does not support it");
|
"set to true because the device provider does not support it");
|
||||||
|
|
||||||
ClearLayout();
|
if (layout != null && layout.IsValid)
|
||||||
if (layout.IsValid)
|
|
||||||
layout.ApplyTo(RgbDevice, createMissingLeds, removeExcessiveLeds);
|
layout.ApplyTo(RgbDevice, createMissingLeds, removeExcessiveLeds);
|
||||||
|
|
||||||
|
|
||||||
UpdateLeds();
|
UpdateLeds();
|
||||||
|
|
||||||
Layout = layout;
|
Layout = layout;
|
||||||
Layout.ApplyDevice(this);
|
Layout?.ApplyDevice(this);
|
||||||
|
|
||||||
CalculateRenderProperties();
|
CalculateRenderProperties();
|
||||||
OnDeviceUpdated();
|
OnDeviceUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearLayout()
|
|
||||||
{
|
|
||||||
if (Layout == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
RgbDevice.DeviceInfo.LayoutMetadata = null;
|
|
||||||
RgbDevice.Size = _originalSize;
|
|
||||||
Layout = null;
|
|
||||||
|
|
||||||
while (RgbDevice.Any())
|
|
||||||
RgbDevice.RemoveLed(RgbDevice.First().Id);
|
|
||||||
foreach (OriginalLed originalLed in _originalLeds)
|
|
||||||
RgbDevice.AddLed(originalLed.Id, originalLed.Location, originalLed.Size, originalLed.CustomData);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void ApplyToEntity()
|
internal void ApplyToEntity()
|
||||||
{
|
{
|
||||||
// Other properties are computed
|
// Other properties are computed
|
||||||
|
|||||||
@ -24,7 +24,7 @@ internal sealed class SurfaceManager : IDisposable
|
|||||||
public SurfaceManager(IRenderer renderer, IManagedGraphicsContext? graphicsContext, int targetFrameRate, float renderScale)
|
public SurfaceManager(IRenderer renderer, IManagedGraphicsContext? graphicsContext, int targetFrameRate, float renderScale)
|
||||||
{
|
{
|
||||||
_renderer = renderer;
|
_renderer = renderer;
|
||||||
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFrameRate};
|
_updateTrigger = new TimerUpdateTrigger(false) {UpdateFrequency = 1.0 / targetFrameRate};
|
||||||
|
|
||||||
GraphicsContext = graphicsContext;
|
GraphicsContext = graphicsContext;
|
||||||
TargetFrameRate = targetFrameRate;
|
TargetFrameRate = targetFrameRate;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user