Switched WinUI projects to file-scoped namespaces
このコミットが含まれているのは:
1 親
c3ee451c0b
コミット
f2d410f270
13ファイル変更
+982
-995
検索条件に一致するファイルはありません
@@ -1,33 +1,32 @@
|
||||
using ComputeSharp.SwapChain.WinUI.Views;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI
|
||||
namespace ComputeSharp.SwapChain.WinUI;
|
||||
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides application-specific behavior to supplement the default Application class.
|
||||
/// The main application window
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
private Window? mainWindow;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
/// <summary>
|
||||
/// The main application window
|
||||
/// </summary>
|
||||
private Window? mainWindow;
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
/// </summary>
|
||||
public App()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
mainWindow = new MainWindow();
|
||||
mainWindow.Closed += (_, _) => Exit();
|
||||
mainWindow.Activate();
|
||||
}
|
||||
/// <inheritdoc/>
|
||||
protected override void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
mainWindow = new MainWindow();
|
||||
mainWindow.Closed += (_, _) => Exit();
|
||||
mainWindow.Activate();
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI.Converters
|
||||
namespace ComputeSharp.SwapChain.WinUI.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// A class with some static converters for rendering state.
|
||||
/// </summary>
|
||||
public static class RenderingPauseConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// A class with some static converters for rendering state.
|
||||
/// Gets a symbol for an input rendering state.
|
||||
/// </summary>
|
||||
public static class RenderingPauseConverter
|
||||
/// <param name="value">Whether or not the rendering is currently paaused.</param>
|
||||
/// <returns>A symbol representing the next action for the rendering.</returns>
|
||||
public static Symbol ConvertPausedToSymbol(bool value)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a symbol for an input rendering state.
|
||||
/// </summary>
|
||||
/// <param name="value">Whether or not the rendering is currently paaused.</param>
|
||||
/// <returns>A symbol representing the next action for the rendering.</returns>
|
||||
public static Symbol ConvertPausedToSymbol(bool value)
|
||||
{
|
||||
return value ? Symbol.Play : Symbol.Pause;
|
||||
}
|
||||
return value ? Symbol.Play : Symbol.Pause;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,27 @@
|
||||
namespace ComputeSharp.SwapChain.WinUI.Converters
|
||||
namespace ComputeSharp.SwapChain.WinUI.Converters;
|
||||
|
||||
/// <summary>
|
||||
/// A class with some static converters for resolution scale settings.
|
||||
/// </summary>
|
||||
public static class ResolutionScaleConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// A class with some static converters for resolution scale settings.
|
||||
/// Converts a resolution scale to a formatted string.
|
||||
/// </summary>
|
||||
public static class ResolutionScaleConverter
|
||||
/// <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)
|
||||
{
|
||||
/// <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}%";
|
||||
}
|
||||
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;
|
||||
}
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +1,43 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using ComputeSharp.WinUI;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI.Models
|
||||
namespace ComputeSharp.SwapChain.WinUI.Models;
|
||||
|
||||
/// <summary>
|
||||
/// A model for a compute shader.
|
||||
/// </summary>
|
||||
/// <remarks>This can be converted to a record when bindings are fixed, see notes in the XAML code.</remarks>
|
||||
public sealed class ComputeShader : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// A model for a compute shader.
|
||||
/// Creates a new <see cref="ComputeShader"/> instance.
|
||||
/// </summary>
|
||||
/// <remarks>This can be converted to a record when bindings are fixed, see notes in the XAML code.</remarks>
|
||||
public sealed class ComputeShader : ObservableObject
|
||||
/// <param name="name">The name of the shader.</param>
|
||||
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
|
||||
public ComputeShader(string name, IShaderRunner shaderRunner)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ComputeShader"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the shader.</param>
|
||||
/// <param name="shaderRunner">The <see cref="IShaderRunner"/> instance to execute.</param>
|
||||
public ComputeShader(string name, IShaderRunner shaderRunner)
|
||||
{
|
||||
Name = name;
|
||||
ShaderRunner = shaderRunner;
|
||||
}
|
||||
Name = name;
|
||||
ShaderRunner = shaderRunner;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the shader.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
/// <summary>
|
||||
/// Gets the name of the shader.
|
||||
/// </summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IShaderRunner"/> instance to execute.
|
||||
/// </summary>
|
||||
public IShaderRunner ShaderRunner { get; }
|
||||
/// <summary>
|
||||
/// Gets the <see cref="IShaderRunner"/> instance to execute.
|
||||
/// </summary>
|
||||
public IShaderRunner ShaderRunner { get; }
|
||||
|
||||
private bool isSelected;
|
||||
private bool isSelected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the current shader is selected.
|
||||
/// </summary>
|
||||
public bool IsSelected
|
||||
{
|
||||
get => this.isSelected;
|
||||
set => SetProperty(ref this.isSelected, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets whether the current shader is selected.
|
||||
/// </summary>
|
||||
public bool IsSelected
|
||||
{
|
||||
get => this.isSelected;
|
||||
set => SetProperty(ref this.isSelected, value);
|
||||
}
|
||||
}
|
||||
@@ -4,29 +4,28 @@ using ComputeSharp.SwapChain.Shaders;
|
||||
using ComputeSharp.WinUI;
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI.Shaders.Runners
|
||||
namespace ComputeSharp.SwapChain.WinUI.Shaders.Runners;
|
||||
|
||||
/// <summary>
|
||||
/// A specialized <see cref="IShaderRunner"/> for <see cref="ContouredLayers"/>.
|
||||
/// </summary>
|
||||
public sealed class ContouredLayersRunner : IShaderRunner
|
||||
{
|
||||
/// <summary>
|
||||
/// A specialized <see cref="IShaderRunner"/> for <see cref="ContouredLayers"/>.
|
||||
/// A texture for <c>\Textures\RustyMetal.png</c>.
|
||||
/// </summary>
|
||||
public sealed class ContouredLayersRunner : IShaderRunner
|
||||
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan)
|
||||
{
|
||||
/// <summary>
|
||||
/// A texture for <c>\Textures\RustyMetal.png</c>.
|
||||
/// </summary>
|
||||
private ReadOnlyTexture2D<Rgba32, Float4>? texture;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute(IReadWriteTexture2D<Float4> texture, TimeSpan timespan)
|
||||
if (this.texture is null)
|
||||
{
|
||||
if (this.texture is null)
|
||||
{
|
||||
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
|
||||
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
|
||||
|
||||
this.texture = Gpu.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
|
||||
}
|
||||
|
||||
Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
|
||||
this.texture = Gpu.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
|
||||
}
|
||||
|
||||
Gpu.Default.ForEach(texture, new ContouredLayers((float)timespan.TotalSeconds, this.texture));
|
||||
}
|
||||
}
|
||||
@@ -6,72 +6,72 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ComputeSharp.SwapChain.WinUI.Shaders.Runners;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI.ViewModels
|
||||
namespace ComputeSharp.SwapChain.WinUI.ViewModels;
|
||||
|
||||
/// <summary>
|
||||
/// The viewmodel for for a view that allows users to select shaders and customize settings.
|
||||
/// </summary>
|
||||
public sealed class MainViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// The viewmodel for for a view that allows users to select shaders and customize settings.
|
||||
/// Creates a new <see cref="MainViewModel"/> instance.
|
||||
/// </summary>
|
||||
public sealed class MainViewModel : ObservableObject
|
||||
public MainViewModel()
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MainViewModel"/> instance.
|
||||
/// </summary>
|
||||
public MainViewModel()
|
||||
{
|
||||
this.isDynamicResolutionEnabled = true;
|
||||
this.selectedResolutionScale = 100;
|
||||
this.selectedComputeShader = ComputeShaderOptions[0];
|
||||
this.selectedComputeShader.IsSelected = true;
|
||||
this.isDynamicResolutionEnabled = true;
|
||||
this.selectedResolutionScale = 100;
|
||||
this.selectedComputeShader = ComputeShaderOptions[0];
|
||||
this.selectedComputeShader.IsSelected = true;
|
||||
|
||||
SetResolutionScaleCommand = new RelayCommand<int>(SetResolutionScale);
|
||||
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
|
||||
}
|
||||
SetResolutionScaleCommand = new RelayCommand<int>(SetResolutionScale);
|
||||
ToggleRenderingPausedCommand = new RelayCommand(ToggleRenderingPaused);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the available resolution scaling options (as percentage values).
|
||||
/// </summary>
|
||||
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
|
||||
/// <summary>
|
||||
/// Gets the available resolution scaling options (as percentage values).
|
||||
/// </summary>
|
||||
public IList<int> ResolutionScaleOptions { get; } = new[] { 25, 50, 75, 100 };
|
||||
|
||||
private bool isDynamicResolutionEnabled;
|
||||
private bool isDynamicResolutionEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the dynamic resolution is enabled.
|
||||
/// </summary>
|
||||
public bool IsDynamicResolutionEnabled
|
||||
{
|
||||
get => this.isDynamicResolutionEnabled;
|
||||
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets whether the dynamic resolution is enabled.
|
||||
/// </summary>
|
||||
public bool IsDynamicResolutionEnabled
|
||||
{
|
||||
get => this.isDynamicResolutionEnabled;
|
||||
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
|
||||
}
|
||||
|
||||
private int selectedResolutionScale;
|
||||
private int selectedResolutionScale;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the currently selected resolution scale setting (as percentage valaue).
|
||||
/// </summary>
|
||||
public int SelectedResolutionScale
|
||||
{
|
||||
get => this.selectedResolutionScale;
|
||||
private set => SetProperty(ref this.selectedResolutionScale, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the currently selected resolution scale setting (as percentage valaue).
|
||||
/// </summary>
|
||||
public int SelectedResolutionScale
|
||||
{
|
||||
get => this.selectedResolutionScale;
|
||||
private set => SetProperty(ref this.selectedResolutionScale, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command that sets <see cref="SelectedResolutionScale"/>.
|
||||
/// </summary>
|
||||
public IRelayCommand SetResolutionScaleCommand { get; }
|
||||
/// <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>
|
||||
/// Sets <see cref="SelectedResolutionScale"/>.
|
||||
/// </summary>
|
||||
private void SetResolutionScale(int resolutionScale)
|
||||
{
|
||||
SelectedResolutionScale = resolutionScale;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of available compute shader.
|
||||
/// </summary>
|
||||
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the collection of available compute shader.
|
||||
/// </summary>
|
||||
public IReadOnlyList<ComputeShader> ComputeShaderOptions { get; } = new ComputeShader[]
|
||||
{
|
||||
new("Colorful infinity", new ShaderRunner<ColorfulInfinity>(static time => new((float)time.TotalSeconds))),
|
||||
new("Extruded truchet", new ShaderRunner<ExtrudedTruchetPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Fractal tiling", new ShaderRunner<FractalTiling>(static time => new((float)time.TotalSeconds))),
|
||||
@@ -82,50 +82,49 @@ namespace ComputeSharp.SwapChain.WinUI.ViewModels
|
||||
new("Pyramid pattern", new ShaderRunner<PyramidPattern>(static time => new((float)time.TotalSeconds))),
|
||||
new("Triangle grid contouring", new ShaderRunner<TriangleGridContouring>(static time => new((float)time.TotalSeconds))),
|
||||
new("Contoured layers", new ContouredLayersRunner())
|
||||
};
|
||||
};
|
||||
|
||||
private ComputeShader selectedComputeShader;
|
||||
private ComputeShader selectedComputeShader;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected compute shader.
|
||||
/// </summary>
|
||||
public ComputeShader SelectedComputeShader
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected compute shader.
|
||||
/// </summary>
|
||||
public ComputeShader SelectedComputeShader
|
||||
{
|
||||
get => this.selectedComputeShader;
|
||||
set
|
||||
{
|
||||
get => this.selectedComputeShader;
|
||||
set
|
||||
{
|
||||
this.selectedComputeShader.IsSelected = false;
|
||||
this.selectedComputeShader.IsSelected = false;
|
||||
|
||||
if (SetProperty(ref this.selectedComputeShader, value) &&
|
||||
value is not null)
|
||||
{
|
||||
value.IsSelected = true;
|
||||
}
|
||||
if (SetProperty(ref this.selectedComputeShader, value) &&
|
||||
value is not null)
|
||||
{
|
||||
value.IsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool isRenderingPaused;
|
||||
private bool isRenderingPaused;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether the rendering is currently paused.
|
||||
/// </summary>
|
||||
public bool IsRenderingPaused
|
||||
{
|
||||
get => this.isRenderingPaused;
|
||||
set => SetProperty(ref this.isRenderingPaused, value);
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets whether the rendering is currently paused.
|
||||
/// </summary>
|
||||
public bool IsRenderingPaused
|
||||
{
|
||||
get => this.isRenderingPaused;
|
||||
set => SetProperty(ref this.isRenderingPaused, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the command that toggles <see cref="IsRenderingPaused"/>.
|
||||
/// </summary>
|
||||
public IRelayCommand ToggleRenderingPausedCommand { get; }
|
||||
/// <summary>
|
||||
/// Gets the command that toggles <see cref="IsRenderingPaused"/>.
|
||||
/// </summary>
|
||||
public IRelayCommand ToggleRenderingPausedCommand { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Toggles <see cref="IsRenderingPaused"/>.
|
||||
/// </summary>
|
||||
private void ToggleRenderingPaused()
|
||||
{
|
||||
IsRenderingPaused = !IsRenderingPaused;
|
||||
}
|
||||
/// <summary>
|
||||
/// Toggles <see cref="IsRenderingPaused"/>.
|
||||
/// </summary>
|
||||
private void ToggleRenderingPaused()
|
||||
{
|
||||
IsRenderingPaused = !IsRenderingPaused;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,31 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
|
||||
namespace ComputeSharp.SwapChain.WinUI.Views
|
||||
namespace ComputeSharp.SwapChain.WinUI.Views;
|
||||
|
||||
/// <summary>
|
||||
/// A view for <see cref="MainViewModel"/>.
|
||||
/// </summary>
|
||||
public sealed partial class MainWindow : Window
|
||||
{
|
||||
/// <summary>
|
||||
/// A view for <see cref="MainViewModel"/>.
|
||||
/// </summary>
|
||||
public sealed partial class MainWindow : Window
|
||||
public MainWindow()
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.ExtendsContentIntoTitleBar = true;
|
||||
this.InitializeComponent();
|
||||
this.ExtendsContentIntoTitleBar = true;
|
||||
|
||||
SetTitleBar(TitleBarRectangle);
|
||||
}
|
||||
SetTitleBar(TitleBarRectangle);
|
||||
}
|
||||
|
||||
// Opens the shader selection panel
|
||||
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Root.Resources.Remove("ShaderSelectionPanel");
|
||||
Root.Children.Add(ShaderSelectionPanel);
|
||||
}
|
||||
// Opens the shader selection panel
|
||||
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Root.Resources.Remove("ShaderSelectionPanel");
|
||||
Root.Children.Add(ShaderSelectionPanel);
|
||||
}
|
||||
|
||||
// Hides the shader selection panel
|
||||
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
Root.Children.Remove(ShaderSelectionPanel);
|
||||
}
|
||||
// Hides the shader selection panel
|
||||
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
Root.Children.Remove(ShaderSelectionPanel);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする