mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Surface rearranging WIP
This commit is contained in:
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;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Artemis.UI.ViewModels.Interfaces
|
||||
{
|
||||
public interface IEditorViewModel : IScreenViewModel
|
||||
public interface ISurfaceEditorViewModel : IScreenViewModel
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Controls.Editor;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class EditorViewModel : Screen, IEditorViewModel
|
||||
{
|
||||
public EditorViewModel(IRgbService rgbService)
|
||||
{
|
||||
SurfaceEditorViewModel = new SurfaceEditorViewModel(rgbService);
|
||||
}
|
||||
|
||||
public SurfaceEditorViewModel SurfaceEditorViewModel { get; set; }
|
||||
public string Title => "Editor";
|
||||
}
|
||||
}
|
||||
@@ -102,8 +102,8 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
case "Workshop":
|
||||
// ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(WorkshopViewModel)));
|
||||
break;
|
||||
case "Editor":
|
||||
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(EditorViewModel)));
|
||||
case "SurfaceEditor":
|
||||
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(SurfaceEditorViewModel)));
|
||||
break;
|
||||
case "Settings":
|
||||
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(SettingsViewModel)));
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Controls.RgbDevice;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
using Point = System.Windows.Point;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class SurfaceEditorViewModel : Screen, ISurfaceEditorViewModel
|
||||
{
|
||||
private readonly IRgbService _rgbService;
|
||||
|
||||
|
||||
public SurfaceEditorViewModel(IRgbService rgbService)
|
||||
{
|
||||
Devices = new ObservableCollection<RgbDeviceViewModel>();
|
||||
SelectionRectangle = new RectangleGeometry();
|
||||
|
||||
_rgbService = rgbService;
|
||||
_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);
|
||||
|
||||
Devices.Add(device);
|
||||
}
|
||||
}
|
||||
|
||||
public RectangleGeometry SelectionRectangle { get; set; }
|
||||
public ObservableCollection<RgbDeviceViewModel> Devices { get; set; }
|
||||
|
||||
public string Title => "Surface Editor";
|
||||
|
||||
private void RgbServiceOnDeviceLoaded(object sender, DeviceEventArgs e)
|
||||
{
|
||||
Execute.OnUIThread(() =>
|
||||
{
|
||||
if (Devices.All(d => d.Device != e.Device))
|
||||
{
|
||||
var device = new RgbDeviceViewModel(e.Device) {Cursor = Cursors.Hand};
|
||||
device.SetColorsEnabled(false);
|
||||
Devices.Add(device);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void SurfaceOnUpdated(UpdatedEventArgs args)
|
||||
{
|
||||
foreach (var rgbDeviceViewModel in Devices)
|
||||
rgbDeviceViewModel.Update();
|
||||
}
|
||||
|
||||
#region Selection
|
||||
|
||||
private bool _editorSelecting;
|
||||
private Point _selectionStartPoint;
|
||||
|
||||
private void StartSelection(Point position)
|
||||
{
|
||||
_selectionStartPoint = position;
|
||||
_editorSelecting = true;
|
||||
|
||||
SelectionRectangle.Rect = new Rect();
|
||||
Mouse.OverrideCursor = Cursors.Arrow;
|
||||
}
|
||||
|
||||
private void StopSelection(Point position)
|
||||
{
|
||||
_editorSelecting = false;
|
||||
Mouse.OverrideCursor = null;
|
||||
|
||||
var selectedRect = new Rect(_selectionStartPoint, position);
|
||||
foreach (var device in Devices)
|
||||
{
|
||||
if (device.DeviceRectangle.IntersectsWith(selectedRect))
|
||||
device.SelectionStatus = SelectionStatus.Selected;
|
||||
else
|
||||
device.SelectionStatus = SelectionStatus.None;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSelection(Point position)
|
||||
{
|
||||
var selectedRect = new Rect(_selectionStartPoint, position);
|
||||
SelectionRectangle.Rect = selectedRect;
|
||||
|
||||
foreach (var device in Devices)
|
||||
{
|
||||
if (device.DeviceRectangle.IntersectsWith(selectedRect))
|
||||
device.SelectionStatus = SelectionStatus.Selected;
|
||||
else
|
||||
device.SelectionStatus = SelectionStatus.None;
|
||||
}
|
||||
}
|
||||
|
||||
public void EditorGridMouseClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
var position = e.GetPosition((IInputElement) sender);
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
StartSelection(position);
|
||||
else
|
||||
StopSelection(position);
|
||||
}
|
||||
|
||||
public void EditorGridMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (!_editorSelecting)
|
||||
return;
|
||||
|
||||
var position = e.GetPosition((IInputElement) sender);
|
||||
UpdateSelection(position);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user