diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index edd689c..bf0c4bc 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -307,7 +307,7 @@ public sealed class D3D12Renderer : IAquariumRenderer private DebugUi CreateDebugUi(AquariumUiDocument clientUi) { - var ui = new DebugUi("Debug", 18.0f, 82.0f, 360.0f, debugTabTitles, () => activeDebugTab, SelectDebugTab) + var ui = new DebugUi("Debug", 18.0f, 18.0f, 520.0f, debugTabTitles, () => activeDebugTab, SelectDebugTab) .Panel(panel => { panel @@ -323,7 +323,7 @@ public sealed class D3D12Renderer : IAquariumRenderer .Section("Synth Playground", () => activeDebugTab == 2) .Options("Preset", () => synthPlaygroundPreset, SelectSynthPreset, SynthPresetOptions, "Loads a built-in synth patch.", () => activeDebugTab == 2) .Readout("Status", () => $"{synthPlaygroundStatus.State}: {synthPlaygroundStatus.Message}", isVisible: () => activeDebugTab == 2) - .TextBox("Patch", () => synthPlaygroundScript, value => synthPlaygroundScript = value, lines: 7, acceptsReturn: true, monospace: true, tooltip: "Patch DSL source.", isVisible: () => activeDebugTab == 2) + .TextBox("Patch", () => synthPlaygroundScript, value => synthPlaygroundScript = value, lines: 18, acceptsReturn: true, monospace: true, tooltip: "Patch DSL source.", isVisible: () => activeDebugTab == 2) .Slider("Gain", () => synthPlaygroundGain, value => synthPlaygroundGain = Math.Clamp(value, 0.0f, 1.0f), 0.0f, 1.0f, "0.###", "Playground patch gain.", () => activeDebugTab == 2) .Button("Play", () => synthPlaygroundPlayRevision++, "Triggers the compiled playground patch.", () => activeDebugTab == 2); }); diff --git a/src/Aquarium.Engine/Render/DirectWriteOverlay.cs b/src/Aquarium.Engine/Render/DirectWriteOverlay.cs index c4ad2be..b1698a3 100644 --- a/src/Aquarium.Engine/Render/DirectWriteOverlay.cs +++ b/src/Aquarium.Engine/Render/DirectWriteOverlay.cs @@ -87,32 +87,6 @@ internal sealed class DirectWriteOverlay : IDisposable public void Render(AquariumFrame frame, int renderDebugMode, DebugUi? debugUi, IReadOnlyList clientUiPanels) { renderTarget.BeginDraw(); - DrawHeader( - "directwrite overlay", - titleFormat, - RectFromEdges(18, 14, Math.Min(width - 18, 340), 42), - primaryTextBrush); - renderTarget.DrawText( - $"view r {frame.View.Radius:0.00} cam z {frame.CameraPosition.Z:0.00}", - smallFormat, - RectFromEdges(18, 38, Math.Min(width - 18, 420), 62), - quietTextBrush, - DrawTextOptions.Clip); - if (renderDebugMode > 0) - { - renderTarget.DrawText( - $"render debug {renderDebugMode} F1 cycle debug panel selects", - smallFormat, - RectFromEdges(18, 56, Math.Min(width - 18, 420), 80), - quietTextBrush, - DrawTextOptions.Clip); - } - renderTarget.DrawText( - "crisp text belongs after tonemapping", - smallFormat, - RectFromEdges(18, Math.Max(64, height - 36), Math.Min(width - 18, 420), height - 12), - quietTextBrush, - DrawTextOptions.Clip); debugUi?.Draw( renderTarget, directWriteFactory, diff --git a/src/Aquarium.Engine/Render/Ui/DebugUi.cs b/src/Aquarium.Engine/Render/Ui/DebugUi.cs index 3ff08a8..308659a 100644 --- a/src/Aquarium.Engine/Render/Ui/DebugUi.cs +++ b/src/Aquarium.Engine/Render/Ui/DebugUi.cs @@ -183,6 +183,21 @@ internal sealed class DebugUi return; } + if (Math.Abs(input.WheelDelta) > 0.0f) + { + for (var index = controls.Count - 1; index >= 0; index--) + { + var control = controls[index]; + if (control.IsVisible + && control.HitTest(mousePosition) + && control is ITextInputControl textControl + && textControl.Scroll(input.WheelDelta)) + { + return; + } + } + } + if (activeSliderId is { } sliderId) { if (controls.FirstOrDefault(control => control.IsVisible && control.Id == sliderId) is SliderControl activeSlider) @@ -431,7 +446,10 @@ internal sealed class DebugUi y += height + (control is SectionControl ? 2.0f : RowGap); } - panelBounds = RectFromEdges(panelLeft, panelTop, panelLeft + panelWidth, y + 12.0f); + var bottom = lastViewportHeight > 0 + ? Math.Max(y + 12.0f, lastViewportHeight - panelLeft) + : y + 12.0f; + panelBounds = RectFromEdges(panelLeft, panelTop, panelLeft + panelWidth, bottom); } private Rect CloseButtonBounds() @@ -636,6 +654,8 @@ internal sealed class DebugUi void ApplyTextInput(InputState input); void SelectToPoint(Vector2 point); + + bool Scroll(float wheelDelta); } internal abstract class DebugUiControl(string label, string? tooltip = null, Func? isVisible = null) @@ -1095,6 +1115,8 @@ internal sealed class DebugUi { } + public bool Scroll(float wheelDelta) => false; + public override void Draw( ID2D1RenderTarget target, IDWriteFactory6 directWriteFactory, @@ -1136,6 +1158,7 @@ internal sealed class DebugUi private readonly List lineHitCache = []; private int caretIndex = -1; private int selectionAnchor = -1; + private int firstVisibleLine = -1; private string lastValue = string.Empty; public override float LayoutHeight => LabelLineHeight + VerticalPadding * 2.0f + Math.Max(1, lines) * TextLineHeight; @@ -1235,6 +1258,23 @@ internal sealed class DebugUi MoveCaret(IndexFromPoint(point), selecting: true, NormalizedValue); } + public bool Scroll(float wheelDelta) + { + var value = NormalizedValue; + var totalLines = LineCount(value); + var maxFirstLine = Math.Max(0, totalLines - lines); + if (maxFirstLine == 0) + { + firstVisibleLine = alignBottom ? 0 : -1; + return false; + } + + var step = wheelDelta > 0.0f ? -3 : 3; + var current = VisibleStartLine(totalLines); + firstVisibleLine = Math.Clamp(current + step, 0, maxFirstLine); + return firstVisibleLine != current; + } + public override void Click(Vector2 mouse) { SyncEditingState(); @@ -1305,18 +1345,14 @@ internal sealed class DebugUi private string[] DisplayLines() { var split = NormalizedValue.Split('\n'); - return split.Length <= lines ? split : split.Skip(split.Length - lines).ToArray(); + var startLine = VisibleStartLine(split.Length); + return split.Skip(startLine).Take(lines).ToArray(); } private int DisplayStartIndex() { var split = NormalizedValue.Split('\n'); - if (split.Length <= lines) - { - return 0; - } - - var skippedLines = split.Length - lines; + var skippedLines = VisibleStartLine(split.Length); var index = 0; for (var line = 0; line < skippedLines; line++) { @@ -1337,6 +1373,7 @@ internal sealed class DebugUi lastValue = value; caretIndex = ClampEditableIndex(value.Length, value); selectionAnchor = caretIndex; + firstVisibleLine = alignBottom ? Math.Max(0, LineCount(value) - lines) : 0; } private void SyncCommittedValue(string value) @@ -1344,6 +1381,8 @@ internal sealed class DebugUi lastValue = value; caretIndex = ClampEditableIndex(caretIndex, value); selectionAnchor = ClampEditableIndex(selectionAnchor, value); + firstVisibleLine = Math.Clamp(firstVisibleLine, 0, Math.Max(0, LineCount(value) - lines)); + EnsureCaretVisible(value); } private void MoveCaret(int index, bool selecting, string value) @@ -1357,6 +1396,8 @@ internal sealed class DebugUi { selectionAnchor = ClampEditableIndex(selectionAnchor, value); } + + EnsureCaretVisible(value); } private string InsertText(string value, string text) @@ -1644,6 +1685,59 @@ internal sealed class DebugUi return value.Length; } + private int VisibleStartLine(int totalLines) + { + var maxFirstLine = Math.Max(0, totalLines - lines); + if (firstVisibleLine < 0) + { + return alignBottom ? maxFirstLine : 0; + } + + return Math.Clamp(firstVisibleLine, 0, maxFirstLine); + } + + private void EnsureCaretVisible(string value) + { + var totalLines = LineCount(value); + var maxFirstLine = Math.Max(0, totalLines - lines); + var caretLine = LineNumber(value, caretIndex); + var first = VisibleStartLine(totalLines); + if (caretLine < first) + { + firstVisibleLine = caretLine; + } + else if (caretLine >= first + lines) + { + firstVisibleLine = caretLine - lines + 1; + } + else if (firstVisibleLine < 0) + { + firstVisibleLine = first; + } + + firstVisibleLine = Math.Clamp(firstVisibleLine, 0, maxFirstLine); + } + + private static int LineCount(string value) + { + return value.Count(ch => ch == '\n') + 1; + } + + private static int LineNumber(string value, int index) + { + var clamped = Math.Clamp(index, 0, value.Length); + var line = 0; + for (var i = 0; i < clamped; i++) + { + if (value[i] == '\n') + { + line++; + } + } + + return line; + } + private readonly record struct LineHitCache(int GlobalStart, float OriginX, float OriginY, float[] Edges); private readonly record struct TextHit(float X, float Top, float Height); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 95dbc16..33519c2 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -77,3 +77,4 @@ {"timestamp":"2026-05-12T21:28:22+01:00","topic":"single-solution-authority","lesson":"Keep one solution inventory for Aquarium. Maintaining both Aquarium.Engine.sln and Aquarium.Engine.slnx created duplicate project authority, Rider confusion, and verification races when both were built against shared obj/bin outputs. Aquarium.Engine.sln is the canonical solution for IDE and CLI work.","files":["Aquarium.Engine.sln","AGENTS.md","README.md","scripts/dev-watch.ps1","state/map.yaml","state/evidence.jsonl"],"source":"user solution authority cleanup"} {"timestamp":"2026-05-12T21:52:07+01:00","topic":"sfxr-parity-measures","lesson":"SFXR dogfood tests must compare rendered audio against an SFXR-style reference shape, not merely prove that presets are audible and distinct. Use mel-spectrum, envelope, duration, RMS, and zero-crossing comparisons so wrong filter mappings are caught by the engine's actual native Faust render path.","files":["tests/Aquarium.Engine.Tests/SynthPlaybackTests.cs","state/evidence.jsonl"],"source":"user clarified presets sound unlike sfxr"} {"timestamp":"2026-05-12T22:07:56+01:00","topic":"synth-reference-corpus","lesson":"The synth playground should consume AquariumSynth.Dsl reference patches, not a one-line golf catalog. SFXR, BFXR, 808, FM, and wobble presets exist to test and demonstrate DSL expressiveness; readability is part of the product surface because users will edit these patches in the Aquarium UI.","files":["src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"],"source":"user clarified preset purpose for patch DSL iteration"} +{"timestamp":"2026-05-12T22:20:23+01:00","topic":"debug-ui-textarea-scroll","lesson":"Readable multi-line synth patches require the debug text box to own a scrollable visible-line window. Do not truncate text areas to the last N lines, and do not leave DirectWrite overlay diagnostic copy on the canvas once the debug panel is the real UI surface.","files":["src/Aquarium.Engine/Render/Ui/DebugUi.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","state/evidence.jsonl"],"source":"user reported missing patch content in synth playground"}