2020-11-21 19:57:40 +00:00
|
|
|
#ifndef SDLPP_HPP_TEXT_RENDERER
|
|
|
|
#define SDLPP_HPP_TEXT_RENDERER
|
|
|
|
|
|
|
|
#include "sdlpp_common.hpp"
|
|
|
|
#include "sdlpp_rectrenderer.hpp"
|
2021-01-30 20:32:08 +00:00
|
|
|
#include "sdlpp_fontconfiguration.hpp"
|
2020-11-21 19:57:40 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace SDLPP {
|
2020-11-22 22:37:55 +00:00
|
|
|
class SDLPPSCOPE TextRenderer : public RectangleRender {
|
2020-11-21 19:57:40 +00:00
|
|
|
public:
|
|
|
|
TextRenderer() = delete;
|
|
|
|
TextRenderer( double x, double y, double w, double h,
|
|
|
|
std::shared_ptr< Renderer > &r );
|
|
|
|
TextRenderer( double x, double y, double w, double h,
|
2021-01-30 15:43:43 +00:00
|
|
|
std::shared_ptr< Renderer > &r, std::shared_ptr< Font > font,
|
2020-11-21 19:57:40 +00:00
|
|
|
const std::string &text, const std::string &color = "FFFFFF",
|
|
|
|
const std::string &outline_color = "000000",
|
2020-12-18 14:10:13 +00:00
|
|
|
double outline_size = -1, int flags = SDLPP_TEXT_CENTER );
|
2021-01-30 20:32:08 +00:00
|
|
|
TextRenderer( double x, double y, double w, double h,
|
|
|
|
std::shared_ptr< Renderer > &r, const std::string &text,
|
|
|
|
std::shared_ptr< FontConfiguration > config,
|
|
|
|
int flags = SDLPP_TEXT_CENTER );
|
2021-01-30 15:43:43 +00:00
|
|
|
void setText( std::shared_ptr< Font > font, const std::string &text,
|
2020-11-21 19:57:40 +00:00
|
|
|
const std::string &color = "FFFFFF",
|
|
|
|
const std::string &outline_color = "000000",
|
2020-12-18 14:10:13 +00:00
|
|
|
double outline_size = -1 );
|
2021-01-30 20:32:08 +00:00
|
|
|
void setText( const std::string &text,
|
|
|
|
std::shared_ptr< FontConfiguration > config );
|
2021-01-30 15:43:43 +00:00
|
|
|
void setTextColor( std::shared_ptr< Font > font,
|
|
|
|
const std::string &color = "FFFFFF",
|
2020-11-21 19:57:40 +00:00
|
|
|
const std::string &outline_color = "000000",
|
2020-12-18 14:10:13 +00:00
|
|
|
double outline_size = -1 );
|
2021-01-30 20:32:08 +00:00
|
|
|
void setTextColor( std::shared_ptr< FontConfiguration > config );
|
2020-11-21 19:57:40 +00:00
|
|
|
void changeText( const std::string &text );
|
|
|
|
void setFlags( int flags );
|
|
|
|
virtual void render() override;
|
|
|
|
virtual void updateSizeAndPosition() override;
|
|
|
|
virtual std::shared_ptr< RenderObject > copySelf() override;
|
|
|
|
|
|
|
|
private:
|
2021-01-30 15:43:43 +00:00
|
|
|
virtual void copyTo( std::shared_ptr< RenderObject > other ) override;
|
2021-03-07 11:20:00 +00:00
|
|
|
void updateTexture();
|
2020-11-21 19:57:40 +00:00
|
|
|
void updateDstRect();
|
2021-01-30 15:43:43 +00:00
|
|
|
void saveFontConfig( std::shared_ptr< Font > font, const std::string &color,
|
|
|
|
const std::string &outline_color,
|
|
|
|
double outline_size );
|
2021-01-30 20:32:08 +00:00
|
|
|
void saveFontConfig( std::shared_ptr< FontConfiguration > config );
|
2020-11-21 19:57:40 +00:00
|
|
|
std::string _text{};
|
|
|
|
int position_flags = 0;
|
|
|
|
SDL_Rect dst_rect{};
|
2021-01-30 20:32:08 +00:00
|
|
|
std::shared_ptr< FontConfiguration > _config;
|
2020-11-21 19:57:40 +00:00
|
|
|
};
|
|
|
|
} // end of namespace SDLPP
|
|
|
|
#endif
|