game/sdlpp/sdlpp_textrenderer.hpp

59 lines
2.4 KiB
C++
Raw Normal View History

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"
#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,
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",
double outline_size = -1, int flags = SDLPP_TEXT_CENTER );
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 );
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",
double outline_size = -1 );
void setText( const std::string &text,
std::shared_ptr< FontConfiguration > config );
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",
double outline_size = -1 );
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:
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();
void saveFontConfig( std::shared_ptr< Font > font, const std::string &color,
const std::string &outline_color,
double outline_size );
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{};
std::shared_ptr< FontConfiguration > _config;
bool text_change = false;
2020-11-21 19:57:40 +00:00
};
} // end of namespace SDLPP
#endif