65 lines
1.7 KiB
C++
65 lines
1.7 KiB
C++
#include "SDL.h"
|
|
#include "SDL_ttf.h"
|
|
#include "sdl2-gfx/SDL2_rotozoom.h"
|
|
|
|
#include "Model.hpp"
|
|
#include "Color.hpp"
|
|
|
|
namespace sb
|
|
{
|
|
class Text : public sb::Plane
|
|
{
|
|
|
|
private:
|
|
|
|
inline static const sb::Color DEFAULT_FG {0.0f, 0.0f, 0.0f, 255.0f};
|
|
inline static const sb::Color DEFAULT_BG {0.0f, 0.0f, 0.0f, 0.0f};
|
|
|
|
std::string _content;
|
|
sb::Color _foreground, _background;
|
|
std::shared_ptr<TTF_Font> _font;
|
|
|
|
/*!
|
|
* Set the texture to the appropriate SDL_Surface created by the SDL TTF library.
|
|
*/
|
|
void refresh();
|
|
|
|
public:
|
|
|
|
Text(const std::string& content = "", const sb::Color& foreground = DEFAULT_FG, const sb::Color& background = DEFAULT_BG) :
|
|
_content(content), _foreground(foreground), _background(background)
|
|
{
|
|
/* Assign a default constructed Texture object to be the default texture */
|
|
texture(sb::Texture());
|
|
}
|
|
|
|
Text(std::shared_ptr<TTF_Font> font, const std::string& content = "", const sb::Color& foreground = DEFAULT_FG,
|
|
const sb::Color& background = DEFAULT_BG) : Text(content, foreground, background)
|
|
{
|
|
_font = font;
|
|
}
|
|
|
|
/*!
|
|
* @param content text to be displayed
|
|
*/
|
|
void content(const std::string& content);
|
|
|
|
/*!
|
|
* @param foreground text color
|
|
*/
|
|
void foreground(const sb::Color& foreground);
|
|
|
|
/*!
|
|
* @param background text background color which fills the Plane
|
|
*/
|
|
void background(const sb::Color& background);
|
|
|
|
/*!
|
|
* @param font shared pointer to a TTF_Font
|
|
*/
|
|
void font(std::shared_ptr<TTF_Font> font);
|
|
};
|
|
}
|
|
|
|
#include "Game.hpp"
|