Using latest SFML2 from giit (LaurentGomila-SFML-c02e375)
I seem to be unable to centre sf::Text within a box without manually tuning it. Setting the origin of the text to the centre of its bounds results in the text (and its bounding box) showing with an offset from the expected position.
Minimal code:
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Text Test");
window.setFramerateLimit(60);
sf::RectangleShape shape(sf::Vector2f(50, 50));
shape.setPosition(100, 100);
shape.setFillColor(sf::Color::Blue);
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Text text("A", font, 20);
text.setOrigin(text.getLocalBounds().width/2, text.getLocalBounds().height/2);
text.setColor(sf::Color::White);
text.setPosition(125,125);
sf::RectangleShape textbox(sf::Vector2f(text.getLocalBounds().width, text.getLocalBounds().height));
textbox.setPosition(text.getGlobalBounds().left, text.getGlobalBounds().top);
textbox.setFillColor(sf::Color::Transparent);
textbox.setOutlineColor(sf::Color::White);
textbox.setOutlineThickness(1);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(shape);
window.draw(textbox);
window.draw(text);
window.display();
}
return EXIT_SUCCESS;
}
Unless I've missed something, i'd expect the above code to result in the letter (or at least its bounding box) being centred in the bigger blue box. Whether or not the origin for text is set, there still seems to be an odd offset from the expected position.
Having searched, this thread -
http://en.sfml-dev.org/forums/index.php?topic=9235.0 - appears to be related, though I can't see a resolution for it.
Any thoughts on why it's happening, or if it is indeed a bug?
Thanks!