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#
Preview: a new project starts at frame 0; a click on empty picture space deselects
Alexander Graefa2adb6c28077
diff --git a/CLAUDE.md b/CLAUDE.mdindex a3fc8d2..c916d8e 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -60,7 +60,8 @@ WPF shell as it stands:while it fills, so nothing coerces it), Live is switched off whatever the button said, and thescratch frame stays on screen until the store has that frame. An edit during an automatic runstops it at once (its snapshot is obsolete) and the quiet period starts a fresh one; a run the- user started keeps going and is just marked stale. Discarding a run keeps the position too.+ user started keeps going and is just marked stale. Discarding a run keeps the position too; a replaced project (New, Open, Import, Close) stops playback and+ puts the timeline back to frame 0 (`PreviewPane.OnProjectReplaced`, the user's rule, 2026-10-15).**Play means "show me the simulation"**: Play/Space issues `SimulationCommands.EnsureRun`, whichstarts an automatic run when there is none or it is stale (position kept, Live off, playback notinterrupted); while the run has not reached the playhead, playback holds at the newest frame@@ -279,7 +280,9 @@ WPF shell as it stands:and colour scheme (agreed 2026-10-09 after thin white rings vanished on the intensity picture).Dragging writes `Source.X/Y`, `Probe.AX/AY/BX/BY` in canvas pixels; the arrow keys move thefocused handle by one pixel (ten with Shift); grabbing or focusing a handle selects the item- (`PreviewPane.SelectedItem` ↔ `MainWindow.SelectedItem` ↔ the Project tree, both ways). Handles+ (`PreviewPane.SelectedItem` ↔ `MainWindow.SelectedItem` ↔ the Project tree, both ways); a left click on+ empty picture space deselects (the user's rule, 2026-10-15: the pictures' `MouseDown`, which the thumbs do+ not let through, sets the item to null and `ProjectTree.ClearSelection` lets the tree go too). Handlescarry AutomationIds `Source:<name>`, `Probe:<name>:A|B`. The overlay is styled explicitly where itis placed: WPF applies implicit styles inside a control template only to `Control`s, and theoverlay is a `Panel` (its handles came out as bare default thumbs until then). `Editors.xaml` gained the editable-combo text@@ -439,7 +442,8 @@ The two legacy harnesses are console programs compiled with `csc` against the `W`System.Windows.Automation` properties. Do **not** call UIA *patterns* (`Invoke`, `SetValue`,`Select`, `SetFocus`): on this app each one focuses its target and activates the window. Modifierkeys cannot be posted (WPF reads them from the real keyboard state), so only unmodified shortcuts- are testable.+ are testable. Posted mouse messages (`WM_LBUTTONDOWN`/`UP` after a `WM_MOUSEMOVE`) are dropped by WPF as well+ (verified 2026-10-15: a posted click on Play did nothing), so a click can only be checked by hand.`_tools/ui_check/ComboListShot.ps1` opens the speed combo by keyboard and screenshots the list(the popup has no HWND in UIA, so its screen rectangle is copied), for judging list colours.`PrintWindow(…, PW_RENDERFULLCONTENT)` captures the inactive window. UIA lookups can miss whilediff --git a/WaveDude.WPF/Controls/TreeViewExtensions.cs b/WaveDude.WPF/Controls/TreeViewExtensions.csindex 111c9c9..7dd526f 100644--- a/WaveDude.WPF/Controls/TreeViewExtensions.cs+++ b/WaveDude.WPF/Controls/TreeViewExtensions.cs@@ -11,10 +11,15 @@ public static class TreeViewExtensions/// keeps the focus, 2026-10-14). Only realised containers are searched, so call it once the/// tree has generated its items. Returns false when the item was not found./// </summary>- public static bool SetSelectedItem(this TreeView tree, object item, bool expand = false, bool focus = true) =>- SetSelected(tree, item, expand, focus);+ /// <param name="tree">The tree.</param>+ /// <param name="item">The data item whose container is wanted.</param>+ /// <param name="expand">Expand the container too.</param>+ /// <param name="focus">Give the container keyboard focus.</param>+ /// <param name="select">Select the container; false deselects it instead (nothing else is touched then).</param>+ public static bool SetSelectedItem(this TreeView tree, object item, bool expand = false, bool focus = true, bool select = true) =>+ SetSelected(tree, item, expand, focus, select);- private static bool SetSelected(ItemsControl? parent, object item, bool expand, bool focus)+ private static bool SetSelected(ItemsControl? parent, object item, bool expand, bool focus, bool select){if (parent == null){@@ -22,20 +27,20 @@ public static class TreeViewExtensions}if (parent.ItemContainerGenerator.ContainerFromItem(item) is TreeViewItem container){- if (focus)+ if (focus && select){container.Focus();}- if (expand)+ if (expand && select){container.IsExpanded = true;}- container.IsSelected = true;+ container.IsSelected = select;return true;}foreach (object child in parent.Items){- if (SetSelected(parent.ItemContainerGenerator.ContainerFromItem(child) as ItemsControl, item, expand, focus))+ if (SetSelected(parent.ItemContainerGenerator.ContainerFromItem(child) as ItemsControl, item, expand, focus, select)){return true;}diff --git a/WaveDude.WPF/MainWindow.xaml.cs b/WaveDude.WPF/MainWindow.xaml.csindex de4b2c9..a526762 100644--- a/WaveDude.WPF/MainWindow.xaml.cs+++ b/WaveDude.WPF/MainWindow.xaml.cs@@ -118,7 +118,12 @@ public partial class MainWindow : Windowprivate void OnSelectedItemChanged(object? item){CommandManager.InvalidateRequerySuggested();- if (item != null && !ReferenceEquals(projectTree.SelectedItem, item))+ if (item == null)+ {+ // deselected on the preview (a click on empty space): the tree lets go too+ projectTree.ClearSelection();+ }+ else if (!ReferenceEquals(projectTree.SelectedItem, item)){projectTree.Select(item, focus: false);}diff --git a/WaveDude.WPF/Panes/PreviewPane.xaml.cs b/WaveDude.WPF/Panes/PreviewPane.xaml.csindex 6501f99..20a0191 100644--- a/WaveDude.WPF/Panes/PreviewPane.xaml.cs+++ b/WaveDude.WPF/Panes/PreviewPane.xaml.cs@@ -65,7 +65,7 @@ public partial class PreviewPane : UserControl/// <summary>Identifies the <see cref="Project"/> property.</summary>public static readonly DependencyProperty ProjectProperty = DependencyProperty.Register(- nameof(Project), typeof(Project), typeof(PreviewPane));+ nameof(Project), typeof(Project), typeof(PreviewPane), new PropertyMetadata(null, (d, _) => ((PreviewPane)d).OnProjectReplaced()));/// <summary>Identifies the <see cref="Run"/> property.</summary>public static readonly DependencyProperty RunProperty = DependencyProperty.Register(@@ -657,6 +657,14 @@ public partial class PreviewPane : UserControl/// <summary>The canvas follows the project's size while nothing is shown.</summary>private void UpdateCanvas() => UpdateSource();+ /// <summary>Another project (new, opened, imported or closed): playback stops and the timeline goes back to frame 0 (the user's rule, 2026-10-15).</summary>+ private void OnProjectReplaced()+ {+ IsPlaying = false;+ IsLive = false;+ Position = 0;+ }+/// <summary>A black picture of the given size, frozen; what the pane shows before any run.</summary>private static BitmapSource BlackFrame(int width, int height){@@ -993,7 +1001,19 @@ public partial class PreviewPane : UserControl}/// <summary>A click on the pictures gives the pane keyboard focus so that Space toggles playback.</summary>- private void OnPicturesMouseDown(object sender, MouseButtonEventArgs e) => Focus();+ /// <summary>+ /// A click on the pictures gives the pane keyboard focus so that Space toggles playback, and a left click on+ /// empty space (the handles and graph boxes are thumbs, which handle their own press) deselects the current+ /// item (the user's rule, 2026-10-15).+ /// </summary>+ private void OnPicturesMouseDown(object sender, MouseButtonEventArgs e)+ {+ if (e.ChangedButton == MouseButton.Left)+ {+ SelectedItem = null;+ }+ Focus();+ }/// <summary>Puts the splitter back in the middle: both pictures get an equal star share of the split dimension.</summary>private void ResetSplit()diff --git a/WaveDude.WPF/Panes/ProjectTree.xaml.cs b/WaveDude.WPF/Panes/ProjectTree.xaml.csindex 6cca1d5..ad52d2a 100644--- a/WaveDude.WPF/Panes/ProjectTree.xaml.cs+++ b/WaveDude.WPF/Panes/ProjectTree.xaml.cs@@ -59,6 +59,15 @@ public partial class ProjectTree : UserControlpublic event RoutedPropertyChangedEventHandler<object>? SelectedItemChanged;/// <summary>Selects the node of a model object once the tree has generated it; with <paramref name="focus"/> the node also takes keyboard focus.</summary>+ /// <summary>Deselects the selected node, if any; the tree then raises its change with null (2026-10-15, a click on empty preview space).</summary>+ public void ClearSelection()+ {+ if (tree.SelectedItem is { } item)+ {+ tree.SetSelectedItem(item, expand: false, focus: false, select: false);+ }+ }+public void Select(object item, bool focus = true) =>Dispatcher.InvokeAsync(() => tree.SetSelectedItem(item, expand: true, focus), DispatcherPriority.Loaded);