Enabled resolution scaling setting

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-20 00:27:59 +01:00
1 親 255db239ea
コミット 2c13b3ed85
5ファイル変更
+75 -8

検索条件に一致するファイルはありません

+1 -2
ファイルの表示
@@ -1,8 +1,7 @@
<Application
x:Class="ComputeSharp.SwapChain.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ComputeSharp.SwapChain.WinUI">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
@@ -0,0 +1,28 @@
namespace ComputeSharp.SwapChain.WinUI.Converters
{
/// <summary>
/// A class with some static converters for resolution scale settings.
/// </summary>
public static class ResolutionScaleConverter
{
/// <summary>
/// Converts a resolution scale to a formatted string.
/// </summary>
/// <param name="value">The input resolution scale (in percentage).</param>
/// <returns>A formatted percentage string for <paramref name="value"/>.</returns>
public static string ConvertPercentageToFormattedString(int value)
{
return $"{value}%";
}
/// <summary>
/// Converts a percentage value to a scaled value in the [0, 1] range.
/// </summary>
/// <param name="value">The input percentage value to scale.</param>
/// <returns>The input percentage scaled to the [0, 1] range.</returns>
public static double ConvertPercentageToScale(int value)
{
return value / 100.0;
}
}
}
@@ -21,23 +21,37 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels
this.selectedComputeShader = ComputeShaderOptions[0];
this.selectedComputeShader.IsSelected = true;
SetResolutionScaleCommand = new RelayCommand<int>(SetResolutionScale);
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
}
/// <summary>
/// Gets the available resolution scaling options (as percentage values).
/// </summary>
public IReadOnlyList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
private int selectedResolutionScale;
/// <summary>
/// Gets or sets the currently selected resolution scale setting (as percentage valaue).
/// Gets the currently selected resolution scale setting (as percentage valaue).
/// </summary>
public int SelectedResolutionScale
{
get => this.selectedResolutionScale;
set => SetProperty(ref this.selectedResolutionScale, value);
private set => SetProperty(ref this.selectedResolutionScale, value);
}
/// <summary>
/// Gets the command that sets <see cref="SelectedResolutionScale"/>.
/// </summary>
public IRelayCommand SetResolutionScaleCommand { get; }
/// <summary>
/// Sets <see cref="SelectedResolutionScale"/>.
/// </summary>
private void SetResolutionScale(int resolutionScale)
{
SelectedResolutionScale = resolutionScale;
}
/// <summary>
+26 -2
ファイルの表示
@@ -24,7 +24,7 @@
x:Name="ShaderPanel"
Grid.Row="1"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}"
ResolutionScale="{x:Bind ViewModel.SelectedResolutionScale, Mode=OneWay}"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"/>
<!--Invisible title bar-->
@@ -56,7 +56,7 @@
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Select shader"
Click="Button_Click">
Click="OpenShaderSelectionPanelButton_Click">
<SymbolIcon Symbol="Pictures"/>
</Button>
@@ -66,6 +66,30 @@
CornerRadius="9999"
ToolTipService.ToolTip="Settings">
<SymbolIcon Symbol="Setting"/>
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[0])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[0]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[0]), Mode=OneWay}"/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[1])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[1]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[1]), Mode=OneWay}"/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[2])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[2]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[2]), Mode=OneWay}"/>
<ToggleMenuFlyoutItem
Text="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToFormattedString(ViewModel.ResolutionScaleOptions[3])}"
Command="{x:Bind ViewModel.SetResolutionScaleCommand}"
CommandParameter="{x:Bind ViewModel.ResolutionScaleOptions[3]}"
IsChecked="{x:Bind ViewModel.SelectedResolutionScale.Equals(ViewModel.ResolutionScaleOptions[3]), Mode=OneWay}"/>
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
@@ -16,11 +16,13 @@ namespace ComputeSharp.SwapChain.WinUI.Views
SetTitleBar(TitleBarRectangle);
}
private void Button_Click(object sender, RoutedEventArgs e)
// Opens the shader selection panel
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
{
ShaderSelectionPanel.Visibility = Visibility.Visible;
}
// Hides the shader selection panel
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
{
ShaderSelectionPanel.Visibility = Visibility.Collapsed;