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
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.ProfileEditor
|
||||
{
|
||||
public class ProfileDeviceViewModel : PropertyChangedBase
|
||||
{
|
||||
private readonly List<ProfileLedViewModel> _leds;
|
||||
|
||||
public ProfileDeviceViewModel(IRGBDevice device)
|
||||
{
|
||||
Device = device;
|
||||
_leds = new List<ProfileLedViewModel>();
|
||||
|
||||
foreach (var led in Device)
|
||||
_leds.Add(new ProfileLedViewModel(led));
|
||||
}
|
||||
|
||||
public IRGBDevice Device { get; }
|
||||
public IReadOnlyCollection<ProfileLedViewModel> Leds => _leds.AsReadOnly();
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (var ledViewModel in _leds)
|
||||
ledViewModel.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-5
@@ -1,18 +1,16 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.UI.Extensions;
|
||||
using PropertyChanged;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
using Color = System.Windows.Media.Color;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.RgbDevice
|
||||
namespace Artemis.UI.ViewModels.Controls.ProfileEditor
|
||||
{
|
||||
public class RgbLedViewModel : PropertyChangedBase
|
||||
public class ProfileLedViewModel : PropertyChangedBase
|
||||
{
|
||||
public RgbLedViewModel(Led led)
|
||||
public ProfileLedViewModel(Led led)
|
||||
{
|
||||
Led = led;
|
||||
|
||||
+11
-24
@@ -6,40 +6,29 @@ using RGB.NET.Core;
|
||||
using Stylet;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.RgbDevice
|
||||
namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
|
||||
{
|
||||
public class RgbDeviceViewModel : PropertyChangedBase
|
||||
public class SurfaceDeviceViewModel : PropertyChangedBase
|
||||
{
|
||||
private readonly List<RgbLedViewModel> _leds;
|
||||
private double _dragOffsetX;
|
||||
private double _dragOffsetY;
|
||||
private readonly List<SurfaceLedViewModel> _leds;
|
||||
|
||||
public RgbDeviceViewModel(IRGBDevice device)
|
||||
public SurfaceDeviceViewModel(IRGBDevice device)
|
||||
{
|
||||
Device = device;
|
||||
_leds = new List<RgbLedViewModel>();
|
||||
_leds = new List<SurfaceLedViewModel>();
|
||||
|
||||
foreach (var led in Device)
|
||||
_leds.Add(new RgbLedViewModel(led));
|
||||
_leds.Add(new SurfaceLedViewModel(led));
|
||||
}
|
||||
|
||||
public Cursor Cursor { get; set; }
|
||||
public SelectionStatus SelectionStatus { get; set; }
|
||||
|
||||
public IRGBDevice Device { get; }
|
||||
public IReadOnlyCollection<RgbLedViewModel> Leds => _leds.AsReadOnly();
|
||||
public SelectionStatus SelectionStatus { get; set; }
|
||||
public Cursor Cursor { get; set; }
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (var rgbLedViewModel in _leds)
|
||||
rgbLedViewModel.Update();
|
||||
}
|
||||
|
||||
public void SetColorsEnabled(bool enabled)
|
||||
{
|
||||
foreach (var rgbLedViewModel in _leds)
|
||||
rgbLedViewModel.ColorsEnabled = enabled;
|
||||
}
|
||||
public IReadOnlyCollection<SurfaceLedViewModel> Leds => _leds.AsReadOnly();
|
||||
public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
|
||||
|
||||
public void StartMouseDrag(Point mouseStartPosition)
|
||||
{
|
||||
@@ -51,7 +40,7 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
|
||||
{
|
||||
var roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
||||
var roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
|
||||
this.Device.Location = new RGB.NET.Core.Point(roundedX, roundedY);
|
||||
Device.Location = new RGB.NET.Core.Point(roundedX, roundedY);
|
||||
}
|
||||
|
||||
public void FinishMouseDrag(Point mouseEndPosition)
|
||||
@@ -78,8 +67,6 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
|
||||
Cursor = Cursors.Arrow;
|
||||
}
|
||||
}
|
||||
|
||||
public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
|
||||
}
|
||||
|
||||
public enum SelectionStatus
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
|
||||
{
|
||||
public class SurfaceLedViewModel : PropertyChangedBase
|
||||
{
|
||||
public SurfaceLedViewModel(Led led)
|
||||
{
|
||||
Led = led;
|
||||
Update();
|
||||
}
|
||||
|
||||
public Led Led { get; }
|
||||
|
||||
public double X { get; private set; }
|
||||
public double Y { get; private set; }
|
||||
public double Width { get; private set; }
|
||||
public double Height { get; private set; }
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (Math.Abs(Led.LedRectangle.X - X) > 0.1)
|
||||
X = Led.LedRectangle.X;
|
||||
|
||||
if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1)
|
||||
Y = Led.LedRectangle.Y;
|
||||
|
||||
if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1)
|
||||
Width = Led.LedRectangle.Width;
|
||||
|
||||
if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1)
|
||||
Height = Led.LedRectangle.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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