using System; using System.Runtime.CompilerServices; using ComputeSharp.SwapChain.Core.Services; using ComputeSharp.SwapChain.Core.ViewModels; using ComputeSharp.WinUI; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Input; namespace ComputeSharp.SwapChain.WinUI.Views; /// /// A view for . /// public sealed partial class MainWindow : Window { /// /// The mapping of currently alive shader panels. /// private readonly ConditionalWeakTable shaderPanels = new(); public MainWindow() { this.InitializeComponent(); this.ExtendsContentIntoTitleBar = true; SetTitleBar(TitleBarRectangle); Root.DataContext = new MainViewModel(new DebugAnalyticsService()); } /// /// Gets the instance for the current view. /// public MainViewModel ViewModel => (MainViewModel)Root.DataContext; /// /// Stops all rendering when the application is closing. /// public void OnShutdown() { ShaderPanel.ShaderRunner = null; foreach (var (panel, _) in this.shaderPanels) { panel.ShaderRunner = null; } } // 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); } // Updates the size of the shaders list panel private void UserControl_SizeChanged(object sender, WindowSizeChangedEventArgs e) { ShadersListContainerPanel.Height = Math.Round(e.Size.Height * 0.35); } // Tracks the current panel private void AnimatedComputeShaderPanel_Loaded(object sender, RoutedEventArgs e) { this.shaderPanels.AddOrUpdate((AnimatedComputeShaderPanel)sender, null); } }