53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
#ifndef GAME_RENDERER_HPP
|
|
#define GAME_RENDERER_HPP
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <SDL2/SDL.h>
|
|
#include <SDL2/SDL_ttf.h>
|
|
#include "Sprite.hpp"
|
|
#include "Color.hpp"
|
|
|
|
typedef TTF_Font Font;
|
|
|
|
class GameRenderer
|
|
{
|
|
private:
|
|
SDL_Renderer *renderer;
|
|
SDL_Window *window;
|
|
|
|
std::string title;
|
|
|
|
public:
|
|
int screen_width;
|
|
int screen_height;
|
|
|
|
GameRenderer(const std::string &title, int screen_width, int screen_height);
|
|
|
|
~GameRenderer();
|
|
|
|
[[nodiscard]] Font *load_font(const std::string &file, int font_size);
|
|
|
|
int get_text_width(Font *font, const std::string &text) const;
|
|
|
|
void draw_text(Font *font, const std::string &text, int x, int y, Color color) const;
|
|
|
|
[[nodiscard]] std::unique_ptr<Sprite> load_sprite(const std::string &file, int width, int height) const;
|
|
|
|
void draw_sprite(const Sprite &sprite, int x, int y) const;
|
|
|
|
void draw_sprite_flipped(const Sprite &sprite, int x, int y) const;
|
|
|
|
void draw_sprite_rotated(const Sprite &sprite, int x, int y, double angle) const;
|
|
|
|
void draw_rect(int x, int y, int width, int height, Color color) const;
|
|
|
|
void clear_screen(Color color) const;
|
|
|
|
void flush() const;
|
|
|
|
void redraw() const;
|
|
};
|
|
|
|
#endif
|