Initial commit
This commit is contained in:
57
include/widgets.h
Normal file
57
include/widgets.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class Widget {
|
||||
public:
|
||||
Widget(SDL_Renderer* renderer, SDL_Rect dest_rect);
|
||||
|
||||
virtual void update_rect(SDL_Rect new_rect);
|
||||
|
||||
virtual void draw() = 0;
|
||||
|
||||
protected:
|
||||
SDL_Renderer* renderer;
|
||||
SDL_Rect dest_rect;
|
||||
};
|
||||
|
||||
class TextureWidget : public Widget {
|
||||
public:
|
||||
TextureWidget(SDL_Renderer* renderer, SDL_Rect dest_rect,
|
||||
std::optional<SDL_Texture*> texture);
|
||||
~TextureWidget();
|
||||
|
||||
virtual void draw() override;
|
||||
|
||||
void update_texture(SDL_Texture* new_texture);
|
||||
|
||||
private:
|
||||
std::optional<SDL_Texture*> texture;
|
||||
};
|
||||
|
||||
class ImageWidget : public TextureWidget {
|
||||
public:
|
||||
ImageWidget(SDL_Renderer* renderer, SDL_Rect dest_rect,
|
||||
const std::string& path);
|
||||
};
|
||||
|
||||
class TextWidget : public TextureWidget {
|
||||
public:
|
||||
TextWidget(SDL_Renderer* renderer, SDL_Rect dest_rect,
|
||||
const std::string& font_path,
|
||||
const std::string& initial_text = "");
|
||||
~TextWidget();
|
||||
|
||||
void update_text(const std::string& new_text);
|
||||
|
||||
protected:
|
||||
TTF_Font* font;
|
||||
|
||||
std::string text;
|
||||
|
||||
SDL_Texture* generate_text(const std::string& text);
|
||||
};
|
||||
Reference in New Issue
Block a user