SDLPP: make text change only happen in render()

This commit is contained in:
zv0n 2021-07-23 00:05:13 +02:00
parent 76f5c43197
commit 0e71dfa7d5
2 changed files with 11 additions and 3 deletions

View File

@ -29,12 +29,12 @@ void TextRenderer::setText( std::shared_ptr< Font > font,
const std::string &text, const std::string &color, const std::string &text, const std::string &color,
const std::string &outline_color, const std::string &outline_color,
double outline_size ) { double outline_size ) {
_text = text; changeText(text);
setTextColor( font, color, outline_color, outline_size ); setTextColor( font, color, outline_color, outline_size );
} }
void TextRenderer::setText( const std::string &text, void TextRenderer::setText( const std::string &text,
std::shared_ptr< FontConfiguration > config ) { std::shared_ptr< FontConfiguration > config ) {
_text = text; changeText(text);
setTextColor( config ); setTextColor( config );
} }
void TextRenderer::setTextColor( std::shared_ptr< Font > font, void TextRenderer::setTextColor( std::shared_ptr< Font > font,
@ -48,12 +48,17 @@ void TextRenderer::setTextColor( std::shared_ptr< FontConfiguration > config ) {
} }
void TextRenderer::changeText( const std::string &text ) { void TextRenderer::changeText( const std::string &text ) {
_text = text; _text = text;
text_change = true;
} }
void TextRenderer::setFlags( int flags ) { void TextRenderer::setFlags( int flags ) {
position_flags = flags; position_flags = flags;
updateDstRect(); updateDstRect();
} }
void TextRenderer::render() { void TextRenderer::render() {
if(text_change) {
updateTexture();
text_change = false;
}
if ( !getHidden() ) { if ( !getHidden() ) {
if ( polygon ) if ( polygon )
polygon->render( *renderer ); polygon->render( *renderer );
@ -86,7 +91,8 @@ void TextRenderer::updateTexture() {
void TextRenderer::updateSizeAndPosition() { void TextRenderer::updateSizeAndPosition() {
RectangleRender::updateSizeAndPosition(); RectangleRender::updateSizeAndPosition();
// TODO only if size actually changed // TODO only if size actually changed
updateTexture(); // updateTexture();
text_change = true;
updateDstRect(); updateDstRect();
} }
std::shared_ptr< RenderObject > TextRenderer::copySelf() { std::shared_ptr< RenderObject > TextRenderer::copySelf() {
@ -144,6 +150,7 @@ void TextRenderer::saveFontConfig( std::shared_ptr< Font > font,
double outline_size ) { double outline_size ) {
_config = std::make_shared< FontConfiguration >( font, color, outline_color, _config = std::make_shared< FontConfiguration >( font, color, outline_color,
outline_size ); outline_size );
text_change = true;
} }
void TextRenderer::saveFontConfig( void TextRenderer::saveFontConfig(
std::shared_ptr< FontConfiguration > config ) { std::shared_ptr< FontConfiguration > config ) {

View File

@ -52,6 +52,7 @@ private:
int position_flags = 0; int position_flags = 0;
SDL_Rect dst_rect{}; SDL_Rect dst_rect{};
std::shared_ptr< FontConfiguration > _config; std::shared_ptr< FontConfiguration > _config;
bool text_change = false;
}; };
} // end of namespace SDLPP } // end of namespace SDLPP
#endif #endif