1
Window / [MAC OS X - SFML2] GetMouseX() after SetCursorPosition(x,y)
« on: December 06, 2010, 12:31:14 pm »
This example won't output 400,300 after pressing 's'. Why is that? What is the correct way of doing it?
Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <map>
#include <math.h>
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");
// Create a clock to measure the total time elapsed
sf::Clock clock;
// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.GetEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
if (event.Type == sf::Event::KeyPressed)
{
// Escape key : exit
if (event.Key.Code == sf::Key::Escape)
window.Close();
if (event.Key.Code == sf::Key::S)
{
window.SetCursorPosition(400, 300);
printf("%d %d\n", window.GetInput().GetMouseX(), window.GetInput().GetMouseY());
}
}
if (event.Type == sf::Event::MouseMoved)
{
printf("%d %d\n", event.MouseMove.X, event.MouseMove.Y);
}
}
// Finally, display the rendered frame on screen
window.Display();
}
return EXIT_SUCCESS;
}