mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Device visualizer - Added LedClicked event
Device properties - Added the ability to select LEDs by clicking on them in the preview
This commit is contained in:
parent
6005535000
commit
5611ad420a
@ -25,10 +25,10 @@ namespace Artemis.Core
|
|||||||
public static SKRect ToSKRect(this Rectangle rectangle)
|
public static SKRect ToSKRect(this Rectangle rectangle)
|
||||||
{
|
{
|
||||||
return SKRect.Create(
|
return SKRect.Create(
|
||||||
(float) rectangle.Location.X,
|
rectangle.Location.X,
|
||||||
(float) rectangle.Location.Y,
|
rectangle.Location.Y,
|
||||||
(float) rectangle.Size.Width,
|
rectangle.Size.Width,
|
||||||
(float) rectangle.Size.Height
|
rectangle.Size.Height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -337,6 +337,7 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
Layout = layout;
|
Layout = layout;
|
||||||
Layout.ApplyDevice(this);
|
Layout.ApplyDevice(this);
|
||||||
|
CalculateRenderProperties();
|
||||||
OnDeviceUpdated();
|
OnDeviceUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,9 +6,11 @@ using System.Linq;
|
|||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
|
using SkiaSharp;
|
||||||
using Stylet;
|
using Stylet;
|
||||||
|
|
||||||
namespace Artemis.UI.Shared
|
namespace Artemis.UI.Shared
|
||||||
@ -54,6 +56,7 @@ namespace Artemis.UI.Shared
|
|||||||
_timer = new Timer(40);
|
_timer = new Timer(40);
|
||||||
_timer.Elapsed += TimerOnTick;
|
_timer.Elapsed += TimerOnTick;
|
||||||
|
|
||||||
|
MouseLeftButtonUp += OnMouseLeftButtonUp;
|
||||||
Loaded += OnLoaded;
|
Loaded += OnLoaded;
|
||||||
Unloaded += OnUnloaded;
|
Unloaded += OnUnloaded;
|
||||||
}
|
}
|
||||||
@ -85,18 +88,6 @@ namespace Artemis.UI.Shared
|
|||||||
set => SetValue(HighlightedLedsProperty, value);
|
set => SetValue(HighlightedLedsProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">
|
|
||||||
/// <see langword="true" /> to release both managed and unmanaged resources;
|
|
||||||
/// <see langword="false" /> to release only unmanaged resources.
|
|
||||||
/// </param>
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing) _timer.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnRender(DrawingContext drawingContext)
|
protected override void OnRender(DrawingContext drawingContext)
|
||||||
{
|
{
|
||||||
@ -149,6 +140,7 @@ namespace Artemis.UI.Shared
|
|||||||
return ResizeKeepAspect(deviceSize, availableSize.Width, availableSize.Height);
|
return ResizeKeepAspect(deviceSize, availableSize.Width, availableSize.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static Size ResizeKeepAspect(Size src, double maxWidth, double maxHeight)
|
private static Size ResizeKeepAspect(Size src, double maxWidth, double maxHeight)
|
||||||
{
|
{
|
||||||
double scale;
|
double scale;
|
||||||
@ -191,6 +183,21 @@ namespace Artemis.UI.Shared
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
if (Device == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Point position = e.GetPosition(this);
|
||||||
|
double x = (position.X / RenderSize.Width);
|
||||||
|
double y = (position.Y / RenderSize.Height);
|
||||||
|
|
||||||
|
Point scaledPosition = new(x * Device.Rectangle.Width, y * Device.Rectangle.Height);
|
||||||
|
DeviceVisualizerLed? deviceVisualizerLed = _deviceVisualizerLeds.FirstOrDefault(l => l.DisplayGeometry != null && l.LedRect.Contains(scaledPosition));
|
||||||
|
if (deviceVisualizerLed != null)
|
||||||
|
OnLedClicked(new LedClickedEventArgs(deviceVisualizerLed.Led.Device, deviceVisualizerLed.Led));
|
||||||
|
}
|
||||||
|
|
||||||
private void OnLoaded(object? sender, RoutedEventArgs e)
|
private void OnLoaded(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
_timer.Start();
|
_timer.Start();
|
||||||
@ -310,11 +317,43 @@ namespace Artemis.UI.Shared
|
|||||||
drawingContext.Close();
|
drawingContext.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
public event EventHandler<LedClickedEventArgs>? LedClicked;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Invokes the <see cref="LedClicked" /> event
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
protected virtual void OnLedClicked(LedClickedEventArgs e)
|
||||||
|
{
|
||||||
|
LedClicked?.Invoke(this, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region IDisposable
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">
|
||||||
|
/// <see langword="true" /> to release both managed and unmanaged resources;
|
||||||
|
/// <see langword="false" /> to release only unmanaged resources.
|
||||||
|
/// </param>
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing) _timer.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
27
src/Artemis.UI.Shared/Events/LedClickedEventArgs.cs
Normal file
27
src/Artemis.UI.Shared/Events/LedClickedEventArgs.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using Artemis.Core;
|
||||||
|
|
||||||
|
namespace Artemis.UI.Shared
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Provides data on LED click events raised by the device visualizer
|
||||||
|
/// </summary>
|
||||||
|
public class LedClickedEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
internal LedClickedEventArgs(ArtemisDevice device, ArtemisLed led)
|
||||||
|
{
|
||||||
|
Device = device;
|
||||||
|
Led = led;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The device that was clicked
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisDevice Device { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The LED that was clicked
|
||||||
|
/// </summary>
|
||||||
|
public ArtemisLed Led { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -110,7 +110,7 @@
|
|||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
ShowColors="True"
|
ShowColors="True"
|
||||||
Margin="0 0 100 0" />
|
LedClicked="{s:Action OnLedClicked}"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<GridSplitter Grid.Column="1" Width="15" Margin="-15 0 0 0" Background="Transparent" HorizontalAlignment="Stretch" Panel.ZIndex="3" />
|
<GridSplitter Grid.Column="1" Width="15" Margin="-15 0 0 0" Background="Transparent" HorizontalAlignment="Stretch" Panel.ZIndex="3" />
|
||||||
|
|||||||
@ -8,6 +8,7 @@ using Artemis.Core;
|
|||||||
using Artemis.Core.Services;
|
using Artemis.Core.Services;
|
||||||
using Artemis.UI.Ninject.Factories;
|
using Artemis.UI.Ninject.Factories;
|
||||||
using Artemis.UI.Screens.Shared;
|
using Artemis.UI.Screens.Shared;
|
||||||
|
using Artemis.UI.Shared;
|
||||||
using Artemis.UI.Shared.Services;
|
using Artemis.UI.Shared.Services;
|
||||||
using MaterialDesignThemes.Wpf;
|
using MaterialDesignThemes.Wpf;
|
||||||
using Ookii.Dialogs.Wpf;
|
using Ookii.Dialogs.Wpf;
|
||||||
@ -197,6 +198,11 @@ namespace Artemis.UI.Screens.Settings.Device
|
|||||||
NotifyOfPropertyChange(nameof(CanExportLayout));
|
NotifyOfPropertyChange(nameof(CanExportLayout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnLedClicked(object sender, LedClickedEventArgs e)
|
||||||
|
{
|
||||||
|
SelectedLed = e.Led;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user