Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
gunt3001 committed Jul 22, 2024
2 parents 627db46 + eef10eb commit 5208941
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion HsrGraphicsTool/HsrGraphicsTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<Version>1.2</Version>
<Version>1.3</Version>
<PublishSingleFile>true</PublishSingleFile>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
Expand All @@ -26,5 +26,6 @@
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.0.10" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.0.10" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
<PackageReference Include="System.Drawing.Common" Version="8.0.7" />
</ItemGroup>
</Project>
31 changes: 31 additions & 0 deletions HsrGraphicsTool/Models/DisplayUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Drawing;
using System.Runtime.InteropServices;

namespace HsrGraphicsTool.Models;

/// <summary>
/// Utilities for capturing Windows display information using the Windows GDI API.
/// Adapted from this S/O answer: https://stackoverflow.com/a/76670176
/// </summary>
public static class DisplayUtils
{
[DllImport("gdi32.dll")]
private static extern int GetDeviceCaps(nint hdc, int nIndex);

private enum DeviceCap
{
Desktopvertres = 117,
Desktophorzres = 118
}

public static Size GetPhysicalDisplaySize()
{
var g = Graphics.FromHwnd(nint.Zero);
var desktop = g.GetHdc();

var physicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.Desktopvertres);
var physicalScreenWidth = GetDeviceCaps(desktop, (int)DeviceCap.Desktophorzres);

return new Size(physicalScreenWidth, physicalScreenHeight);
}
}
8 changes: 8 additions & 0 deletions HsrGraphicsTool/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public class MainWindowViewModel : ViewModelBase

// Commands

public ReactiveCommand<Unit, Unit>? UsePrimaryMonitorResolution { get; }
public ReactiveCommand<Unit, Unit>? DiscardChanges { get; }
public ReactiveCommand<Unit, Unit>? ApplyChanges { get; }

Expand Down Expand Up @@ -208,6 +209,13 @@ public MainWindowViewModel(IHsrRegistryManager hsrRegistryManager)
.Subscribe(_ => { GraphicsPreset = GraphicsPresetOption.Custom; });

// Button commands
// Using primary montior resolution
UsePrimaryMonitorResolution = ReactiveCommand.Create(() =>
{
var screenSize = DisplayUtils.GetPhysicalDisplaySize();
Width = screenSize.Width;
Height = screenSize.Height;
});
// Reverting changes
DiscardChanges = ReactiveCommand.Create(() => ApplyConfigToProperties(LastKnownConfig));
// Applying changes
Expand Down
6 changes: 5 additions & 1 deletion HsrGraphicsTool/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<StackPanel Margin="10" IsVisible="{Binding !IsControlsDisabled}">
<TextBlock Classes="header">Graphics Settings</TextBlock>
<!-- Resolution options -->
<Grid Classes="option" ColumnDefinitions="140, 270">
<Grid Classes="option" ColumnDefinitions="140, 270" RowDefinitions="Auto, Auto">
<TextBlock Classes="option-label">Resolution</TextBlock>
<StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="8" HorizontalAlignment="Right">
<NumericUpDown ShowButtonSpinner="False" Minimum="1" Increment="128" FormatString="0"
Expand All @@ -75,6 +75,10 @@
Value="{Binding Height}" Width="50" />
<CheckBox IsChecked="{Binding IsFullscreen}">Full screen</CheckBox>
</StackPanel>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding UsePrimaryMonitorResolution}"
Classes="action">
Use primary monitor resolution
</Button>
</Grid>
<Grid Classes="option" ColumnDefinitions="140, 270">
<TextBlock Classes="option-label">Graphics quality</TextBlock>
Expand Down

0 comments on commit 5208941

Please sign in to comment.