diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/App.xaml b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/App.xaml index b87dceb4..6429e2e4 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/App.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/App.xaml @@ -1,8 +1,7 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/ResolutionScaleConverter.cs b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/ResolutionScaleConverter.cs new file mode 100644 index 00000000..de1408b4 --- /dev/null +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Converters/ResolutionScaleConverter.cs @@ -0,0 +1,28 @@ +namespace ComputeSharp.SwapChain.WinUI.Converters +{ + /// + /// A class with some static converters for resolution scale settings. + /// + public static class ResolutionScaleConverter + { + /// + /// Converts a resolution scale to a formatted string. + /// + /// The input resolution scale (in percentage). + /// A formatted percentage string for . + public static string ConvertPercentageToFormattedString(int value) + { + return $"{value}%"; + } + + /// + /// Converts a percentage value to a scaled value in the [0, 1] range. + /// + /// The input percentage value to scale. + /// The input percentage scaled to the [0, 1] range. + public static double ConvertPercentageToScale(int value) + { + return value / 100.0; + } + } +} diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs index c71153fb..51bd210a 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/ViewModels/MainViewModel.cs @@ -21,23 +21,37 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels this.selectedComputeShader = ComputeShaderOptions[0]; this.selectedComputeShader.IsSelected = true; + SetResolutionScaleCommand = new RelayCommand(SetResolutionScale); ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused); } /// /// Gets the available resolution scaling options (as percentage values). /// - public IReadOnlyList ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 }; + public IList ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 }; private int selectedResolutionScale; /// - /// Gets or sets the currently selected resolution scale setting (as percentage valaue). + /// Gets the currently selected resolution scale setting (as percentage valaue). /// public int SelectedResolutionScale { get => this.selectedResolutionScale; - set => SetProperty(ref this.selectedResolutionScale, value); + private set => SetProperty(ref this.selectedResolutionScale, value); + } + + /// + /// Gets the command that sets . + /// + public IRelayCommand SetResolutionScaleCommand { get; } + + /// + /// Sets . + /// + private void SetResolutionScale(int resolutionScale) + { + SelectedResolutionScale = resolutionScale; } /// diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml index 8648baea..f2067ab5 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml @@ -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}"/> @@ -56,7 +56,7 @@ Padding="20" CornerRadius="9999" ToolTipService.ToolTip="Select shader" - Click="Button_Click"> + Click="OpenShaderSelectionPanelButton_Click"> @@ -66,6 +66,30 @@ CornerRadius="9999" ToolTipService.ToolTip="Settings"> + + + + + + + + diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs index 997922da..5593ff0f 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI/Views/MainWindow.xaml.cs @@ -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;