mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added device identification to surface editor
Fixed dialog rendering Cleaned up XAML
This commit is contained in:
1 parent
0d1370af30
commit
6719a36c50
24 files changed
+165
-79
No files matched your search
@@ -40,7 +40,7 @@ namespace Artemis.UI.Screens.Settings.Debug
|
||||
|
||||
var imageSource = ImageSourceFromBitmap(e.Bitmap);
|
||||
imageSource.Freeze();
|
||||
Execute.OnUIThread(() => { CurrentFrame = imageSource; });
|
||||
Execute.PostToUIThread(() => { CurrentFrame = imageSource; });
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendering(object sender, FrameRenderingEventArgs e)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services.Storage;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Settings.Debug;
|
||||
using Artemis.UI.Screens.Settings.Tabs.Devices;
|
||||
using Ninject;
|
||||
@@ -11,19 +10,23 @@ namespace Artemis.UI.Screens.Settings
|
||||
{
|
||||
public class SettingsViewModel : Screen, IScreenViewModel
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IDeviceSettingsViewModelFactory _deviceSettingsViewModelFactory;
|
||||
private readonly IKernel _kernel;
|
||||
private readonly ISettingsService _settingsService;
|
||||
private readonly ISurfaceService _surfaceService;
|
||||
private readonly IWindowManager _windowManager;
|
||||
|
||||
public SettingsViewModel(IKernel kernel, ICoreService coreService, ISurfaceService surfaceService, IWindowManager windowManager, ISettingsService settingsService)
|
||||
public SettingsViewModel(IKernel kernel,
|
||||
ISurfaceService surfaceService,
|
||||
IWindowManager windowManager,
|
||||
ISettingsService settingsService,
|
||||
IDeviceSettingsViewModelFactory deviceSettingsViewModelFactory)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_coreService = coreService;
|
||||
_surfaceService = surfaceService;
|
||||
_windowManager = windowManager;
|
||||
_settingsService = settingsService;
|
||||
_deviceSettingsViewModelFactory = deviceSettingsViewModelFactory;
|
||||
|
||||
DeviceSettingsViewModels = new BindableCollection<DeviceSettingsViewModel>();
|
||||
}
|
||||
@@ -56,7 +59,7 @@ namespace Artemis.UI.Screens.Settings
|
||||
{
|
||||
DeviceSettingsViewModels.Clear();
|
||||
foreach (var device in _surfaceService.ActiveSurface.Devices)
|
||||
DeviceSettingsViewModels.Add(new DeviceSettingsViewModel(device, _coreService));
|
||||
DeviceSettingsViewModels.Add(_deviceSettingsViewModelFactory.Create(device));
|
||||
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
d:DataContext="{d:DesignInstance settings:DeviceSettingsViewModel}"
|
||||
xmlns:devices="clr-namespace:Artemis.UI.Screens.Settings.Tabs.Devices"
|
||||
d:DataContext="{d:DesignInstance devices:DeviceSettingsViewModel}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<UserControl.Resources>
|
||||
@@ -36,7 +37,7 @@
|
||||
VerticalAlignment="Bottom"
|
||||
Margin="0 0 16 -20"
|
||||
ToolTip="Identify"
|
||||
Command="{s:Action Identify}">
|
||||
Command="{s:Action IdentifyDevice}">
|
||||
<materialDesign:PackIcon Kind="AlarmLight" />
|
||||
</Button>
|
||||
<StackPanel Grid.Row="1" Margin="8 24 8 0">
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Core.Services;
|
||||
using Humanizer;
|
||||
|
||||
namespace Artemis.UI.Screens.Settings.Tabs.Devices
|
||||
{
|
||||
public class DeviceSettingsViewModel
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IDeviceService _deviceService;
|
||||
|
||||
public DeviceSettingsViewModel(Device device, ICoreService coreService)
|
||||
public DeviceSettingsViewModel(Device device, IDeviceService deviceService)
|
||||
{
|
||||
_coreService = coreService;
|
||||
|
||||
_deviceService = deviceService;
|
||||
Device = device;
|
||||
|
||||
Type = Device.RgbDevice.DeviceInfo.DeviceType.ToString().Humanize();
|
||||
@@ -31,38 +27,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.Devices
|
||||
public string Manufacturer { get; set; }
|
||||
public bool IsDeviceEnabled { get; set; }
|
||||
|
||||
public void Identify()
|
||||
public void IdentifyDevice()
|
||||
{
|
||||
BlinkDevice(0);
|
||||
_deviceService.IdentifyDevice(Device);
|
||||
}
|
||||
|
||||
private void BlinkDevice(int blinkCount)
|
||||
{
|
||||
// Draw a white overlay over the device
|
||||
void DrawOverlay(object sender, FrameRenderingEventArgs args)
|
||||
{
|
||||
using (var g = Graphics.FromImage(args.Bitmap))
|
||||
{
|
||||
g.FillPath(new SolidBrush(Color.White), Device.RenderPath);
|
||||
}
|
||||
}
|
||||
|
||||
_coreService.FrameRendering += DrawOverlay;
|
||||
|
||||
// After 200ms, stop drawing the overlay
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(200);
|
||||
_coreService.FrameRendering -= DrawOverlay;
|
||||
|
||||
if (blinkCount < 5)
|
||||
{
|
||||
// After another 200ms, draw the overlay again, repeat six times
|
||||
await Task.Delay(200);
|
||||
BlinkDevice(blinkCount + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void ShowDeviceDebugger()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user