1
Graphics / [Solved] Text Coords and Shape Coords
« on: December 21, 2010, 11:43:00 am »Quote from: "Laurent"
Yes... but you need to find the code that doesn't produce the expected results. It doesn't help to know that SetPosition and GetPosition work, I already knew that
...
Explain how this works:
Code: [Select]
void SFMLRenderer::DrawText(std::string& text, Point& position) {
Gum::Base::Size size = MeasureText(text);
Gum::Base::Rect rect = Gum::Base::Rect(position.x, position.y, 0, 0);
sf::Text sfText = sf::Text(text, sf::Font::GetDefaultFont(), 10);
sfText.SetColor(m_Color);
sfText.SetPosition(sf::Vector2f(rect.Left, rect.Top));
m_pTarget->Draw(sfText);
}
Edit:
I'm starting to think my compiler is messing things up because, this draws perfectly centered text.
Code: [Select]
Gum::Base::Size size = GetRenderer()->MeasureText(GetCaption());
Gum::Base::Point position;
position.x = GetGlobalPos().x;
position.y = GetGlobalPos().y;
position.y += (GetSize().w - size.w) / 2;
position.x += (GetSize().h - size.h) / 2;
if(m_Pressed) {
position.x++;
position.y++;
}