mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using Artemis.Core.Events;
|
|
using Artemis.Core.Services.Interfaces;
|
|
using Artemis.UI.ViewModels.Controls.RgbDevice;
|
|
using RGB.NET.Core;
|
|
using Stylet;
|
|
|
|
namespace Artemis.UI.ViewModels.Controls.Editor
|
|
{
|
|
public class SurfaceEditorViewModel
|
|
{
|
|
private readonly IRgbService _rgbService;
|
|
|
|
public SurfaceEditorViewModel(IRgbService rgbService)
|
|
{
|
|
Devices = new ObservableCollection<RgbDeviceViewModel>();
|
|
|
|
_rgbService = rgbService;
|
|
_rgbService.DeviceLoaded += RgbServiceOnDeviceLoaded;
|
|
_rgbService.Surface.Updated += SurfaceOnUpdated;
|
|
|
|
foreach (var surfaceDevice in _rgbService.Surface.Devices)
|
|
Devices.Add(new RgbDeviceViewModel(surfaceDevice));
|
|
}
|
|
|
|
|
|
public ObservableCollection<RgbDeviceViewModel> Devices { get; set; }
|
|
|
|
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
|
|
{
|
|
Execute.OnUIThread(() =>
|
|
{
|
|
if (Devices.All(d => d.Device != e.Device))
|
|
Devices.Add(new RgbDeviceViewModel(e.Device));
|
|
});
|
|
}
|
|
|
|
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
|
{
|
|
foreach (var rgbDeviceViewModel in Devices)
|
|
{
|
|
rgbDeviceViewModel.Update();
|
|
}
|
|
}
|
|
}
|
|
} |