Skip to content

Commit 7049bb7

Browse files
committed
Merge branch 'release/v2.2'
2 parents 33d134a + 66d3e29 commit 7049bb7

File tree

15 files changed

+122
-18
lines changed

15 files changed

+122
-18
lines changed

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040

4141
steps:
4242
- name: Checkout repository
43-
uses: actions/checkout@v5
43+
uses: actions/checkout@v6
4444
with:
4545
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
4646

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: windows-latest
1616

1717
steps:
18-
- uses: actions/checkout@v5
18+
- uses: actions/checkout@v6
1919
with:
2020
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
2121
- name: Setup .NET

StreamDeckSimHub.Installer/Tools/Configuration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2024 Martin Renner
1+
// Copyright (C) 2025 Martin Renner
22
// LGPL-3.0-or-later (see file COPYING and COPYING.LESSER)
33

44
using System;
@@ -24,9 +24,9 @@ public static class Configuration
2424

2525
public const string SimHubRegistryFolder = @"HKEY_CURRENT_USER\Software\SimHub";
2626
public const string SimHubRegistryInstallFolder = "InstallDirectory";
27-
public static readonly string SimHubDefaultInstallFolder = Path.Combine("C:", "Program Files (x86)", "SimHub");
27+
public static readonly string SimHubDefaultInstallFolder = Path.Combine(@"C:\", "Program Files (x86)", "SimHub");
2828

2929
public const string SimHubPluginUrl = "https://github.com/pre-martin/SimHubPropertyServer";
30-
public static readonly Version RequiredSimHubPluginVersion = new Version(1, 12, 0);
30+
public static readonly Version RequiredSimHubPluginVersion = new Version(1, 13, 0);
3131
}
3232
}

StreamDeckSimHub.Plugin/Actions/GenericButton/CommandItemHandler.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,6 @@ public async Task Visit(CommandItemSimHubRole commandItem, StreamDeckAction acti
269269
#endregion
270270
}
271271

272-
internal class SalHandlerArgs(StreamDeckAction action) : IHandlerArgs
273-
{
274-
public StreamDeckAction Action { get; } = action;
275-
}
272+
internal record SalHandlerArgs(StreamDeckAction Action) : IHandlerArgs;
276273

277-
internal class DialVisitorArgs(int ticks) : IVisitorArgs
278-
{
279-
public int Ticks { get; } = ticks;
280-
}
274+
internal record DialVisitorArgs(int Ticks) : IVisitorArgs;

StreamDeckSimHub.Plugin/Actions/GenericButton/GenericButtonAction.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace StreamDeckSimHub.Plugin.Actions.GenericButton;
2929
public class GenericButtonAction : StreamDeckAction<SettingsDto>
3030
{
3131
private readonly SettingsConverter _settingsConverter;
32+
private readonly ItemScaler _itemScaler;
3233
private readonly ImageManager _imageManager;
3334
private readonly ActionEditorManager _actionEditorManager;
3435
private readonly ISimHubConnection _simHubConnection;
@@ -45,12 +46,14 @@ public class GenericButtonAction : StreamDeckAction<SettingsDto>
4546

4647
public GenericButtonAction(
4748
SettingsConverter settingsConverter,
49+
ItemScaler itemScaler,
4850
ImageManager imageManager,
4951
ActionEditorManager actionEditorManager,
5052
ISimHubConnection simHubConnection,
5153
NCalcHandler ncalcHandler)
5254
{
5355
_settingsConverter = settingsConverter;
56+
_itemScaler = itemScaler;
5457
_imageManager = imageManager;
5558
_actionEditorManager = actionEditorManager;
5659
_simHubConnection = simHubConnection;
@@ -251,10 +254,17 @@ private async Task<Settings> ConvertSettings(SettingsDto dto, StreamDeckKeyInfo
251254
}
252255
else if (settings.KeySize != sdKeyInfo.KeySize)
253256
{
254-
// GenericButton is used on a different StreamDeck key. Scale it.
255-
// TODO Scale, update KeyInfo and save config with SetSettings()
256-
Logger.LogWarning("({coords}) Key size changed from {old} to {new}", _coordinates, settings.KeySize,
257-
sdKeyInfo.KeySize);
257+
// GenericButton is used on a StreamDeck key/dial with different size. Scale it.
258+
Logger.LogWarning("({coords}) Action is being used on a key/dial with different size ({old} to {new})",
259+
_coordinates, settings.KeySize, sdKeyInfo.KeySize);
260+
261+
var scaleFactorX = (float)sdKeyInfo.KeySize.Width / settings.KeySize.Width;
262+
var scaleFactorY = (float)sdKeyInfo.KeySize.Height / settings.KeySize.Height;
263+
await _itemScaler.ScaleDisplayItems(settings.DisplayItems, scaleFactorX, scaleFactorY);
264+
settings.KeySize = sdKeyInfo.KeySize;
265+
settingsModified = true;
266+
Logger.LogInformation("({coords}) Scaled action by factors x={fx:F2}, y={fy:F2}",
267+
_coordinates, scaleFactorX, scaleFactorY);
258268
}
259269

260270
if (settingsModified)

StreamDeckSimHub.Plugin/Actions/GenericButton/Model/DisplayItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ namespace StreamDeckSimHub.Plugin.Actions.GenericButton.Model;
88
public abstract partial class DisplayItem : Item
99
{
1010
[ObservableProperty] private DisplayParameters _displayParameters = new();
11+
12+
public abstract Task Accept(IDisplayItemVisitor displayItemVisitor, IVisitorArgs? args = null);
1113
}

StreamDeckSimHub.Plugin/Actions/GenericButton/Model/DisplayItemImage.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@ public static DisplayItemImage Create()
2323
{
2424
return new DisplayItemImage();
2525
}
26+
27+
public override async Task Accept(IDisplayItemVisitor displayItemVisitor, IVisitorArgs? args = null)
28+
{
29+
await displayItemVisitor.Visit(this, args);
30+
}
2631
}

StreamDeckSimHub.Plugin/Actions/GenericButton/Model/DisplayItemText.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ public static DisplayItemText Create()
2222
{
2323
return new DisplayItemText();
2424
}
25+
26+
public override async Task Accept(IDisplayItemVisitor displayItemVisitor, IVisitorArgs? args = null)
27+
{
28+
await displayItemVisitor.Visit(this, args);
29+
}
2530
}

StreamDeckSimHub.Plugin/Actions/GenericButton/Model/DisplayItemValue.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@ public static DisplayItemValue Create()
3939
{
4040
return new DisplayItemValue();
4141
}
42+
43+
public override async Task Accept(IDisplayItemVisitor displayItemVisitor, IVisitorArgs? args = null)
44+
{
45+
await displayItemVisitor.Visit(this, args);
46+
}
4247
}
4348

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (C) 2025 Martin Renner
2+
// LGPL-3.0-or-later (see file COPYING and COPYING.LESSER)
3+
4+
using System.Collections.ObjectModel;
5+
using SixLabors.ImageSharp;
6+
7+
namespace StreamDeckSimHub.Plugin.Actions.GenericButton.Model;
8+
9+
/// <summary>
10+
/// Scales display items by a given factor.
11+
/// </summary>
12+
public class ItemScaler : IDisplayItemVisitor
13+
{
14+
public async Task ScaleDisplayItems(Collection<DisplayItem> settingsDisplayItems, float scaleFactorX, float scaleFactorY)
15+
{
16+
foreach (var displayItem in settingsDisplayItems)
17+
{
18+
await displayItem.Accept(this, new ItemScalerArgs(scaleFactorX, scaleFactorY));
19+
}
20+
}
21+
22+
private void ScaleDisplayParameters(DisplayParameters displayParameters, ItemScalerArgs args)
23+
{
24+
displayParameters.Position = new Point(
25+
(int)(args.ScaleFactorX * displayParameters.Position.X),
26+
(int)(args.ScaleFactorY * displayParameters.Position.Y));
27+
28+
if (displayParameters.Size != null)
29+
{
30+
displayParameters.Size = new Size(
31+
(int)(args.ScaleFactorX * displayParameters.Size.Value.Width),
32+
(int)(args.ScaleFactorY * displayParameters.Size.Value.Height));
33+
}
34+
}
35+
36+
#region IDisplayItemVisitor
37+
38+
public Task Visit(DisplayItemImage displayItem, IVisitorArgs? args)
39+
{
40+
var scalerArgs = args as ItemScalerArgs ?? new ItemScalerArgs(1, 1);
41+
ScaleDisplayParameters(displayItem.DisplayParameters, scalerArgs);
42+
return Task.CompletedTask;
43+
}
44+
45+
public Task Visit(DisplayItemText displayItem, IVisitorArgs? args)
46+
{
47+
var scalerArgs = args as ItemScalerArgs ?? new ItemScalerArgs(1, 1);
48+
ScaleDisplayParameters(displayItem.DisplayParameters, scalerArgs);
49+
// Font size is automatically scaled during rendering (see ButtonRendererImageSharp#ScaleFont).
50+
return Task.CompletedTask;
51+
}
52+
53+
public Task Visit(DisplayItemValue displayItem, IVisitorArgs? args)
54+
{
55+
var scalerArgs = args as ItemScalerArgs ?? new ItemScalerArgs(1, 1);
56+
ScaleDisplayParameters(displayItem.DisplayParameters, scalerArgs);
57+
// Font size is automatically scaled during rendering (see ButtonRendererImageSharp#ScaleFont).
58+
return Task.CompletedTask;
59+
}
60+
61+
#endregion
62+
}
63+
64+
internal record ItemScalerArgs(float ScaleFactorX, float ScaleFactorY) : IVisitorArgs;

0 commit comments

Comments
 (0)