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,78 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using RGB.NET.Core;
using Stylet;
using Point = System.Windows.Point;
namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
{
public class SurfaceDeviceViewModel : PropertyChangedBase
{
private double _dragOffsetX;
private double _dragOffsetY;
private readonly List<SurfaceLedViewModel> _leds;
public SurfaceDeviceViewModel(IRGBDevice device)
{
Device = device;
_leds = new List<SurfaceLedViewModel>();
foreach (var led in Device)
_leds.Add(new SurfaceLedViewModel(led));
}
public IRGBDevice Device { get; }
public SelectionStatus SelectionStatus { get; set; }
public Cursor Cursor { get; set; }
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)
{
_dragOffsetX = Device.Location.X - mouseStartPosition.X;
_dragOffsetY = Device.Location.Y - mouseStartPosition.Y;
}
public void UpdateMouseDrag(Point mousePosition)
{
var roundedX = Math.Round((mousePosition.X + _dragOffsetX) / 10, 0, MidpointRounding.AwayFromZero) * 10;
var roundedY = Math.Round((mousePosition.Y + _dragOffsetY) / 10, 0, MidpointRounding.AwayFromZero) * 10;
Device.Location = new RGB.NET.Core.Point(roundedX, roundedY);
}
public void FinishMouseDrag(Point mouseEndPosition)
{
// TODO: Save and update
}
// ReSharper disable once UnusedMember.Global - Called from view
public void MouseEnter()
{
if (SelectionStatus == SelectionStatus.None)
{
SelectionStatus = SelectionStatus.Hover;
Cursor = Cursors.Hand;
}
}
// ReSharper disable once UnusedMember.Global - Called from view
public void MouseLeave()
{
if (SelectionStatus == SelectionStatus.Hover)
{
SelectionStatus = SelectionStatus.None;
Cursor = Cursors.Arrow;
}
}
}
public enum SelectionStatus
{
None,
Hover,
Selected
}
}