mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Split up RGBService into RenderService and DeviceService
Core - Removed rendering from CoreService Core - Store and restore original device LEDs when applying/clearing layouts
This commit is contained in:
1 parent
919199a8d0
commit
2a0a0f3cfd
43 files changed
+1363
-1189
No files matched your search
@@ -27,8 +27,8 @@ namespace Artemis.UI.Shared;
|
||||
/// </summary>
|
||||
public class DeviceVisualizer : Control
|
||||
{
|
||||
internal static readonly Dictionary<ArtemisDevice, RenderTargetBitmap?> BitmapCache = new();
|
||||
private readonly ICoreService _coreService;
|
||||
internal static readonly Dictionary<string, RenderTargetBitmap?> BitmapCache = new();
|
||||
private readonly IRenderService _renderService;
|
||||
private readonly List<DeviceVisualizerLed> _deviceVisualizerLeds;
|
||||
|
||||
private Rect _deviceBounds;
|
||||
@@ -40,7 +40,7 @@ public class DeviceVisualizer : Control
|
||||
/// <inheritdoc />
|
||||
public DeviceVisualizer()
|
||||
{
|
||||
_coreService = UI.Locator.Resolve<ICoreService>();
|
||||
_renderService = UI.Locator.Resolve<IRenderService>();
|
||||
_deviceVisualizerLeds = new List<DeviceVisualizerLed>();
|
||||
|
||||
PointerReleased += OnPointerReleased;
|
||||
@@ -195,16 +195,6 @@ public class DeviceVisualizer : Control
|
||||
SetupForDevice();
|
||||
}
|
||||
|
||||
private void DevicePropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(async () =>
|
||||
{
|
||||
if (Device != null)
|
||||
BitmapCache.Remove(Device);
|
||||
await SetupForDevice();
|
||||
}, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private void DeviceUpdated(object? sender, EventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Invoke(SetupForDevice, DispatcherPriority.Background);
|
||||
@@ -251,7 +241,6 @@ public class DeviceVisualizer : Control
|
||||
{
|
||||
if (Device != null)
|
||||
{
|
||||
Device.RgbDevice.PropertyChanged -= DevicePropertyChanged;
|
||||
Device.DeviceUpdated -= DeviceUpdated;
|
||||
}
|
||||
|
||||
@@ -261,7 +250,7 @@ public class DeviceVisualizer : Control
|
||||
/// <inheritdoc />
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
_coreService.FrameRendered += OnFrameRendered;
|
||||
_renderService.FrameRendered += OnFrameRendered;
|
||||
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
}
|
||||
@@ -269,7 +258,7 @@ public class DeviceVisualizer : Control
|
||||
/// <inheritdoc />
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
_coreService.FrameRendered -= OnFrameRendered;
|
||||
_renderService.FrameRendered -= OnFrameRendered;
|
||||
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
}
|
||||
@@ -283,7 +272,6 @@ public class DeviceVisualizer : Control
|
||||
|
||||
if (_oldDevice != null)
|
||||
{
|
||||
_oldDevice.RgbDevice.PropertyChanged -= DevicePropertyChanged;
|
||||
_oldDevice.DeviceUpdated -= DeviceUpdated;
|
||||
}
|
||||
|
||||
@@ -294,7 +282,6 @@ public class DeviceVisualizer : Control
|
||||
_deviceBounds = MeasureDevice();
|
||||
_loading = true;
|
||||
|
||||
Device.RgbDevice.PropertyChanged += DevicePropertyChanged;
|
||||
Device.DeviceUpdated += DeviceUpdated;
|
||||
|
||||
// Create all the LEDs
|
||||
@@ -321,12 +308,15 @@ public class DeviceVisualizer : Control
|
||||
|
||||
private RenderTargetBitmap? GetDeviceImage(ArtemisDevice device)
|
||||
{
|
||||
if (BitmapCache.TryGetValue(device, out RenderTargetBitmap? existingBitmap))
|
||||
string? path = device.Layout?.Image?.LocalPath;
|
||||
if (path == null)
|
||||
return null;
|
||||
|
||||
if (BitmapCache.TryGetValue(path, out RenderTargetBitmap? existingBitmap))
|
||||
return existingBitmap;
|
||||
|
||||
if (device.Layout?.Image == null || !File.Exists(device.Layout.Image.LocalPath))
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
BitmapCache[device] = null;
|
||||
BitmapCache[path] = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -335,7 +325,7 @@ public class DeviceVisualizer : Control
|
||||
RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) device.RgbDevice.ActualSize.Width * 2, (int) device.RgbDevice.ActualSize.Height * 2));
|
||||
|
||||
using DrawingContext context = renderTargetBitmap.CreateDrawingContext();
|
||||
using Bitmap bitmap = new(device.Layout.Image.LocalPath);
|
||||
using Bitmap bitmap = new(path);
|
||||
using Bitmap scaledBitmap = bitmap.CreateScaledBitmap(renderTargetBitmap.PixelSize);
|
||||
|
||||
context.DrawImage(scaledBitmap, new Rect(scaledBitmap.Size));
|
||||
@@ -345,7 +335,7 @@ public class DeviceVisualizer : Control
|
||||
deviceVisualizerLed.DrawBitmap(context, 2 * device.Scale);
|
||||
}
|
||||
|
||||
BitmapCache[device] = renderTargetBitmap;
|
||||
BitmapCache[path] = renderTargetBitmap;
|
||||
return renderTargetBitmap;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
private readonly ILayerBrushService _layerBrushService;
|
||||
private readonly BehaviorSubject<ILayerProperty?> _layerPropertySubject = new(null);
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDeviceService _deviceService;
|
||||
private readonly IModuleService _moduleService;
|
||||
private readonly BehaviorSubject<int> _pixelsPerSecondSubject = new(120);
|
||||
private readonly BehaviorSubject<bool> _playingSubject = new(false);
|
||||
@@ -28,7 +29,6 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
private readonly Dictionary<ProfileConfiguration, ProfileEditorHistory> _profileEditorHistories = new();
|
||||
private readonly BehaviorSubject<RenderProfileElement?> _profileElementSubject = new(null);
|
||||
private readonly IProfileService _profileService;
|
||||
private readonly IRgbService _rgbService;
|
||||
private readonly SourceList<ILayerPropertyKeyframe> _selectedKeyframes;
|
||||
private readonly BehaviorSubject<bool> _suspendedEditingSubject = new(false);
|
||||
private readonly BehaviorSubject<TimeSpan> _timeSubject = new(TimeSpan.Zero);
|
||||
@@ -36,17 +36,17 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
private ProfileEditorCommandScope? _profileEditorHistoryScope;
|
||||
|
||||
public ProfileEditorService(ILogger logger,
|
||||
IDeviceService deviceService,
|
||||
IProfileService profileService,
|
||||
IModuleService moduleService,
|
||||
IRgbService rgbService,
|
||||
ILayerBrushService layerBrushService,
|
||||
IMainWindowService mainWindowService,
|
||||
IWindowService windowService)
|
||||
{
|
||||
_logger = logger;
|
||||
_deviceService = deviceService;
|
||||
_profileService = profileService;
|
||||
_moduleService = moduleService;
|
||||
_rgbService = rgbService;
|
||||
_layerBrushService = layerBrushService;
|
||||
_windowService = windowService;
|
||||
|
||||
@@ -369,7 +369,7 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
Layer layer = new(targetLayer.Parent, targetLayer.GetNewLayerName());
|
||||
_layerBrushService.ApplyDefaultBrush(layer);
|
||||
|
||||
layer.AddLeds(_rgbService.EnabledDevices.SelectMany(d => d.Leds));
|
||||
layer.AddLeds(_deviceService.EnabledDevices.SelectMany(d => d.Leds));
|
||||
ExecuteCommand(new AddProfileElement(layer, targetLayer.Parent, targetLayer.Order));
|
||||
|
||||
return layer;
|
||||
@@ -379,7 +379,7 @@ internal class ProfileEditorService : IProfileEditorService
|
||||
Layer layer = new(target, target.GetNewLayerName());
|
||||
_layerBrushService.ApplyDefaultBrush(layer);
|
||||
|
||||
layer.AddLeds(_rgbService.EnabledDevices.SelectMany(d => d.Leds));
|
||||
layer.AddLeds(_deviceService.EnabledDevices.SelectMany(d => d.Leds));
|
||||
ExecuteCommand(new AddProfileElement(layer, target, 0));
|
||||
|
||||
return layer;
|
||||
|
||||
Reference in new issue
Block a user