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

Author Topic: Text returns incorrect global bounds  (Read 2526 times)

0 Members and 1 Guest are viewing this topic.

JNoid75

  • Newbie
  • *
  • Posts: 1
    • View Profile
Text returns incorrect global bounds
« on: April 23, 2012, 10:53:42 pm »
Calling getGlobalBounds() on a sf::Text object gives some weird results. This has been causing trouble for me as it makes positioning text a real pain. I apologize if this has been answered somewhere else (or if it's just me being a noob, I'm kind of new to SFML), I looked and didn't see anything.


Code I'm using:

    sf::Text text("||| Bounds don't line up with the text |||", font, 24);
    text.setOrigin(text.getGlobalBounds().width/2, text.getGlobalBounds().height/2);
    text.setPosition(window->getSize().x/2, window->getSize().y/2);
    text.setColor(sf::Color::Green);
 
    sf::RectangleShape R;
    R.setSize(sf::Vector2f(text.getGlobalBounds().width, text.getGlobalBounds().height));
    R.setOrigin(R.getGlobalBounds().width/2, text.getGlobalBounds().height/2);
    R.setOutlineThickness(1);
    R.setOutlineColor(sf::Color::Black);
    R.setFillColor(sf::Color::Red);
    R.setPosition(window->getSize().x/2, window->getSize().y/2);
 
« Last Edit: April 23, 2012, 10:55:59 pm by JNoid75 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Text returns incorrect global bounds
« Reply #1 on: April 24, 2012, 08:06:13 am »
Hint: the global bounds is a rectangle, it also has left and top coordinates that can't be ignored (especially with sf::Text). Otherwise it would have been a simple "global size" ;)
Laurent Gomila - SFML developer