Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Setting the mouse position relative to window position  (Read 5352 times)

0 Members and 1 Guest are viewing this topic.

SiXoS

  • Newbie
  • *
  • Posts: 4
    • View Profile
Setting the mouse position relative to window position
« 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.

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Setting the mouse position relative to window position
« Reply #1 on: January 13, 2016, 02:14:54 pm »
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.

SiXoS

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Setting the mouse position relative to window position
« Reply #2 on: January 13, 2016, 02:28:50 pm »
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?

SpeCter

  • Full Member
  • ***
  • Posts: 151
    • View Profile
Re: Setting the mouse position relative to window position
« Reply #3 on: January 13, 2016, 02:51:29 pm »
The getPosition method of your window returns the position of the render area.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Setting the mouse position relative to window position
« Reply #4 on: January 13, 2016, 10:20:22 pm »
sf::Mouse::getPosition(window)
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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*