SFML community forums

General => Feature requests => Topic started by: SFJ on December 28, 2014, 02:19:52 pm

Title: Relative mouse mode
Post by: SFJ on December 28, 2014, 02:19:52 pm
I'm trying to accomplish something like SDL2's "SDL_SetRelativeMouseMode(SDL_TRUE)". I want to use SFML instead of SDL, because SFML has got some much easier functions for keyboard, window, font/text and audio/music control. Did I maybe overlook this feature? I also tried setting the mouse to the center of the window every frame, but when the program is really slow, the user is still able to make the mouse cursor escape the window. With SDL2's relative mouse mode, this cannot happen.

So, how can I reach this in SFML?:

//In the window constructor (the initialize mouse part):
SDL_WarpMouseInWindow(window, width/2, height/2);
SDL_SetRelativeMouseMode(SDL_TRUE);                             // <---- this

//In the event loop
SDL_Event e;
while(SDL_PollEvent(&e))
{
        if(e.type == SDL_MOUSEMOTION)                           // <---- and this
        {
                mouseXChg = e.motion.xrel;
                mouseYChg = e.motion.yrel;
        }
}
 
Title: Re: Relative mouse mode
Post by: Laurent on December 28, 2014, 02:32:19 pm
This feature has already been discussed, did you search first?
Title: Re: Relative mouse mode
Post by: Hiura on December 28, 2014, 06:10:40 pm
There was an old discussion here http://en.sfml-dev.org/forums/index.php?topic=1876.0 that was brought back from the dead one year ago. But this FR is slightly different: on the other thread and on https://github.com/SFML/SFML/pull/614 we are discussion about grabbing the cursor, here it's about relative movement (and thus hiding and locking the cursor). Actually, I mentioned that alternative very quickly in the last ยง of #614's description as a way to "fix" the OS X implementation.

It would be interesting to discuss whether or not we need both of those strategies.

As I see it now, the second one is more powerful and allows the user to build the "mouse grab" feature on top of it.
Title: Re: Relative mouse mode
Post by: Laurent on December 28, 2014, 06:48:07 pm
Issue #304 (https://github.com/SFML/SFML/issues/304)

Although it may not be obvious, this one would directly lead to the implementation of the desired behavior, and I think this is how SDL2 implements it too.
Title: Re: Relative mouse mode
Post by: Hiura on December 29, 2014, 06:02:03 pm
I thought #304 was a Windows thing. >_<

But the question remains. Should we add "grabMouse" or "enableRelativeMove" or both? I'd say only "enableRelativeMove" for the same argument as before.

SDL has both: SDL_SetRelativeMouseMode and SDL_SetWindowGrab.