From: <eli...@us...> - 2006-10-26 20:49:21
|
Revision: 2611 http://svn.sourceforge.net/java-game-lib/?rev=2611&view=rev Author: elias_naur Date: 2006-10-26 13:49:07 -0700 (Thu, 26 Oct 2006) Log Message: ----------- Mac OS X: Moved mouse handling from MacOSXDisplay to MacOSXMouseEventQueue Modified Paths: -------------- trunk/LWJGL/build.xml trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java trunk/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.c Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-10-26 20:33:40 UTC (rev 2610) +++ trunk/LWJGL/build.xml 2006-10-26 20:49:07 UTC (rev 2611) @@ -524,6 +524,7 @@ </javah> <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx" force="yes"> + <class name="org.lwjgl.opengl.MacOSXMouseEventQueue" /> <class name="org.lwjgl.opengl.MacOSXCanvasPeerInfo" /> <class name="org.lwjgl.opengl.MacOSXPeerInfo" /> <class name="org.lwjgl.opengl.MacOSXPbufferPeerInfo" /> Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-10-26 20:33:40 UTC (rev 2610) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2006-10-26 20:49:07 UTC (rev 2611) @@ -69,7 +69,7 @@ private static final int GAMMA_LENGTH = 256; private MacOSXFrame frame; - private MouseEventQueue mouse_queue; + private MacOSXMouseEventQueue mouse_queue; private KeyboardEventQueue keyboard_queue; private java.awt.DisplayMode requested_mode; @@ -256,20 +256,11 @@ GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport); GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3)); } - if (frame.syncShouldWarpCursor()) { - warpCursor(); + if (frame.syncShouldWarpCursor() && mouse_queue != null) { + mouse_queue.warpCursor(); } } - private void warpCursor() { - if (mouse_queue != null && mouse_queue.isGrabbed()) { - Rectangle bounds = frame.syncGetBounds(); - int x = bounds.x + bounds.width/2; - int y = bounds.y + bounds.height/2; - nWarpCursor(x, y); - } - } - /** * This is an interface to the native Carbon call * SetSystemUIMode. It is used to hide the dock in a way @@ -286,8 +277,6 @@ private native void nHideUI(boolean hide); - native void getMouseDeltas(IntBuffer delta_buffer); - public void reshape(int x, int y, int width, int height) { frame.resize(x, y, width, height); } @@ -323,14 +312,8 @@ public void grabMouse(boolean grab) { mouse_queue.setGrabbed(grab); - warpCursor(); - nGrabMouse(grab); } - private native void nWarpCursor(int x, int y); - - private native void nGrabMouse(boolean grab); - public int getNativeCursorCapabilities() { return AWTUtil.getNativeCursorCapabilities(); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java 2006-10-26 20:33:40 UTC (rev 2610) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXMouseEventQueue.java 2006-10-26 20:49:07 UTC (rev 2611) @@ -42,6 +42,7 @@ import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.Component; +import java.awt.Rectangle; import java.nio.ByteBuffer; import java.nio.IntBuffer; @@ -55,16 +56,22 @@ super(component); } + public void setGrabbed(boolean grab) { + super.setGrabbed(grab); + warpCursor(); + nGrabMouse(grab); + } + protected void resetCursorToCenter() { super.resetCursorToCenter(); /* Clear accumulated deltas */ - ((MacOSXDisplay)Display.getImplementation()).getMouseDeltas(delta_buffer); + getMouseDeltas(delta_buffer); } protected void updateDeltas(long nanos) { super.updateDeltas(nanos); synchronized ( this ) { - ((MacOSXDisplay)Display.getImplementation()).getMouseDeltas(delta_buffer); + getMouseDeltas(delta_buffer); int dx = delta_buffer.get(0); int dy = -delta_buffer.get(1); if ( dx != 0 || dy != 0 ) { @@ -73,4 +80,19 @@ } } } + + void warpCursor() { + if (isGrabbed()) { + Rectangle bounds = getComponent().getBounds(); + int x = bounds.x + bounds.width/2; + int y = bounds.y + bounds.height/2; + nWarpCursor(x, y); + } + } + + private static native void getMouseDeltas(IntBuffer delta_buffer); + + private static native void nWarpCursor(int x, int y); + + private static native void nGrabMouse(boolean grab); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-10-26 20:33:40 UTC (rev 2610) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MouseEventQueue.java 2006-10-26 20:49:07 UTC (rev 2611) @@ -56,7 +56,6 @@ private boolean grabbed; - /** The accumulated mouse deltas returned by poll() */ private int accum_dx; private int accum_dy; @@ -93,6 +92,10 @@ component.removeMouseWheelListener(this); } + protected Component getComponent() { + return component; + } + public synchronized void setGrabbed(boolean grabbed) { this.grabbed = grabbed; resetCursorToCenter(); Modified: trunk/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.c =================================================================== --- trunk/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.c 2006-10-26 20:33:40 UTC (rev 2610) +++ trunk/LWJGL/src/native/macosx/org_lwjgl_input_Mouse.c 2006-10-26 20:49:07 UTC (rev 2611) @@ -41,11 +41,12 @@ #include <jni.h> #include <ApplicationServices/ApplicationServices.h> +#include "org_lwjgl_opengl_MacOSXMouseEventQueue.h" #include "common_tools.h" static bool is_grabbed; -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nGrabMouse(JNIEnv *env, jobject this, jboolean grab) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_nGrabMouse(JNIEnv *env, jclass unused, jboolean grab) { bool new_grabbed = grab == JNI_TRUE; if (is_grabbed != new_grabbed) { is_grabbed = new_grabbed; @@ -57,14 +58,14 @@ } } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nWarpCursor(JNIEnv *env, jobject this, jint x, jint y) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_nWarpCursor(JNIEnv *env, jclass unused, jint x, jint y) { CGPoint p; p.x = x; p.y = y; CGWarpMouseCursorPosition(p); } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_getMouseDeltas(JNIEnv *env, jobject this, jobject delta_buffer) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXMouseEventQueue_getMouseDeltas(JNIEnv *env, jclass unused, jobject delta_buffer) { CGMouseDelta dx, dy; CGGetLastMouseDelta(&dx, &dy); int buffer_length = (*env)->GetDirectBufferCapacity(env, delta_buffer); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |