Surface rearranging WIP

This commit is contained in:
SpoinkyNL committed 2019-08-24 23:24:13 +02:00
1 parent a35774eeb4
commit 171f63a1db
24 files changed
+308 -648

No files matched your search

@@ -1,47 +0,0 @@
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();
}
}
}
}
@@ -1,9 +1,13 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using RGB.NET.Core;
using Stylet;
namespace Artemis.UI.ViewModels.Controls.RgbDevice
{
public class RgbDeviceViewModel
public class RgbDeviceViewModel : PropertyChangedBase
{
private readonly List<RgbLedViewModel> _leds;
@@ -16,6 +20,9 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
_leds.Add(new RgbLedViewModel(led));
}
public Cursor Cursor { get; set; }
public SelectionStatus SelectionStatus { get; set; }
public IRGBDevice Device { get; }
public IReadOnlyCollection<RgbLedViewModel> Leds => _leds.AsReadOnly();
@@ -24,5 +31,20 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
foreach (var rgbLedViewModel in _leds)
rgbLedViewModel.Update();
}
public void SetColorsEnabled(bool enabled)
{
foreach (var rgbLedViewModel in _leds)
rgbLedViewModel.ColorsEnabled = enabled;
}
public Rect DeviceRectangle => new Rect(Device.Location.X, Device.Location.Y, Device.Size.Width, Device.Size.Height);
}
public enum SelectionStatus
{
None,
Hover,
Selected
}
}
@@ -1,5 +1,6 @@
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Artemis.UI.Extensions;
using PropertyChanged;
@@ -14,7 +15,7 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
public RgbLedViewModel(Led led)
{
Led = led;
Execute.OnUIThread(CreateLedGeometry);
Update();
}
@@ -30,6 +31,7 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
public Geometry DisplayGeometry { get; private set; }
public Geometry StrokeGeometry { get; private set; }
public Color DisplayColor { get; private set; }
public bool ColorsEnabled { get; set; } = true;
public string Tooltip => $"{Led.Id} - {Led.LedRectangle}";
@@ -93,8 +95,11 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
public void Update()
{
var newColor = Led.Color.ToMediaColor();
SetColor(newColor);
if (ColorsEnabled)
{
var newColor = Led.Color.ToMediaColor();
SetColor(newColor);
}
if (Math.Abs(Led.LedRectangle.X - X) > 0.1)
X = Led.LedRectangle.X;