Skip to content

Instantly share code, notes, and snippets.

@coolhome
Created June 16, 2011 17:18
Show Gist options
  • Save coolhome/1029724 to your computer and use it in GitHub Desktop.
Save coolhome/1029724 to your computer and use it in GitHub Desktop.
Testing sf::Window::GetPosition();
#include <SFML/Graphics.hpp>
#include <iostream>
#include <sstream>
#include <string>
//Hack! I know lol
std::string IntToString(int x)
{
std::ostringstream output;
output << x;
return output.str();
}
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Font arial;
if(! arial.LoadFromFile("arial.ttf"))
return EXIT_FAILURE;
sf::Text coords;
coords.SetFont(arial);
coords.SetCharacterSize(32);
sf::String coordStr;
sf::Vector2i windowPos;
while(window.IsOpened())
{
sf::Event event;
while(window.PollEvent(event))
{
if(event.Type == sf::Event::Closed)
window.Close();
}
windowPos = window.GetPosition();
coordStr = ("Window Position: " + IntToString(windowPos.x) + ", " + IntToString(windowPos.y));
coords.SetString(coordStr);
window.Clear();
window.Draw(coords);
window.Display();
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment