From 41c1458b5af460769fdd06b9e86fe4b03ef54ed2 Mon Sep 17 00:00:00 2001 From: Robert Date: Mon, 9 Oct 2023 20:54:59 +0200 Subject: [PATCH] Undo device changes --- .../Models/Surface/ArtemisDevice.cs | 47 +++---------------- .../Services/Core/SurfaceManager.cs | 2 +- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index ef29c01f7..f81a44d87 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -15,17 +15,11 @@ namespace Artemis.Core; /// public class ArtemisDevice : CorePropertyChanged { - private readonly List _originalLeds; - private readonly Size _originalSize; private SKPath? _path; private SKRect _rectangle; internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider) { - _originalLeds = new List(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(); DeviceEntity = new DeviceEntity(); RgbDevice = rgbDevice; @@ -54,10 +48,6 @@ public class ArtemisDevice : CorePropertyChanged internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, DeviceEntity deviceEntity) { - _originalLeds = new List(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(); DeviceEntity = deviceEntity; RgbDevice = rgbDevice; @@ -359,7 +349,7 @@ public class ArtemisDevice : CorePropertyChanged return mappedLed; return artemisLed; } - + /// /// Returns the most preferred device layout for this device. /// @@ -461,16 +451,6 @@ public class ArtemisDevice : CorePropertyChanged /// internal void ApplyLayout(ArtemisLayout? layout, bool createMissingLeds, bool removeExcessiveLeds) { - if (layout == null) - { - ClearLayout(); - UpdateLeds(); - - CalculateRenderProperties(); - OnDeviceUpdated(); - return; - } - if (createMissingLeds && !DeviceProvider.CreateMissingLedsSupported) throw new ArtemisCoreException($"Cannot apply layout with {nameof(createMissingLeds)} " + "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)} " + "set to true because the device provider does not support it"); - ClearLayout(); - if (layout.IsValid) + if (layout != null && layout.IsValid) layout.ApplyTo(RgbDevice, createMissingLeds, removeExcessiveLeds); + + UpdateLeds(); - + Layout = layout; - Layout.ApplyDevice(this); - + Layout?.ApplyDevice(this); CalculateRenderProperties(); 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() { // Other properties are computed diff --git a/src/Artemis.Core/Services/Core/SurfaceManager.cs b/src/Artemis.Core/Services/Core/SurfaceManager.cs index 8630186ca..99c2a78c9 100644 --- a/src/Artemis.Core/Services/Core/SurfaceManager.cs +++ b/src/Artemis.Core/Services/Core/SurfaceManager.cs @@ -24,7 +24,7 @@ internal sealed class SurfaceManager : IDisposable public SurfaceManager(IRenderer renderer, IManagedGraphicsContext? graphicsContext, int targetFrameRate, float renderScale) { _renderer = renderer; - _updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFrameRate}; + _updateTrigger = new TimerUpdateTrigger(false) {UpdateFrequency = 1.0 / targetFrameRate}; GraphicsContext = graphicsContext; TargetFrameRate = targetFrameRate;