Interactive 2D wave optics simulator. Turn any image into a refractive scene, add sources, watch waves refract, diffract and interfere. Probes, intensity maps, video export.
C#
Message boxes are the app's own themed window; the native file dialogs stay
Alexander Graef22a30cea0b8a
diff --git a/WaveDudeNext.WPF/Dialogs/MessageWindow.xaml b/WaveDudeNext.WPF/Dialogs/MessageWindow.xamlnew file mode 100644index 0000000..2d1e809--- /dev/null+++ b/WaveDudeNext.WPF/Dialogs/MessageWindow.xaml@@ -0,0 +1,49 @@+<!--+SPDX-License-Identifier: GPL-3.0-or-later+Copyright (C) 2026 Alexander Graef <[email protected]>++This file is part of WaveDude Next, a 2D wave simulator.++Based on the work of+ JJM Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026+ <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>+ Manuel (0x23, Diffraction Limited), author of WaveSimulator2D+ <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>++WaveDude Next is free software: you can redistribute it and/or modify it under+the terms of the GNU General Public License as published by the Free Software+Foundation, either version 3 of the License, or (at your option) any later+version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or+<https://www.gnu.org/licenses/>.+-->+++<Window x:Class="WaveDudeNext.WPF.Dialogs.MessageWindow"+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"+ Title="{DynamicResource Title}" Icon="/App.ico"+ Width="440" SizeToContent="Height" ResizeMode="NoResize" ShowInTaskbar="False"+ WindowStartupLocation="CenterOwner"+ Background="{DynamicResource WindowBackground}" Foreground="{DynamicResource WindowForeground}"+ AutomationProperties.AutomationId="MessageWindow">+ <!-- the app's own message box: a disc with "!" or "?" in the theme's colours, the wrapped text, and the buttons+ the code-behind adds for the chosen set (Enter takes the default, Esc the cancel button, the underlined+ letters work without Alt); the native MessageBox was never themed -->+ <Grid Margin="20,18,20,16">+ <Grid.RowDefinitions>+ <RowDefinition Height="Auto" />+ <RowDefinition Height="Auto" />+ </Grid.RowDefinitions>++ <DockPanel Grid.Row="0">+ <Grid Width="32" Height="32" Margin="0,0,16,0" VerticalAlignment="Top" DockPanel.Dock="Left">+ <Ellipse x:Name="iconDisc" />+ <TextBlock x:Name="iconGlyph" FontSize="20" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" />+ </Grid>+ <TextBlock x:Name="messageText" TextWrapping="Wrap" VerticalAlignment="Center" MinHeight="32"+ AutomationProperties.AutomationId="MessageText" />+ </DockPanel>++ <StackPanel x:Name="buttonRow" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,18,0,0" />+ </Grid>+</Window>diff --git a/WaveDudeNext.WPF/Dialogs/MessageWindow.xaml.cs b/WaveDudeNext.WPF/Dialogs/MessageWindow.xaml.csnew file mode 100644index 0000000..12a3f21--- /dev/null+++ b/WaveDudeNext.WPF/Dialogs/MessageWindow.xaml.cs@@ -0,0 +1,139 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 Alexander Graef <[email protected]>+//+// This file is part of WaveDude Next, a 2D wave simulator.+//+// Based on the work of+// JJM Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>+// Manuel (0x23, Diffraction Limited), author of WaveSimulator2D+// <https://www.youtube.com/@DiffractionLimited>, <https://github.com/0x23/WaveSimulator2D>+//+// WaveDude Next is free software: you can redistribute it and/or modify it under+// the terms of the GNU General Public License as published by the Free Software+// Foundation, either version 3 of the License, or (at your option) any later+// version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or+// <https://www.gnu.org/licenses/>.+++using System.Media;+using System.Windows;+using System.Windows.Automation;+using System.Windows.Controls;+using System.Windows.Input;+using System.Windows.Shapes;+using NLog;+using WaveDudeNext.WPF.Theming;++namespace WaveDudeNext.WPF.Dialogs;++/// <summary>What a <see cref="MessageWindow"/> reports: an error (red disc, the error sound) or a question (accent disc).</summary>+public enum MessageKind+{+ /// <summary>Something failed; the text names it.</summary>+ Error,+ /// <summary>A decision the user has to take.</summary>+ Question,+}++/// <summary>The button sets a <see cref="MessageWindow"/> offers.</summary>+public enum MessageButtons+{+ /// <summary>OK alone; Enter, Esc and the close box all give <see cref="MessageAnswer.Ok"/>.</summary>+ Ok,+ /// <summary>Yes (default) and No (Esc and the close box).</summary>+ YesNo,+ /// <summary>Save (default), Don't save, and Cancel (Esc and the close box).</summary>+ SaveDiscardCancel,+}++/// <summary>The button a <see cref="MessageWindow"/> was closed with.</summary>+public enum MessageAnswer+{+ /// <summary>Cancel, Esc or the close box of a <see cref="MessageButtons.SaveDiscardCancel"/> window.</summary>+ Cancel,+ /// <summary>OK, or any way of closing a <see cref="MessageButtons.Ok"/> window.</summary>+ Ok,+ /// <summary>Yes.</summary>+ Yes,+ /// <summary>No, Esc or the close box of a <see cref="MessageButtons.YesNo"/> window.</summary>+ No,+ /// <summary>Save.</summary>+ Save,+ /// <summary>Don't save.</summary>+ Discard,+}++/// <summary>+/// The application's message box, replacing the native <see cref="MessageBox"/>, which no theme reaches: a modal window+/// owned by its caller with the theme's brushes and title bar, the text wrapped beside an error or question disc, and+/// the buttons of a <see cref="MessageButtons"/> set with labels from the string tables (<c>Dialog*</c> keys), so they+/// speak the app's language, not the operating system's. Enter takes the default button, Esc the cancel button, the+/// access keys work without Alt; the buttons carry <c>Message<Answer></c> automation ids. UI thread only.+/// </summary>+public partial class MessageWindow : Window+{+ private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();+ private MessageAnswer _answer;++ private MessageWindow(string text, MessageKind kind, MessageButtons buttons)+ {+ InitializeComponent();+ SourceInitialized += (_, _) => ThemeController.Instance.ApplyTitleBar(this);+ messageText.Text = text;+ bool error = kind == MessageKind.Error;+ iconDisc.SetResourceReference(Shape.FillProperty, error ? "StatusBarErrorBackground" : "Accent");+ iconGlyph.SetResourceReference(ForegroundProperty, error ? "StatusBarErrorForeground" : "StatusBarForeground");+ iconGlyph.Text = error ? "!" : "?";+ // the answer for the close box: what the cancel button of the set would give+ switch (buttons)+ {+ case MessageButtons.Ok:+ _answer = MessageAnswer.Ok;+ AddButton("DialogOk", MessageAnswer.Ok, isDefault: true, isCancel: true);+ break;+ case MessageButtons.YesNo:+ _answer = MessageAnswer.No;+ AddButton("DialogYes", MessageAnswer.Yes, isDefault: true, isCancel: false);+ AddButton("DialogNo", MessageAnswer.No, isDefault: false, isCancel: true);+ break;+ default:+ _answer = MessageAnswer.Cancel;+ AddButton("DialogSave", MessageAnswer.Save, isDefault: true, isCancel: false);+ AddButton("DialogDiscard", MessageAnswer.Discard, isDefault: false, isCancel: false);+ AddButton("DialogCancel", MessageAnswer.Cancel, isDefault: false, isCancel: true);+ break;+ }+ }++ /// <summary>+ /// Shows <paramref name="text"/> modally over <paramref name="owner"/> with the sound of its+ /// <paramref name="kind"/> and returns the button it was closed with. UI thread only.+ /// </summary>+ public static MessageAnswer Show(Window owner, string text, MessageKind kind, MessageButtons buttons)+ {+ Logger.Debug("Message ({Kind}, {Buttons}): {Text}", kind, buttons, text.ReplaceLineEndings(" "));+ (kind == MessageKind.Error ? SystemSounds.Hand : SystemSounds.Question).Play();+ var window = new MessageWindow(text, kind, buttons) { Owner = owner };+ window.ShowDialog();+ Logger.Debug("Message answered: {Answer}", window._answer);+ return window._answer;+ }++ private void AddButton(string labelKey, MessageAnswer answer, bool isDefault, bool isCancel)+ {+ var button = new Button { MinWidth = 90, Margin = new Thickness(8, 0, 0, 0), IsDefault = isDefault, IsCancel = isCancel };+ button.SetResourceReference(ContentProperty, labelKey);+ AutomationProperties.SetAutomationId(button, "Message" + answer);+ button.Click += (_, _) =>+ {+ _answer = answer;+ DialogResult = true;+ };+ buttonRow.Children.Add(button);+ if (isDefault)+ {+ FocusManager.SetFocusedElement(this, button);+ }+ }+}diff --git a/WaveDudeNext.WPF/MainWindow.Export.cs b/WaveDudeNext.WPF/MainWindow.Export.csindex 774faa5..b4839f6 100644--- a/WaveDudeNext.WPF/MainWindow.Export.cs+++ b/WaveDudeNext.WPF/MainWindow.Export.cs@@ -24,6 +24,7 @@ using WaveDudeNext.Export;using WaveDudeNext.Model;using WaveDudeNext.Rendering;using WaveDudeNext.Runs;+using WaveDudeNext.WPF.Dialogs;using WaveDudeNext.WPF.Properties;using WaveDudeNext.WPF.Rendering;@@ -153,7 +154,7 @@ public partial class MainWindowif (!ExportFormats.IsAvailable(format)){Logger.Error("MP4 export is not available: Media Foundation is missing on this computer (Windows N needs the Media Feature Pack)");- MessageBox.Show(this, (string)FindResource("ExportError"), (string)FindResource("Title"), MessageBoxButton.OK, MessageBoxImage.Error);+ MessageWindow.Show(this, (string)FindResource("ExportError"), MessageKind.Error, MessageButtons.Ok);return;}// the output paths: one per layer; "both" takes the chosen name without a layer suffix and appends its own@@ -184,7 +185,7 @@ public partial class MainWindow{string folder = ExportFormats.SequenceFolder(path);if (Directory.Exists(folder) && Directory.EnumerateFileSystemEntries(folder).Any()- && MessageBox.Show(this, string.Format((string)FindResource("ExportFolderExistsFormat"), folder), (string)FindResource("Title"), MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)+ && MessageWindow.Show(this, string.Format((string)FindResource("ExportFolderExistsFormat"), folder), MessageKind.Question, MessageButtons.YesNo) != MessageAnswer.Yes){Logger.Debug("Export cancelled: {Folder} kept", folder);return;diff --git a/WaveDudeNext.WPF/MainWindow.xaml.cs b/WaveDudeNext.WPF/MainWindow.xaml.csindex bd2eb62..6c1c976 100644--- a/WaveDudeNext.WPF/MainWindow.xaml.cs+++ b/WaveDudeNext.WPF/MainWindow.xaml.cs@@ -28,6 +28,7 @@ using NLog;using WaveDudeNext.Model;using WaveDudeNext.Runs;using WaveDudeNext.Rendering;+using WaveDudeNext.WPF.Dialogs;using WaveDudeNext.WPF.Docking;using WaveDudeNext.WPF.Localization;using WaveDudeNext.WPF.Properties;@@ -307,11 +308,11 @@ public partial class MainWindow : Window}private void ShowError(string message, Exception ex) =>- MessageBox.Show(this, $"{message}\n{ex.Message}", (string)FindResource("Title"), MessageBoxButton.OK, MessageBoxImage.Error);+ MessageWindow.Show(this, $"{message}\n{ex.Message}", MessageKind.Error, MessageButtons.Ok);/// <summary>- /// Asks whether to save an edited project before it is discarded: Yes saves (through Save As when it has- /// no file yet), No discards, Cancel keeps it. True when the caller may go on.+ /// Asks whether to save an edited project before it is discarded: Save saves (through Save As when it has+ /// no file yet), Don't save discards, Cancel keeps it. True when the caller may go on./// </summary>private bool ConfirmDiscard(){@@ -326,12 +327,12 @@ public partial class MainWindow : Windowreturn true;}string name = Filename != null ? Path.GetFileName(Filename) : (string)FindResource("Untitled");- MessageBoxResult answer = MessageBox.Show(this, string.Format((string)FindResource("SaveChangesFormat"), name), (string)FindResource("Title"),- MessageBoxButton.YesNoCancel, MessageBoxImage.Question);+ MessageAnswer answer = MessageWindow.Show(this, string.Format((string)FindResource("SaveChangesFormat"), name),+ MessageKind.Question, MessageButtons.SaveDiscardCancel);return answer switch{- MessageBoxResult.Yes => SaveInteractively(),- MessageBoxResult.No => true,+ MessageAnswer.Save => SaveInteractively(),+ MessageAnswer.Discard => true,_ => false,};}diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xamlindex 4cb4823..5eda585 100644--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml@@ -201,6 +201,13 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipExportCancel">Export abbrechen (Esc)</s:String><s:String x:Key="Untitled">Unbenannt</s:String><s:String x:Key="SaveChangesFormat">Änderungen an {0} speichern?</s:String>+ <!-- the buttons of the message window -->+ <s:String x:Key="DialogOk">OK</s:String>+ <s:String x:Key="DialogYes">_Ja</s:String>+ <s:String x:Key="DialogNo">_Nein</s:String>+ <s:String x:Key="DialogSave">_Speichern</s:String>+ <s:String x:Key="DialogDiscard">_Nicht speichern</s:String>+ <s:String x:Key="DialogCancel">_Abbrechen</s:String><s:String x:Key="NoSelection">Keine Auswahl</s:String><s:String x:Key="TreeProject">Projekt</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xamlindex 0b5e85a..ec73ee0 100644--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml@@ -203,6 +203,13 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipExportCancel">Cancel the export (Esc)</s:String><s:String x:Key="Untitled">Untitled</s:String><s:String x:Key="SaveChangesFormat">Save the changes to {0}?</s:String>+ <!-- the buttons of the message window -->+ <s:String x:Key="DialogOk">OK</s:String>+ <s:String x:Key="DialogYes">_Yes</s:String>+ <s:String x:Key="DialogNo">_No</s:String>+ <s:String x:Key="DialogSave">_Save</s:String>+ <s:String x:Key="DialogDiscard">_Don't save</s:String>+ <s:String x:Key="DialogCancel">_Cancel</s:String><s:String x:Key="NoSelection">No selection</s:String><s:String x:Key="TreeProject">Project</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xamlindex 12e72c8..1d709fa 100644--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml@@ -201,6 +201,13 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipExportCancel">Annuler l'export (Échap)</s:String><s:String x:Key="Untitled">Sans titre</s:String><s:String x:Key="SaveChangesFormat">Enregistrer les modifications de {0} ?</s:String>+ <!-- the buttons of the message window -->+ <s:String x:Key="DialogOk">OK</s:String>+ <s:String x:Key="DialogYes">_Oui</s:String>+ <s:String x:Key="DialogNo">_Non</s:String>+ <s:String x:Key="DialogSave">_Enregistrer</s:String>+ <s:String x:Key="DialogDiscard">_Ne pas enregistrer</s:String>+ <s:String x:Key="DialogCancel">_Annuler</s:String><s:String x:Key="NoSelection">Aucune sélection</s:String><s:String x:Key="TreeProject">Projet</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xamlindex b0194c0..5a38ed1 100644--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml@@ -201,6 +201,13 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipExportCancel">Export annuleren (Esc)</s:String><s:String x:Key="Untitled">Naamloos</s:String><s:String x:Key="SaveChangesFormat">Wijzigingen in {0} opslaan?</s:String>+ <!-- the buttons of the message window -->+ <s:String x:Key="DialogOk">OK</s:String>+ <s:String x:Key="DialogYes">_Ja</s:String>+ <s:String x:Key="DialogNo">_Nee</s:String>+ <s:String x:Key="DialogSave">_Opslaan</s:String>+ <s:String x:Key="DialogDiscard">_Niet opslaan</s:String>+ <s:String x:Key="DialogCancel">_Annuleren</s:String><s:String x:Key="NoSelection">Geen selectie</s:String><s:String x:Key="TreeProject">Project</s:String>diff --git a/_tools/ui_check/Common.ps1 b/_tools/ui_check/Common.ps1index c57e646..63785f2 100644--- a/_tools/ui_check/Common.ps1+++ b/_tools/ui_check/Common.ps1@@ -237,7 +237,8 @@ function WaitFor([scriptblock]$condition, [int]$timeoutMs = 10000, [int]$pollMs# is busy elsewhere this silently fails and the foreground stays theirs, which is just as good): every# check must then leave the app inactive.function Start-App([string]$Exe, [string]$ProjectFile = "") {- # an edited project asks "save?" on closing (2026-10-14); a harness cannot answer a message box by posted keys, so the app is told to discard+ # an edited project asks "save?" on closing (2026-10-14) in the app's own message window (MessageWindow, 2026-10-18); the harnesses+ # have no business there, so the app is told to discard$env:WAVEDUDE_DISCARD_EDITS = "1"if ($ProjectFile -ne "") { $script:p = Start-Process -FilePath $Exe -ArgumentList ('"' + $ProjectFile + '"') -PassThru }else { $script:p = Start-Process -FilePath $Exe -PassThru }