using System.Numerics; using AcDream.App.Rendering; namespace AcDream.App.UI; /// /// Per-frame drawing context passed through the /// tree. Wraps a (our 2D sprite batcher) and a /// transform stack so elements can draw in local coordinates. /// /// Retail equivalent: the implicit context FUN_005da8f0 walks with /// when iterating the UI tree. Our version is explicit so it plugs /// cleanly into Silk.NET. /// public sealed class UiRenderContext { public TextRenderer TextRenderer { get; } public BitmapFont? DefaultFont { get; set; } public Vector2 ScreenSize { get; } // Transform stack — simple 2D translate (no rotation/scale for UI). private readonly System.Collections.Generic.List _stack = new(); private Vector2 _current; public UiRenderContext(TextRenderer tr, Vector2 screenSize, BitmapFont? defaultFont = null) { TextRenderer = tr; ScreenSize = screenSize; DefaultFont = defaultFont; } /// Push a relative translate. Must be paired with . public void PushTransform(float dx, float dy) { _stack.Add(_current); _current += new Vector2(dx, dy); } public void PopTransform() { if (_stack.Count == 0) return; _current = _stack[^1]; _stack.RemoveAt(_stack.Count - 1); } public Vector2 CurrentOrigin => _current; // ── Pass-through draw helpers (add current translate) ────────────── public void DrawRect(float x, float y, float w, float h, Vector4 color) => TextRenderer.DrawRect(_current.X + x, _current.Y + y, w, h, color); public void DrawRectOutline(float x, float y, float w, float h, Vector4 color, float thickness = 1f) => TextRenderer.DrawRectOutline(_current.X + x, _current.Y + y, w, h, color, thickness); public void DrawString(string text, float x, float y, Vector4 color, BitmapFont? font = null) { var f = font ?? DefaultFont; if (f is null) return; TextRenderer.DrawString(f, text, _current.X + x, _current.Y + y, color); } }