From fc38dd0d69e86017e4bbdba27e394ad82b5312e2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 1 Jun 2026 14:26:33 +0100 Subject: [PATCH] Add preview hover guides and editor hotkeys --- .../Input/InputState.cs | 5 ++ .../Ui/AquariumUi.cs | 19 ++++++- src/Aquarium.Engine/Platform/Win32Window.cs | 20 ++++++++ src/Aquarium.Engine/Render/D3D12Renderer.cs | 25 +++++++++- .../Render/DirectWriteOverlay.cs | 50 +++++++++++++++---- state/evidence.jsonl | 1 + state/map.yaml | 5 +- 7 files changed, 112 insertions(+), 13 deletions(-) diff --git a/src/Aquarium.Engine.Contracts/Input/InputState.cs b/src/Aquarium.Engine.Contracts/Input/InputState.cs index 8911258..3f2930e 100644 --- a/src/Aquarium.Engine.Contracts/Input/InputState.cs +++ b/src/Aquarium.Engine.Contracts/Input/InputState.cs @@ -128,8 +128,13 @@ public enum KeyCode Delete, Enter, LeftArrow, + UpArrow, RightArrow, + DownArrow, Home, End, + PageUp, + PageDown, Shift, + Control, } diff --git a/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs b/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs index 1b90059..1abb797 100644 --- a/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs +++ b/src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs @@ -100,6 +100,17 @@ public readonly record struct AquariumUiPreviewInteraction( float DeltaX, float DeltaY); +public readonly record struct AquariumUiPreviewState( + string HoverItemId = "", + string HoverHandle = "", + string ActiveItemId = "", + string ActiveHandle = ""); + +public readonly record struct AquariumUiPreviewGuide( + string Axis, + float Position, + string Tone = "neutral"); + public sealed record AquariumUiElement( string Id, string Kind, @@ -120,6 +131,8 @@ public sealed record AquariumUiElement( Action? WriteOption = null, IReadOnlyList? Options = null, Func>? ReadPreviewItems = null, + Func? ReadPreviewState = null, + Func>? ReadPreviewGuides = null, bool PreviewBlitsOutputBuffer = false, Action? HandlePreviewInteraction = null, Action? Invoke = null, @@ -217,13 +230,17 @@ public sealed class AquariumUiSurfaceBuilder(List children) Func> readItems, float weight = 1.0f, bool blitOutputBuffer = false, - Action? handleInteraction = null) + Action? handleInteraction = null, + Func? readState = null, + Func>? readGuides = null) { children.Add(new AquariumUiElement( id, "preview", label, ReadPreviewItems: readItems, + ReadPreviewState: readState, + ReadPreviewGuides: readGuides, PreviewBlitsOutputBuffer: blitOutputBuffer, HandlePreviewInteraction: handleInteraction, Weight: Math.Max(0.001f, weight))); diff --git a/src/Aquarium.Engine/Platform/Win32Window.cs b/src/Aquarium.Engine/Platform/Win32Window.cs index 5754be8..a118917 100644 --- a/src/Aquarium.Engine/Platform/Win32Window.cs +++ b/src/Aquarium.Engine/Platform/Win32Window.cs @@ -69,10 +69,15 @@ public sealed class Win32Window : IDisposable private const int VK_DELETE = 0x2E; private const int VK_RETURN = 0x0D; private const int VK_LEFT = 0x25; + private const int VK_UP = 0x26; private const int VK_RIGHT = 0x27; + private const int VK_DOWN = 0x28; private const int VK_HOME = 0x24; private const int VK_END = 0x23; + private const int VK_PRIOR = 0x21; + private const int VK_NEXT = 0x22; private const int VK_SHIFT = 0x10; + private const int VK_CONTROL = 0x11; private const int WHEEL_DELTA = 120; private readonly WndProc windowProcedure; @@ -824,18 +829,33 @@ public sealed class Win32Window : IDisposable case VK_LEFT: input.SetKey(KeyCode.LeftArrow, isDown); break; + case VK_UP: + input.SetKey(KeyCode.UpArrow, isDown); + break; case VK_RIGHT: input.SetKey(KeyCode.RightArrow, isDown); break; + case VK_DOWN: + input.SetKey(KeyCode.DownArrow, isDown); + break; case VK_HOME: input.SetKey(KeyCode.Home, isDown); break; case VK_END: input.SetKey(KeyCode.End, isDown); break; + case VK_PRIOR: + input.SetKey(KeyCode.PageUp, isDown); + break; + case VK_NEXT: + input.SetKey(KeyCode.PageDown, isDown); + break; case VK_SHIFT: input.SetKey(KeyCode.Shift, isDown); break; + case VK_CONTROL: + input.SetKey(KeyCode.Control, isDown); + break; } } diff --git a/src/Aquarium.Engine/Render/D3D12Renderer.cs b/src/Aquarium.Engine/Render/D3D12Renderer.cs index fb84ca0..31f22dd 100644 --- a/src/Aquarium.Engine/Render/D3D12Renderer.cs +++ b/src/Aquarium.Engine/Render/D3D12Renderer.cs @@ -613,6 +613,14 @@ public sealed class D3D12Renderer : IAquariumRenderer clientUiSurfaceWantsMouse = true; if (!input.LeftMouseDown) { + active.Element.HandlePreviewInteraction?.Invoke(new AquariumUiPreviewInteraction( + active.ItemId, + active.Handle, + "end", + Math.Clamp((input.MousePosition.X - active.Canvas.Left) / Math.Max(1.0f, active.Canvas.Width), 0.0f, 1.0f), + Math.Clamp((input.MousePosition.Y - active.Canvas.Top) / Math.Max(1.0f, active.Canvas.Height), 0.0f, 1.0f), + 0.0f, + 0.0f)); activePreviewDrag = null; return; } @@ -633,6 +641,14 @@ public sealed class D3D12Renderer : IAquariumRenderer if (TryHitPreview(input.MousePosition, out var hit)) { clientUiSurfaceWantsMouse = true; + hit.Element.HandlePreviewInteraction?.Invoke(new AquariumUiPreviewInteraction( + hit.ItemId, + hit.Handle, + "hover", + hit.X, + hit.Y, + 0.0f, + 0.0f)); if (input.IsMousePressed(MouseButton.Left)) { activePreviewDrag = new AquariumUiPreviewDrag(hit.Element, hit.ItemId, hit.Handle, hit.Canvas); @@ -766,7 +782,14 @@ public sealed class D3D12Renderer : IAquariumRenderer return true; } - return false; + hit = new AquariumUiPreviewHit( + element, + "", + "canvas", + canvas, + Math.Clamp((point.X - canvas.Left) / Math.Max(1.0f, canvas.Width), 0.0f, 1.0f), + Math.Clamp((point.Y - canvas.Top) / Math.Max(1.0f, canvas.Height), 0.0f, 1.0f)); + return true; } private static bool TryPreviewCanvas(Rect bounds, bool hasLabel, out Rect canvas) diff --git a/src/Aquarium.Engine/Render/DirectWriteOverlay.cs b/src/Aquarium.Engine/Render/DirectWriteOverlay.cs index 3247118..0b40843 100644 --- a/src/Aquarium.Engine/Render/DirectWriteOverlay.cs +++ b/src/Aquarium.Engine/Render/DirectWriteOverlay.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Vortice.DCommon; using Vortice.Direct2D1; using Vortice.DirectWrite; @@ -396,8 +397,10 @@ internal sealed class DirectWriteOverlay : IDisposable } renderTarget.DrawRectangle(canvas, outlineBrush, 1.0f); + DrawPreviewGuides(element, canvas); var items = element.ReadPreviewItems?.Invoke() ?? []; + var state = element.ReadPreviewState?.Invoke() ?? default; foreach (var item in items) { var left = canvas.Left + Math.Clamp(item.X, 0.0f, 1.0f) * canvas.Width; @@ -410,24 +413,51 @@ internal sealed class DirectWriteOverlay : IDisposable continue; } - var brush = item.Selected ? accentBrush : ToneBrush(item.Tone); - renderTarget.FillRectangle(itemBounds, item.Selected ? hoverRowBrush : rowBrush); - renderTarget.DrawRectangle(itemBounds, brush, item.Selected ? 2.0f : 1.0f); + var hovered = string.Equals(state.HoverItemId, item.Id, StringComparison.Ordinal); + var active = string.Equals(state.ActiveItemId, item.Id, StringComparison.Ordinal); + var brush = active || item.Selected ? accentBrush : ToneBrush(item.Tone); + renderTarget.FillRectangle(itemBounds, active ? activeRowBrush : hovered ? hoverRowBrush : rowBrush); + renderTarget.DrawRectangle(itemBounds, brush, active || item.Selected ? 2.0f : hovered ? 1.5f : 1.0f); renderTarget.DrawText(item.Label, smallFormat, RectFromEdges(itemBounds.Left + 6.0f, itemBounds.Top + 3.0f, itemBounds.Right - 6.0f, itemBounds.Bottom), primaryTextBrush, DrawTextOptions.Clip); if (item.Selected && element.HandlePreviewInteraction is not null) { - DrawPreviewHandle(itemBounds.Left, itemBounds.Top); - DrawPreviewHandle(itemBounds.Right, itemBounds.Top); - DrawPreviewHandle(itemBounds.Left, itemBounds.Bottom); - DrawPreviewHandle(itemBounds.Right, itemBounds.Bottom); + DrawPreviewHandle(itemBounds.Left, itemBounds.Top, state, item.Id, "nw"); + DrawPreviewHandle(itemBounds.Right, itemBounds.Top, state, item.Id, "ne"); + DrawPreviewHandle(itemBounds.Left, itemBounds.Bottom, state, item.Id, "sw"); + DrawPreviewHandle(itemBounds.Right, itemBounds.Bottom, state, item.Id, "se"); } } } - private void DrawPreviewHandle(float x, float y) + private void DrawPreviewGuides(AquariumUiElement element, Rect canvas) { - var handle = RectFromEdges(x - 4.0f, y - 4.0f, x + 4.0f, y + 4.0f); - renderTarget.FillRectangle(handle, accentActiveBrush); + var guides = element.ReadPreviewGuides?.Invoke() ?? []; + foreach (var guide in guides) + { + var position = Math.Clamp(guide.Position, 0.0f, 1.0f); + var brush = ToneBrush(guide.Tone); + if (string.Equals(guide.Axis, "x", StringComparison.Ordinal)) + { + var x = canvas.Left + position * canvas.Width; + renderTarget.DrawLine(new Vector2(x, canvas.Top), new Vector2(x, canvas.Bottom), brush, 1.25f); + } + else if (string.Equals(guide.Axis, "y", StringComparison.Ordinal)) + { + var y = canvas.Top + position * canvas.Height; + renderTarget.DrawLine(new Vector2(canvas.Left, y), new Vector2(canvas.Right, y), brush, 1.25f); + } + } + } + + private void DrawPreviewHandle(float x, float y, AquariumUiPreviewState state, string itemId, string handleId) + { + var active = string.Equals(state.ActiveItemId, itemId, StringComparison.Ordinal) && + string.Equals(state.ActiveHandle, handleId, StringComparison.Ordinal); + var hovered = string.Equals(state.HoverItemId, itemId, StringComparison.Ordinal) && + string.Equals(state.HoverHandle, handleId, StringComparison.Ordinal); + var radius = active ? 6.0f : hovered ? 5.0f : 4.0f; + var handle = RectFromEdges(x - radius, y - radius, x + radius, y + radius); + renderTarget.FillRectangle(handle, active ? accentActiveBrush : hovered ? accentHoverBrush : accentBrush); renderTarget.DrawRectangle(handle, panelBrush, 1.0f); } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 1f1ab51..d1e28a4 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -327,3 +327,4 @@ {"ts":"2026-05-31T22:17:00+01:00","type":"implementation","status":"ok","note":"CultUI preview elements are now flexible layout surfaces rather than fixed preferred-height controls. Containers with flexible children report as flexible to their parent, so editor panes containing a compositor preview can take the available center-panel space instead of collapsing to a small fixed strip.","files":["src/Aquarium.Engine/Render/DirectWriteOverlay.cs"],"source":"dotnet build src/Aquarium.Engine/Aquarium.Engine.csproj --no-restore; Mimir headless capture artifacts/runtime/mimir-editor-preview-maximized-headless.png"} {"ts":"2026-05-31T22:55:00+01:00","type":"implementation","status":"ok","note":"CultUI preview lowering treats an empty preview label as an intentional chrome-free canvas: no nested frame/title is drawn, and padding collapses to two pixels. Mimir uses this for the central OBS-style program compositor so the preview fills the editor center instead of rendering as a card-within-a-pane.","files":["src/Aquarium.Engine/Render/DirectWriteOverlay.cs"],"source":"dotnet build src/Aquarium.Engine/Aquarium.Engine.csproj; dotnet build E:/Projects/Mimir/src/Mimir.App/Mimir.App.csproj; Mimir.App --headless --headless-width 1280 --headless-height 720 --capture-frame artifacts/runtime/mimir-editor-flat-2d-program-mixer-headless.png"} {"ts":"2026-06-01T13:48:00+01:00","type":"implementation","status":"ok","note":"CultUI preview elements now support direct compositor gestures. AquariumUiElement can carry a preview interaction callback, D3D12Renderer hit-tests preview item bodies and selected corner handles in normalized canvas coordinates, captures input while dragging, and DirectWriteOverlay draws visible selected corner handles. Clients still own gesture meaning; Fensalir owns the reusable UI hit-test and rendering affordance.","files":["src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs"],"source":"dotnet build src/Aquarium.Engine.Contracts/Aquarium.Engine.Contracts.csproj -p:UseSharedCompilation=false; dotnet build src/Aquarium.Engine/Aquarium.Engine.csproj -p:UseSharedCompilation=false"} +{"ts":"2026-06-01T14:12:00+01:00","type":"implementation","status":"ok","note":"CultUI preview affordances now include hover/active state, empty-canvas hits, drag-end events, and normalized guide rendering. D3D12Renderer emits hover/begin/drag/end interactions for preview bodies, handles, and empty canvas; DirectWriteOverlay draws hovered/active selected handles and client-provided x/y guides. Added Up/Down/PageUp/PageDown/Control key codes for editor hotkeys.","files":["src/Aquarium.Engine.Contracts/Input/InputState.cs","src/Aquarium.Engine.Contracts/Ui/AquariumUi.cs","src/Aquarium.Engine/Platform/Win32Window.cs","src/Aquarium.Engine/Render/D3D12Renderer.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs"],"source":"dotnet build src/Aquarium.Engine.Contracts/Aquarium.Engine.Contracts.csproj -p:UseSharedCompilation=false; dotnet build src/Aquarium.Engine/Aquarium.Engine.csproj -p:UseSharedCompilation=false"} diff --git a/state/map.yaml b/state/map.yaml index bf3946a..b70c0b6 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -133,7 +133,10 @@ invariants: repos still own dashboard state, accepted commands, and meaning. CultUI preview elements may expose reusable item-body/corner-handle gestures in normalized preview coordinates, but the client remains the owner of what - those gestures do. + those gestures do. The preview primitive also carries hover/active state, + empty-canvas hits, drag-end events, and client-provided normalized guides + so compositor surfaces can show snap/selection feedback without becoming + renderer-owned policy. - Planetary ocean/atmosphere flow is an engine field organ when reduced to reusable stochastic advection machinery. Fensalir owns cube-sphere flow addressing, dataset provenance, model contracts, stochastic advection