//
// Created by m on 12/3/21.
//

#ifndef RLA_IIPP_SDLRENDERER_HPP
#define RLA_IIPP_SDLRENDERER_HPP
#include "../renderer.hpp"
#include "sdltexturemanager.hpp"
#include "sdlfontmanager.hpp"
#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_image.h>

struct SDL_WindowDeleter {
    void operator()(SDL_Window* window) { SDL_DestroyWindow(window);}
};

class SdlRenderer : public Renderer {
public:
    ~SdlRenderer();
    void draw_text(std::optional<TextRenderDetails> details, std::string text, int x, int y) override;
    void initialize(RendererParams params) override;
    void flush() override;
    void draw_point(int x, int y, Color color) override;

    void draw_sprite(Sprite sprite, int x, int y) override;

private:
    RendererParams renderer_params;
    std::unique_ptr<SDL_Window, SDL_WindowDeleter> window;
    std::shared_ptr<SDL_Renderer> renderer = nullptr;
    std::unique_ptr<SdlTextureManager> texture_manager = nullptr;
    std::unique_ptr<SdlFontManager> font_manager = nullptr;
    void render_texture(int x, int y, const std::shared_ptr<SDL_Texture>& texture, SDL_Rect *src);
};


#endif //RLA_IIPP_SDLRENDERER_HPP
