SFML community forums

Help => Window => Topic started by: etam on May 02, 2011, 10:12:55 pm

Title: [sfml2][linux] sf::Input::GetMouse* after creating window
Post by: etam on May 02, 2011, 10:12:55 pm
After creating window I want to know where the mouse is, but my method doesn't seem to work.

minimal code:
Code: [Select]
#include <SFML/OpenGL.hpp>
#include <SFML/Window.hpp>
#include <iostream>

int main() {
    sf::Window window(sf::VideoMode(800, 600), "SFML window");
    window.Display();
    std::cout << "x:" << window.GetInput().GetMouseX() << " y:" << window.GetInput().GetMouseX() << std::endl;
    window.Close();
    return 0;
}

In this example window appears and disappears immediately, but wherever mouse is it always returns "x:0 y:0".
Title: [sfml2][linux] sf::Input::GetMouse* after creating window
Post by: Laurent on May 02, 2011, 10:15:55 pm
sf::Input is not directly connected to the OS, it relies on the events processed when you call PollEvent. So basically you can't use sf::Input without an event loop.
Title: [sfml2][linux] sf::Input::GetMouse* after creating window
Post by: etam on May 02, 2011, 10:47:16 pm
So as long as mouse is unmoved I can't get its position? Looks like a bug.
Title: [sfml2][linux] sf::Input::GetMouse* after creating window
Post by: Laurent on May 02, 2011, 11:18:11 pm
Quote
So as long as mouse is unmoved I can't get its position?

Correct.

Quote
Looks like a bug

But it's not.
I know that sf::Input has some limitations, but making it rely on the OS functions rather than sf::Event would bring new problems.