SDLPP TextRenderer: change font size based on rectangle height

This commit is contained in:
zv0n 2020-12-18 15:10:13 +01:00
parent 57143262ac
commit 7267cb7b9a
2 changed files with 14 additions and 7 deletions

View File

@ -7,7 +7,7 @@ TextRenderer::TextRenderer( double x, double y, double w, double h,
TextRenderer::TextRenderer( double x, double y, double w, double h, TextRenderer::TextRenderer( double x, double y, double w, double h,
std::shared_ptr< Renderer > &r, Font &font, std::shared_ptr< Renderer > &r, Font &font,
const std::string &text, const std::string &color, const std::string &text, const std::string &color,
const std::string &outline_color, int outline_size, const std::string &outline_color, double outline_size,
int flags ) int flags )
: RectangleRender( x, y, w, h, r ) { : RectangleRender( x, y, w, h, r ) {
position_flags = flags; position_flags = flags;
@ -16,14 +16,21 @@ TextRenderer::TextRenderer( double x, double y, double w, double h,
void TextRenderer::setText( Font &font, const std::string &text, void TextRenderer::setText( Font &font, const std::string &text,
const std::string &color, const std::string &color,
const std::string &outline_color, const std::string &outline_color,
int outline_size ) { double outline_size ) {
_text = text; _text = text;
setTextColor( font, color, outline_color, outline_size ); setTextColor( font, color, outline_color, outline_size );
} }
void TextRenderer::setTextColor( Font &font, const std::string &color, void TextRenderer::setTextColor( Font &font, const std::string &color,
const std::string &outline_color, const std::string &outline_color,
int outline_size ) { double outline_size ) {
setTexture( font, _text, color, outline_color, outline_size ); int fontSize = 0.6 * getRect().h;
font.changeFontSize(fontSize);
int intOutline = outline_size;
if(intOutline != -1) {
intOutline = outline_size * fontSize;
}
setTexture( font, _text, color, outline_color, intOutline );
font.revertSize();
updateDstRect(); updateDstRect();
} }
void TextRenderer::changeText( const std::string &text ) { void TextRenderer::changeText( const std::string &text ) {

View File

@ -17,14 +17,14 @@ public:
std::shared_ptr< Renderer > &r, Font &font, std::shared_ptr< Renderer > &r, Font &font,
const std::string &text, const std::string &color = "FFFFFF", const std::string &text, const std::string &color = "FFFFFF",
const std::string &outline_color = "000000", const std::string &outline_color = "000000",
int outline_size = -1, int flags = SDLPP_TEXT_CENTER ); double outline_size = -1, int flags = SDLPP_TEXT_CENTER );
void setText( Font &font, const std::string &text, void setText( Font &font, const std::string &text,
const std::string &color = "FFFFFF", const std::string &color = "FFFFFF",
const std::string &outline_color = "000000", const std::string &outline_color = "000000",
int outline_size = -1 ); double outline_size = -1 );
void setTextColor( Font &font, const std::string &color = "FFFFFF", void setTextColor( Font &font, const std::string &color = "FFFFFF",
const std::string &outline_color = "000000", const std::string &outline_color = "000000",
int outline_size = -1 ); double outline_size = -1 );
void changeText( const std::string &text ); void changeText( const std::string &text );
void setFlags( int flags ); void setFlags( int flags );
virtual void render() override; virtual void render() override;