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

Author Topic: Mouse capture/grab  (Read 50597 times)

0 Members and 1 Guest are viewing this topic.

Tarindel

  • Newbie
  • *
  • Posts: 1
    • View Profile
Mouse capture/grab
« Reply #15 on: September 19, 2010, 09:09:00 am »
I'd like to see this feature as well.  It'd be useful for writing windowed games where the mouse is used to look around the scene.

apoc

  • Newbie
  • *
  • Posts: 1
    • View Profile
Mouse capture/grab
« Reply #16 on: October 26, 2010, 08:29:05 pm »
So is there really no grab input (like SDL_WM_GrabInput in SDL) for SFML? I'm currently trying to implement mouse look but looks like its impossible in window mode?!

Update!
The mouse look is working now, currently I'm using the workaround described by l0calh05t. But it would be really great if SFML is implementing a cross-platform input grabbing feature like SDL does with SDL_WM_GrabInput. Here is for instance the X11 implementation using XGrabPointer: X11_GrabInputNoLock

Crank1d

  • Newbie
  • *
  • Posts: 14
    • View Profile
Mouse capture/grab
« Reply #17 on: December 14, 2010, 04:04:24 pm »
I was also dissapointed when i found that SFML doesnt support this feature, especially because of OpenGL... (first person camera)
Will this feature be implemented in next SFML version?  :?:

Zweistein

  • Newbie
  • *
  • Posts: 29
    • View Profile
Mouse capture/grab
« Reply #18 on: January 06, 2011, 03:17:32 am »
Another Request from me, pls :)

jmp

  • Newbie
  • *
  • Posts: 3
    • View Profile
Mouse capture/grab
« Reply #19 on: January 06, 2011, 02:36:44 pm »
I would also like to see this feature.  It's pretty much essential for any program that implements mouse look.

Zweistein

  • Newbie
  • *
  • Posts: 29
    • View Profile
Mouse capture/grab
« Reply #20 on: January 06, 2011, 02:51:34 pm »
Can anybody post a workaround until we get it?

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Mouse capture/grab
« Reply #21 on: January 06, 2011, 03:03:45 pm »
Quote from: "Zweistein"
Can anybody post a workaround until we get it?


Code: [Select]

window.SetCursorPosition(halfScreenWidth, halfScreenHeight);

jmp

  • Newbie
  • *
  • Posts: 3
    • View Profile
Mouse capture/grab
« Reply #22 on: January 06, 2011, 03:27:40 pm »
Quote from: "Walker"
window.SetCursorPosition(halfScreenWidth, halfScreenHeight);

Unfortunately that isn't sufficient because the user can still move the mouse outside the window. What's even worse, if the user clicks when the mouse is outside the window, the SFML window loses focus.

Quote from: "Zweistein"
Can anybody post a workaround until we get it?

SFML 2* and Windows only:

Get the HWND of the SFML window with sf::Window::GetSystemHandle.
Get the window area coordinates to a RECT with GetClientRect.
Translate the window coordinates to screen coordinates with ClientToScreen.
Supply those coordinates to ClipCursor. That limits the the mouse movement to the window area.

For sample code (and how to do it on X11 / OSX), you could check how SDL does it.

To ungrab mouse, just call ClipCursor(NULL).

*SFML 1.x has no sf::Window::GetSystemHandle, so you would need to get the HWND some other way.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Mouse capture/grab
« Reply #23 on: January 06, 2011, 11:21:40 pm »
Quote from: "jmp"

Unfortunately that isn't sufficient because the user can still move the mouse outside the window. What's even worse, if the user clicks when the mouse is outside the window, the SFML window loses focus.


Oh I see. I guess at lower framerates this becomes more and more of a problem as well. In my programs (and my hardware) I've never been able to "escape", even with my stupid-fast mouse settings but I see the problem. I will probably try to implement your method now :).

You could always make your game fullscreen :D

Zweistein

  • Newbie
  • *
  • Posts: 29
    • View Profile
Mouse capture/grab
« Reply #24 on: January 10, 2011, 05:43:03 pm »
i am going to wait until its implemented :) As long as its implemented before 20th February :)

lg

Wiz

  • Newbie
  • *
  • Posts: 6
    • View Profile
Mouse capture/grab
« Reply #25 on: March 13, 2011, 05:17:43 pm »
I need this feature for X11, so I tried calling XGrabPointer but my sfml window now receives no more mouse event, whatever I put as owner_events and event_mask.
Does anyone managed to make it work ?
And are there any news on some implementation of this ?

cmc5788

  • Newbie
  • *
  • Posts: 11
    • View Profile
Mouse capture/grab
« Reply #26 on: March 29, 2011, 02:09:06 am »
EDIT:

So, I solved the problem this post was originally about.

If anyone else is having trouble getting mouse look to work with SFML and OpenGL, I'd be willing to upload my code, which handles restricting the mouse to the window and translating the mouse X and Y velocities into mouse look.  Also it seems to function properly with alt-tab and minimizing, which was hell to figure out.  Just let me know if anyone is interested.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Mouse capture/grab
« Reply #27 on: March 29, 2011, 08:30:21 am »
Would be nice if you could add that to the wiki.

cmc5788

  • Newbie
  • *
  • Posts: 11
    • View Profile
Mouse capture/grab
« Reply #28 on: March 29, 2011, 07:18:12 pm »
Quote from: "Tank"
Would be nice if you could add that to the wiki.


I will once I clean it up.  Unfortunately, I had to resort to some Windows-specific functions to make sure that the program played nice with alt-tabbing.

It would really be nice if SFML exposed some of the functionality to check on more nuanced window states.  I discovered that windows has a "minimized but active" state that sends a FocusGained event, but keeps the window minimized.  I had to manually check for that specific window state to make sure that my mouselook code didn't try to hijack the mouse cursor when this happened.

Specifically, I'm referring to this GetWindowPlacement function.  It would be really nice if SFML had a wrapper around this.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Mouse capture/grab
« Reply #29 on: March 29, 2011, 08:08:58 pm »
Quote
It would be really nice if SFML had a wrapper around this.

+1

 

anything