SFML community forums

Help => Graphics => Topic started by: Kingdom of Fish on March 04, 2008, 02:09:15 pm

Title: Width of text
Post by: Kingdom of Fish 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.
Title: Width of text
Post by: Laurent 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.
Title: Width of text
Post by: Kingdom of Fish on March 05, 2008, 01:03:32 pm
I use the SVN version and the screen looks like this:
(http://img187.imageshack.us/img187/2100/screenshotspinitmfjo4.th.png) (http://img187.imageshack.us/my.php?image=screenshotspinitmfjo4.png)

All those texts should be centered in the screen and as you can see they are not.
Title: Width of text
Post by: Laurent on March 05, 2008, 01:33:23 pm
Can you show us the corresponding code (should be very short) ?
Title: Width of text
Post by: Kingdom of Fish 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.
Title: Width of text
Post by: Laurent 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 :)
Title: Width of text
Post by: Kingdom of Fish on March 06, 2008, 02:07:52 pm
oh, sweet :)