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#
Icons in the project tree: handle glyphs for sources and probes, part drawings, font glyphs
Alexander Graeffd3cfc8004cf
diff --git a/WaveDudeNext.WPF/Controls/IconView.cs b/WaveDudeNext.WPF/Controls/IconView.csnew file mode 100644index 0000000..b7bf801--- /dev/null+++ b/WaveDudeNext.WPF/Controls/IconView.cs@@ -0,0 +1,97 @@+// 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.Windows;+using System.Windows.Controls;+using System.Windows.Data;+using System.Windows.Documents;+using System.Windows.Shapes;++namespace WaveDudeNext.WPF.Controls;++/// <summary>+/// A 16 px icon (2026-10-23): a <see cref="Glyph"/> of Windows' icon font, or one of the app's own <see cref="Drawing"/>s,+/// in its inherited text colour, so it greys out with the text beside it. Used in the project tree's rows and, through+/// <see cref="Create"/>, by <see cref="MenuIcon"/>. Not focusable. UI thread.+/// </summary>+public sealed class IconView : ContentControl+{+ /// <summary>Identifies the <see cref="Glyph"/> property.</summary>+ public static readonly DependencyProperty GlyphProperty = DependencyProperty.Register(+ nameof(Glyph), typeof(string), typeof(IconView), new PropertyMetadata(null, OnIconChanged));++ /// <summary>Identifies the <see cref="Drawing"/> property.</summary>+ public static readonly DependencyProperty DrawingProperty = DependencyProperty.Register(+ nameof(Drawing), typeof(string), typeof(IconView), new PropertyMetadata(null, OnIconChanged));++ public IconView()+ {+ Focusable = false;+ IsTabStop = false;+ Width = 16;+ Height = 16;+ }++ /// <summary>The icon font's character (Segoe Fluent Icons, Segoe MDL2 Assets on Windows 10), or null.</summary>+ public string? Glyph+ {+ get => (string?)GetValue(GlyphProperty);+ set => SetValue(GlyphProperty, value);+ }++ /// <summary>+ /// The name of one of the app's drawings: the theme's stroked geometry <c>Icon{name}</c> and, where part of it is solid,+ /// the filled <c>Icon{name}Fill</c>, both on a 16 px grid; or null.+ /// </summary>+ public string? Drawing+ {+ get => (string?)GetValue(DrawingProperty);+ set => SetValue(DrawingProperty, value);+ }++ private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)+ {+ var view = (IconView)d;+ view.Content = Create(view.Glyph, view.Drawing);+ }++ /// <summary>The element showing <paramref name="glyph"/>, else <paramref name="drawing"/>; null for neither.</summary>+ public static UIElement? Create(string? glyph, string? drawing)+ {+ if (glyph is { Length: > 0 })+ {+ var text = new TextBlock { Text = glyph };+ // resolved once the element is in place, so a menu built in code finds the theme's style too+ text.SetResourceReference(FrameworkElement.StyleProperty, "MenuIconText");+ return text;+ }+ if (drawing is not { Length: > 0 })+ {+ return null;+ }+ // the inherited text colour each path holds itself (an ancestor lookup ran before the icon was in place and never+ // found one, 2026-10-23)+ var colour = new Binding { Path = new PropertyPath(TextElement.ForegroundProperty), RelativeSource = RelativeSource.Self };+ var stroke = new Path { StrokeThickness = 1.0 };+ stroke.SetResourceReference(Path.DataProperty, "Icon" + drawing);+ stroke.SetBinding(Shape.StrokeProperty, colour);+ var fill = new Path();+ fill.SetResourceReference(Path.DataProperty, "Icon" + drawing + "Fill");+ fill.SetBinding(Shape.FillProperty, colour);+ return new Grid { Width = 16, Height = 16, Children = { stroke, fill } };+ }+}diff --git a/WaveDudeNext.WPF/Controls/MenuIcon.cs b/WaveDudeNext.WPF/Controls/MenuIcon.csindex 34af32d..d0064a5 100644--- a/WaveDudeNext.WPF/Controls/MenuIcon.cs+++ b/WaveDudeNext.WPF/Controls/MenuIcon.cs@@ -17,9 +17,6 @@using System.Windows;using System.Windows.Controls;-using System.Windows.Data;-using System.Windows.Documents;-using System.Windows.Shapes;namespace WaveDudeNext.WPF.Controls;@@ -28,7 +25,7 @@ namespace WaveDudeNext.WPF.Controls;/// the app's own drawings (<see cref="DrawingProperty"/>). The glyph is attached as/// <c>controls:MenuIcon.Glyph="&#xE74E;"</c>, it gives the <see cref="MenuItem"/> a <see cref="TextBlock"/> of that/// character in the theme's <c>MenuIconText</c> style (Segoe Fluent Icons on Windows 11, Segoe MDL2 Assets on Windows 10,-/// in the entry's text colour). UI thread.+/// in the entry's text colour); both are made by <see cref="IconView.Create"/>, as the tree's icons are. UI thread./// </summary>public static class MenuIcon{@@ -58,41 +55,17 @@ public static class MenuIconprivate static void OnDrawingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){- if (d is not MenuItem item)+ if (d is MenuItem item){- return;+ item.Icon = IconView.Create(null, e.NewValue as string);}- if (e.NewValue is not string { Length: > 0 } name)- {- item.Icon = null;- return;- }- // the entry's text colour, which greys out when it is disabled, like a font glyph's: the inherited text foreground- // each path holds itself (an ancestor lookup ran before the icon was in its menu and never found one)- var colour = new Binding { Path = new PropertyPath(TextElement.ForegroundProperty), RelativeSource = RelativeSource.Self };- var stroke = new Path { StrokeThickness = 1.0 };- stroke.SetResourceReference(Path.DataProperty, "Icon" + name);- stroke.SetBinding(Shape.StrokeProperty, colour);- var fill = new Path();- fill.SetResourceReference(Path.DataProperty, "Icon" + name + "Fill");- fill.SetBinding(Shape.FillProperty, colour);- item.Icon = new Grid { Width = 16, Height = 16, Children = { stroke, fill } };}private static void OnGlyphChanged(DependencyObject d, DependencyPropertyChangedEventArgs e){- if (d is not MenuItem item)- {- return;- }- if (e.NewValue is not string { Length: > 0 } glyph)+ if (d is MenuItem item){- item.Icon = null;- return;+ item.Icon = IconView.Create(e.NewValue as string, null);}- var text = new TextBlock { Text = glyph };- // resolved once the entry is in its menu, so a context menu built in code finds the theme's style too- text.SetResourceReference(FrameworkElement.StyleProperty, "MenuIconText");- item.Icon = text;}}diff --git a/WaveDudeNext.WPF/Converters/PartIconConverter.cs b/WaveDudeNext.WPF/Converters/PartIconConverter.csnew file mode 100644index 0000000..894aa2b--- /dev/null+++ b/WaveDudeNext.WPF/Converters/PartIconConverter.cs@@ -0,0 +1,37 @@+// 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.Globalization;+using System.Windows.Data;+using WaveDudeNext.Model;++namespace WaveDudeNext.WPF.Converters;++/// <summary>+/// The icon drawing of an optical part (2026-10-23): its class name without "Part" (a <see cref="LensPart"/> is "Lens", an+/// <see cref="XorGatePart"/> "XorGate"), the name of the theme's <c>Icon{name}</c> geometry the Add part menu shows too.+/// </summary>+public sealed class PartIconConverter : IValueConverter+{+ /// <inheritdoc/>+ public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>+ value is OpticalPart part ? part.GetType().Name.Replace("Part", "", StringComparison.Ordinal) : null;++ /// <inheritdoc/>+ public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) =>+ throw new NotSupportedException();+}diff --git a/WaveDudeNext.WPF/Panes/PreviewPane.xaml b/WaveDudeNext.WPF/Panes/PreviewPane.xamlindex 389bd88..d51780e 100644--- a/WaveDudeNext.WPF/Panes/PreviewPane.xaml+++ b/WaveDudeNext.WPF/Panes/PreviewPane.xaml@@ -163,12 +163,9 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or</Setter></Style>- <!-- the handles of the sources and probes on the pictures: a ring for a source, a square for a probe- point, each with four crosshair ticks outside it and a gap around the exact pixel; every stroke is- drawn twice, a dark halo first, so the glyph reads on any picture. The selected item's handle and- the focused handle show the accent. Glyphs are 20 x 20 with the point at (10, 10) -->- <StreamGeometry x:Key="SourceGlyph">M4,10 A6,6 0 1 1 16,10 A6,6 0 1 1 4,10 M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10</StreamGeometry>- <StreamGeometry x:Key="ProbeGlyph">M4.5,4.5 L15.5,4.5 L15.5,15.5 L4.5,15.5 Z M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10</StreamGeometry>+ <!-- the handle glyphs (SourceGlyph, ProbeGlyph, PartGlyph) are in Themes/Controls.xaml, shared with the project tree's icons;+ every stroke is drawn twice here, a dark halo first, so the glyph reads on any picture. The selected item's handle and+ the focused handle show the accent --><Style x:Key="MarkerBase" TargetType="{x:Type controls:MarkerThumb}"><Setter Property="Width" Value="20" /><Setter Property="Height" Value="20" />@@ -207,8 +204,6 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or</Setter.Value></Setter></Style>- <!-- an optical part: the source's circular crosshair with an inner ring instead of the dot (a lens-shaped glyph read as squashed, 2026-10-18) -->- <StreamGeometry x:Key="PartGlyph">M4,10 A6,6 0 1 1 16,10 A6,6 0 1 1 4,10 M7.5,10 A2.5,2.5 0 1 1 12.5,10 A2.5,2.5 0 1 1 7.5,10 M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10</StreamGeometry><Style x:Key="PartMarker" TargetType="{x:Type controls:MarkerThumb}" BasedOn="{StaticResource MarkerBase}"><Setter Property="Template"><Setter.Value>diff --git a/WaveDudeNext.WPF/Panes/ProjectTree.xaml b/WaveDudeNext.WPF/Panes/ProjectTree.xamlindex bf74c0d..6d9b4cd 100644--- a/WaveDudeNext.WPF/Panes/ProjectTree.xaml+++ b/WaveDudeNext.WPF/Panes/ProjectTree.xaml@@ -33,6 +33,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<converters:ColorSchemeBrushConverter x:Key="ColorSchemeBrush" /><converters:TreeIdConverter x:Key="TreeId" /><converters:IsTypeConverter x:Key="IsType" />+ <converters:PartIconConverter x:Key="PartIcon" /><StreamGeometry x:Key="PlusGeometry">M4,0 L4,8 M0,4 L8,4</StreamGeometry><StreamGeometry x:Key="MinusGeometry">M0,4 L8,4</StreamGeometry>@@ -220,17 +221,29 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<Binding Path="ColorSchemes" /></MultiBinding></HierarchicalDataTemplate.ItemsSource>- <TextBlock Text="{DynamicResource TreeProject}" />+ <StackPanel Orientation="Horizontal">+ <controls:IconView Drawing="Project" Margin="0,0,4,0" VerticalAlignment="Center" />+ <TextBlock Text="{DynamicResource TreeProject}" VerticalAlignment="Center" />+ </StackPanel></HierarchicalDataTemplate><DataTemplate DataType="{x:Type model:Scene}">- <TextBlock Text="{DynamicResource TreeScene}" />+ <StackPanel Orientation="Horizontal">+ <controls:IconView Glyph="" Margin="0,0,4,0" VerticalAlignment="Center" />+ <TextBlock Text="{DynamicResource TreeScene}" VerticalAlignment="Center" />+ </StackPanel></DataTemplate><DataTemplate DataType="{x:Type model:Simulation}">- <TextBlock Text="{DynamicResource TreeSimulation}" />+ <StackPanel Orientation="Horizontal">+ <controls:IconView Glyph="" Margin="0,0,4,0" VerticalAlignment="Center" />+ <TextBlock Text="{DynamicResource TreeSimulation}" VerticalAlignment="Center" />+ </StackPanel></DataTemplate><DataTemplate DataType="{x:Type model:Display}">- <TextBlock Text="{DynamicResource TreeDisplay}" />+ <StackPanel Orientation="Horizontal">+ <controls:IconView Glyph="" Margin="0,0,4,0" VerticalAlignment="Center" />+ <TextBlock Text="{DynamicResource TreeDisplay}" VerticalAlignment="Center" />+ </StackPanel></DataTemplate><!-- folder row: name and an add button; the Parts folder's button carries the menu of kinds, which Add opens -->@@ -248,6 +261,27 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or</Style></Button.Style></Button>+ <!-- the folder shows the icon of what it holds: the handle glyphs, the palette for schemes -->+ <controls:IconView DockPanel.Dock="Left" Margin="0,0,4,0" VerticalAlignment="Center">+ <controls:IconView.Style>+ <Style TargetType="{x:Type controls:IconView}">+ <Style.Triggers>+ <DataTrigger Binding="{Binding Key}" Value="TreeSources">+ <Setter Property="Drawing" Value="Source" />+ </DataTrigger>+ <DataTrigger Binding="{Binding Key}" Value="TreeParts">+ <Setter Property="Drawing" Value="Part" />+ </DataTrigger>+ <DataTrigger Binding="{Binding Key}" Value="TreeProbes">+ <Setter Property="Drawing" Value="Probe" />+ </DataTrigger>+ <DataTrigger Binding="{Binding Key}" Value="TreeColorSchemes">+ <Setter Property="Glyph" Value="" />+ </DataTrigger>+ </Style.Triggers>+ </Style>+ </controls:IconView.Style>+ </controls:IconView><TextBlock Text="{Binding Label}" VerticalAlignment="Center" /></DockPanel></HierarchicalDataTemplate>@@ -265,6 +299,17 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<CheckBox DockPanel.Dock="Left" Focusable="False" IsTabStop="False" MinHeight="0" Margin="0,0,4,0" VerticalAlignment="Center"IsChecked="{Binding Enabled}" ToolTip="{DynamicResource TipSourceEnabled}"AutomationProperties.Name="{DynamicResource TipSourceEnabled}" AutomationProperties.AutomationId="{Binding Name, StringFormat='Enabled:{0}'}" />+ <controls:IconView DockPanel.Dock="Left" Drawing="Source" Margin="0,0,4,0" VerticalAlignment="Center">+ <controls:IconView.Style>+ <Style TargetType="{x:Type controls:IconView}">+ <Style.Triggers>+ <DataTrigger Binding="{Binding Enabled}" Value="False">+ <Setter Property="Foreground" Value="{DynamicResource GrayText}" />+ </DataTrigger>+ </Style.Triggers>+ </Style>+ </controls:IconView.Style>+ </controls:IconView><TextBlock Text="{Binding Name}" VerticalAlignment="Center"><TextBlock.Style><Style TargetType="{x:Type TextBlock}">@@ -290,6 +335,17 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<CheckBox DockPanel.Dock="Left" Focusable="False" IsTabStop="False" MinHeight="0" Margin="0,0,4,0" VerticalAlignment="Center"IsChecked="{Binding Enabled}" ToolTip="{DynamicResource TipPartEnabled}"AutomationProperties.Name="{DynamicResource TipPartEnabled}" AutomationProperties.AutomationId="{Binding Name, StringFormat='Enabled:{0}'}" />+ <controls:IconView DockPanel.Dock="Left" Drawing="{Binding Converter={StaticResource PartIcon}}" Margin="0,0,4,0" VerticalAlignment="Center">+ <controls:IconView.Style>+ <Style TargetType="{x:Type controls:IconView}">+ <Style.Triggers>+ <DataTrigger Binding="{Binding Enabled}" Value="False">+ <Setter Property="Foreground" Value="{DynamicResource GrayText}" />+ </DataTrigger>+ </Style.Triggers>+ </Style>+ </controls:IconView.Style>+ </controls:IconView><TextBlock Text="{Binding Name}" VerticalAlignment="Center"><TextBlock.Style><Style TargetType="{x:Type TextBlock}">@@ -329,6 +385,17 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<CheckBox DockPanel.Dock="Left" Focusable="False" IsTabStop="False" MinHeight="0" Margin="0,0,4,0" VerticalAlignment="Center"IsChecked="{Binding Active}" ToolTip="{DynamicResource TipProbeActive}"AutomationProperties.Name="{DynamicResource TipProbeActive}" AutomationProperties.AutomationId="{Binding Name, StringFormat='Enabled:{0}'}" />+ <controls:IconView DockPanel.Dock="Left" Drawing="Probe" Margin="0,0,4,0" VerticalAlignment="Center">+ <controls:IconView.Style>+ <Style TargetType="{x:Type controls:IconView}">+ <Style.Triggers>+ <DataTrigger Binding="{Binding Active}" Value="False">+ <Setter Property="Foreground" Value="{DynamicResource GrayText}" />+ </DataTrigger>+ </Style.Triggers>+ </Style>+ </controls:IconView.Style>+ </controls:IconView><TextBlock Text="{Binding Name}" VerticalAlignment="Center"><TextBlock.Style><Style TargetType="{x:Type TextBlock}">diff --git a/WaveDudeNext.WPF/Themes/Controls.xaml b/WaveDudeNext.WPF/Themes/Controls.xamlindex c90e757..b29d950 100644--- a/WaveDudeNext.WPF/Themes/Controls.xaml+++ b/WaveDudeNext.WPF/Themes/Controls.xaml@@ -213,6 +213,8 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<Setter Property="FontSize" Value="16" /><Setter Property="LineHeight" Value="16" /><Setter Property="LineStackingStrategy" Value="BlockLineHeight" />+ <!-- greyscale: ClearType's colour fringes are for letters, on an icon they show as red and blue edges -->+ <Setter Property="TextOptions.TextRenderingMode" Value="Grayscale" /><Setter Property="RenderTransform"><Setter.Value><TranslateTransform Y="3" />@@ -222,6 +224,20 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<Setter Property="VerticalAlignment" Value="Center" /></Style>+ <!-- the handles of the sources, parts and probes on the pictures (moved here 2026-10-23, shared with the project tree):+ a ring for a source, a ring with an inner ring for a part (a lens-shaped glyph read as squashed, 2026-10-18), a square+ for a probe point, each with four crosshair ticks outside it and a gap around the exact pixel. Glyphs are 20 x 20 with+ the point at (10, 10) -->+ <StreamGeometry x:Key="SourceGlyph">M4,10 A6,6 0 1 1 16,10 A6,6 0 1 1 4,10 M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10</StreamGeometry>+ <StreamGeometry x:Key="ProbeGlyph">M4.5,4.5 L15.5,4.5 L15.5,15.5 L4.5,15.5 Z M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10</StreamGeometry>+ <StreamGeometry x:Key="PartGlyph">M4,10 A6,6 0 1 1 16,10 A6,6 0 1 1 4,10 M7.5,10 A2.5,2.5 0 1 1 12.5,10 A2.5,2.5 0 1 1 7.5,10 M10,0 L10,2.5 M10,17.5 L10,20 M0,10 L2.5,10 M17.5,10 L20,10</StreamGeometry>+ <!-- the same glyphs as 16 px icons for the tree's rows and folders (IconView Drawing="Source", "Probe", "Part") -->+ <GeometryGroup x:Key="IconSource" Transform="0.8,0,0,0.8,0,0"><StaticResource ResourceKey="SourceGlyph" /></GeometryGroup>+ <GeometryGroup x:Key="IconProbe" Transform="0.8,0,0,0.8,0,0"><StaticResource ResourceKey="ProbeGlyph" /></GeometryGroup>+ <GeometryGroup x:Key="IconPart" Transform="0.8,0,0,0.8,0,0"><StaticResource ResourceKey="PartGlyph" /></GeometryGroup>+ <!-- the project root: a wave on its canvas -->+ <StreamGeometry x:Key="IconProject">M1.5,2.5 H14.5 V13.5 H1.5 Z M3,8 C4.5,4.5 6.5,4.5 8,8 C9.5,11.5 11.5,11.5 13,8</StreamGeometry>+<!-- the app's own menu icons (controls:MenuIcon.Drawing, 2026-10-23) for entries the icon font has no glyph for: 16 pxline drawings, stroked at 1 px on half pixels so the lines are crisp at 100 %, a Fill geometry for the solid parts --><!-- a biconvex lens -->