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#
The manual loads its document again when the UI zoom changes the text formatting mode: no blurred text after a live change
Alexander Graef4116cd48f76f
diff --git a/CLAUDE.md b/CLAUDE.mdindex 0108a1e..8369916 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -98,7 +98,8 @@ harnesses run.the log).- **Do not resurrect**: a probe signal lane, timeline tracks, zoom and pan of the axis, thumbnails, a run progressbar, the scratch budget and its "not computed" note, a GPU JPEG front end, a Direct3D display path, a bent- rotation lever, an unreadable settings file moved aside (2026-11-03: nobody would find it, the log quotes it). **Do not+ rotation lever, an unreadable settings file moved aside (2026-11-03: nobody would find it, the log quotes it), Ideal+ text formatting for the manual at 100 % (2026-11-05: less readable, see UI zoom). **Do notchange**: the readout showing both frame and step (undecided).- Collect the reusable rules for other projects only when he asks.@@ -452,7 +453,19 @@ FrameStore: native memory up to the budget, the rest in a temp file (%LOCALAPPDAgrid under the full transform; at 100 % the arithmetic is the old one, pixel for pixel. The handle glyphs (1.5 pxstrokes over a halo), the dashed probe lines and the marquee are antialiased by design and stay so. The window mustfit the screen for a capture: the Desktop Window Manager composes nothing off it, so PrintWindow returns white there. `PreviewQualityCheck` and `LanguageCheck` count- the View menu's entries past the new one.+ the View menu's entries past the new one. **The manual loads its document again when the zoom changes the text+ formatting mode** (2026-11-04, the user's report: the manual's text blurred at a live change and came back sharp+ reopened): WPF reads `TextOptions.TextFormattingMode` once, at a flow document's first formatting, into the text+ formatter it keeps for the document's life (`StructuralCache.EnsurePtsContext` in WPF's source), so the inherited+ change reached the document and re-formatted its lines with the Display-mode formatter, whose glyphs are drawn scaled,+ soft, and wrapped as at 100 %; a mode set on the document itself changes nothing either. `ManualWindow.ReloadDocument`:+ a new copy from BAML (130–180 ms), the headings re-pointed so the tree's rows stay, the place kept as a share of the+ height; the old text stays on screen, scaled, until the new copy is laid out, about half a second in all, which the+ user sees as the text sharpening a moment after the change (the log line names both times). The rule for the mode at+ a zoom is `WindowZoom.TextFormattingAt`. About is modal, so no zoom change reaches its license document. Proven by a+ probe that captures the manual at a live change and reopened: pixel for pixel the same. Ideal formatting for the+ manual at every zoom, which spares the reload, was built for the user to see and refused (2026-11-05, his decision: a+ zoom change with the manual open is rare and the delay short, and Ideal costs readability at 100 %).- **Optical parts** (2026-10-18; **`OpticalParts.md` is the reference**: the kinds, the painting rules, the measurementsand how to add a kind): subclasses of `OpticalPart` in `Project.Parts`, one class and one XML element per kind, theclass being the kind (no enum, 2026-10-22): a lens or mirror, the shapes under `ShapePart` (polygon, rectangle, ellipse,diff --git a/WaveDudeNext.WPF/Help/ManualHeading.cs b/WaveDudeNext.WPF/Help/ManualHeading.csindex 09f1425..1851d87 100644--- a/WaveDudeNext.WPF/Help/ManualHeading.cs+++ b/WaveDudeNext.WPF/Help/ManualHeading.cs@@ -39,8 +39,8 @@ public sealed class ManualHeading(string text, int level, string anchor, Paragra/// <summary>GitHub's anchor of the heading (lower case, a hyphen for each space), what a link "#anchor" names.</summary>public string Anchor { get; } = anchor;- /// <summary>The heading's paragraph in the document.</summary>- public Paragraph Paragraph { get; } = paragraph;+ /// <summary>The heading's paragraph in the document; pointed at a new copy's when the window loads the document again.</summary>+ public Paragraph Paragraph { get; internal set; } = paragraph;/// <summary>The headings of a higher level up to the next one of this level or lower, in document order.</summary>public List<ManualHeading> Children { get; } = [];diff --git a/WaveDudeNext.WPF/Help/ManualWindow.xaml.cs b/WaveDudeNext.WPF/Help/ManualWindow.xaml.csindex 0c00a6d..b5988d8 100644--- a/WaveDudeNext.WPF/Help/ManualWindow.xaml.cs+++ b/WaveDudeNext.WPF/Help/ManualWindow.xaml.cs@@ -16,6 +16,7 @@// <https://www.gnu.org/licenses/>.+using System.ComponentModel;using System.Diagnostics;using System.Windows;using System.Windows.Controls;@@ -25,6 +26,7 @@ using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Media3D;using System.Windows.Navigation;+using System.Windows.Threading;using NLog;using WaveDudeNext.WPF.Theming;@@ -36,7 +38,8 @@ namespace WaveDudeNext.WPF.Help;/// opens with the text at its top and the first chapter's row taken; taking a row goes to its heading, which then/// stands at the top of the text; a link to "#anchor" goes to that heading, a web link opens in the browser. The text/// scrolls by whole pixels, so a screenshot that fits the column stays drawn 1:1. Not modal, but owned by the main window-/// (the user's choice): minimised and restored with it, kept above it, opened once and closed with it. UI thread only.+/// (the user's choice): minimised and restored with it, kept above it, opened once and closed with it. A change of the UI+/// zoom that changes the text formatting mode loads the document again (<see cref="ReloadDocument"/>). UI thread only./// </summary>public partial class ManualWindow : Window{@@ -47,6 +50,8 @@ public partial class ManualWindow : Windowprivate ScrollViewer? _scroller;/// <summary>Set while the first row is taken on opening, so the text stays at its top instead of going to the heading.</summary>private bool _opening;+ /// <summary>The text formatting mode the shown document was formatted with: the window content's at its first layout.</summary>+ private TextFormattingMode _formattedMode;/// <summary>Loads the manual and its headings; the window opens with the text at its top and the first row taken, the tree focused.</summary>public ManualWindow()@@ -65,10 +70,84 @@ public partial class ManualWindow : WindowLoaded += OnLoaded;ContentRendered += (_, _) => Logger.Debug("Manual open: {Headings} headings, the document read in {Read:0} ms, on screen after {Shown:0} ms",Count(_all), read, Stopwatch.GetElapsedTime(start).TotalMilliseconds);+ Settings.Default.PropertyChanged += OnSettingChanged;}- /// <summary>The manual.</summary>- public FlowDocument Document { get; }+ /// <summary>Identifies the <see cref="Document"/> property.</summary>+ public static readonly DependencyProperty DocumentProperty = DependencyProperty.Register(+ nameof(Document), typeof(FlowDocument), typeof(ManualWindow));++ /// <summary>The manual: a new copy after a change of the UI zoom that changes the text formatting mode (<see cref="ReloadDocument"/>).</summary>+ public FlowDocument Document+ {+ get => (FlowDocument)GetValue(DocumentProperty);+ private set => SetValue(DocumentProperty, value);+ }++ /// <summary>Lets go of the settings' event, which outlives the window.</summary>+ protected override void OnClosed(EventArgs e)+ {+ Settings.Default.PropertyChanged -= OnSettingChanged;+ base.OnClosed(e);+ }++ /// <summary>+ /// A change of the UI zoom that changes the content's text formatting mode (the theme's Display at 1, Ideal when+ /// scaled) loads the document again (2026-11-04, the user's report: the text had blurred at a live change and came+ /// back sharp reopened): WPF reads the mode once, at a document's first formatting, into the text formatter it keeps+ /// for the document's life, so the lines were formatted again with the Display-mode one and drawn scaled, soft and+ /// wrapped as at 100 %.+ /// </summary>+ private void OnSettingChanged(object? sender, PropertyChangedEventArgs e)+ {+ if (e.PropertyName == nameof(Settings.UiZoom) && IsLoaded && WindowZoom.TextFormattingAt(this, Settings.Default.UiZoom) != _formattedMode)+ {+ ReloadDocument();+ }+ }++ /// <summary>+ /// A new copy of the document in the viewer, the headings pointed at its paragraphs, the text at the same share of+ /// its height. The old text stays on screen, scaled, until the new copy is laid out: about 180 ms to read it and the+ /// layout of the whole document after that, half a second in all, which the user sees as the text sharpening a+ /// moment after the zoom changed (2026-11-04). The log line names both times.+ /// </summary>+ private void ReloadDocument()+ {+ long start = Stopwatch.GetTimestamp();+ double zoom = Settings.Default.UiZoom;+ double share = _scroller is { ScrollableHeight: > 0 } scroller ? scroller.VerticalOffset / scroller.ScrollableHeight : 0;+ FlowDocument fresh = ManualDocument.Load();+ Relink(_all, ManualDocument.Contents(fresh));+ double read = Stopwatch.GetElapsedTime(start).TotalMilliseconds;+ Document = fresh;+ _formattedMode = WindowZoom.TextFormattingAt(this, zoom);+ // after the new document's layout (at Render priority): its lines wrap differently, so the place is kept as a share+ Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () =>+ {+ if (share > 0 && _scroller != null)+ {+ _scroller.ScrollToVerticalOffset(WholePixels(share * _scroller.ScrollableHeight));+ }+ Logger.Debug("Manual: the document loaded again, formatted {Mode} at UI zoom {Zoom}: read in {Read:0} ms, laid out after {Shown:0} ms",+ _formattedMode, zoom, read, Stopwatch.GetElapsedTime(start).TotalMilliseconds);+ });+ }++ /// <summary>The headings pointed at the paragraphs of a new copy of the same document, so the tree's rows stay.</summary>+ private static void Relink(IReadOnlyList<ManualHeading> headings, IReadOnlyList<ManualHeading> fresh)+ {+ if (headings.Count != fresh.Count)+ {+ Logger.Warn("Manual: {Count} headings in the document loaded again, {Known} before; the contents tree goes nowhere until the manual is opened again", fresh.Count, headings.Count);+ return;+ }+ for (int i = 0; i < headings.Count; i++)+ {+ headings[i].Paragraph = fresh[i].Paragraph;+ Relink(headings[i].Children, fresh[i].Children);+ }+ }/// <summary>The contents tree's rows: the manual's chapters, each with its sections under it.</summary>public IReadOnlyList<ManualHeading> Headings { get; }@@ -87,6 +166,7 @@ public partial class ManualWindow : Windowprivate void OnLoaded(object sender, RoutedEventArgs e){+ _formattedMode = WindowZoom.TextFormattingAt(this, Settings.Default.UiZoom);_scroller = documentView.Template.FindName("PART_ContentHost", documentView) as ScrollViewer;if (_scroller != null){diff --git a/WaveDudeNext.WPF/Theming/WindowZoom.cs b/WaveDudeNext.WPF/Theming/WindowZoom.csindex db70474..a179cda 100644--- a/WaveDudeNext.WPF/Theming/WindowZoom.cs+++ b/WaveDudeNext.WPF/Theming/WindowZoom.cs@@ -210,6 +210,15 @@ public static class WindowZoomKeepOnScreen(window);}+ /// <summary>+ /// The text formatting mode a window's content has at a zoom, what <see cref="ZoomContent"/> gives it: Ideal when+ /// scaled, else the window's own (the theme's Display). A flow document must be loaded again when it changes+ /// (<see cref="Help.ManualWindow"/>): WPF reads the mode once, at the document's first formatting, into the text+ /// formatter it keeps for the document's life, so a change re-formats the lines with the old one.+ /// </summary>+ public static TextFormattingMode TextFormattingAt(Window window, double zoom) =>+ zoom == 1 ? TextOptions.GetTextFormattingMode(window) : TextFormattingMode.Ideal;+// ---------------------------------------------------------------- popupsprivate static void OnPopupChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)