SFML community forums

Help => General => Topic started by: MrDoomMaster on November 30, 2007, 11:57:38 pm

Title: Relative Cursor Movement
Post by: MrDoomMaster on November 30, 2007, 11:57:38 pm
Hi,

I was wondering if there was any functionality in SFML to facilitate relative cursor movement. For example, each time the MouseMove event is dispatched it would contain the delta x,y position of the cursor (as compared to its last position) instead of the absolute screen coordinates.

If it doesn't facilitate this behavior, I will need to do so myself. The only way I know how to do this is to manually move the cursor back to the center of the screen each time it is moved and calculate the change that way. Is there a way to set the cursor position? If so, does it generate MouseMove events? If it does, that will also be a problem as it will cause redundant and unauthentic MouseMove events.

Any tips on achieving this? Thanks.
Title: Relative Cursor Movement
Post by: Laurent on December 01, 2007, 11:07:07 am
Quote
The only way I know how to do this is to manually move the cursor back to the center of the screen each time it is moved and calculate the change that way

That's the way to do it (see sf::Window::SetCursorPosition). It generates mouse move events, but I'll see if I can remove them.
Title: Relative Cursor Movement
Post by: PM on December 01, 2007, 04:12:43 pm
I don't see sf::Window::SetCursorPosition function in the docs. It's probably in SVN, so I don't have the exact header.

Anyway, You should be able to add one more argument to this function, and give a default value to it:
Code: [Select]

...
void SetCursorPosition(..., bool generateEvent = true);
...

That way, it won't break existing code, and will let people to change the position without generating an event in the new code.
Title: Relative Cursor Movement
Post by: Laurent on December 01, 2007, 04:31:32 pm
That's what I'm going to do, I just need to check if the X11 and Win32 APIs can do it easily.
Title: Relative Cursor Movement
Post by: MrDoomMaster on April 18, 2008, 10:37:10 pm
Laurent,

Did you ever figure out this issue? Right now I think SetCursorPosition is still generating WM_MOUSEMOVE events, which cause me to get additional redundant MouseMove messages.
Title: Relative Cursor Movement
Post by: Laurent on April 19, 2008, 03:26:33 am
No, sorry. I'll try to work on this soon.
Title: Relative Cursor Movement
Post by: Laurent on April 19, 2008, 01:43:40 pm
Done ;)

As I couldn't find any reliable way to do it directly at the OS level, I added some simple code to sf::Window to discard MouseMoved events generated by SetCursorPosition.
Title: Relative Cursor Movement
Post by: MrDoomMaster on April 21, 2008, 02:42:31 am
Quote from: "Laurent"
Done ;)

As I couldn't find any reliable way to do it directly at the OS level, I added some simple code to sf::Window to discard MouseMoved events generated by SetCursorPosition.


Great! Thanks :)

Do you have a release date for SFML 1.3 (I'm assuming 1.3 is the next)?
Title: Relative Cursor Movement
Post by: Laurent on April 21, 2008, 03:11:19 am
Should be in the next few weeks, I'm mainly waiting for the MacOS port to be ready.