#ifndef RENDERER_H
#define RENDERER_H

#include "math/Vector.h"
#include "rendering/FileTexture.h"
#include "rendering/VertexBuffer.h"
#include "utils/Buffer.h"
#include "utils/Color.h"

class Renderer final {
    VertexBuffer vertexBuffer;
    Buffer buffer;
    FileTexture font;
    Color4 color;
    const char* text;
    int index;
    int maxIndex;
    float x;
    float y;
    int vertices;

public:
    Renderer();
    bool init();

    void renderString(const Vector2& pos, const char* text, int limit = -1);
    Vector2 getStringSize(const char* text, int limit = -1);
    void renderRectangle(const Vector2& pos, const Vector2& size, Color4 c);
    int charsInSpace(float width);

private:
    void setupStringRead(const char* s, int limit);
    void setupString(const Vector2& pos, const char* s, int limit);
    bool hasStringData() const;
    char32_t readUnicode();
    bool readColor(char32_t c);
    void addChar(char32_t c);

    void update();
};

#endif