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

Author Topic: Graphics or Icons in sf::Text  (Read 1544 times)

0 Members and 1 Guest are viewing this topic.

NoobsArePeople2

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Graphics or Icons in sf::Text
« on: May 02, 2014, 08:25:49 pm »
I'd like to display a label with the following text:

Quote
Press ENTER to start

But have "ENTER" be a graphic that looks like an enter key. I'd like to be able to do similar things with, say, a graphic of the left mouse button. The text in this graphic shows something similar to what I'd like to achieve:


I'm looking for some input on the best way to achieve this in SFML. What I've come up with so far is to either implement a bitmap font and use special characters that I wouldn't otherwise use in the text of my game (e.g., ~) as stand-ins for my graphics. In this case the actual text would be:

Quote
Press ~ to start

and in the bitmap font the ~ character would be the enter graphic. This is somewhat hacky but I can live with that, the real downside is that I'd have to implement a bitmap font myself.

Another possibility to is to expand on a TTF font, adding the icons similar to an icon font like Font Awesome. On the upside this doesn't require me to implement anything in SFML but now I'm mucking around editing fonts.

Either way, getting this to work is going to involve some work on my part. So I'd like to hear some critiques of my two ideas and some thoughts from others about how to approach this issue.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Graphics or Icons in sf::Text
« Reply #1 on: May 02, 2014, 08:47:23 pm »
Or you could do it really simple and primitive like this:

Say you want "text1" image "text2".

Start by simply drawing "text1". Then calculate a bounding box for text1 and draw a sprite with your image at the proper position right of text1. Then calculate the position (based on text1 and size of sprite) where text2 should start and draw text2 there.

Not saying that it's the most elegant solution or even that it's the best solution. I'm just trying to provide another option to consider :-)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Graphics or Icons in sf::Text
« Reply #2 on: May 02, 2014, 08:49:51 pm »
Maybe you can leave spaces in your text, and then fill them later with sprites (using Text::getCharacterPosition to find the exact position of the spaces to fill). Or use several sf::Text + sf::Sprite instances, and align them manually.
Laurent Gomila - SFML developer

 

anything