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

Author Topic: Relative mouse mode  (Read 3680 times)

0 Members and 1 Guest are viewing this topic.

SFJ

  • Newbie
  • *
  • Posts: 5
    • View Profile
Relative mouse mode
« 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;
        }
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Relative mouse mode
« Reply #1 on: December 28, 2014, 02:32:19 pm »
This feature has already been discussed, did you search first?
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Relative mouse mode
« Reply #2 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.
SFML / OS X developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Relative mouse mode
« Reply #3 on: December 28, 2014, 06:48:07 pm »
Issue #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.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Relative mouse mode
« Reply #4 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.
SFML / OS X developer