Skip to content

Instantly share code, notes, and snippets.

Created October 21, 2011 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1303504 to your computer and use it in GitHub Desktop.
Save anonymous/1303504 to your computer and use it in GitHub Desktop.
// SFML string positioning
// note: window is a sf::RenderWindow
// Top,Left
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Top,Left");
txt.SetPosition(windowRect.Left,windowRect.Top);
window.Draw(txt);
}
// Top,Center
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Top,Center");
txt.SetPosition(windowRect.GetWidth()*0.5f - txt.GetRect().GetWidth()*0.5f,windowRect.Top);
window.Draw(txt);
}
// Top,Right
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Top,Right");
txt.SetPosition(windowRect.Right - txt.GetRect().GetWidth(),windowRect.Top);
window.Draw(txt);
}
// Center,Left
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Center,Left");
txt.SetPosition(windowRect.Left,windowRect.GetHeight()*0.5f - txt.GetRect().GetHeight()*0.5f);
window.Draw(txt);
}
// Center,Center
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Center,Center");
txt.SetPosition(windowRect.GetWidth()*0.5f - txt.GetRect().GetWidth()*0.5f,windowRect.GetHeight()*0.5f - txt.GetRect().GetHeight()*0.5f);
window.Draw(txt);
}
// Center,Right
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Center,Right");
txt.SetPosition(windowRect.Right - txt.GetRect().GetWidth(),windowRect.GetHeight()*0.5f - txt.GetRect().GetHeight()*0.5f);
window.Draw(txt);
}
// Bottom,Left
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Bottom,Left");
txt.SetPosition(windowRect.Left,windowRect.Bottom-txt.GetRect().GetHeight());
window.Draw(txt);
}
// Bottom,Center
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Bottom,Center");
txt.SetPosition(windowRect.GetWidth()*0.5f - txt.GetRect().GetWidth()*0.5f,windowRect.Bottom-txt.GetRect().GetHeight());
window.Draw(txt);
}
// Bottom,Right
{
sf::FloatRect windowRect(window.GetDefaultView().GetRect());
sf::String txt("Bottom,Right");
txt.SetPosition(windowRect.Right - txt.GetRect().GetWidth(),windowRect.Bottom-txt.GetRect().GetHeight());
window.Draw(txt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment