mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Router - Added reload
Workshop - Added image management to existing entries Workshop - Fixed pagination in layouts page
This commit is contained in:
1 parent
19082481c3
commit
78b96deeab
25 files changed
+328
-100
No files matched your search
@@ -19,14 +19,16 @@ public static class ArtemisLayoutExtensions
|
||||
/// Renders the layout to a bitmap.
|
||||
/// </summary>
|
||||
/// <param name="layout">The layout to render</param>
|
||||
/// <param name="previewLeds">A value indicating whether or not to draw LEDs on the image.</param>
|
||||
/// <param name="scale">The scale at which to draw the layout.</param>
|
||||
/// <returns>The resulting bitmap.</returns>
|
||||
public static RenderTargetBitmap RenderLayout(this ArtemisLayout layout, bool previewLeds)
|
||||
public static RenderTargetBitmap RenderLayout(this ArtemisLayout layout, bool previewLeds, int scale = 2)
|
||||
{
|
||||
string? path = layout.Image?.LocalPath;
|
||||
|
||||
// Create a bitmap that'll be used to render the device and LED images just once
|
||||
// Render 4 times the actual size of the device to make sure things look sharp when zoomed in
|
||||
RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) layout.RgbLayout.Width * 2, (int) layout.RgbLayout.Height * 2));
|
||||
RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) layout.RgbLayout.Width * scale, (int) layout.RgbLayout.Height * scale));
|
||||
|
||||
using DrawingContext context = renderTargetBitmap.CreateDrawingContext();
|
||||
|
||||
@@ -45,8 +47,8 @@ public static class ArtemisLayoutExtensions
|
||||
if (ledPath == null || !File.Exists(ledPath))
|
||||
continue;
|
||||
using Bitmap bitmap = new(ledPath);
|
||||
using Bitmap scaledBitmap = bitmap.CreateScaledBitmap(new PixelSize((led.RgbLayout.Width * 2).RoundToInt(), (led.RgbLayout.Height * 2).RoundToInt()));
|
||||
context.DrawImage(scaledBitmap, new Rect(led.RgbLayout.X * 2, led.RgbLayout.Y * 2, scaledBitmap.Size.Width, scaledBitmap.Size.Height));
|
||||
using Bitmap scaledBitmap = bitmap.CreateScaledBitmap(new PixelSize((led.RgbLayout.Width * scale).RoundToInt(), (led.RgbLayout.Height * scale).RoundToInt()));
|
||||
context.DrawImage(scaledBitmap, new Rect(led.RgbLayout.X * scale, led.RgbLayout.Y * scale, scaledBitmap.Size.Width, scaledBitmap.Size.Height));
|
||||
}
|
||||
|
||||
if (!previewLeds)
|
||||
@@ -55,14 +57,14 @@ public static class ArtemisLayoutExtensions
|
||||
// Draw LED geometry using a rainbow gradient
|
||||
ColorGradient colors = ColorGradient.GetUnicornBarf();
|
||||
colors.ToggleSeamless();
|
||||
context.PushTransform(Matrix.CreateScale(2, 2));
|
||||
context.PushTransform(Matrix.CreateScale(scale, scale));
|
||||
foreach (ArtemisLedLayout led in layout.Leds)
|
||||
{
|
||||
Geometry? geometry = CreateLedGeometry(led);
|
||||
if (geometry == null)
|
||||
continue;
|
||||
|
||||
Color color = colors.GetColor((led.RgbLayout.X + led.RgbLayout.Width / 2) / layout.RgbLayout.Width).ToColor();
|
||||
Color color = colors.GetColor((led.RgbLayout.X + led.RgbLayout.Width / scale) / layout.RgbLayout.Width).ToColor();
|
||||
SolidColorBrush fillBrush = new() {Color = color, Opacity = 0.4};
|
||||
SolidColorBrush penBrush = new() {Color = color};
|
||||
Pen pen = new(penBrush) {LineJoin = PenLineJoin.Round};
|
||||
|
||||
@@ -27,6 +27,12 @@ public interface IRouter
|
||||
/// <param name="options">Optional navigation options used to control navigation behaviour.</param>
|
||||
/// <returns>A task representing the operation</returns>
|
||||
Task Navigate(string path, RouterNavigationOptions? options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously reloads the current route
|
||||
/// </summary>
|
||||
/// <returns>A task representing the operation</returns>
|
||||
Task Reload();
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously navigates back to the previous active route.
|
||||
|
||||
@@ -79,6 +79,19 @@ internal class Router : CorePropertyChanged, IRouter, IDisposable
|
||||
await Dispatcher.UIThread.InvokeAsync(() => InternalNavigate(path, options));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task Reload()
|
||||
{
|
||||
string path = _currentRouteSubject.Value ?? "blank";
|
||||
|
||||
// Routing takes place on the UI thread with processing heavy tasks offloaded by the router itself
|
||||
await Dispatcher.UIThread.InvokeAsync(async () =>
|
||||
{
|
||||
await InternalNavigate("blank", new RouterNavigationOptions {AddToHistory = false, RecycleScreens = false, EnableLogging = false});
|
||||
await InternalNavigate(path, new RouterNavigationOptions {AddToHistory = false, RecycleScreens = false});
|
||||
});
|
||||
}
|
||||
|
||||
private async Task InternalNavigate(string path, RouterNavigationOptions options)
|
||||
{
|
||||
if (_root == null)
|
||||
|
||||
Reference in new issue
Block a user