SFML community forums

Help => Graphics => Topic started by: xqbt on July 10, 2016, 09:44:11 am

Title: Mixed styles in one sf::Text object
Post by: xqbt on July 10, 2016, 09:44:11 am
So I have this string which I have to display and some characters in it may be of different styles than other characters. Something like this:
SFML String
This is one sf::String and I need to draw it. But as far as I can see, sf::Text does not allow for character-based style change.
So, what would be a good (and efficient) way pull it off? For once, I could imagine iterating all the characters and drawing them one-by-one using a separate sf::Text object along with getCharacterPos().
I mean that's not too bad, but maybe I am missing something.
Title: Re: Mixed styles in one sf::Text object
Post by: killerloader on July 10, 2016, 01:08:21 pm
As you said, you could draw each character separately with their own style (or split it into substrings with different styles)
However, if the text doesn't constantly change, then i'd suggest drawing the text to a RenderTexture, and then drawing the RenderTexture to the window.
Title: Re: Mixed styles in one sf::Text object
Post by: xqbt on July 10, 2016, 02:47:06 pm
Thanks for reply :) I thought about that too, turns out it is even slower (http://en.sfml-dev.org/forums/index.php?topic=20485.0). But piece-by-piece stylization will work anyway.
Title: Re: Mixed styles in one sf::Text object
Post by: eXpl0it3r on July 10, 2016, 05:34:32 pm
You can take a look at RichText (https://github.com/skyrpex/RichText) which provides different options to change the text style on the fly.
Title: Re: Mixed styles in one sf::Text object
Post by: xqbt on July 10, 2016, 05:53:49 pm
eXpl0it3r, thanks for the link, I will check it out!