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

Author Topic: Width of text  (Read 5636 times)

0 Members and 1 Guest are viewing this topic.

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Width of text
« on: March 04, 2008, 02:09:15 pm »
How do i get the actual width of a text, lets say if i want to put the text in the center of the screen i get the rect from the font object divide the width by two and put that in the center but the text seem to be a little off. If you dont get what i mean i'll post screens but i have non atm.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Width of text
« Reply #1 on: March 04, 2008, 02:19:54 pm »
Which version of SFML are you using ? If it's not the current SVN one, then forget about it : fonts and text rendering have been completely redone ;)

Otherwise, screenshots could help.
Laurent Gomila - SFML developer

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Width of text
« Reply #2 on: March 05, 2008, 01:03:32 pm »
I use the SVN version and the screen looks like this:


All those texts should be centered in the screen and as you can see they are not.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Width of text
« Reply #3 on: March 05, 2008, 01:33:23 pm »
Can you show us the corresponding code (should be very short) ?
Laurent Gomila - SFML developer

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Width of text
« Reply #4 on: March 05, 2008, 02:24:19 pm »
This is the code i use to place each of the options:

Code: [Select]
void MenuScene::addOption(string opt, float offset)
{
sf::String* s = new sf::String(opt);
s->SetSize(40);
float width = s->GetRect().GetWidth();
s->SetCenter(width/2.0, 20);
s->SetPosition(400, nextOption+offset);
s->SetColor(sf::Color::Red);
nextOption += (60+offset);
mOptions.push_back(s);
}


Since i haven't really got the hang of fonts i dont use it just accept the default.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Width of text
« Reply #5 on: March 06, 2008, 12:28:50 pm »
There was a bug in the sf::String rendering. It's now fixed.

Thanks for your help :)
Laurent Gomila - SFML developer

Kingdom of Fish

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Width of text
« Reply #6 on: March 06, 2008, 02:07:52 pm »
oh, sweet :)

 

anything