Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mixed styles in one sf::Text object  (Read 1837 times)

0 Members and 1 Guest are viewing this topic.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Mixed styles in one sf::Text object
« 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.

killerloader

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Mixed styles in one sf::Text object
« Reply #1 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.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Mixed styles in one sf::Text object
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10913
    • View Profile
    • development blog
    • Email
Re: Mixed styles in one sf::Text object
« Reply #3 on: July 10, 2016, 05:34:32 pm »
You can take a look at RichText which provides different options to change the text style on the fly.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Mixed styles in one sf::Text object
« Reply #4 on: July 10, 2016, 05:53:49 pm »
eXpl0it3r, thanks for the link, I will check it out!

 

anything