Migrated WinUI 3 sample UI elements

このコミットが含まれているのは:
Sergio Pedri committed 2021-11-20 00:29:37 +01:00
1 親 75d2fbb2e8
コミット 7db58d0a0c
7ファイル変更
+16 -86

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

+2 -5
ファイルの表示
@@ -1,15 +1,12 @@
<Application
x:Class="ComputeSharp.WinUI3.App"
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.WinUI3">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</Application>
+13 -31
ファイルの表示
@@ -1,31 +1,18 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Shapes;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using ComputeSharp.SwapChain.WinUI.Views;
using Microsoft.UI.Xaml;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ComputeSharp.WinUI3
namespace ComputeSharp.SwapChain.WinUI
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// The main application window
/// </summary>
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().
@@ -35,17 +22,12 @@ namespace ComputeSharp.WinUI3
this.InitializeComponent();
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
/// <inheritdoc/>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
mainWindow = new MainWindow();
mainWindow.Closed += (_, _) => Exit();
mainWindow.Activate();
}
private Window m_window;
}
}
-13
ファイルの表示
@@ -1,13 +0,0 @@
<Window
x:Class="ComputeSharp.WinUI3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ComputeSharp.WinUI3"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
</Window>
-36
ファイルの表示
@@ -1,36 +0,0 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ComputeSharp.WinUI3
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
}
private void myButton_Click(object sender, RoutedEventArgs e)
{
myButton.Content = "Clicked";
}
}
}
+1 -1
ファイルの表示
@@ -21,7 +21,7 @@ namespace ComputeSharp.SwapChain.WinUI.Shaders.Runners
{
if (this.texture is null)
{
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Images", "Textures", "RustyMetal.png");
string filename = Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Textures", "RustyMetal.png");
this.texture = Gpu.Default.LoadReadOnlyTexture2D<Rgba32, Float4>(filename);
}
+212
ファイルの表示
@@ -0,0 +1,212 @@
<Window
x:Class="ComputeSharp.SwapChain.WinUI.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:ui="using:CommunityToolkit.WinUI.UI"
xmlns:animations="using:CommunityToolkit.WinUI.UI.Animations"
xmlns:media="using:CommunityToolkit.WinUI.UI.Media"
xmlns:computesharp="using:ComputeSharp.WinUI"
xmlns:converters="using:ComputeSharp.SwapChain.WinUI.Converters"
xmlns:viewmodels="using:ComputeSharp.SwapChain.WinUI.ViewModels"
xmlns:models="using:ComputeSharp.SwapChain.WinUI.Models"
mc:Ignorable="d">
<Grid x:Name="Root">
<Grid.DataContext>
<viewmodels:MainViewModel x:Name="ViewModel"/>
</Grid.DataContext>
<Grid.Resources>
<!--Shader selection panel. This is declared as a resource and then added and removed to the visual
tree entirely instead of just changing its visibility, so that the loaded panels can detect the
change and stop their render loops. This avoids wasting GPU resources when the panel isn't visible.-->
<Border
x:Key="ShaderSelectionPanel"
x:Name="ShaderSelectionPanel"
IsTapEnabled="True"
Tapped="ShaderSelectionPanel_Tapped">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation Duration="0:0:0.5" From="0" To="1.0"/>
</animations:Implicit.ShowAnimations>
<animations:Implicit.HideAnimations>
<animations:OpacityAnimation Duration="0:0:0.5" From="1.0" To="0"/>
</animations:Implicit.HideAnimations>
<Border.Background>
<media:AcrylicBrush
TintColor="#FF222222"
TintOpacity="0.2"
BlurAmount="12"
TextureUri="ms-appx:///Images/Misc/noise_low.png"/>
</Border.Background>
<!--Shadow panel with the shaders list-->
<controls:DropShadowPanel
ShadowOpacity="1"
BlurRadius="20"
OffsetY="-2"
OffsetX="-12"
IsMasked="True"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalAlignment="Bottom">
<animations:Implicit.ShowAnimations>
<animations:TranslationAnimation Duration="0:0:0.5" From="0,320,0" To="0"/>
</animations:Implicit.ShowAnimations>
<animations:Implicit.HideAnimations>
<animations:TranslationAnimation Duration="0:0:0.5" From="0" To="0,320,0"/>
</animations:Implicit.HideAnimations>
<Border
Height="320"
Margin="-20,0,-20,0"
Background="#FF222222">
<!--Shaders list-->
<ListView
ItemsSource="{x:Bind ViewModel.ComputeShaderOptions}"
SelectionMode="Single"
SelectedItem="{x:Bind ViewModel.SelectedComputeShader, Mode=TwoWay}"
ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollMode="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Hidden">
<ListView.Resources>
<!--Lightweight styling to remove the selection background with the accent color, and
to remove the padding and stretch the list items to occupy all the available space-->
<SolidColorBrush x:Key="ListViewItemBackgroundSelected" Color="Transparent"/>
<SolidColorBrush x:Key="ListViewItemBackgroundSelectedPointerOver" Color="Transparent"/>
<SolidColorBrush x:Key="ListViewItemBackgroundSelectedPressed" Color="Transparent"/>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="VerticalContentAlignment" Value="Stretch"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Padding" Value="0"/>
</Style>
</ListView.Resources>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemTemplate>
<!--Shader template-->
<DataTemplate x:DataType="models:ComputeShader">
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ui:UIElementExtensions.ClipToBounds="True">
<!--Shader preview-->
<computesharp:ComputeShaderPanel
Width="568"
ShaderRunner="{x:Bind ShaderRunner}"/>
<!--Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
current template scope. Once that's fixed in WinUI 3, this can be rewritten as a multi-binding like this:
Visibility="{x:Bind system:Object.ReferenceEquals((local:ComputeShader), ViewModel.SelectedComputeShader), Mode=OneWay}".
When that is working, the ComputeShader.IsSelected property can also be removed, as it will no longer be needed.-->
<Border
BorderThickness="4"
BorderBrush="White"
Visibility="{x:Bind IsSelected, Mode=OneWay}">
<Polygon
VerticalAlignment="Top"
HorizontalAlignment="Right"
Points="0,0 32,0 32,32"
Fill="White"/>
</Border>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Border>
</controls:DropShadowPanel>
</Border>
</Grid.Resources>
<!--Shader-->
<computesharp:ComputeShaderPanel
x:Name="ShaderPanel"
Grid.Row="1"
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}"
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"/>
<!--Settings panel-->
<StackPanel
Orientation="Horizontal"
Spacing="20"
VerticalAlignment="Bottom"
HorizontalAlignment="Right"
Margin="48">
<!--Shader pause button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Select shader"
Command="{x:Bind ViewModel.ToggleRenderingPausedCommand}">
<SymbolIcon Symbol="{x:Bind converters:RenderingPauseConverter.ConvertPausedToSymbol(ViewModel.IsRenderingPaused), Mode=OneWay}"/>
</Button>
<!--Shader selection button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Select shader"
Click="OpenShaderSelectionPanelButton_Click">
<SymbolIcon Symbol="Pictures"/>
</Button>
<!--Settings button-->
<Button
Padding="20"
CornerRadius="9999"
ToolTipService.ToolTip="Settings">
<SymbolIcon Symbol="Setting"/>
<Button.Flyout>
<MenuFlyout>
<ToggleMenuFlyoutItem
Text="Dynamic resolution"
IsChecked="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=TwoWay}"/>
<MenuFlyoutSeparator/>
<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>
<!--Invisible title bar-->
<Rectangle
x:Name="TitleBarRectangle"
VerticalAlignment="Top"
HorizontalAlignment="Stretch"
Height="32"
Fill="Transparent"/>
</Grid>
</Window>
+32
ファイルの表示
@@ -0,0 +1,32 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
namespace ComputeSharp.SwapChain.WinUI.Views
{
/// <summary>
/// A view for <see cref="MainViewModel"/>.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
this.ExtendsContentIntoTitleBar = true;
SetTitleBar(TitleBarRectangle);
}
// 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);
}
}
}