diff --git a/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs b/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs index c6b7d5d0..1b3ffd11 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.CoreWindow/App.cs @@ -13,6 +13,22 @@ namespace ComputeSharp.SwapChain.D2D1; /// public sealed partial class App : IFrameworkViewSource, IFrameworkView { + /// + /// The collection of available pixel shader effects. + /// + private static readonly PixelShaderEffect[] Effects = + [ + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))), + new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))) + ]; + /// /// The for the current app instance. /// @@ -23,6 +39,11 @@ public sealed partial class App : IFrameworkViewSource, IFrameworkView /// private CoreWindow? window; + /// + /// The currently selected effect (one of the items in ). + /// + private PixelShaderEffect selectedEffect = Effects[0]; + /// /// The entry point for the application. /// @@ -63,12 +84,23 @@ public sealed partial class App : IFrameworkViewSource, IFrameworkView ApplicationView.GetForCurrentView().TitleBar.StyleTitleBarForExtendedIntoViewMode(); - PixelShaderEffect effect = new PixelShaderEffect.For(static (time, width, height) => new((float)time.TotalSeconds, new int2(width, height))); + // Switch the shader to use when pressing the number keys + this.window!.CharacterReceived += (s, e) => + { + if (e.KeyCode is >= '1' and <= '9') + { + this.selectedEffect = Effects[(int)(e.KeyCode - '1')]; + + e.Handled = true; + } + }; CoreWindowApplication application = new(); application.Draw += (s, e) => { + PixelShaderEffect effect = this.selectedEffect; + // Set the effect properties effect.ElapsedTime = e.TotalTime; effect.ScreenWidth = (int)e.ScreenWidth; @@ -78,7 +110,7 @@ public sealed partial class App : IFrameworkViewSource, IFrameworkView e.DrawingSession.DrawImage(effect); }; - CoreWindowApplicationRunner.Run(application, this.window!); + CoreWindowApplicationRunner.Run(application, this.window); } ///