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

UI - Decreased device visualizer CPU usage

Keyframes - Snap to closest 50 ms while Ctrl is held down
This commit is contained in:
Robert 2021-04-17 10:22:33 +02:00
parent 651fc515d2
commit 5e345fed7c
8 changed files with 73 additions and 62 deletions

View File

@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Artemis.Core.Properties;
namespace Artemis.Core
{
@ -44,6 +45,7 @@ namespace Artemis.Core
/// .
/// </param>
/// <returns><c>true</c> if the value was changed, <c>false</c> if the existing value matched the desired value.</returns>
[NotifyPropertyChangedInvocator]
protected virtual bool SetAndNotify<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
{
if (!RequiresUpdate(ref storage, value)) return false;

View File

@ -109,6 +109,9 @@ namespace Artemis.Core
/// </summary>
public List<ArtemisDeviceInputIdentifier> InputIdentifiers { get; }
/// <summary>
/// Gets a list of input mappings configured on the device
/// </summary>
public Dictionary<ArtemisLed, ArtemisLed> InputMappings { get; }
/// <summary>
@ -288,7 +291,10 @@ namespace Artemis.Core
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="Led" />
/// </summary>
/// <param name="led">The RGB.NET <see cref="Led" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
/// <param name="applyInputMapping">If <see langword="true"/>, LEDs mapped to different LEDs <see cref="InputMappings"/> are taken into consideration</param>
/// <param name="applyInputMapping">
/// If <see langword="true" />, LEDs mapped to different LEDs <see cref="InputMappings" />
/// are taken into consideration
/// </param>
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
public ArtemisLed? GetLed(Led led, bool applyInputMapping)
{
@ -299,7 +305,10 @@ namespace Artemis.Core
/// Attempts to retrieve the <see cref="ArtemisLed" /> that corresponds the provided RGB.NET <see cref="LedId" />
/// </summary>
/// <param name="ledId">The RGB.NET <see cref="LedId" /> to find the corresponding <see cref="ArtemisLed" /> for </param>
/// <param name="applyInputMapping">If <see langword="true"/>, LEDs mapped to different LEDs <see cref="InputMappings"/> are taken into consideration</param>
/// <param name="applyInputMapping">
/// If <see langword="true" />, LEDs mapped to different LEDs <see cref="InputMappings" />
/// are taken into consideration
/// </param>
/// <returns>If found, the corresponding <see cref="ArtemisLed" />; otherwise <see langword="null" />.</returns>
public ArtemisLed? GetLed(LedId ledId, bool applyInputMapping)
{
@ -329,12 +338,31 @@ namespace Artemis.Core
return fileName;
}
/// <summary>
/// Occurs when the underlying RGB.NET device was updated
/// </summary>
public event EventHandler? DeviceUpdated;
/// <summary>
/// Invokes the <see cref="DeviceUpdated" /> event
/// </summary>
protected virtual void OnDeviceUpdated()
{
DeviceUpdated?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Applies the provided layout to the device
/// </summary>
/// <param name="layout">The layout to apply</param>
/// <param name="createMissingLeds">A boolean indicating whether to add missing LEDs defined in the layout but missing on the device</param>
/// <param name="removeExcessiveLeds">A boolean indicating whether to remove excess LEDs present in the device but missing in the layout</param>
/// <param name="createMissingLeds">
/// A boolean indicating whether to add missing LEDs defined in the layout but missing on
/// the device
/// </param>
/// <param name="removeExcessiveLeds">
/// A boolean indicating whether to remove excess LEDs present in the device but missing
/// in the layout
/// </param>
internal void ApplyLayout(ArtemisLayout layout, bool createMissingLeds, bool removeExcessiveLeds)
{
if (createMissingLeds && !DeviceProvider.CreateMissingLedsSupported)
@ -355,21 +383,6 @@ namespace Artemis.Core
OnDeviceUpdated();
}
private void UpdateLeds()
{
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
InputMappings.Clear();
foreach (InputMappingEntity deviceEntityInputMapping in DeviceEntity.InputMappings)
{
ArtemisLed? original = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.OriginalLedId);
ArtemisLed? mapped = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.MappedLedId);
if (original != null && mapped != null)
InputMappings.Add(original, mapped);
}
}
internal void ApplyToEntity()
{
// Other properties are computed
@ -427,6 +440,21 @@ namespace Artemis.Core
Path = path;
}
private void UpdateLeds()
{
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
InputMappings.Clear();
foreach (InputMappingEntity deviceEntityInputMapping in DeviceEntity.InputMappings)
{
ArtemisLed? original = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.OriginalLedId);
ArtemisLed? mapped = Leds.FirstOrDefault(l => l.RgbLed.Id == (LedId) deviceEntityInputMapping.MappedLedId);
if (original != null && mapped != null)
InputMappings.Add(original, mapped);
}
}
private void ApplyKeyboardLayout()
{
if (RgbDevice.DeviceInfo.DeviceType != RGBDeviceType.Keyboard)
@ -443,22 +471,5 @@ namespace Artemis.Core
else
LogicalLayout = DeviceEntity.LogicalLayout;
}
#region Events
/// <summary>
/// Occurs when the underlying RGB.NET device was updated
/// </summary>
public event EventHandler? DeviceUpdated;
/// <summary>
/// Invokes the <see cref="DeviceUpdated" /> event
/// </summary>
protected virtual void OnDeviceUpdated()
{
DeviceUpdated?.Invoke(this, EventArgs.Empty);
}
#endregion
}
}

View File

@ -1,17 +1,18 @@
using Artemis.Core.Services;
using RGB.NET.Core;
namespace Artemis.Core
namespace Artemis.Core
{
/// <summary>
/// Represents a device input identifier used by a specific <see cref="Services.InputProvider" /> to identify the device
/// Represents a device input identifier used by a specific <see cref="Services.InputProvider" /> to identify the
/// device
/// </summary>
public class ArtemisDeviceInputIdentifier
{
/// <summary>
/// Creates a new instance of the <see cref="ArtemisDeviceInputIdentifier" /> class
/// </summary>
/// <param name="inputProvider">The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is used by</param>
/// <param name="inputProvider">
/// The full type and namespace of the <see cref="Services.InputProvider" /> this identifier is
/// used by
/// </param>
/// <param name="identifier">A value used to identify the device</param>
internal ArtemisDeviceInputIdentifier(string inputProvider, object identifier)
{
@ -29,16 +30,4 @@ namespace Artemis.Core
/// </summary>
public object Identifier { get; set; }
}
public class ArtemisDeviceInputMapping
{
public ArtemisLed OriginalLed { get; }
public ArtemisLed MappedLed { get; }
internal ArtemisDeviceInputMapping(ArtemisLed originalLed, ArtemisLed mappedLed)
{
OriginalLed = originalLed;
MappedLed = mappedLed;
}
}
}

View File

@ -330,14 +330,15 @@ namespace Artemis.UI.Shared
private void Render()
{
DrawingContext drawingContext = _backingStore.Open();
DrawingContext drawingContext = _backingStore.Append();
// DrawingContext drawingContext = _backingStore.Open();
if (HighlightedLeds != null && HighlightedLeds.Any())
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderColor(drawingContext, !HighlightedLeds.Contains(deviceVisualizerLed.Led));
deviceVisualizerLed.RenderColor(_backingStore, drawingContext, !HighlightedLeds.Contains(deviceVisualizerLed.Led));
else
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
deviceVisualizerLed.RenderColor(drawingContext, false);
deviceVisualizerLed.RenderColor(_backingStore, drawingContext, false);
drawingContext.Close();
}

View File

@ -14,9 +14,10 @@ namespace Artemis.UI.Shared
{
private const byte Dimmed = 100;
private const byte NonDimmed = 255;
private GeometryDrawing? _geometryDrawing;
private Color _renderColor;
private SolidColorBrush? _renderColorBrush;
private Color _renderColor;
public DeviceVisualizerLed(ArtemisLed led)
{
@ -40,12 +41,13 @@ namespace Artemis.UI.Shared
public BitmapImage? LedImage { get; set; }
public Geometry? DisplayGeometry { get; private set; }
public void RenderColor(DrawingContext drawingContext, bool isDimmed)
public void RenderColor(DrawingGroup backingStore, DrawingContext drawingContext, bool isDimmed)
{
if (DisplayGeometry == null)
return;
_renderColorBrush ??= new SolidColorBrush();
_geometryDrawing ??= new GeometryDrawing(_renderColorBrush, null, new RectangleGeometry(LedRect));
byte r = Led.RgbLed.Color.GetR();
byte g = Led.RgbLed.Color.GetG();
@ -56,7 +58,10 @@ namespace Artemis.UI.Shared
_renderColor.G = g;
_renderColor.B = b;
_renderColorBrush.Color = _renderColor;
drawingContext.DrawRectangle(_renderColorBrush, null, LedRect);
if (!backingStore.Children.Contains(_geometryDrawing))
backingStore.Children.Add(_geometryDrawing);
}
public void RenderImage(DrawingContext drawingContext)

View File

@ -55,7 +55,7 @@ namespace Artemis.UI.DefaultTypes.PropertyInput
Execute.PostToUIThread(async () =>
{
await Task.Delay(400);
_dialogService.ShowDialogAt<LayerBrushPresetViewModel>("LayerProperties", new Dictionary<string, object> {{"layerBrush", layer.LayerBrush}});
await _dialogService.ShowDialogAt<LayerBrushPresetViewModel>("LayerProperties", new Dictionary<string, object> {{"layerBrush", layer.LayerBrush}});
});
}
}

View File

@ -322,6 +322,9 @@ namespace Artemis.UI.Screens.ProfileEditor.LayerProperties.Timeline
false,
keyframeViewModels.Where(k => k != sourceKeyframeViewModel).Select(k => k.Position).ToList()
);
// If holding down control, round to the closest 50ms
else if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
cursorTime = TimeSpan.FromMilliseconds(Math.Round(cursorTime.TotalMilliseconds / 50.0) * 50.0);
sourceKeyframeViewModel.UpdatePosition(cursorTime);

View File

@ -9,7 +9,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
mc:Ignorable="d"
Title="Plugin configuration"
Title="Plugin Configuration | Artemis"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="pack://application:,,,/MaterialDesignThemes.Wpf;component/Resources/Roboto/#Roboto"
UseLayoutRounding="True"