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#
Colour picker for the scheme stops: an in-house popup with square, hue strip, channels and hex
Alexander Graef2779f436dad1
diff --git a/CLAUDE.md b/CLAUDE.mdindex 245bf01..d9b117d 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -198,9 +198,26 @@ WPF shell as it stands:Both go through the model, so the project turns dirty (asterisk, save prompt), the run goes stale and theframe is recomputed; a path change alone is not a simulation change. No hash: the embedded bytes are thebaseline and the file has to be read to re-embed it anyway. Open decisions: base64 vs BaseXML for the- bytes (base64 is what `XmlSerializer` does natively; BaseXML would need an in-house codec); a colour- picker dialog for the stops (hex text only today; the WinForms `ColorDialog` would need- `UseWindowsForms`); renaming a project scheme does not update the layers that refer to it.+ bytes (base64 is what `XmlSerializer` does natively; BaseXML would need an in-house codec); renaming a project+ scheme does not update the layers that refer to it. **The colour picker** (2026-10-15, the user's choice of an+ in-house picker over the Windows dialog, which is not themed, has no live preview and cannot be driven by posted+ keys): each stop row's swatch is a `Controls/ColorPickerButton` (a `ToggleButton`; Space, Enter or Down open a+ popup below it, id `StopSwatch:<position>`, the hex box beside it `StopColor:<position>`, both in the locale's+ number spelling) holding a `Controls/ColorPicker`: a saturation/value square under the pure hue (white-to-clear+ and clear-to-black overlays), a hue strip, R/G/B `NumberBox`es and the hex, all views of its one `Color`+ (`Rgb.ToHsv`/`FromHsv` in the library, exact round trip for every 8-bit colour, harness-checked; the HSV side+ keeps its hue for a grey and whenever the colour set from outside is what the current hue, saturation and value+ give, so a drag never jumps). Keyboard: the square and the strip are `Thumb`s (a thumb captures the mouse for+ the drag and has an automation peer, a Border has neither), arrows move saturation/value by 1/100 and the hue+ by a degree, ten with Shift; the colour follows every move, so the gradient and the preview recolour live, but+ **the owner is told at most ten times a second** (`ColorPicker.CommitInterval`, 2026-10-15, after a drag felt+ sluggish: every commit sets off the scheme's change, the gradient bar, the dirty flag and a re-render of both+ pictures; the markers and the square move at once, the commit follows within 100 ms and once more when the drag+ ends, and a colour set from outside, Escape's revert included, cancels a pending one); Enter keeps (a text box being edited is committed first), Escape puts the colour back and closes, a click+ outside closes (the click that lands on the swatch is swallowed for 250 ms, else it reopened the popup). Ids+ `ColorSquare`, `ColorHue`, `ColorRed|Green|Blue`, `ColorHex`. The markers live in the thumbs' own templates, so+ the picker finds them through `Template.FindName` after `ApplyTemplate` on the thumb; `GetTemplateChild` on+ the picker returned null and left both markers at the top-left corner.- **Scene image in the preview** (2026-10-13, the user's choice after the author's app was checked):the original shows the scene image itself as the picking background of its Sources/Probes tabs andlays a "glowing edges" outline (per-channel Sobel × 0.25, clamped) over the field and intensity@@ -697,7 +714,15 @@ passing harnesses for comfort, never all of them after an edit.file and turns the project dirty, the status bar says so, the scene view shows the path; then the file isoverwritten on disk and the picture follows within a moment; a second project without a path finds itsimage by name in `scene_images` and stores the relative path (8 checks, about 40 s).- `_tools/ui_check/AboutCheck.ps1` (2026-10-15, 17 checks, about 10 s) opens Help > About by keyboard (F10, Left wraps+ `_tools/ui_check/ColorPickerCheck.ps1` (2026-10-15, 11 checks, about 12 s) drives the stop swatch's picker on+ `tiny_scheme.wdproj` (tiny plus a project scheme with a middle stop #4080C0): End in the tree selects the scheme+ (the tree is one tab stop, End goes to its last visible item), Tab reaches the swatch, Space opens the popup with+ the focus on the square, ten Left arrows make the stop #538AC0 at once (hue 210, saturation 2/3 - 1/10, value+ 0.753, the number the library check also asserts), Escape puts #4080C0 back, Tab walks strip and red box, five+ Up arrows make #4580C0, Enter keeps it; the popup's own window is captured as `%TEMP%\wavedude_color_picker.popup.png`.+ A `Rectangle` has no automation peer (the gradient's id `SchemeGradient` is invisible to UIA; the "Add stop"+ button marks the editor instead).+ `_tools/ui_check/AboutCheck.ps1` (2026-10-15, 18 checks, about 10 s) opens Help > About by keyboard (F10, Left wrapsto the Help header, Down, Enter), finds the dialog as a child of the main window, posts its keys to the dialog's ownhandle (`DKey`), and checks the version line against `git rev-parse --short=7 HEAD`, the copyright and credit lines,the five links, the eight system lines, the focus on Close, the Tab cycle, Space on the license toggle showing the@@ -962,8 +987,7 @@ progress and cancel are in, and the still of the shown frame; `library_check --cover them. Left: probe data as CSV (series per step, profiles per frame), an integer upscale for smallcanvases, HEVC (Media Foundation has it on some machines). Author's point 10.-**Also open, smaller.** A colour picker dialog for stops (hex only now; WinForms `ColorDialog` needs `UseWindowsForms`);-offer `ColorScheme.Simplify` in the editor; renaming a project scheme does not update the layers that+**Also open, smaller.** Offer `ColorScheme.Simplify` in the editor; renaming a project scheme does not update the layers thatrefer to it; base64 vs BaseXML for the embedded image; the RAM-first frame store (numbers above);dropping the 9-point Laplacian (author's suggestion, user undecided); timeline event tracks, zoom andpan (roadmap); dock pane titles are not exposed to UI Automation.diff --git a/WaveDudeNext.WPF/Controls/ColorPicker.cs b/WaveDudeNext.WPF/Controls/ColorPicker.csnew file mode 100644index 0000000..504ca45--- /dev/null+++ b/WaveDudeNext.WPF/Controls/ColorPicker.cs@@ -0,0 +1,382 @@+// 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.Windows;+using System.Windows.Controls;+using System.Windows.Controls.Primitives;+using System.Windows.Input;+using System.Windows.Media;+using System.Windows.Threading;+using WaveDudeNext.Rendering;++namespace WaveDudeNext.WPF.Controls;++/// <summary>+/// The colour picker inside a <see cref="ColorPickerButton"/>'s popup (2026-10-15, the user's choice of an in-house+/// picker over the Windows dialog): a saturation/value square under the pure hue, a hue strip, red, green and blue+/// number boxes and the hex text, all editing the one <see cref="Color"/>, which the owner binds two-way. Keyboard:+/// the square and the strip are focusable; on the square the arrow keys move saturation (left, right) and value+/// (up, down) by 1/100, on the strip Up and Down move the hue by a degree, ten with Shift; the mouse drags both+/// markers. The HSV side keeps its hue for a grey (a grey has no hue) and whenever the colour set from outside is+/// what the current hue, saturation and value already give, so a drag never jumps. **The owner is told at most+/// ten times a second** (2026-10-15, after a drag felt sluggish): a change of hue, saturation or value moves the+/// markers and recolours the square at once, but <see cref="Color"/>, which the owner binds and which sets off the+/// scheme's change, the gradient bar, the dirty flag and a re-render of both preview pictures, is committed after+/// <see cref="CommitInterval"/> at most, and once more when a drag ends; a colour set from outside cancels a+/// pending commit (Escape puts the old colour back and nothing may overwrite it). The template in+/// <c>Editors.xaml</c> names PART_Square and PART_HueStrip (both <see cref="Thumb"/>s: a thumb captures the mouse+/// for the drag by itself and has an automation peer, so a harness sees which one has the focus; a Border has+/// neither) and PART_SquareMarker and PART_HueMarker, which sit on a Canvas and are placed from here. UI thread only.+/// </summary>+[TemplatePart(Name = SquarePart, Type = typeof(Thumb))]+[TemplatePart(Name = SquareMarkerPart, Type = typeof(FrameworkElement))]+[TemplatePart(Name = HueStripPart, Type = typeof(Thumb))]+[TemplatePart(Name = HueMarkerPart, Type = typeof(FrameworkElement))]+public class ColorPicker : Control+{+ private const string SquarePart = "PART_Square";+ private const string SquareMarkerPart = "PART_SquareMarker";+ private const string HueStripPart = "PART_HueStrip";+ private const string HueMarkerPart = "PART_HueMarker";++ /// <summary>Identifies the <see cref="Color"/> property.</summary>+ public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(+ nameof(Color), typeof(Rgb), typeof(ColorPicker),+ new FrameworkPropertyMetadata(default(Rgb), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnColorChanged));++ /// <summary>Identifies the <see cref="Hue"/> property.</summary>+ public static readonly DependencyProperty HueProperty = DependencyProperty.Register(+ nameof(Hue), typeof(double), typeof(ColorPicker), new PropertyMetadata(0.0, OnHsvChanged));++ /// <summary>Identifies the <see cref="Saturation"/> property.</summary>+ public static readonly DependencyProperty SaturationProperty = DependencyProperty.Register(+ nameof(Saturation), typeof(double), typeof(ColorPicker), new PropertyMetadata(0.0, OnHsvChanged));++ /// <summary>Identifies the <see cref="Value"/> property.</summary>+ public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(+ nameof(Value), typeof(double), typeof(ColorPicker), new PropertyMetadata(0.0, OnHsvChanged));++ /// <summary>Identifies the <see cref="Red"/> property.</summary>+ public static readonly DependencyProperty RedProperty = DependencyProperty.Register(+ nameof(Red), typeof(int), typeof(ColorPicker), new PropertyMetadata(0, OnChannelChanged));++ /// <summary>Identifies the <see cref="Green"/> property.</summary>+ public static readonly DependencyProperty GreenProperty = DependencyProperty.Register(+ nameof(Green), typeof(int), typeof(ColorPicker), new PropertyMetadata(0, OnChannelChanged));++ /// <summary>Identifies the <see cref="Blue"/> property.</summary>+ public static readonly DependencyProperty BlueProperty = DependencyProperty.Register(+ nameof(Blue), typeof(int), typeof(ColorPicker), new PropertyMetadata(0, OnChannelChanged));++ /// <summary>Identifies the <see cref="HueBrush"/> property.</summary>+ public static readonly DependencyProperty HueBrushProperty = DependencyProperty.Register(+ nameof(HueBrush), typeof(Brush), typeof(ColorPicker), new PropertyMetadata(Brushes.Red));++ /// <summary>The least time between two commits of <see cref="Color"/> to the owner while the picker is being worked.</summary>+ public const int CommitInterval = 100;++ private readonly DispatcherTimer _commitTimer;+ private Thumb? _square, _strip;+ private FrameworkElement? _squareMarker, _hueMarker;+ private bool _updating, _pending;+ private Rgb _pendingColor;+ private long _lastCommit;++ /// <summary>Builds the picker with its commit timer.</summary>+ public ColorPicker()+ {+ _commitTimer = new DispatcherTimer(DispatcherPriority.Background) { Interval = TimeSpan.FromMilliseconds(CommitInterval) };+ _commitTimer.Tick += (_, _) => Commit();+ }++ /// <summary>The colour being edited; every other property is a view of it.</summary>+ public Rgb Color+ {+ get => (Rgb)GetValue(ColorProperty);+ set => SetValue(ColorProperty, value);+ }++ /// <summary>Hue in degrees, 0 to 360 (red at 0, green at 120, blue at 240).</summary>+ public double Hue+ {+ get => (double)GetValue(HueProperty);+ set => SetValue(HueProperty, value);+ }++ /// <summary>Saturation 0 (grey) to 1 (the pure hue).</summary>+ public double Saturation+ {+ get => (double)GetValue(SaturationProperty);+ set => SetValue(SaturationProperty, value);+ }++ /// <summary>Value (brightness) 0 (black) to 1.</summary>+ public double Value+ {+ get => (double)GetValue(ValueProperty);+ set => SetValue(ValueProperty, value);+ }++ /// <summary>The red channel, 0 to 255.</summary>+ public int Red+ {+ get => (int)GetValue(RedProperty);+ set => SetValue(RedProperty, value);+ }++ /// <summary>The green channel, 0 to 255.</summary>+ public int Green+ {+ get => (int)GetValue(GreenProperty);+ set => SetValue(GreenProperty, value);+ }++ /// <summary>The blue channel, 0 to 255.</summary>+ public int Blue+ {+ get => (int)GetValue(BlueProperty);+ set => SetValue(BlueProperty, value);+ }++ /// <summary>The pure hue at full saturation and value, the square's background.</summary>+ public Brush HueBrush+ {+ get => (Brush)GetValue(HueBrushProperty);+ set => SetValue(HueBrushProperty, value);+ }++ /// <summary>Puts the keyboard focus on the saturation/value square (the popup does this when it opens).</summary>+ public void FocusSquare() => _square?.Focus();++ /// <inheritdoc />+ public override void OnApplyTemplate()+ {+ base.OnApplyTemplate();+ _square = GetTemplateChild(SquarePart) as Thumb;+ _strip = GetTemplateChild(HueStripPart) as Thumb;+ // the markers live in the thumbs' own templates, which have to be applied before their names resolve+ _squareMarker = MarkerOf(_square, SquareMarkerPart);+ _hueMarker = MarkerOf(_strip, HueMarkerPart);+ if (_square != null)+ {+ _square.DragStarted += OnSquareDrag;+ _square.DragDelta += OnSquareDrag;+ _square.DragCompleted += (_, _) => Commit();+ _square.SizeChanged += (_, _) => UpdateMarkers();+ }+ if (_strip != null)+ {+ _strip.DragStarted += OnStripDrag;+ _strip.DragDelta += OnStripDrag;+ _strip.DragCompleted += (_, _) => Commit();+ _strip.SizeChanged += (_, _) => UpdateMarkers();+ }+ ApplyColor(Color);+ }++ private static FrameworkElement? MarkerOf(Thumb? thumb, string name)+ {+ if (thumb == null)+ {+ return null;+ }+ thumb.ApplyTemplate();+ return thumb.Template?.FindName(name, thumb) as FrameworkElement;+ }++ private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => ((ColorPicker)d).ApplyColor((Rgb)e.NewValue);++ /// <summary>The colour changed from outside (the owner, the hex box or the channels): the other views follow.</summary>+ private void ApplyColor(Rgb color)+ {+ if (_updating)+ {+ return;+ }+ _commitTimer.Stop();+ _pending = false;+ _updating = true;+ try+ {+ Red = color.R;+ Green = color.G;+ Blue = color.B;+ if (Rgb.FromHsv(Hue, Saturation, Value) != color)+ {+ (double hue, double saturation, double value) = color.ToHsv();+ if (saturation > 0 && value > 0)+ {+ Hue = hue;+ }+ Saturation = saturation;+ Value = value;+ UpdateHueBrush();+ }+ }+ finally+ {+ _updating = false;+ }+ UpdateMarkers();+ }++ /// <summary>+ /// Hue, saturation or value changed (keys, mouse or a binding): the channels, the square and the markers follow at+ /// once, the owner's colour through the throttled commit.+ /// </summary>+ private static void OnHsvChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)+ {+ var picker = (ColorPicker)d;+ if (picker._updating)+ {+ return;+ }+ picker._updating = true;+ Rgb color;+ try+ {+ color = Rgb.FromHsv(picker.Hue, picker.Saturation, picker.Value);+ picker.Red = color.R;+ picker.Green = color.G;+ picker.Blue = color.B;+ picker.UpdateHueBrush();+ }+ finally+ {+ picker._updating = false;+ }+ picker.UpdateMarkers();+ picker.RequestCommit(color);+ }++ /// <summary>Commits now when the last commit is <see cref="CommitInterval"/> or more ago, else when the timer fires.</summary>+ private void RequestCommit(Rgb color)+ {+ _pendingColor = color;+ _pending = true;+ if (Environment.TickCount64 - _lastCommit >= CommitInterval)+ {+ Commit();+ }+ else if (!_commitTimer.IsEnabled)+ {+ _commitTimer.Start();+ }+ }++ /// <summary>Hands the pending colour to the owner; the colour's own change handler is skipped, the views are current.</summary>+ private void Commit()+ {+ _commitTimer.Stop();+ if (!_pending)+ {+ return;+ }+ _pending = false;+ _lastCommit = Environment.TickCount64;+ _updating = true;+ try+ {+ Color = _pendingColor;+ }+ finally+ {+ _updating = false;+ }+ }++ /// <summary>A channel box changed: the colour follows, and through it the HSV side.</summary>+ private static void OnChannelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)+ {+ var picker = (ColorPicker)d;+ if (!picker._updating)+ {+ picker.Color = Rgb.Clamped(picker.Red, picker.Green, picker.Blue);+ }+ }++ private void UpdateHueBrush()+ {+ Rgb pure = Rgb.FromHsv(Hue, 1, 1);+ HueBrush = new SolidColorBrush(System.Windows.Media.Color.FromRgb(pure.R, pure.G, pure.B));+ }++ /// <summary>Places the two markers: saturation along the square, value up it, hue down the strip.</summary>+ private void UpdateMarkers()+ {+ if (_square != null && _squareMarker != null)+ {+ Canvas.SetLeft(_squareMarker, Saturation * _square.ActualWidth - _squareMarker.Width / 2);+ Canvas.SetTop(_squareMarker, (1 - Value) * _square.ActualHeight - _squareMarker.Height / 2);+ }+ if (_strip != null && _hueMarker != null)+ {+ Canvas.SetTop(_hueMarker, Hue / 360 * _strip.ActualHeight - _hueMarker.Height / 2);+ }+ }++ // ---------------------------------------------------------------- mouse (the thumbs capture it; the position is read, not the delta)++ private void OnSquareDrag(object sender, RoutedEventArgs e)+ {+ _square!.Focus();+ Point p = Mouse.GetPosition(_square);+ Saturation = Math.Clamp(p.X / _square.ActualWidth, 0, 1);+ Value = Math.Clamp(1 - p.Y / _square.ActualHeight, 0, 1);+ }++ private void OnStripDrag(object sender, RoutedEventArgs e)+ {+ _strip!.Focus();+ Hue = Math.Clamp(Mouse.GetPosition(_strip).Y / _strip.ActualHeight, 0, 1) * 360 % 360;+ }++ // ---------------------------------------------------------------- keyboard++ /// <inheritdoc />+ protected override void OnKeyDown(KeyEventArgs e)+ {+ bool shift = (Keyboard.Modifiers & ModifierKeys.Shift) != 0;+ if (_square?.IsKeyboardFocused == true)+ {+ double step = shift ? 0.1 : 0.01;+ switch (e.Key)+ {+ case Key.Left: Saturation = Math.Clamp(Saturation - step, 0, 1); break;+ case Key.Right: Saturation = Math.Clamp(Saturation + step, 0, 1); break;+ case Key.Up: Value = Math.Clamp(Value + step, 0, 1); break;+ case Key.Down: Value = Math.Clamp(Value - step, 0, 1); break;+ default: base.OnKeyDown(e); return;+ }+ e.Handled = true;+ return;+ }+ if (_strip?.IsKeyboardFocused == true)+ {+ double degrees = shift ? 10 : 1;+ switch (e.Key)+ {+ case Key.Up: Hue = (Hue - degrees + 360) % 360; break;+ case Key.Down: Hue = (Hue + degrees) % 360; break;+ default: base.OnKeyDown(e); return;+ }+ e.Handled = true;+ return;+ }+ base.OnKeyDown(e);+ }+}diff --git a/WaveDudeNext.WPF/Controls/ColorPickerButton.cs b/WaveDudeNext.WPF/Controls/ColorPickerButton.csnew file mode 100644index 0000000..122b7ec--- /dev/null+++ b/WaveDudeNext.WPF/Controls/ColorPickerButton.cs@@ -0,0 +1,136 @@+// 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.Windows;+using System.Windows.Controls;+using System.Windows.Controls.Primitives;+using System.Windows.Data;+using System.Windows.Input;+using System.Windows.Threading;+using WaveDudeNext.Rendering;++namespace WaveDudeNext.WPF.Controls;++/// <summary>+/// A colour swatch that opens a <see cref="ColorPicker"/> in a popup below it (2026-10-15): the stop rows of the+/// colour scheme editor use it next to the hex box. A toggle button whose checked state is the popup; Space, Enter+/// or Down open it, the focus goes to the picker's square, the colour follows every move at once (the gradient and+/// the preview recolour live, as the hex box does), Enter keeps and closes, Escape puts the colour back as it was+/// and closes, and a click outside closes (the click that lands on the swatch itself is swallowed, else it would+/// reopen the popup at once). The template in <c>Editors.xaml</c> names PART_Popup and PART_Picker. UI thread only.+/// </summary>+[TemplatePart(Name = PopupPart, Type = typeof(Popup))]+[TemplatePart(Name = PickerPart, Type = typeof(ColorPicker))]+public class ColorPickerButton : ToggleButton+{+ private const string PopupPart = "PART_Popup";+ private const string PickerPart = "PART_Picker";++ /// <summary>Identifies the <see cref="Color"/> property.</summary>+ public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(+ nameof(Color), typeof(Rgb), typeof(ColorPickerButton),+ new FrameworkPropertyMetadata(default(Rgb), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));++ private Popup? _popup;+ private ColorPicker? _picker;+ private Rgb _original;+ private long _closedAt;++ /// <summary>The colour shown and edited; bind it two-way to the model's colour.</summary>+ public Rgb Color+ {+ get => (Rgb)GetValue(ColorProperty);+ set => SetValue(ColorProperty, value);+ }++ /// <inheritdoc />+ public override void OnApplyTemplate()+ {+ base.OnApplyTemplate();+ if (_popup != null)+ {+ _popup.Opened -= OnOpened;+ _popup.Closed -= OnClosed;+ _popup.PreviewKeyDown -= OnPopupKeyDown;+ }+ _popup = GetTemplateChild(PopupPart) as Popup;+ _picker = GetTemplateChild(PickerPart) as ColorPicker;+ if (_popup != null)+ {+ _popup.Opened += OnOpened;+ _popup.Closed += OnClosed;+ _popup.PreviewKeyDown += OnPopupKeyDown;+ }+ }++ private void OnOpened(object? sender, EventArgs e)+ {+ _original = Color;+ Dispatcher.BeginInvoke(DispatcherPriority.Input, () => _picker?.FocusSquare());+ }++ private void OnClosed(object? sender, EventArgs e)+ {+ _closedAt = Environment.TickCount64;+ IsChecked = false;+ Focus();+ }++ /// <summary>Enter commits a text box being edited and keeps the colour; Escape puts the original back; both close.</summary>+ private void OnPopupKeyDown(object sender, KeyEventArgs e)+ {+ switch (e.Key)+ {+ case Key.Enter:+ if (Keyboard.FocusedElement is TextBox box)+ {+ box.GetBindingExpression(TextBox.TextProperty)?.UpdateSource();+ }+ IsChecked = false;+ e.Handled = true;+ break;+ case Key.Escape:+ Color = _original;+ IsChecked = false;+ e.Handled = true;+ break;+ }+ }++ /// <inheritdoc />+ protected override void OnKeyDown(KeyEventArgs e)+ {+ if (e.Key == Key.Down && IsChecked != true)+ {+ IsChecked = true;+ e.Handled = true;+ return;+ }+ base.OnKeyDown(e);+ }++ /// <summary>The click that closed the popup (a click outside it, on this swatch) must not reopen it.</summary>+ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)+ {+ if (Environment.TickCount64 - _closedAt < 250)+ {+ e.Handled = true;+ return;+ }+ base.OnPreviewMouseLeftButtonDown(e);+ }+}diff --git a/WaveDudeNext.WPF/Strings/Strings.DE.xaml b/WaveDudeNext.WPF/Strings/Strings.DE.xamlindex 7c410cd..f11dbf7 100644--- a/WaveDudeNext.WPF/Strings/Strings.DE.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.DE.xaml@@ -255,6 +255,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipRemoveStop">Diesen Stützpunkt entfernen</s:String><s:String x:Key="TipStopPosition">Position im Verlauf: 0 beim kleinsten Wert, 1 beim größten</s:String><s:String x:Key="TipStopColor">Farbe als #RRGGBB; Eingabe übernimmt sie</s:String>+ <s:String x:Key="TipStopSwatch">Farbe wählen: Leertaste öffnet die Auswahl, Eingabe übernimmt, Escape stellt die alte Farbe wieder her</s:String>+ <s:String x:Key="TipColorSquare">Sättigung (Links, Rechts) und Helligkeit (Auf, Ab); Umschalt bewegt um zehn Schritte</s:String>+ <s:String x:Key="TipColorHue">Farbton: Auf und Ab bewegen um ein Grad, zehn mit Umschalt</s:String>+ <s:String x:Key="TipColorChannel">Kanal 0 bis 255; Auf und Ab verändern ihn</s:String><s:String x:Key="OpenFileDialogFilter">Wave-Dude-Projekte (*.wdproj)|*.wdproj|Wave-Dude-2D-Projekte (configuration.json)|configuration.json;*.json|XML-Dateien (*.xml)|*.xml|Alle Dateien (*.*)|*.*</s:String><s:String x:Key="SaveFileDialogFilter">Wave-Dude-Projekte (*.wdproj)|*.wdproj|XML-Dateien (*.xml)|*.xml</s:String><s:String x:Key="OpenError">'{0}' konnte nicht geöffnet werden.</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.EN.xaml b/WaveDudeNext.WPF/Strings/Strings.EN.xamlindex b9f5162..5619398 100644--- a/WaveDudeNext.WPF/Strings/Strings.EN.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.EN.xaml@@ -257,6 +257,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipRemoveStop">Remove this stop</s:String><s:String x:Key="TipStopPosition">Position along the gradient: 0 at the lowest value, 1 at the highest</s:String><s:String x:Key="TipStopColor">Colour as #RRGGBB; Enter applies it</s:String>+ <s:String x:Key="TipStopSwatch">Pick the colour: Space opens the picker, Enter keeps it, Escape puts the old colour back</s:String>+ <s:String x:Key="TipColorSquare">Saturation (Left, Right) and brightness (Up, Down); Shift moves by ten steps</s:String>+ <s:String x:Key="TipColorHue">Hue: Up and Down move by a degree, ten with Shift</s:String>+ <s:String x:Key="TipColorChannel">Channel 0 to 255; Up and Down step it</s:String><s:String x:Key="OpenFileDialogFilter">WaveDude Next projects (*.wdproj)|*.wdproj|Wave Dude 2D projects (configuration.json)|configuration.json;*.json|XML files (*.xml)|*.xml|All files (*.*)|*.*</s:String><s:String x:Key="SaveFileDialogFilter">WaveDude Next projects (*.wdproj)|*.wdproj|XML files (*.xml)|*.xml</s:String><s:String x:Key="OpenError">Could not open '{0}'.</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.FR.xaml b/WaveDudeNext.WPF/Strings/Strings.FR.xamlindex 2cf29f5..db1ab22 100644--- a/WaveDudeNext.WPF/Strings/Strings.FR.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.FR.xaml@@ -255,6 +255,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipRemoveStop">Supprimer ce point</s:String><s:String x:Key="TipStopPosition">Position dans le dégradé : 0 à la valeur la plus basse, 1 à la plus haute</s:String><s:String x:Key="TipStopColor">Couleur en #RRGGBB ; Entrée l'applique</s:String>+ <s:String x:Key="TipStopSwatch">Choisir la couleur : Espace ouvre le sélecteur, Entrée la garde, Échap remet l'ancienne couleur</s:String>+ <s:String x:Key="TipColorSquare">Saturation (Gauche, Droite) et luminosité (Haut, Bas) ; Maj déplace de dix pas</s:String>+ <s:String x:Key="TipColorHue">Teinte : Haut et Bas déplacent d'un degré, dix avec Maj</s:String>+ <s:String x:Key="TipColorChannel">Canal de 0 à 255 ; Haut et Bas le modifient</s:String><s:String x:Key="OpenFileDialogFilter">Projets WaveDude Next (*.wdproj)|*.wdproj|Projets Wave Dude 2D (configuration.json)|configuration.json;*.json|Fichiers XML (*.xml)|*.xml|Tous les fichiers (*.*)|*.*</s:String><s:String x:Key="SaveFileDialogFilter">Projets WaveDude Next (*.wdproj)|*.wdproj|Fichiers XML (*.xml)|*.xml</s:String><s:String x:Key="OpenError">Impossible d'ouvrir '{0}'.</s:String>diff --git a/WaveDudeNext.WPF/Strings/Strings.NL.xaml b/WaveDudeNext.WPF/Strings/Strings.NL.xamlindex 3fcf71e..9f164d5 100644--- a/WaveDudeNext.WPF/Strings/Strings.NL.xaml+++ b/WaveDudeNext.WPF/Strings/Strings.NL.xaml@@ -255,6 +255,10 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<s:String x:Key="TipRemoveStop">Dit punt verwijderen</s:String><s:String x:Key="TipStopPosition">Positie in het verloop: 0 bij de laagste waarde, 1 bij de hoogste</s:String><s:String x:Key="TipStopColor">Kleur als #RRGGBB; Enter past hem toe</s:String>+ <s:String x:Key="TipStopSwatch">Kleur kiezen: spatie opent de kiezer, Enter houdt hem, Escape zet de oude kleur terug</s:String>+ <s:String x:Key="TipColorSquare">Verzadiging (links, rechts) en helderheid (omhoog, omlaag); Shift verplaatst tien stappen</s:String>+ <s:String x:Key="TipColorHue">Tint: omhoog en omlaag verplaatsen een graad, tien met Shift</s:String>+ <s:String x:Key="TipColorChannel">Kanaal 0 tot 255; omhoog en omlaag veranderen het</s:String><s:String x:Key="OpenFileDialogFilter">WaveDude Next-projecten (*.wdproj)|*.wdproj|Wave Dude 2D-projecten (configuration.json)|configuration.json;*.json|XML-bestanden (*.xml)|*.xml|Alle bestanden (*.*)|*.*</s:String><s:String x:Key="SaveFileDialogFilter">WaveDude Next-projecten (*.wdproj)|*.wdproj|XML-bestanden (*.xml)|*.xml</s:String><s:String x:Key="OpenError">Kan '{0}' niet openen.</s:String>diff --git a/WaveDudeNext.WPF/Themes/Editors.xaml b/WaveDudeNext.WPF/Themes/Editors.xamlindex 61853df..033be63 100644--- a/WaveDudeNext.WPF/Themes/Editors.xaml+++ b/WaveDudeNext.WPF/Themes/Editors.xaml@@ -380,6 +380,140 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<!-- property forms --><!-- a group header in the Properties pane: the name over a rule across the width, so the groups read apart(2026-10-15, after the Field and Intensity groups of the Display view were taken for one list) -->+ <!-- the colour picker (2026-10-15): the square is the pure hue under a white-to-clear and a clear-to-black overlay,+ the strip the hue circle top to bottom; the markers are placed by the control; square and strip take the focus -->+ <converters:RgbBrushConverter x:Key="RgbBrush" />+ <Style TargetType="{x:Type controls:ColorPicker}">+ <Setter Property="Focusable" Value="False" />+ <Setter Property="Template">+ <Setter.Value>+ <ControlTemplate TargetType="{x:Type controls:ColorPicker}">+ <StackPanel Margin="8">+ <DockPanel>+ <Thumb x:Name="PART_Square" DockPanel.Dock="Left" Width="160" Height="160" Focusable="True" FocusVisualStyle="{x:Null}"+ BorderThickness="1" BorderBrush="{DynamicResource TextBoxBorder}" ToolTip="{DynamicResource TipColorSquare}"+ AutomationProperties.AutomationId="ColorSquare">+ <Thumb.Template>+ <ControlTemplate TargetType="{x:Type Thumb}">+ <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">+ <Grid Background="{Binding HueBrush, RelativeSource={RelativeSource AncestorType={x:Type controls:ColorPicker}}}">+ <Rectangle>+ <Rectangle.Fill>+ <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">+ <GradientStop Color="#FFFFFFFF" Offset="0" />+ <GradientStop Color="#00FFFFFF" Offset="1" />+ </LinearGradientBrush>+ </Rectangle.Fill>+ </Rectangle>+ <Rectangle>+ <Rectangle.Fill>+ <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">+ <GradientStop Color="#00000000" Offset="0" />+ <GradientStop Color="#FF000000" Offset="1" />+ </LinearGradientBrush>+ </Rectangle.Fill>+ </Rectangle>+ <Canvas IsHitTestVisible="False">+ <Grid x:Name="PART_SquareMarker" Width="13" Height="13">+ <Ellipse Stroke="Black" StrokeThickness="3" />+ <Ellipse Stroke="White" StrokeThickness="1.5" Margin="0.75" />+ </Grid>+ </Canvas>+ </Grid>+ </Border>+ </ControlTemplate>+ </Thumb.Template>+ </Thumb>+ <Thumb x:Name="PART_HueStrip" Width="20" Height="160" Margin="8,0,0,0" HorizontalAlignment="Left" Focusable="True" FocusVisualStyle="{x:Null}"+ BorderThickness="1" BorderBrush="{DynamicResource TextBoxBorder}" ToolTip="{DynamicResource TipColorHue}"+ AutomationProperties.AutomationId="ColorHue">+ <Thumb.Template>+ <ControlTemplate TargetType="{x:Type Thumb}">+ <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">+ <Grid>+ <Rectangle>+ <Rectangle.Fill>+ <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">+ <GradientStop Color="#FF0000" Offset="0" />+ <GradientStop Color="#FFFF00" Offset="0.1667" />+ <GradientStop Color="#00FF00" Offset="0.3333" />+ <GradientStop Color="#00FFFF" Offset="0.5" />+ <GradientStop Color="#0000FF" Offset="0.6667" />+ <GradientStop Color="#FF00FF" Offset="0.8333" />+ <GradientStop Color="#FF0000" Offset="1" />+ </LinearGradientBrush>+ </Rectangle.Fill>+ </Rectangle>+ <Canvas IsHitTestVisible="False">+ <Border x:Name="PART_HueMarker" Width="22" Height="7" Canvas.Left="-2" BorderBrush="White" BorderThickness="1">+ <Border BorderBrush="Black" BorderThickness="1" />+ </Border>+ </Canvas>+ </Grid>+ </Border>+ </ControlTemplate>+ </Thumb.Template>+ </Thumb>+ </DockPanel>+ <DockPanel Margin="0,8,0,0">+ <TextBlock DockPanel.Dock="Left" Text="R" VerticalAlignment="Center" Margin="0,0,3,0" />+ <controls:NumberBox DockPanel.Dock="Left" Width="56" Minimum="0" Maximum="255" Increment="1" ToolTip="{DynamicResource TipColorChannel}"+ Text="{Binding Red, RelativeSource={RelativeSource TemplatedParent}}" AutomationProperties.AutomationId="ColorRed" />+ <TextBlock DockPanel.Dock="Left" Text="G" VerticalAlignment="Center" Margin="8,0,3,0" />+ <controls:NumberBox DockPanel.Dock="Left" Width="56" Minimum="0" Maximum="255" Increment="1" ToolTip="{DynamicResource TipColorChannel}"+ Text="{Binding Green, RelativeSource={RelativeSource TemplatedParent}}" AutomationProperties.AutomationId="ColorGreen" />+ <TextBlock DockPanel.Dock="Left" Text="B" VerticalAlignment="Center" Margin="8,0,3,0" />+ <controls:NumberBox DockPanel.Dock="Left" Width="56" Minimum="0" Maximum="255" Increment="1" ToolTip="{DynamicResource TipColorChannel}"+ Text="{Binding Blue, RelativeSource={RelativeSource TemplatedParent}}" AutomationProperties.AutomationId="ColorBlue" />+ <TextBox Margin="8,0,0,0" ToolTip="{DynamicResource TipStopColor}" AutomationProperties.AutomationId="ColorHex"+ Text="{Binding Color, RelativeSource={RelativeSource TemplatedParent}}" />+ </DockPanel>+ </StackPanel>+ <ControlTemplate.Triggers>+ <Trigger SourceName="PART_Square" Property="IsKeyboardFocused" Value="True">+ <Setter TargetName="PART_Square" Property="BorderBrush" Value="{DynamicResource Accent}" />+ </Trigger>+ <Trigger SourceName="PART_HueStrip" Property="IsKeyboardFocused" Value="True">+ <Setter TargetName="PART_HueStrip" Property="BorderBrush" Value="{DynamicResource Accent}" />+ </Trigger>+ </ControlTemplate.Triggers>+ </ControlTemplate>+ </Setter.Value>+ </Setter>+ </Style>++ <!-- the swatch that opens the picker in a popup below it; the popup's open state is the button's checked state -->+ <Style TargetType="{x:Type controls:ColorPickerButton}">+ <Setter Property="Width" Value="22" />+ <Setter Property="Height" Value="18" />+ <Setter Property="FocusVisualStyle" Value="{x:Null}" />+ <Setter Property="Template">+ <Setter.Value>+ <ControlTemplate TargetType="{x:Type controls:ColorPickerButton}">+ <Grid>+ <Border x:Name="Bd" BorderBrush="{DynamicResource TextBoxBorder}" BorderThickness="1" SnapsToDevicePixels="True"+ Background="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource RgbBrush}}" />+ <Popup x:Name="PART_Popup" Placement="Bottom" StaysOpen="False" AllowsTransparency="True" PopupAnimation="None"+ PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"+ IsOpen="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}">+ <Border Background="{DynamicResource ComboBoxListBackground}" BorderBrush="{DynamicResource MenuPopupBorder}" BorderThickness="1" SnapsToDevicePixels="True">+ <controls:ColorPicker x:Name="PART_Picker" Color="{Binding Color, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" />+ </Border>+ </Popup>+ </Grid>+ <ControlTemplate.Triggers>+ <Trigger Property="IsMouseOver" Value="True">+ <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource TextBoxHoverBorder}" />+ </Trigger>+ <Trigger Property="IsKeyboardFocused" Value="True">+ <Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Accent}" />+ </Trigger>+ </ControlTemplate.Triggers>+ </ControlTemplate>+ </Setter.Value>+ </Setter>+ </Style>+<!-- links (About): accent colour, underlined on hover and when focused by keyboard; the focus rectangle is WPF's own --><Style TargetType="{x:Type Hyperlink}"><Setter Property="Foreground" Value="{DynamicResource Accent}" />diff --git a/WaveDudeNext.WPF/Views/ColorSchemeView.xaml b/WaveDudeNext.WPF/Views/ColorSchemeView.xamlindex 243a537..da376e0 100644--- a/WaveDudeNext.WPF/Views/ColorSchemeView.xaml+++ b/WaveDudeNext.WPF/Views/ColorSchemeView.xaml@@ -109,7 +109,7 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file or<Rectangle Height="18" Margin="0,0,0,6" Stroke="{DynamicResource TextBoxBorder}" StrokeThickness="1"Fill="{Binding Stops, Converter={StaticResource ColorSchemeBrush}}" AutomationProperties.AutomationId="SchemeGradient" />- <!-- one row per stop: position (0..1), swatch, colour as #RRGGBB, remove -->+ <!-- one row per stop: position (0..1), swatch (the picker), colour as #RRGGBB, remove --><ItemsControl ItemsSource="{Binding Stops}" Focusable="False"><ItemsControl.ItemTemplate><DataTemplate>@@ -118,9 +118,11 @@ version. It is distributed WITHOUT ANY WARRANTY. See the LICENSE.md file orCommand="{x:Static commands:ColorSchemeCommands.RemoveStop}" CommandParameter="{Binding}" /><controls:NumberBox DockPanel.Dock="Left" Width="64" Minimum="0" Maximum="1" Increment="0.01" Text="{Binding Position}"ToolTip="{DynamicResource TipStopPosition}" />- <Rectangle DockPanel.Dock="Left" Width="22" Height="18" Margin="4,0" Stroke="{DynamicResource TextBoxBorder}" StrokeThickness="1"- Fill="{Binding Color, Converter={StaticResource RgbBrush}}" />- <TextBox Text="{Binding Color}" ToolTip="{DynamicResource TipStopColor}" />+ <!-- the swatch opens the colour picker (Space, Enter, Down); ids carry the stop's position -->+ <controls:ColorPickerButton DockPanel.Dock="Left" Margin="4,0" Color="{Binding Color}" ToolTip="{DynamicResource TipStopSwatch}"+ AutomationProperties.AutomationId="{Binding Position, StringFormat='StopSwatch:{0}'}" />+ <TextBox Text="{Binding Color}" ToolTip="{DynamicResource TipStopColor}"+ AutomationProperties.AutomationId="{Binding Position, StringFormat='StopColor:{0}'}" /></DockPanel></DataTemplate></ItemsControl.ItemTemplate>diff --git a/WaveDudeNext/Rendering/Rgb.cs b/WaveDudeNext/Rendering/Rgb.csindex 604e9a8..8c7d381 100644--- a/WaveDudeNext/Rendering/Rgb.cs+++ b/WaveDudeNext/Rendering/Rgb.cs@@ -42,6 +42,50 @@ public readonly record struct Rgb(byte R, byte G, byte B)/// <summary><c>#RRGGBB</c>, upper case.</summary>public override string ToString() => $"#{R:X2}{G:X2}{B:X2}";+ /// <summary>+ /// Hue in degrees (0 to 360, 0 for a grey), saturation and value (0 to 1) of this colour: the HSV model the+ /// colour picker works in (2026-10-15). <see cref="FromHsv"/> gives the colour back exactly for every 8-bit colour.+ /// </summary>+ public (double Hue, double Saturation, double Value) ToHsv()+ {+ double r = R / 255.0, g = G / 255.0, b = B / 255.0;+ double max = Math.Max(r, Math.Max(g, b)), min = Math.Min(r, Math.Min(g, b)), delta = max - min;+ double hue = 0;+ if (delta > 0)+ {+ hue = 60 * (max == r ? (g - b) / delta : max == g ? (b - r) / delta + 2 : (r - g) / delta + 4);+ if (hue < 0)+ {+ hue += 360;+ }+ }+ return (hue, max > 0 ? delta / max : 0, max);+ }++ /// <summary>+ /// The colour of a hue in degrees (wrapped into 0 to 360), a saturation and a value (both clamped to 0 to 1),+ /// each channel rounded to 8 bits.+ /// </summary>+ public static Rgb FromHsv(double hue, double saturation, double value)+ {+ hue = (hue % 360 + 360) % 360;+ saturation = Math.Clamp(saturation, 0, 1);+ value = Math.Clamp(value, 0, 1);+ double c = value * saturation;+ double x = c * (1 - Math.Abs(hue / 60 % 2 - 1));+ double m = value - c;+ (double r, double g, double b) = hue switch+ {+ < 60 => (c, x, 0.0),+ < 120 => (x, c, 0.0),+ < 180 => (0.0, c, x),+ < 240 => (0.0, x, c),+ < 300 => (x, 0.0, c),+ _ => (c, 0.0, x),+ };+ return Clamped((int)Math.Round((r + m) * 255), (int)Math.Round((g + m) * 255), (int)Math.Round((b + m) * 255));+ }+/// <summary>Parses <c>#RRGGBB</c>, <c>RRGGBB</c>, <c>#RGB</c> or <c>[r,g,b]</c>.</summary>/// <exception cref="FormatException">The text is none of those.</exception>public static Rgb Parse(string text) =>diff --git a/_tools/library_check/Program.cs b/_tools/library_check/Program.csindex ace5dd6..6dab52c 100644--- a/_tools/library_check/Program.cs+++ b/_tools/library_check/Program.cs@@ -1014,6 +1014,22 @@ internal static class ProgramCheck(uneven.GetEntry(0) == new Rgb(0, 0, 0) && uneven.GetEntry(127) == new Rgb(170, 170, 255) && uneven.GetEntry(254) == new Rgb(0, 0, 255) && uneven.GetEntry(32) == new Rgb(129, 129, 129), "stops at any position interpolate between their neighbours (0, 0.25, 1)");ColorStop added = uneven.AddStop();Check(uneven.Stops.Count == 4 && Math.Abs(added.Position - 0.625) < 1e-9 && uneven.Stops.IndexOf(added) == 2, "AddStop fills the widest gap, in position order");+ bool hsvRoundTrip = true;+ for (int r = 0; r < 256; r += 5)+ {+ for (int g = 0; g < 256; g += 5)+ {+ for (int b = 0; b < 256; b += 5)+ {+ var c = new Rgb((byte)r, (byte)g, (byte)b);+ (double h, double s, double v) = c.ToHsv();+ hsvRoundTrip &= Rgb.FromHsv(h, s, v) == c;+ }+ }+ }+ Check(hsvRoundTrip && Rgb.FromHsv(0, 1, 1) == new Rgb(255, 0, 0) && Rgb.FromHsv(120, 1, 1) == new Rgb(0, 255, 0) && Rgb.FromHsv(240, 1, 0.5) == new Rgb(0, 0, 128)+ && new Rgb(64, 128, 192).ToHsv().Hue == 210 && Rgb.FromHsv(210, 0.5667, 0.7529) == new Rgb(83, 138, 192) && Rgb.FromHsv(-150, 2, 1) == Rgb.FromHsv(210, 1, 1),+ "HSV: every sampled colour round-trips, the primaries, #4080C0's hue, a lowered saturation and the wrapping come out right");var project = new Project();project.ColorSchemes.Add(field.Clone("Mine"));project.Scene.ImageData = [1, 2, 3, 4, 250, 0, 255];diff --git a/_tools/ui_check/ColorPickerCheck.ps1 b/_tools/ui_check/ColorPickerCheck.ps1new file mode 100644index 0000000..c9ae340--- /dev/null+++ b/_tools/ui_check/ColorPickerCheck.ps1@@ -0,0 +1,114 @@+# 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/>.++# Drives the colour picker of the scheme editor's stop rows by keyboard (2026-10-15) on tiny_scheme.wdproj, whose+# project scheme "Harness scheme" has a middle stop #4080C0 (hue 210, saturation 2/3, value 0.753): selects the+# scheme in the tree, Tabs to the stop's swatch, Space opens the popup with the focus on the saturation/value+# square, ten Left arrows lower the saturation by a tenth (the hex box beside the swatch shows #538AC0 at once),+# Escape puts #4080C0 back and closes, a second opening Tabs to the red channel box, five Up arrows make it #4580C0+# and Enter keeps it; the project is dirty afterwards. See Common.ps1 for the rules (no mouse, no activation, no+# UIA patterns). Prints PASS/FAIL per check and exits with the failure count.+#+# powershell -ExecutionPolicy Bypass -File _tools\ui_check\ColorPickerCheck.ps1 [-Exe <path>] [-Shot <png>] [-Trace]++param(+ [string]$Exe = (Join-Path $PSScriptRoot "..\..\WaveDudeNext.WPF\bin\Debug\net10.0-windows\WaveDudeNext.WPF.exe"),+ [string]$Shot = (Join-Path $env:TEMP "wavedude_color_picker.png"), # the window with the picker open, for the look+ [switch]$Trace+)++. (Join-Path $PSScriptRoot "Common.ps1")++# the popup is a top-level window of the process; its elements are found by id across those windows+function PopupFind([string]$id) {+ $byProcess = New-Object System.Windows.Automation.PropertyCondition($A::ProcessIdProperty, $script:p.Id)+ $c = New-Object System.Windows.Automation.PropertyCondition($A::AutomationIdProperty, $id)+ foreach ($top in $A::RootElement.FindAll([System.Windows.Automation.TreeScope]::Children, $byProcess)) {+ $e = $top.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $c)+ if ($e -ne $null) { return $e }+ }+ return $null+}+# the top-level window (the popup) holding the element of this id+function PopupTop([string]$id) {+ $byProcess = New-Object System.Windows.Automation.PropertyCondition($A::ProcessIdProperty, $script:p.Id)+ $c = New-Object System.Windows.Automation.PropertyCondition($A::AutomationIdProperty, $id)+ foreach ($top in $A::RootElement.FindAll([System.Windows.Automation.TreeScope]::Children, $byProcess)) {+ if ($top.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $c) -ne $null) { return $top }+ }+ return $null+}+function PopupFocusedId() {+ $byProcess = New-Object System.Windows.Automation.PropertyCondition($A::ProcessIdProperty, $script:p.Id)+ $focused = New-Object System.Windows.Automation.PropertyCondition($A::HasKeyboardFocusProperty, $true)+ foreach ($top in $A::RootElement.FindAll([System.Windows.Automation.TreeScope]::Children, $byProcess)) {+ $e = $top.FindFirst([System.Windows.Automation.TreeScope]::Descendants, $focused)+ if ($e -ne $null) { return $e.Current.AutomationId }+ }+ return "(none)"+}+function Hex([string]$id) { return (Pattern (Find $id) "Value").Current.Value }+function Step([string]$what, [int]$vk, [int]$settle) {+ Key $vk $settle+ if ($Trace) { " {0,-8} focus {1} popup focus {2} foreground {3}" -f $what, (FocusedId), (PopupFocusedId), (Foreground) }+}++Start-App $Exe (Join-Path $PSScriptRoot "tiny_scheme.wdproj")+try {+ # the stop ids carry the position in the locale's spelling ("0,5" where the decimal separator is a comma)+ $half = (0.5).ToString([System.Globalization.CultureInfo]::CurrentCulture)+ $swatch = "StopSwatch:$half"; $hexBox = "StopColor:$half"+ # the tree is one tab stop (its selected item); End goes to its last visible item, the scheme in its expanded folder+ FocusOn "Tree:Project"+ Step "End" $VK_END 300+ $null = WaitFor { try { (Find "SchemeAddStop") -ne $null } catch { $false } } 5000 100+ Check "End in the tree selects the scheme, whose editor appears" ((FocusedId) -eq "Tree:Harness scheme" -and (Find "SchemeAddStop") -ne $null) (FocusedId)+ FocusOn $swatch+ Check "Tab reaches the middle stop's swatch, whose hex box says #4080C0" ((Hex $hexBox) -eq "#4080C0") (Hex $hexBox)++ Step "Space" $VK_SPACE 400+ Check "Space opens the picker with the focus on the saturation/value square" ((PopupFocusedId) -eq "ColorSquare") (PopupFocusedId)+ for ($i = 0; $i -lt 10; $i++) { Step "Left" $VK_LEFT 40 }+ Start-Sleep -Milliseconds 200+ Check "ten Left arrows lower the saturation by a tenth: the stop is #538AC0 at once" ((Hex $hexBox) -eq "#538AC0") (Hex $hexBox)+ [Native]::Capture($hwnd, $Shot)+ Write-Output "screenshot: $Shot"+ # the popup is its own window: captured apart, for the look of the picker+ $popupShot = [System.IO.Path]::ChangeExtension($Shot, $null) + "popup.png"+ [Native]::Capture([IntPtr](PopupTop "ColorSquare").Current.NativeWindowHandle, $popupShot)+ Write-Output "screenshot: $popupShot"+ Step "Escape" $VK_ESCAPE 400+ Check "Escape puts #4080C0 back, closes the popup and returns the focus to the swatch" ((Hex $hexBox) -eq "#4080C0" -and (PopupFind "ColorSquare") -eq $null -and (FocusedId) -eq $swatch) ("{0}, focus {1}" -f (Hex $hexBox), (FocusedId))++ Step "Space" $VK_SPACE 400+ Step "Tab" $VK_TAB 150+ Check "Tab moves to the hue strip" ((PopupFocusedId) -eq "ColorHue") (PopupFocusedId)+ Step "Tab" $VK_TAB 150+ Check "and on to the red channel box" ((PopupFocusedId) -eq "ColorRed") (PopupFocusedId)+ for ($i = 0; $i -lt 5; $i++) { Step "Up" $VK_UP 60 }+ Start-Sleep -Milliseconds 200+ Check "five Up arrows on the red box make the stop #4580C0" ((Hex $hexBox) -eq "#4580C0") (Hex $hexBox)+ Step "Enter" $VK_RETURN 400+ Check "Enter keeps #4580C0, closes the popup and returns the focus to the swatch" ((Hex $hexBox) -eq "#4580C0" -and (PopupFind "ColorSquare") -eq $null -and (FocusedId) -eq $swatch) ("{0}, focus {1}" -f (Hex $hexBox), (FocusedId))+ Check "the project is dirty" ($win.Current.Name -like "*`**") $win.Current.Name+ Check "app never became the foreground window" ((Foreground) -ne "APP") (Foreground)+}+finally {+ Stop-App+}+Write-Output ("{0} failure(s)" -f $script:failures)+exit $script:failuresdiff --git a/_tools/ui_check/tiny_scheme.wdproj b/_tools/ui_check/tiny_scheme.wdprojnew file mode 100644index 0000000..4ffbb90--- /dev/null+++ b/_tools/ui_check/tiny_scheme.wdproj@@ -0,0 +1,16 @@+<?xml version="1.0" encoding="utf-8"?>+<Project Version="1" Seed="12345">+ <Description>Harness project: tiny.wdproj plus one project colour scheme with three stops, for the colour picker check.</Description>+ <Scene Width="64" Height="48" DampingEdge="4" />+ <Simulation Steps="200" VisualizeEvery="2" />+ <Display>+ <Field ColorScheme="Harness scheme" BlackLevel="-0.05" />+ <Intensity ColorScheme="Default intensity" />+ </Display>+ <Source Name="Source 1" X="20" Y="24" Frequency="120" />+ <ColorScheme Name="Harness scheme" Kind="Field">+ <Stop At="0" Color="#000000" />+ <Stop At="0.5" Color="#4080C0" />+ <Stop At="1" Color="#FFFFFF" />+ </ColorScheme>+</Project>