mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Core - Ensure devices owned by ArtemisDevice always have valid dimensions
This commit is contained in:
parent
76d424012a
commit
38f18613c1
@ -1,4 +1,5 @@
|
|||||||
using System.Text;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
using SkiaSharp;
|
using SkiaSharp;
|
||||||
|
|
||||||
@ -18,6 +19,18 @@ internal static class RgbDeviceExtensions
|
|||||||
builder.Append(rgbDevice.DeviceInfo.DeviceType);
|
builder.Append(rgbDevice.DeviceInfo.DeviceType);
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void EnsureValidDimensions(this IRGBDevice rgbDevice)
|
||||||
|
{
|
||||||
|
if (rgbDevice.Location == Point.Invalid)
|
||||||
|
rgbDevice.Location = new Point(0, 0);
|
||||||
|
|
||||||
|
if (rgbDevice.Size == Size.Invalid)
|
||||||
|
{
|
||||||
|
Rectangle ledRectangle = new(rgbDevice.Select(x => x.Boundary));
|
||||||
|
rgbDevice.Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class RgbRectangleExtensions
|
internal static class RgbRectangleExtensions
|
||||||
|
|||||||
@ -22,13 +22,13 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
|
|
||||||
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider)
|
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider)
|
||||||
{
|
{
|
||||||
Rectangle ledRectangle = new(rgbDevice.Select(x => x.Boundary));
|
rgbDevice.EnsureValidDimensions();
|
||||||
_originalLeds = new List<OriginalLed>(rgbDevice.Select(l => new OriginalLed(l)));
|
_originalLeds = new List<OriginalLed>(rgbDevice.Select(l => new OriginalLed(l)));
|
||||||
_originalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
_originalSize = rgbDevice.Size;
|
||||||
|
|
||||||
|
RgbDevice = rgbDevice;
|
||||||
Identifier = rgbDevice.GetDeviceIdentifier();
|
Identifier = rgbDevice.GetDeviceIdentifier();
|
||||||
DeviceEntity = new DeviceEntity();
|
DeviceEntity = new DeviceEntity();
|
||||||
RgbDevice = rgbDevice;
|
|
||||||
DeviceProvider = deviceProvider;
|
DeviceProvider = deviceProvider;
|
||||||
|
|
||||||
Rotation = 0;
|
Rotation = 0;
|
||||||
@ -58,13 +58,13 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
|
|
||||||
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, DeviceEntity deviceEntity)
|
internal ArtemisDevice(IRGBDevice rgbDevice, DeviceProvider deviceProvider, DeviceEntity deviceEntity)
|
||||||
{
|
{
|
||||||
Rectangle ledRectangle = new(rgbDevice.Select(x => x.Boundary));
|
rgbDevice.EnsureValidDimensions();
|
||||||
_originalLeds = new List<OriginalLed>(rgbDevice.Select(l => new OriginalLed(l)));
|
_originalLeds = new List<OriginalLed>(rgbDevice.Select(l => new OriginalLed(l)));
|
||||||
_originalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
_originalSize = rgbDevice.Size;
|
||||||
|
|
||||||
|
RgbDevice = rgbDevice;
|
||||||
Identifier = rgbDevice.GetDeviceIdentifier();
|
Identifier = rgbDevice.GetDeviceIdentifier();
|
||||||
DeviceEntity = deviceEntity;
|
DeviceEntity = deviceEntity;
|
||||||
RgbDevice = rgbDevice;
|
|
||||||
DeviceProvider = deviceProvider;
|
DeviceProvider = deviceProvider;
|
||||||
|
|
||||||
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(new Dictionary<LedId, ArtemisLed>());
|
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(new Dictionary<LedId, ArtemisLed>());
|
||||||
@ -609,9 +609,9 @@ public class ArtemisDevice : CorePropertyChanged
|
|||||||
|
|
||||||
private void RgbDeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
private void RgbDeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.PropertyName != nameof(IRGBDevice.Surface))
|
if (e.PropertyName != nameof(IRGBDevice.Surface) || RgbDevice.Surface == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
RgbDevice.Rotation = DeviceEntity.Rotation;
|
RgbDevice.Rotation = DeviceEntity.Rotation;
|
||||||
RgbDevice.Scale = DeviceEntity.Scale;
|
RgbDevice.Scale = DeviceEntity.Scale;
|
||||||
ApplyLocation(DeviceEntity.X, DeviceEntity.Y);
|
ApplyLocation(DeviceEntity.X, DeviceEntity.Y);
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
|
using System.Reactive.Disposables;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
@ -37,6 +39,12 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
|||||||
DetectInput = ReactiveCommand.CreateFromTask(ExecuteDetectInput, this.WhenAnyValue(vm => vm.CanDetectInput));
|
DetectInput = ReactiveCommand.CreateFromTask(ExecuteDetectInput, this.WhenAnyValue(vm => vm.CanDetectInput));
|
||||||
X = device.X;
|
X = device.X;
|
||||||
Y = device.Y;
|
Y = device.Y;
|
||||||
|
|
||||||
|
this.WhenActivated(d =>
|
||||||
|
{
|
||||||
|
Device.PropertyChanged += DeviceOnPropertyChanged;
|
||||||
|
Disposable.Create(() => Device.PropertyChanged -= DeviceOnPropertyChanged).DisposeWith(d);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReactiveCommand<Unit, Unit> DetectInput { get; }
|
public ReactiveCommand<Unit, Unit> DetectInput { get; }
|
||||||
@ -143,4 +151,12 @@ public class SurfaceDeviceViewModel : ActivatableViewModelBase
|
|||||||
Device.X = X;
|
Device.X = X;
|
||||||
Device.Y = Y;
|
Device.Y = Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DeviceOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.PropertyName == nameof(Device.X))
|
||||||
|
X = Device.X;
|
||||||
|
if (e.PropertyName == nameof(Device.Y))
|
||||||
|
Y = Device.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user