Split device views/VMs for surface and profile editors

Added support for devices without images to the surface editor
This commit is contained in:
SpoinkyNL committed 2019-10-12 18:00:21 +02:00
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();
}
}
}
@@ -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;
@@ -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;
}
}
}