SFML community forums
Help => Window => Topic started by: SiXoS on January 13, 2016, 02:00:50 pm
-
I'm using linux and I'm trying to set the mouse cursor position in relation to the window position but the position returned by the window is wrong. The position returned is 10 pixels above and 10 pixels to the left of the actual window corner. This wouldn't be a problem if you could get the whole window size (not just the rendering size) as you would then calculate the difference in rendering/window size and adjust the position.
However this doesn't change the fact that Mouse::setPosition (const Vector2i &position, const Window &relativeTo) is useless. It doesn't do what it's supposed to do and even though i have not tried it, my guess would be that this behaves differently in different operating systems which makes it even more useless.
So. Have I missed something that would make it possible to set the mouse position in relation to the rendering surface position? Otherwise I'm gonna publish an issue on this.
-
So you are saying that if you set the mouse position relative to the window, it won't account for the window decoration?
If yes, then it is not an error but intended( and documented) behaviour.
If not, please provide a minimal example(and if possible a screenshot) which repoduces(/shows) the error.
-
Ok, I was actually wrong. The setMousePosition does work correctly. What caused an error was that in a different spot I used the x and y value from getPosition. And i assumed the same point was used to set the mouse position.
So I now have a new question: Can I get the position of the render area?
-
The getPosition method of your window returns the position of the render area.
-
sf::Mouse::getPosition(window) (http://www.sfml-dev.org/tutorials/2.3/window-inputs.php#mouse)
will give you the position of the mouse inside of window's render area.
Be aware that this position is the pixel position so if you want to use that position to match the view that SFML is drawing in, you will need to convert the pixel position to world co-ordinates (http://www.sfml-dev.org/tutorials/2.3/graphics-view.php#coordinates-conversions).