mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Device visualizer - Fixed display issues when scaling/rotating
This commit is contained in:
parent
76a6ab5ca0
commit
e68e16df4d
@ -4,7 +4,6 @@ using System.Collections.ObjectModel;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Artemis.Core;
|
using Artemis.Core;
|
||||||
using Artemis.UI.Shared.Events;
|
using Artemis.UI.Shared.Events;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
@ -64,25 +63,22 @@ namespace Artemis.UI.Shared
|
|||||||
using DrawingContext.PushedState translationPush = drawingContext.PushPreTransform(Matrix.CreateTranslation(0 - _deviceBounds.Left, 0 - _deviceBounds.Top));
|
using DrawingContext.PushedState translationPush = drawingContext.PushPreTransform(Matrix.CreateTranslation(0 - _deviceBounds.Left, 0 - _deviceBounds.Top));
|
||||||
using DrawingContext.PushedState rotationPush = drawingContext.PushPreTransform(Matrix.CreateRotation(Matrix.ToRadians(Device.Rotation)));
|
using DrawingContext.PushedState rotationPush = drawingContext.PushPreTransform(Matrix.CreateRotation(Matrix.ToRadians(Device.Rotation)));
|
||||||
|
|
||||||
// Apply device scale
|
|
||||||
using DrawingContext.PushedState scalePush = drawingContext.PushPreTransform(Matrix.CreateScale(Device.Scale, Device.Scale));
|
|
||||||
|
|
||||||
// Render device and LED images
|
// Render device and LED images
|
||||||
if (_deviceImage != null)
|
if (_deviceImage != null)
|
||||||
{
|
|
||||||
drawingContext.DrawImage(
|
drawingContext.DrawImage(
|
||||||
_deviceImage,
|
_deviceImage,
|
||||||
new Rect(_deviceImage.Size),
|
new Rect(_deviceImage.Size),
|
||||||
new Rect(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height),
|
new Rect(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height),
|
||||||
RenderOptions.GetBitmapInterpolationMode(this)
|
RenderOptions.GetBitmapInterpolationMode(this)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
if (!ShowColors)
|
if (!ShowColors)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (_deviceVisualizerLeds)
|
lock (_deviceVisualizerLeds)
|
||||||
{
|
{
|
||||||
|
// Apply device scale
|
||||||
|
using DrawingContext.PushedState scalePush = drawingContext.PushPreTransform(Matrix.CreateScale(Device.Scale, Device.Scale));
|
||||||
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
|
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
|
||||||
deviceVisualizerLed.RenderGeometry(drawingContext, false);
|
deviceVisualizerLed.RenderGeometry(drawingContext, false);
|
||||||
}
|
}
|
||||||
@ -99,7 +95,7 @@ namespace Artemis.UI.Shared
|
|||||||
public event EventHandler<LedClickedEventArgs>? LedClicked;
|
public event EventHandler<LedClickedEventArgs>? LedClicked;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when the device was clicked but not on a LED.
|
/// Occurs when the device was clicked but not on a LED.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<PointerReleasedEventArgs>? Clicked;
|
public event EventHandler<PointerReleasedEventArgs>? Clicked;
|
||||||
|
|
||||||
@ -291,7 +287,7 @@ namespace Artemis.UI.Shared
|
|||||||
|
|
||||||
// Load the device main image on a background thread
|
// Load the device main image on a background thread
|
||||||
ArtemisDevice? device = Device;
|
ArtemisDevice? device = Device;
|
||||||
Task.Run(() =>
|
Dispatcher.UIThread.Post(() =>
|
||||||
{
|
{
|
||||||
if (device.Layout?.Image == null || !File.Exists(device.Layout.Image.LocalPath))
|
if (device.Layout?.Image == null || !File.Exists(device.Layout.Image.LocalPath))
|
||||||
{
|
{
|
||||||
@ -303,15 +299,17 @@ namespace Artemis.UI.Shared
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Create a bitmap that'll be used to render the device and LED images just once
|
// Create a bitmap that'll be used to render the device and LED images just once
|
||||||
RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) device.RgbDevice.Size.Width * 4, (int) device.RgbDevice.Size.Height * 4));
|
// Render 4 times the actual size of the device to make sure things look sharp when zoomed in
|
||||||
|
RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) device.RgbDevice.ActualSize.Width * 2, (int) device.RgbDevice.ActualSize.Height * 2));
|
||||||
|
|
||||||
using IDrawingContextImpl context = renderTargetBitmap.CreateDrawingContext(new ImmediateRenderer(this));
|
using IDrawingContextImpl context = renderTargetBitmap.CreateDrawingContext(new ImmediateRenderer(this));
|
||||||
using Bitmap bitmap = new(device.Layout.Image.LocalPath);
|
using Bitmap bitmap = new(device.Layout.Image.LocalPath);
|
||||||
context.DrawBitmap(bitmap.PlatformImpl, 1, new Rect(bitmap.Size), new Rect(renderTargetBitmap.Size), BitmapInterpolationMode.HighQuality);
|
context.DrawBitmap(bitmap.PlatformImpl, 1, new Rect(bitmap.Size), new Rect(renderTargetBitmap.Size), BitmapInterpolationMode.HighQuality);
|
||||||
|
|
||||||
lock (_deviceVisualizerLeds)
|
lock (_deviceVisualizerLeds)
|
||||||
{
|
{
|
||||||
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
|
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
|
||||||
deviceVisualizerLed.DrawBitmap(context);
|
deviceVisualizerLed.DrawBitmap(context, 2 * Device.Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
_deviceImage?.Dispose();
|
_deviceImage?.Dispose();
|
||||||
@ -319,11 +317,11 @@ namespace Artemis.UI.Shared
|
|||||||
|
|
||||||
Dispatcher.UIThread.Post(InvalidateMeasure);
|
Dispatcher.UIThread.Post(InvalidateMeasure);
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
});
|
}, DispatcherPriority.Background);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@ -40,7 +40,7 @@ namespace Artemis.UI.Shared
|
|||||||
public Rect LedRect { get; set; }
|
public Rect LedRect { get; set; }
|
||||||
public Geometry? DisplayGeometry { get; private set; }
|
public Geometry? DisplayGeometry { get; private set; }
|
||||||
|
|
||||||
public void DrawBitmap(IDrawingContextImpl drawingContext)
|
public void DrawBitmap(IDrawingContextImpl drawingContext, double scale)
|
||||||
{
|
{
|
||||||
if (Led.Layout?.Image == null || !File.Exists(Led.Layout.Image.LocalPath))
|
if (Led.Layout?.Image == null || !File.Exists(Led.Layout.Image.LocalPath))
|
||||||
return;
|
return;
|
||||||
@ -52,7 +52,7 @@ namespace Artemis.UI.Shared
|
|||||||
bitmap.PlatformImpl,
|
bitmap.PlatformImpl,
|
||||||
1,
|
1,
|
||||||
new Rect(bitmap.Size),
|
new Rect(bitmap.Size),
|
||||||
new Rect(Led.RgbLed.Location.X * 4, Led.RgbLed.Location.Y * 4, Led.RgbLed.Size.Width * 4, Led.RgbLed.Size.Height * 4),
|
new Rect(Led.RgbLed.Location.X * scale, Led.RgbLed.Location.Y * scale, Led.RgbLed.Size.Width * scale, Led.RgbLed.Size.Height * scale),
|
||||||
BitmapInterpolationMode.HighQuality
|
BitmapInterpolationMode.HighQuality
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,6 +72,8 @@
|
|||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="10 0"
|
Margin="10 0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
|
Increment="0.1"
|
||||||
|
FormatString="F1"
|
||||||
Value="{CompiledBinding Scale}" />
|
Value="{CompiledBinding Scale}" />
|
||||||
<TextBlock Grid.Row="3" Grid.Column="2" VerticalAlignment="Center">times</TextBlock>
|
<TextBlock Grid.Row="3" Grid.Column="2" VerticalAlignment="Center">times</TextBlock>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user