mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Added a debugger, ironed out rendering pipeline
This commit is contained in:
1 parent
3dc8fa6b1c
commit
28fc7b5dcc
15 files changed
+321
-35
No files matched your search
@@ -51,7 +51,9 @@ namespace Artemis.UI.ViewModels.Controls.SurfaceEditor
|
||||
|
||||
public IReadOnlyCollection<SurfaceLedViewModel> Leds => _leds.AsReadOnly();
|
||||
|
||||
public Rect DeviceRectangle => new Rect(X, Y, DeviceConfiguration.Device.Size.Width, DeviceConfiguration.Device.Size.Height);
|
||||
public Rect DeviceRectangle => DeviceConfiguration.Device == null
|
||||
? new Rect()
|
||||
: new Rect(X, Y, DeviceConfiguration.Device.Size.Width, DeviceConfiguration.Device.Size.Height);
|
||||
|
||||
public void StartMouseDrag(Point mouseStartPosition)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class DebugViewModel : Screen
|
||||
{
|
||||
private readonly ICoreService _coreService;
|
||||
private readonly IRgbService _rgbService;
|
||||
|
||||
public DebugViewModel(ICoreService coreService, IRgbService rgbService)
|
||||
{
|
||||
_coreService = coreService;
|
||||
_rgbService = rgbService;
|
||||
|
||||
_coreService.FrameRendered += CoreServiceOnFrameRendered;
|
||||
}
|
||||
|
||||
public ImageSource CurrentFrame { get; set; }
|
||||
public double CurrentFps { get; set; }
|
||||
|
||||
public void ForceGarbageCollection()
|
||||
{
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
}
|
||||
|
||||
private void CoreServiceOnFrameRendered(object sender, FrameEventArgs e)
|
||||
{
|
||||
var imageSource = ImageSourceFromBitmap(e.Bitmap);
|
||||
imageSource.Freeze();
|
||||
CurrentFps = Math.Round(1.0 / e.DeltaTime, 2);
|
||||
Execute.OnUIThread(() => CurrentFrame = imageSource);
|
||||
}
|
||||
|
||||
protected override void OnClose()
|
||||
{
|
||||
_coreService.FrameRendered -= CoreServiceOnFrameRendered;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
// This is much quicker than saving the bitmap into a memory stream and converting it
|
||||
private static ImageSource ImageSourceFromBitmap(Bitmap bmp)
|
||||
{
|
||||
var handle = bmp.GetHbitmap();
|
||||
try
|
||||
{
|
||||
return Imaging.CreateBitmapSourceFromHBitmap(handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DeleteObject(handle);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool DeleteObject([In] IntPtr hObject);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,20 @@
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.UI.ViewModels.Controls.Settings;
|
||||
using Artemis.UI.ViewModels.Interfaces;
|
||||
using Ninject;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.ViewModels.Screens
|
||||
{
|
||||
public class SettingsViewModel : Screen, ISettingsViewModel
|
||||
{
|
||||
public SettingsViewModel(IRgbService rgbService)
|
||||
private readonly IKernel _kernel;
|
||||
private readonly IWindowManager _windowManager;
|
||||
|
||||
public SettingsViewModel(IKernel kernel, IRgbService rgbService, IWindowManager windowManager)
|
||||
{
|
||||
_kernel = kernel;
|
||||
_windowManager = windowManager;
|
||||
DeviceSettingsViewModels = new BindableCollection<RgbDeviceSettingsViewModel>();
|
||||
foreach (var device in rgbService.LoadedDevices)
|
||||
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(device));
|
||||
@@ -20,6 +26,11 @@ namespace Artemis.UI.ViewModels.Screens
|
||||
public BindableCollection<RgbDeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
|
||||
public string Title => "Settings";
|
||||
|
||||
public void ShowDebugger()
|
||||
{
|
||||
_windowManager.ShowWindow(_kernel.Get<DebugViewModel>());
|
||||
}
|
||||
|
||||
private void UpdateDevices(object sender, DeviceEventArgs deviceEventArgs)
|
||||
{
|
||||
DeviceSettingsViewModels.Add(new RgbDeviceSettingsViewModel(deviceEventArgs.Device));
|
||||
|
||||
Reference in new issue
Block a user