From 0e71dfa7d51d7ea535b23c8d2f3ad50887f26d39 Mon Sep 17 00:00:00 2001 From: zv0n Date: Fri, 23 Jul 2021 00:05:13 +0200 Subject: [PATCH] SDLPP: make text change only happen in render() --- sdlpp/sdlpp_textrenderer.cpp | 13 ++++++++++--- sdlpp/sdlpp_textrenderer.hpp | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/sdlpp/sdlpp_textrenderer.cpp b/sdlpp/sdlpp_textrenderer.cpp index 1bbe4ee..6e33812 100644 --- a/sdlpp/sdlpp_textrenderer.cpp +++ b/sdlpp/sdlpp_textrenderer.cpp @@ -29,12 +29,12 @@ void TextRenderer::setText( std::shared_ptr< Font > font, const std::string &text, const std::string &color, const std::string &outline_color, double outline_size ) { - _text = text; + changeText(text); setTextColor( font, color, outline_color, outline_size ); } void TextRenderer::setText( const std::string &text, std::shared_ptr< FontConfiguration > config ) { - _text = text; + changeText(text); setTextColor( config ); } 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 ) { _text = text; + text_change = true; } void TextRenderer::setFlags( int flags ) { position_flags = flags; updateDstRect(); } void TextRenderer::render() { + if(text_change) { + updateTexture(); + text_change = false; + } if ( !getHidden() ) { if ( polygon ) polygon->render( *renderer ); @@ -86,7 +91,8 @@ void TextRenderer::updateTexture() { void TextRenderer::updateSizeAndPosition() { RectangleRender::updateSizeAndPosition(); // TODO only if size actually changed - updateTexture(); +// updateTexture(); + text_change = true; updateDstRect(); } std::shared_ptr< RenderObject > TextRenderer::copySelf() { @@ -144,6 +150,7 @@ void TextRenderer::saveFontConfig( std::shared_ptr< Font > font, double outline_size ) { _config = std::make_shared< FontConfiguration >( font, color, outline_color, outline_size ); + text_change = true; } void TextRenderer::saveFontConfig( std::shared_ptr< FontConfiguration > config ) { diff --git a/sdlpp/sdlpp_textrenderer.hpp b/sdlpp/sdlpp_textrenderer.hpp index 151822c..1d1eac0 100644 --- a/sdlpp/sdlpp_textrenderer.hpp +++ b/sdlpp/sdlpp_textrenderer.hpp @@ -52,6 +52,7 @@ private: int position_flags = 0; SDL_Rect dst_rect{}; std::shared_ptr< FontConfiguration > _config; + bool text_change = false; }; } // end of namespace SDLPP #endif