1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Device visualizer - Fix framerate drop when processing mouse events

Profile tree - Fixed potential crash when dragging files over Artemis
Module reorder - Fixed potential crash when dragging files over Artemis
This commit is contained in:
SpoinkyNL 2020-12-15 00:05:42 +01:00
parent c401bc6525
commit 7ffe8f3e5b
3 changed files with 31 additions and 30 deletions

View File

@ -3,12 +3,13 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Timers;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Artemis.Core; using Artemis.Core;
using Stylet;
namespace Artemis.UI.Shared namespace Artemis.UI.Shared
{ {
@ -37,7 +38,7 @@ namespace Artemis.UI.Shared
private readonly DrawingGroup _backingStore; private readonly DrawingGroup _backingStore;
private readonly List<DeviceVisualizerLed> _deviceVisualizerLeds; private readonly List<DeviceVisualizerLed> _deviceVisualizerLeds;
private readonly DispatcherTimer _timer; private readonly Timer _timer;
private BitmapImage? _deviceImage; private BitmapImage? _deviceImage;
private ArtemisDevice? _oldDevice; private ArtemisDevice? _oldDevice;
@ -50,8 +51,8 @@ namespace Artemis.UI.Shared
_deviceVisualizerLeds = new List<DeviceVisualizerLed>(); _deviceVisualizerLeds = new List<DeviceVisualizerLed>();
// Run an update timer at 25 fps // Run an update timer at 25 fps
_timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(40)}; _timer = new Timer(40);
_timer.Tick += TimerOnTick; _timer.Elapsed += TimerOnTick;
Loaded += OnLoaded; Loaded += OnLoaded;
Unloaded += OnUnloaded; Unloaded += OnUnloaded;
@ -93,17 +94,7 @@ namespace Artemis.UI.Shared
/// </param> /// </param>
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (disposing) if (disposing) _timer.Stop();
{
_timer.Stop();
}
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -202,9 +193,12 @@ namespace Artemis.UI.Shared
} }
private void TimerOnTick(object? sender, EventArgs e) private void TimerOnTick(object? sender, EventArgs e)
{
Execute.PostToUIThread(() =>
{ {
if (ShowColors && Visibility == Visibility.Visible) if (ShowColors && Visibility == Visibility.Visible)
Render(); Render();
});
} }
private void UpdateTransform() private void UpdateTransform()
@ -295,17 +289,20 @@ namespace Artemis.UI.Shared
DrawingContext drawingContext = _backingStore.Open(); DrawingContext drawingContext = _backingStore.Open();
if (HighlightedLeds != null && HighlightedLeds.Any()) if (HighlightedLeds != null && HighlightedLeds.Any())
{
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds) foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderColor(drawingContext, !HighlightedLeds.Contains(deviceVisualizerLed.Led)); deviceVisualizerLed.RenderColor(drawingContext, !HighlightedLeds.Contains(deviceVisualizerLed.Led));
}
else else
{
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds) foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderColor(drawingContext, false); deviceVisualizerLed.RenderColor(drawingContext, false);
}
drawingContext.Close(); drawingContext.Close();
} }
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
} }
} }

View File

@ -2,7 +2,6 @@
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using Artemis.Core; using Artemis.Core;
using Artemis.Storage.Entities.Profile;
using Artemis.UI.Ninject.Factories; using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem; using Artemis.UI.Screens.ProfileEditor.ProfileTree.TreeItem;
using Artemis.UI.Shared; using Artemis.UI.Shared;
@ -74,8 +73,8 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
private static DragDropType GetDragDropType(IDropInfo dropInfo) private static DragDropType GetDragDropType(IDropInfo dropInfo)
{ {
TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data; if (!(dropInfo.Data is TreeItemViewModel source) || !(dropInfo.TargetItem is TreeItemViewModel target))
TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem; return DragDropType.None;
if (source == target) if (source == target)
return DragDropType.None; return DragDropType.None;
@ -121,8 +120,10 @@ namespace Artemis.UI.Screens.ProfileEditor.ProfileTree
public void Drop(IDropInfo dropInfo) public void Drop(IDropInfo dropInfo)
{ {
TreeItemViewModel source = (TreeItemViewModel)dropInfo.Data; if (!(dropInfo.Data is TreeItemViewModel source) || !(dropInfo.TargetItem is TreeItemViewModel target))
TreeItemViewModel target = (TreeItemViewModel)dropInfo.TargetItem; return;
if (source == target)
return;
DragDropType dragDropType = GetDragDropType(dropInfo); DragDropType dragDropType = GetDragDropType(dropInfo);
switch (dragDropType) switch (dragDropType)

View File

@ -53,8 +53,11 @@ namespace Artemis.UI.Screens.Settings.Tabs.Modules
if (dropInfo.TargetItem == dropInfo.Data) if (dropInfo.TargetItem == dropInfo.Data)
return; return;
ModuleOrderModuleViewModel viewModel = (ModuleOrderModuleViewModel) dropInfo.Data; if (!(dropInfo.Data is ModuleOrderModuleViewModel viewModel))
BindableCollection<ModuleOrderModuleViewModel> targetCollection = (BindableCollection<ModuleOrderModuleViewModel>) dropInfo.TargetCollection; return;
if (!(dropInfo.TargetCollection is BindableCollection<ModuleOrderModuleViewModel> targetCollection))
return;
int insertIndex = dropInfo.InsertIndex; int insertIndex = dropInfo.InsertIndex;
ModulePriorityCategory category; ModulePriorityCategory category;