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#
Select all in the Edit menu with Ctrl+A everywhere; a mnemonic of its own for every menu entry; a click on the title bar lands while a menu is open
Alexander Graefcf3b10cf8b42
diff --git a/CLAUDE.md b/CLAUDE.mdindex 3a9f557..6d7eb3f 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -290,7 +290,17 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDAbox keeps its own) write the step back into the same project object, the lists refilled and the settings objectsreplaced, so the watcher reports it as an edit (stale run, scratch frame, re-run) and nothing is recorded; theselection follows by name, then by index; the title's asterisk clears at the saved step. The Edit menu (between File- and View) holds Undo, Redo, Cut, Copy, Paste and Delete; the UI harnesses step over it.+ and View) holds Undo, Redo, Cut, Copy, Paste, Delete and Select all (2026-11-04, the user's request; Ctrl+A is the+ command's gesture, so it works in the preview too, a text box keeping its own); the UI harnesses step over it. **Every+ entry of a menu has a mnemonic of its own, in all four languages** (2026-11-04: the tree's context menu had A, T, P+ and D shared, so a press moved the highlight and the command needed a second press; a shared string, Cut, Copy, Paste,+ Select all, the three exports, must be unique in every menu it appears in, the Edit menu, the File > Export submenu,+ the tree's and the pictures' context menus; proven by posting the Apps key and the letter once on a tree row). **A+ click on a window's title bar while a menu or a context menu is open lands** (`MenuClickThrough`, 2026-11-04, the+ user's request: the close button had needed a second click): an open menu holds the mouse for Windows too, so the+ dismissing click arrives as a client click; it is hit-tested with WM_NCHITTEST and, on the caption, the system menu+ or a button, posted again as WM_NCLBUTTONDOWN behind the menu's closing; untested by the harnesses, which post no+ mouse, the user tries it.- **Copy, cut, paste, drag and drop** (2026-10-23, the user's choices): `ProjectClipboard` writes sources, parts,probes and schemes (the `INamed` items) and the Scene, Simulation and Display objects as a fragment of their own fileelements, in the app's format and as plain text (read back from text too, so a text editor takes and gives the XML).diff --git a/MANUAL.md b/MANUAL.mdindex 268d1d2..e2e3499 100644--- a/MANUAL.md+++ b/MANUAL.md@@ -199,6 +199,7 @@ The Edit menu.4. **Copy**: Copies them (Ctrl+C), as text in the project's own format, so they can go into a text editor or another window as well.5. **Paste**: Pastes objects behind the selected row (Ctrl+V); a copied Scene, Simulation or Display settings object replaces the project's when pasted on its row or on the project.6. **Delete**: Removes the selected objects (Del).+7. **Select all**: Selects every source, part and probe of the project (Ctrl+A).### The View menudiff --git a/WaveDudeNext.WPF/App.xaml.cs b/WaveDudeNext.WPF/App.xaml.csindex c93ea3c..4ffb8f0 100644--- a/WaveDudeNext.WPF/App.xaml.cs+++ b/WaveDudeNext.WPF/App.xaml.cs@@ -233,6 +233,7 @@ public partial class App : Applicationstring? file = ReadArguments(e.Args);WindowZoom.Install();+ MenuClickThrough.Install();var window = new MainWindow();MainWindow = window;window.Show();diff --git a/WaveDudeNext.WPF/Commands/ProjectCommands.cs b/WaveDudeNext.WPF/Commands/ProjectCommands.csindex 1c5570e..0f0cc2a 100644--- a/WaveDudeNext.WPF/Commands/ProjectCommands.cs+++ b/WaveDudeNext.WPF/Commands/ProjectCommands.cs@@ -51,7 +51,10 @@ public static class ProjectCommandspublic static readonly RoutedUICommand MoveDown = new("Move down", nameof(MoveDown), typeof(ProjectCommands));/// <summary>Selects every source, part and probe (Ctrl+A in the tree and on the preview; the tree's context menu).</summary>- public static readonly RoutedUICommand SelectAll = new("Select all", nameof(SelectAll), typeof(ProjectCommands));+ public static readonly RoutedUICommand SelectAll = new("Select all", nameof(SelectAll), typeof(ProjectCommands),+ // the gesture on the command, so the Edit menu shows it and it works wherever the window's binding is reached, the+ // preview included; a text box keeps its own Ctrl+A, handled before the window sees the key (2026-11-04)+ [new KeyGesture(Key.A, ModifierKeys.Control)]);/// <summary>Adds the item to the selection or takes it out again (Insert or Ctrl+Space on the tree row; the tree's context menu).</summary>public static readonly RoutedUICommand ToggleSelected = new("Select or deselect", nameof(ToggleSelected), typeof(ProjectCommands));diff --git a/WaveDudeNext.WPF/MainWindow.xaml b/WaveDudeNext.WPF/MainWindow.xamlindex b4545fa..4f8a0fc 100644--- a/WaveDudeNext.WPF/MainWindow.xaml+++ b/WaveDudeNext.WPF/MainWindow.xaml@@ -282,6 +282,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<MenuItem Header="{DynamicResource MenuEditCopy}" Command="ApplicationCommands.Copy" AutomationProperties.AutomationId="MenuCopy" controls:MenuIcon.Glyph="" /><MenuItem Header="{DynamicResource MenuEditPaste}" Command="ApplicationCommands.Paste" AutomationProperties.AutomationId="MenuPaste" controls:MenuIcon.Glyph="" /><MenuItem Header="{DynamicResource MenuEditDelete}" Command="{x:Static commands:EditCommands.Delete}" InputGestureText="Del" AutomationProperties.AutomationId="MenuDelete" controls:MenuIcon.Glyph="" />+ <Separator />+ <!-- the tree's Select all, here too (2026-11-04, the user's request); Ctrl+A is the command's gesture, so it works in the preview as well -->+ <MenuItem Header="{DynamicResource MenuProjectSelectAll}" Command="{x:Static commands:ProjectCommands.SelectAll}" AutomationProperties.AutomationId="MenuSelectAll" controls:MenuIcon.Glyph="" /></MenuItem><MenuItem Header="{DynamicResource MenuView}"><MenuItem Header="{DynamicResource MenuViewPanes}" controls:MenuIcon.Glyph=""diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xamlindex ee97be2..fe64c6b 100644--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml@@ -45,7 +45,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuAutoBrightness">_Automatische Helligkeit</s:String><s:String x:Key="ButtonAutoBrightness">Auto</s:String><s:String x:Key="TipAutoBrightness">Die Helligkeit einmal an das gezeigte Bild anpassen: das hellste halbe Prozent erreicht das obere Ende des Farbschemas. Die Helligkeit bleibt danach, wie sie ist.</s:String>- <s:String x:Key="MenuExportProbeCsv">Sonden_daten als CSV exportieren...</s:String>+ <s:String x:Key="MenuExportProbeCsv">Sondendaten als CSV e_xportieren...</s:String><s:String x:Key="MenuFileExit">_Beenden</s:String><s:String x:Key="MenuEdit">_Bearbeiten</s:String><s:String x:Key="MenuEditUndo">_Rückgängig</s:String>@@ -142,7 +142,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipManualSplitter">Ziehen oder Pfeiltasten zum Umverteilen</s:String><s:String x:Key="MenuProjectAddSource">_Quelle hinzufügen</s:String>- <s:String x:Key="MenuProjectAddProbe">_Sonde hinzufügen</s:String>+ <s:String x:Key="MenuProjectAddProbe">S_onde hinzufügen</s:String><s:String x:Key="MenuProjectAddPart">_Bauteil hinzufügen</s:String><s:String x:Key="MenuAddLens">_Linse/Spiegel</s:String><s:String x:Key="MenuAddPolygon">_Polygon</s:String>@@ -158,12 +158,12 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuAddXorGate">_XOR (Mach-Zehnder)</s:String><s:String x:Key="MenuAddAndGate">_AND</s:String><s:String x:Key="MenuAddOrGate">_OR</s:String>- <s:String x:Key="MenuProjectToggleEnabled">_Aktiv</s:String>+ <s:String x:Key="MenuProjectToggleEnabled">Akt_iv</s:String><s:String x:Key="MenuProjectDuplicate">_Duplizieren</s:String>- <s:String x:Key="MenuProjectRemove">_Entfernen</s:String>- <s:String x:Key="MenuProjectMoveUp">Nach _oben</s:String>+ <s:String x:Key="MenuProjectRemove">Ent_fernen</s:String>+ <s:String x:Key="MenuProjectMoveUp">Nach obe_n</s:String><s:String x:Key="MenuProjectMoveDown">Nach _unten</s:String>- <s:String x:Key="MenuProjectSelectAll">_Alles auswählen</s:String>+ <s:String x:Key="MenuProjectSelectAll">Alles au_swählen</s:String><s:String x:Key="MenuProjectToggleSelected">Zur Auswahl hinzufügen oder en_tfernen</s:String><s:String x:Key="ToolAddSource">Quelle</s:String><s:String x:Key="ToolAddProbe">Sonde</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xamlindex 5a64417..8bf7551 100644--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml@@ -36,7 +36,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuFileExport">_Export</s:String><s:String x:Key="MenuFileExportField">Export _field...</s:String><s:String x:Key="MenuFileExportIntensity">Export _intensity...</s:String>- <s:String x:Key="MenuFileExportBoth">Export _both...</s:String>+ <s:String x:Key="MenuFileExportBoth">Export b_oth...</s:String><s:String x:Key="MenuFileExportFieldFrame">Export field f_rame...</s:String><s:String x:Key="MenuFileExportIntensityFrame">Export intensity fra_me...</s:String><s:String x:Key="MenuFileExportLast">Export _last</s:String>@@ -45,7 +45,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuAutoBrightness">_Auto brightness</s:String><s:String x:Key="ButtonAutoBrightness">Auto</s:String><s:String x:Key="TipAutoBrightness">Fit the brightness once to the frame shown: the brightest half percent of it reaches the top of the colour scheme. The brightness then stays as it is.</s:String>- <s:String x:Key="MenuExportProbeCsv">Export probe _data as CSV...</s:String>+ <s:String x:Key="MenuExportProbeCsv">E_xport probe data as CSV...</s:String><s:String x:Key="MenuFileExit">E_xit</s:String><s:String x:Key="MenuEdit">_Edit</s:String><s:String x:Key="MenuEditUndo">_Undo</s:String>@@ -144,8 +144,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipManualSplitter">Drag or use the arrow keys to resize</s:String><s:String x:Key="MenuProjectAddSource">Add _source</s:String>- <s:String x:Key="MenuProjectAddProbe">Add _probe</s:String>- <s:String x:Key="MenuProjectAddPart">Add p_art</s:String>+ <s:String x:Key="MenuProjectAddProbe">Add pro_be</s:String>+ <s:String x:Key="MenuProjectAddPart">Add pa_rt</s:String><s:String x:Key="MenuAddLens">_Lens/Mirror</s:String><s:String x:Key="MenuAddPolygon">_Polygon</s:String><s:String x:Key="MenuAddRectangle">_Rectangle</s:String>@@ -162,11 +162,11 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuAddOrGate">_OR</s:String><s:String x:Key="MenuProjectToggleEnabled">_Enabled</s:String><s:String x:Key="MenuProjectDuplicate">_Duplicate</s:String>- <s:String x:Key="MenuProjectRemove">_Remove</s:String>+ <s:String x:Key="MenuProjectRemove">Remo_ve</s:String><s:String x:Key="MenuProjectMoveUp">Move _up</s:String>- <s:String x:Key="MenuProjectMoveDown">Move _down</s:String>+ <s:String x:Key="MenuProjectMoveDown">Move do_wn</s:String><s:String x:Key="MenuProjectSelectAll">Select _all</s:String>- <s:String x:Key="MenuProjectToggleSelected">Add to or remove from selec_tion</s:String>+ <s:String x:Key="MenuProjectToggleSelected">Add to or remove from se_lection</s:String><s:String x:Key="ToolAddSource">Source</s:String><s:String x:Key="ToolAddProbe">Probe</s:String><s:String x:Key="ToolAddPart">Part</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xamlindex 448077f..9560932 100644--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml@@ -39,13 +39,13 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuFileExportBoth">Exporter les _deux...</s:String><s:String x:Key="MenuFileExportFieldFrame">Exporter l'i_mage du champ...</s:String><s:String x:Key="MenuFileExportIntensityFrame">Exporter l'image de l'intensi_té...</s:String>- <s:String x:Key="MenuFileExportLast">Répéter le _dernier export</s:String>- <s:String x:Key="MenuExportThisFrame">Exporter _cette image...</s:String>+ <s:String x:Key="MenuFileExportLast">Répéter le de_rnier export</s:String>+ <s:String x:Key="MenuExportThisFrame">Exporter c_ette image...</s:String><s:String x:Key="MenuBrightness">_Luminosité</s:String><s:String x:Key="MenuAutoBrightness">Luminosité _automatique</s:String><s:String x:Key="ButtonAutoBrightness">Auto</s:String><s:String x:Key="TipAutoBrightness">Ajuster une fois la luminosité à l'image affichée : le demi-pour-cent le plus clair atteint le haut du jeu de couleurs. La luminosité reste ensuite telle quelle.</s:String>- <s:String x:Key="MenuExportProbeCsv">Exporter les _données de la sonde en CSV...</s:String>+ <s:String x:Key="MenuExportProbeCsv">Exporter les données de la sonde en CS_V...</s:String><s:String x:Key="MenuFileExit">_Quitter</s:String><s:String x:Key="MenuEdit">_Édition</s:String><s:String x:Key="MenuEditUndo">_Annuler</s:String>@@ -141,8 +141,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="ManualContents">Sommaire</s:String><s:String x:Key="TipManualSplitter">Glisser ou utiliser les flèches pour redimensionner</s:String>- <s:String x:Key="MenuProjectAddSource">Ajouter une _source</s:String>- <s:String x:Key="MenuProjectAddProbe">Ajouter une s_onde</s:String>+ <s:String x:Key="MenuProjectAddSource">Ajouter une sou_rce</s:String>+ <s:String x:Key="MenuProjectAddProbe">Ajouter une so_nde</s:String><s:String x:Key="MenuProjectAddPart">Ajouter un _composant</s:String><s:String x:Key="MenuAddLens">_Lentille/Miroir</s:String><s:String x:Key="MenuAddPolygon">_Polygone</s:String>@@ -164,7 +164,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuProjectMoveUp">_Monter</s:String><s:String x:Key="MenuProjectMoveDown">D_escendre</s:String><s:String x:Key="MenuProjectSelectAll">_Tout sélectionner</s:String>- <s:String x:Key="MenuProjectToggleSelected">Ajouter à la sélection ou en re_tirer</s:String>+ <s:String x:Key="MenuProjectToggleSelected">Ajouter à la sélection ou en ret_irer</s:String><s:String x:Key="ToolAddSource">Source</s:String><s:String x:Key="ToolAddProbe">Sonde</s:String><s:String x:Key="ToolAddPart">Composant</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xamlindex eac6212..ca210e4 100644--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml@@ -37,7 +37,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuFileExportField">_Veld exporteren...</s:String><s:String x:Key="MenuFileExportIntensity">_Intensiteit exporteren...</s:String><s:String x:Key="MenuFileExportBoth">_Beide exporteren...</s:String>- <s:String x:Key="MenuFileExportFieldFrame">Veld_beeld exporteren...</s:String>+ <s:String x:Key="MenuFileExportFieldFrame">V_eldbeeld exporteren...</s:String><s:String x:Key="MenuFileExportIntensityFrame">Intensiteitsbeel_d exporteren...</s:String><s:String x:Key="MenuFileExportLast">Laatste export _herhalen</s:String><s:String x:Key="MenuExportThisFrame">_Dit beeld exporteren...</s:String>@@ -164,7 +164,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="MenuProjectMoveUp">Om_hoog</s:String><s:String x:Key="MenuProjectMoveDown">Om_laag</s:String><s:String x:Key="MenuProjectSelectAll">_Alles selecteren</s:String>- <s:String x:Key="MenuProjectToggleSelected">Aan selectie toevoegen of eruit verwij_deren</s:String>+ <s:String x:Key="MenuProjectToggleSelected">Aan selectie toevoegen of eruit verwijde_ren</s:String><s:String x:Key="ToolAddSource">Bron</s:String><s:String x:Key="ToolAddProbe">Sonde</s:String><s:String x:Key="ToolAddPart">Onderdeel</s:String>diff --git a/WaveDudeNext.WPF/Theming/MenuClickThrough.cs b/WaveDudeNext.WPF/Theming/MenuClickThrough.csnew file mode 100644index 0000000..62f4d1e--- /dev/null+++ b/WaveDudeNext.WPF/Theming/MenuClickThrough.cs@@ -0,0 +1,88 @@+// 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+// Jeroen Vleggaar (Huygens Optics), author of Wave Dude 2D, Copyright (C) 2026+// <https://www.youtube.com/@HuygensOptics>, <https://www.huygensoptics.com>+// 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.Runtime.InteropServices;+using System.Windows;+using System.Windows.Controls.Primitives;+using System.Windows.Input;+using System.Windows.Interop;++namespace WaveDudeNext.WPF.Theming;++/// <summary>+/// A click on a window's title bar, its buttons or its system menu while a menu or a context menu is open closes the+/// menu and lands (2026-11-04, the user's request: the main window's close button had needed a second click). An open+/// menu holds the mouse, for WPF and for Windows alike, so the click that dismisses it reaches the window as a client+/// click, never as the non-client click the title bar acts on. The dismissing click is hit-tested against the window+/// under the pointer with <c>WM_NCHITTEST</c> and, when it falls on the caption, the system menu or one of the three+/// buttons, posted again as <c>WM_NCLBUTTONDOWN</c>, which is handled after the menu has closed and let the mouse go:+/// <c>DefWindowProc</c> then treats it as the real click, and the button's release comes from the mouse itself.+/// One class handler on <see cref="MenuBase"/>, so the menu bar's menus and every context menu are covered.+/// </summary>+public static class MenuClickThrough+{+ /// <summary>Registers the handler; once, at start-up.</summary>+ public static void Install() =>+ EventManager.RegisterClassHandler(typeof(MenuBase), Mouse.PreviewMouseDownOutsideCapturedElementEvent, new MouseButtonEventHandler(OnClickOutside));++ private static void OnClickOutside(object sender, MouseButtonEventArgs e)+ {+ if (e.ChangedButton != MouseButton.Left || !GetCursorPos(out NativePoint point))+ {+ return;+ }+ IntPtr hwnd = WindowFromPoint(point);+ // one of this application's windows, and the click on its non-client area+ if (hwnd == IntPtr.Zero || HwndSource.FromHwnd(hwnd) == null)+ {+ return;+ }+ IntPtr position = (IntPtr)((point.Y << 16) | (point.X & 0xFFFF));+ long hit = (long)SendMessage(hwnd, WM_NCHITTEST, IntPtr.Zero, position);+ if (hit is HTCAPTION or HTSYSMENU or HTMINBUTTON or HTMAXBUTTON or HTCLOSE)+ {+ PostMessage(hwnd, WM_NCLBUTTONDOWN, (IntPtr)hit, position);+ }+ }++ private const uint WM_NCHITTEST = 0x0084;+ private const uint WM_NCLBUTTONDOWN = 0x00A1;+ private const long HTCAPTION = 2;+ private const long HTSYSMENU = 3;+ private const long HTMINBUTTON = 8;+ private const long HTMAXBUTTON = 9;+ private const long HTCLOSE = 20;++ [StructLayout(LayoutKind.Sequential)]+ private struct NativePoint+ {+ public int X;+ public int Y;+ }++ [DllImport("user32.dll")]+ private static extern bool GetCursorPos(out NativePoint point);++ [DllImport("user32.dll")]+ private static extern IntPtr WindowFromPoint(NativePoint point);++ [DllImport("user32.dll")]+ private static extern IntPtr SendMessage(IntPtr hwnd, uint message, IntPtr wParam, IntPtr lParam);++ [DllImport("user32.dll")]+ private static extern bool PostMessage(IntPtr hwnd, uint message, IntPtr wParam, IntPtr lParam);+}