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

Author Topic: Easy way of determining spacing of lines of text  (Read 5137 times)

0 Members and 1 Guest are viewing this topic.

Wibbs

  • Newbie
  • *
  • Posts: 40
    • View Profile
Easy way of determining spacing of lines of text
« on: March 16, 2010, 07:36:53 pm »
Hi all,

Just wanted to ask a quick question.  I'm currently implementing the GUI for my game, and am working out how to deal with multiple lines of text.  Given that the height of a String2D varies depending on the characters in the string, is there an easy way of determining the vertical spacing required to ensure that lines of text are evenly spaced for a given font and font size?  

The way I'm thinking of doing it at the moment, is to use a test string containing the highest and lowest characters for a particular font to establish the largest height a String2D could have, but this seems a tad cumbersome.  Is there an easier way?

Thanks,

Wibbs

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Easy way of determining spacing of lines of text
« Reply #1 on: March 16, 2010, 07:51:25 pm »
In SFML 1, the line spacing is simply the character size of the String2D.

In SFML 2, the line spacing is given by the Font.GetLineSpacing function.

In both cases it is a constant, it never depends on the characters in the string.
Laurent Gomila - SFML developer

Wibbs

  • Newbie
  • *
  • Posts: 40
    • View Profile
Easy way of determining spacing of lines of text
« Reply #2 on: March 16, 2010, 08:18:17 pm »
Hi again,

I'm using 1.5 coz I don't want to have to deal with the regular updates to the version 2 code base at the moment.

I'm working out the String2D height by calling .GetRect() and taking the height from the resulting FloatRect.  When I do this for different strings, it gives different heights.  Am I doing this wrong then, because this is the only way I can see of getting a height measurement for the String2D?

Thanks,

Wibbs

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Easy way of determining spacing of lines of text
« Reply #3 on: March 16, 2010, 08:22:19 pm »
This is not wrong, when you call GetRect().Height you get the actual height of the string. When you use the the character size, you have a constant number which is the maximum height that a character can have. Use the one that you need ;)
Laurent Gomila - SFML developer

Wibbs

  • Newbie
  • *
  • Posts: 40
    • View Profile
Easy way of determining spacing of lines of text
« Reply #4 on: March 16, 2010, 09:57:36 pm »
Ah, ok I think I've got what you mean. So, the size I specify when I create the String2D object gives the maximum height of any text entered?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Easy way of determining spacing of lines of text
« Reply #5 on: March 16, 2010, 11:32:08 pm »
Yes.
Laurent Gomila - SFML developer

 

anything