Re: [GtkGLExt] First person shooter games - mouse movement
- From: Michalis Kamburelis <michalis kambi gmail com>
- To: Peter Sivak <petikemail gmail com>
- Cc: gtkglext-list gnome org
- Subject: Re: [GtkGLExt] First person shooter games - mouse movement
- Date: Tue, 09 Feb 2010 05:32:23 +0100
Peter Sivak wrote:
> Hello again,
> I have searched for some Gtkmm function which can place my cursor to the
> center of the window (where the OpenGL scene is displayed) and I have found
> this:
>
> void Gdk::Display::warp_pointer(const Glib::RefPtr<Gdk::Screen>& screen,
> int x, int y)
>
> but the problem is that this function takes the "screen" (e.g. the whole
> monitor) coordinates and "not the window" coordinates, so it will place the
> cursor relative to the whole screen and not to the window.
I'm using the following X11-specific hack:
XWarpPointer(
gdk_x11_drawable_get_xdisplay(GLAreaGtk->Window),
None,
gdk_x11_drawable_get_xid(GLAreaGtk->Window),
0, 0, 0, 0, NewMouseX, NewMouseY);
with GLAreaGtk being my drawable (as GtkWidget*). Yes, this is an ugly
hack, obviously not portable --- you use X11 function. But it works, if
you want to do this on Unix. Seems others do the same:
http://www.mail-archive.com/gtk-app-devel-list gnome org/msg01657.html
I don't know if there's any function in GTK to nicely position mouse
pointer with respect to the window. You could try translating mouse
position from widget to screen coordinates, and then feeding them to
Gdk::Display::warp_pointer, this would be portable... but again I don't
know if there's any function to do this (translate coords from
widget->screen space) easily.
>
> And the second question is about "mouse pointer grabbing".
> I am a little bit confused about the term "grab" - could someone explain me
> what does it mean to grab a mouse pointer? Is it something like that after
> grab, the cursor disappears and does not react, and after ungrab, it appears
> again, or what?
>
"Grabbing" has nothing to do with hiding the mouse, it's orthogonal.
That is, if you want to hide the mouse, you have to do it separately, by
passing to gdk_window_set_cursor a special "empty" PGdkCursor* (empty
cursor = 1x1 bitmap with a single invisible pixel, example on
http://mail.gnome.org/archives/gtk-app-devel-list/2005-January/msg00370.html).
As for the "what is grabbing" --- this is used to "catch" all mouse
events by your window, even when the mouse goes outside of your window.
Longer explanation on http://developer.gnome.org/doc/GGAD/sec-gdkcursor.html
If you're repositioning mouse cursor to the center of your window all
the time, then "grabbing" is only a safety measure, to prevent the user
from leaving the window by moving the mouse very fast. This is only
relevant if you reposition the mouse e.g. after each mouse move, and
your window can have very small size. Normally the grabbing isn't that
critical for mouse look working, at least in my experience --- I have
mouse look working fine without grabbing.
Michalis
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]