mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Split device views/VMs for surface and profile editors
Added support for devices without images to the surface editor
This commit is contained in:
1 parent
a752c75239
commit
d9c2e7b2dc
13 files changed
+334
-109
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -8,7 +9,7 @@ using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
using Artemis.UI.ViewModels.Controls.RgbDevice;
|
||||
using Artemis.UI.ViewModels.Controls.SurfaceEditor;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
@@ -23,26 +24,23 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
|
||||
public SurfaceEditorViewModel(IRgbService rgbService, ISurfaceService surfaceService)
|
||||
{
|
||||
Devices = new ObservableCollection<RgbDeviceViewModel>();
|
||||
Devices = new ObservableCollection<SurfaceDeviceViewModel>();
|
||||
SurfaceConfigurations = new ObservableCollection<SurfaceConfiguration>();
|
||||
SelectionRectangle = new RectangleGeometry();
|
||||
|
||||
_rgbService = rgbService;
|
||||
_surfaceService = surfaceService;
|
||||
_rgbService.DeviceLoaded += RgbServiceOnDeviceLoaded;
|
||||
_rgbService.Surface.Updated += SurfaceOnUpdated;
|
||||
|
||||
foreach (var surfaceDevice in _rgbService.Surface.Devices)
|
||||
{
|
||||
var device = new RgbDeviceViewModel(surfaceDevice) {Cursor = Cursors.Hand};
|
||||
device.SetColorsEnabled(false);
|
||||
|
||||
var device = new SurfaceDeviceViewModel(surfaceDevice) {Cursor = Cursors.Hand};
|
||||
Devices.Add(device);
|
||||
}
|
||||
}
|
||||
|
||||
public RectangleGeometry SelectionRectangle { get; set; }
|
||||
public ObservableCollection<RgbDeviceViewModel> Devices { get; set; }
|
||||
public ObservableCollection<SurfaceDeviceViewModel> Devices { get; set; }
|
||||
|
||||
public SurfaceConfiguration SelectedSurfaceConfiguration { get; set; }
|
||||
public ObservableCollection<SurfaceConfiguration> SurfaceConfigurations { get; set; }
|
||||
@@ -56,47 +54,32 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
if (Devices.All(d => d.Device != e.Device))
|
||||
{
|
||||
var device = new RgbDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
|
||||
device.SetColorsEnabled(false);
|
||||
var device = new SurfaceDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
|
||||
Devices.Add(device);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
||||
{
|
||||
foreach (var rgbDeviceViewModel in Devices)
|
||||
rgbDeviceViewModel.Update();
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
Task.Run(LoadSurfaceConfigurations);
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private async Task LoadSurfaceConfigurations()
|
||||
{
|
||||
SurfaceConfigurations.Clear();
|
||||
Execute.OnUIThread(async () =>
|
||||
{
|
||||
SurfaceConfigurations.Clear();
|
||||
|
||||
// Get surface configs
|
||||
var configs = await _surfaceService.GetSurfaceConfigurations();
|
||||
// Populate the UI collection
|
||||
foreach (var surfaceConfiguration in configs)
|
||||
SurfaceConfigurations.Add(surfaceConfiguration);
|
||||
// Select either the first active surface or the first available surface
|
||||
SelectedSurfaceConfiguration = SurfaceConfigurations.FirstOrDefault(s => s.IsActive) ?? SurfaceConfigurations.FirstOrDefault();
|
||||
// Get surface configs
|
||||
var configs = await _surfaceService.GetSurfaceConfigurations();
|
||||
// Populate the UI collection
|
||||
foreach (var surfaceConfiguration in configs)
|
||||
SurfaceConfigurations.Add(surfaceConfiguration);
|
||||
// Select either the first active surface or the first available surface
|
||||
SelectedSurfaceConfiguration = SurfaceConfigurations.FirstOrDefault(s => s.IsActive) ?? SurfaceConfigurations.FirstOrDefault();
|
||||
|
||||
// Create a default if there is none
|
||||
if (SelectedSurfaceConfiguration == null)
|
||||
SelectedSurfaceConfiguration = AddSurfaceConfiguration("Default");
|
||||
// Create a default if there is none
|
||||
if (SelectedSurfaceConfiguration == null)
|
||||
SelectedSurfaceConfiguration = AddSurfaceConfiguration("Default");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
public SurfaceConfiguration AddSurfaceConfiguration(string name)
|
||||
{
|
||||
var config = new SurfaceConfiguration(name);
|
||||
@@ -111,9 +94,34 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
var newConfig = AddSurfaceConfiguration(NewConfigurationName);
|
||||
SelectedSurfaceConfiguration = newConfig;
|
||||
}
|
||||
|
||||
NewConfigurationName = null;
|
||||
}
|
||||
|
||||
#region Context menu actions
|
||||
|
||||
public void BringToFront(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
Console.WriteLine("Bring to front");
|
||||
}
|
||||
|
||||
public void BringForward(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
Console.WriteLine("Bring forward");
|
||||
}
|
||||
|
||||
public void SendToBack(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
Console.WriteLine("Send to back");
|
||||
}
|
||||
|
||||
public void SendBackward(SurfaceDeviceViewModel surfaceDeviceViewModel)
|
||||
{
|
||||
Console.WriteLine("Send backward");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mouse actions
|
||||
|
||||
private MouseDragStatus _mouseDragStatus;
|
||||
@@ -215,6 +223,16 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
protected override void OnActivate()
|
||||
{
|
||||
Task.Run(LoadSurfaceConfigurations);
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal enum MouseDragStatus
|
||||
|
||||
Reference in new issue
Block a user