mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Started layout editor implementation
Rearranged VMs/Views Updated RGB.NET
This commit is contained in:
1 parent
390dcc6ae1
commit
6e23c079b1
52 files changed
+741
-185
No files matched your search
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.RgbDevice
|
||||
{
|
||||
public class RgbDeviceViewModel
|
||||
{
|
||||
private readonly List<RgbLedViewModel> _leds;
|
||||
|
||||
public RgbDeviceViewModel(IRGBDevice device)
|
||||
{
|
||||
Device = device;
|
||||
_leds = new List<RgbLedViewModel>();
|
||||
|
||||
foreach (var led in Device)
|
||||
_leds.Add(new RgbLedViewModel(led));
|
||||
}
|
||||
|
||||
public IRGBDevice Device { get; }
|
||||
public IReadOnlyCollection<RgbLedViewModel> Leds => _leds.AsReadOnly();
|
||||
|
||||
public void Update()
|
||||
{
|
||||
foreach (var rgbLedViewModel in _leds)
|
||||
rgbLedViewModel.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using RGB.NET.Core;
|
||||
using SharpVectors.Converters;
|
||||
using SharpVectors.Renderers.Wpf;
|
||||
using Stylet;
|
||||
using Color = System.Windows.Media.Color;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.RgbDevice
|
||||
{
|
||||
public class RgbLedViewModel : PropertyChangedBase
|
||||
{
|
||||
public RgbLedViewModel(Led led)
|
||||
{
|
||||
Led = led;
|
||||
|
||||
Execute.OnUIThread(CreateLedGeometry);
|
||||
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 Color FillColor { get; set; }
|
||||
|
||||
public DrawingImage DisplayDrawing { get; private set; }
|
||||
|
||||
public string Tooltip => $"{Led.Id} - {Led.LedRectangle}";
|
||||
|
||||
private void CreateLedGeometry()
|
||||
{
|
||||
// Prepare the SVG for this LED
|
||||
var converter = new FileSvgReader(new WpfDrawingSettings {OptimizePath = true});
|
||||
if (Led.Image != null)
|
||||
{
|
||||
DisplayDrawing = new DrawingImage(converter.Read(Led.Image));
|
||||
}
|
||||
else
|
||||
{
|
||||
var relativeRectangle = new Rect(0, 0, Led.LedRectangle.Width, Led.LedRectangle.Height);
|
||||
Geometry geometry;
|
||||
switch (Led.Shape)
|
||||
{
|
||||
case Shape.Custom:
|
||||
geometry = Geometry.Parse(Led.ShapeData);
|
||||
break;
|
||||
case Shape.Rectangle:
|
||||
geometry = new RectangleGeometry(relativeRectangle, 2, 2);
|
||||
break;
|
||||
case Shape.Circle:
|
||||
geometry = new EllipseGeometry(relativeRectangle);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
var drawing = new GeometryDrawing(null, new Pen(null, 2), geometry);
|
||||
DisplayDrawing = new DrawingImage(drawing);
|
||||
}
|
||||
|
||||
NotifyOfPropertyChange(() => DisplayDrawing);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
FillColor = Color.FromRgb((byte) Math.Round(255 * Led.Color.R), (byte) Math.Round(255 * Led.Color.G), (byte) Math.Round(255 * Led.Color.B));
|
||||
X = Led.LedRectangle.X;
|
||||
Y = Led.LedRectangle.Y;
|
||||
Width = Led.LedRectangle.Width;
|
||||
Height = Led.LedRectangle.Height;
|
||||
|
||||
if (DisplayDrawing != null)
|
||||
{
|
||||
Execute.OnUIThread(() =>
|
||||
{
|
||||
if (DisplayDrawing.Drawing is GeometryDrawing geometryDrawing)
|
||||
{
|
||||
geometryDrawing.Brush = new SolidColorBrush(FillColor) {Opacity = 0.6};
|
||||
geometryDrawing.Pen.Brush = new SolidColorBrush(FillColor);
|
||||
}
|
||||
else if (DisplayDrawing.Drawing is DrawingGroup drawingGroup)
|
||||
drawingGroup.OpacityMask = new SolidColorBrush(FillColor);
|
||||
});
|
||||
NotifyOfPropertyChange(() => DisplayDrawing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Humanizer;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Controls.Settings
|
||||
{
|
||||
public class RgbDeviceSettingsViewModel
|
||||
{
|
||||
public IRGBDevice Device { get; }
|
||||
|
||||
public RgbDeviceSettingsViewModel(IRGBDevice device)
|
||||
{
|
||||
Device = device;
|
||||
|
||||
Type = Device.DeviceInfo.DeviceType.ToString().Humanize();
|
||||
Name = Device.DeviceInfo.Model;
|
||||
Manufacturer = Device.DeviceInfo.Manufacturer;
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
public string Type { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Manufacturer { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Artemis.UI.ViewModels.Interfaces
|
||||
{
|
||||
public interface IEditorViewModel : IScreenViewModel
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Artemis.UI.ViewModels.Interfaces
|
||||
{
|
||||
public interface IHomeViewModel : IArtemisViewModel
|
||||
public interface IHomeViewModel : IScreenViewModel
|
||||
{
|
||||
void OpenUrl(string url);
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Artemis.UI.ViewModels.Interfaces
|
||||
{
|
||||
public interface IArtemisViewModel : IScreen
|
||||
public interface IScreenViewModel : IScreen
|
||||
{
|
||||
string Title { get; }
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Artemis.UI.ViewModels.Interfaces
|
||||
{
|
||||
public interface ISettingsViewModel : IArtemisViewModel
|
||||
public interface ISettingsViewModel : IScreenViewModel
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ using System.Diagnostics;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class HomeViewModel : Screen, IHomeViewModel
|
||||
{
|
||||
+6
-5
@@ -5,20 +5,18 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Core.Plugins.Interfaces;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using Artemis.UI.ViewModels.Settings;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class RootViewModel : Conductor<IScreen>.Collection.OneActive
|
||||
{
|
||||
private readonly ICollection<IArtemisViewModel> _artemisViewModels;
|
||||
private readonly ICollection<IScreenViewModel> _artemisViewModels;
|
||||
private readonly IPluginService _pluginService;
|
||||
|
||||
public RootViewModel(ICollection<IArtemisViewModel> artemisViewModels, IPluginService pluginService)
|
||||
public RootViewModel(ICollection<IScreenViewModel> artemisViewModels, IPluginService pluginService)
|
||||
{
|
||||
_artemisViewModels = artemisViewModels;
|
||||
_pluginService = pluginService;
|
||||
@@ -104,6 +102,9 @@ namespace Artemis.UI.ViewModels
|
||||
case "Workshop":
|
||||
// ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(WorkshopViewModel)));
|
||||
break;
|
||||
case "Editor":
|
||||
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(EditorViewModel)));
|
||||
break;
|
||||
case "Settings":
|
||||
ActivateItem(_artemisViewModels.First(v => v.GetType() == typeof(SettingsViewModel)));
|
||||
break;
|
||||
+7
-7
@@ -1,28 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Controls.Settings;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Settings
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class SettingsViewModel : Screen, ISettingsViewModel
|
||||
{
|
||||
public SettingsViewModel(IRgbService rgbService)
|
||||
{
|
||||
DeviceSettingsViewModels = new List<DeviceSettingsViewModel>();
|
||||
DeviceSettingsViewModels = new BindableCollection<RgbDeviceSettingsViewModel>();
|
||||
foreach (var device in rgbService.Surface.Devices)
|
||||
DeviceSettingsViewModels.Add(new DeviceSettingsViewModel(device));
|
||||
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(device));
|
||||
|
||||
rgbService.DeviceLoaded += UpdateDevices;
|
||||
}
|
||||
|
||||
public List<DeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
|
||||
public BindableCollection<RgbDeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
|
||||
public string Title => "Settings";
|
||||
|
||||
private void UpdateDevices(object sender, DeviceEventArgs deviceEventArgs)
|
||||
{
|
||||
DeviceSettingsViewModels.Add(new DeviceSettingsViewModel(deviceEventArgs.Device));
|
||||
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(deviceEventArgs.Device));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
using Humanizer;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Settings
|
||||
{
|
||||
public class DeviceSettingsViewModel
|
||||
{
|
||||
private readonly IRGBDevice _device;
|
||||
|
||||
public DeviceSettingsViewModel(IRGBDevice device)
|
||||
{
|
||||
_device = device;
|
||||
|
||||
Type = _device.DeviceInfo.DeviceType.ToString().Humanize();
|
||||
Name = _device.DeviceInfo.Model;
|
||||
Manufacturer = _device.DeviceInfo.Manufacturer;
|
||||
Enabled = true;
|
||||
}
|
||||
|
||||
public string Type { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Manufacturer { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user