#pragma once
#include "EngineFrame/Actor/Actor.h"
#include "EngineFrame/Render/Texture.h"
#include "EngineFrame/Component/Sprite.h"
class Canvas : public Actor
{
    struct ImgKey
    {
        std::string img;
        int index;

        bool operator<(const ImgKey &other) const
        {
            if (img != other.img)
            {
                return img < other.img; // 字符串按字典序比较
            }
            return index < other.index; // 字符串相同则比较index
        }
    };
    struct DrawInfo
    {
        ImgKey texture;
        SDL_FRect rect = {0, 0, 0, 0};
    };

private:
    /**纹理 */
    RefPtr<Texture> m_texture = nullptr;
    /**大小 */
    VecSize m_size;
    /**渲染大小 */
    SDL_Rect m_renderRect;
    SDL_FRect m_rect;
    /**脏标记 */
    bool m_dirty = true;
    /**FBO */
    GLuint m_fbo = 0;
    /**绘制纹理集 */
    std::map<ImgKey, RefPtr<Texture>> m_imgMap;
    /**绘制队列 */
    std::vector<DrawInfo> m_drawQueue;

public:
    Canvas(VecSize size);

    void PreRender() override;
    void Render() override;
    void Blend();

    void DrawImg(std::string img, int index, Vec2 pos);
    void DrawImg(std::string img, int index, SDL_FRect rect);
    void Clear();
};
