From: <ka...@us...> - 2010-03-26 19:17:59
|
Revision: 3294 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3294&view=rev Author: kappa1 Date: 2010-03-26 19:17:53 +0000 (Fri, 26 Mar 2010) Log Message: ----------- Consistent mouse grab behaviour on all platforms. Mouse will now ungrab at the same place it was grabbed from. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java Modified: trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2010-03-23 12:43:44 UTC (rev 3293) +++ trunk/LWJGL/src/java/org/lwjgl/input/Mouse.java 2010-03-26 19:17:53 UTC (rev 3294) @@ -125,6 +125,9 @@ private static int event_x; private static int event_y; private static long event_nanos; + /** The position of the mouse it was grabbed at */ + private static int grab_x; + private static int grab_y; /** Buffer size in events */ private static final int BUFFER_SIZE = 50; @@ -611,15 +614,27 @@ */ public static void setGrabbed(boolean grab) { synchronized (OpenGLPackageAccess.global_lock) { - isGrabbed = grab; + if (isCreated()) { - implementation.grabMouse(isGrabbed); + if (grab && !isGrabbed) { + // store location mouse was grabbed + grab_x = x; + grab_y = y; + } + else if (!grab && isGrabbed) { + // move mouse back to location it was grabbed before ungrabbing + if ((Cursor.getCapabilities() & Cursor.CURSOR_ONE_BIT_TRANSPARENCY) != 0) + implementation.setCursorPosition(grab_x, grab_y); + } + + implementation.grabMouse(grab); // Get latest values from native side poll(); event_x = x; event_y = y; resetMouse(); } + isGrabbed = grab; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |