#pragma once

#include "crStruct.h"

class crApp;
class crBatchedLines3D;

// Debug overlay for text: per-glyph wire boxes, per-group (one AddString call) wire box, and the anchor circle.
// Fed from crBatchedTexts::AddString (world-anchored path) in screen-pixel space; drawn on top as wireframe lines (PixelProjection).
class crDevText
{
private:
    bool _debugDrawEnabled = false;

    crBatchedLines3D* _lineBatch = nullptr;
    crApp*            _app       = nullptr;

    bool   _frameStarted = false;   // lazy Begin: batch is filled across AddString calls, flushed once in TryRenderDebugDraw
    float2 _anchor       = {};
    float2 _groupMin     = {};
    float2 _groupMax     = {};
    bool   _hasGlyph     = false;

public:
    void Init( crApp* app );
    void Cleanup();

    void BeginGroup( float2 anchorPx );
    void AddGlyphRect( float2 centerPx, float2 sizePx );
    void EndGroup();

    void TryRenderDebugDraw();   // 2D wireframe lines — call after the post-processing chain

    bool GetDebugDraw() const;
    void SetDebugDraw( bool enable );   // off also releases the line batch memory

private:
    void AddRect( float2 rectMin, float2 rectMax, color4 color );
};
