SDLPP: make text change only happen in render()
This commit is contained in:
parent
76f5c43197
commit
0e71dfa7d5
@ -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 ) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user