Mac OS X: Moved mouse handling from MacOSXDisplay to MacOSXMouseEventQueue
This commit is contained in:
parent
24e913477f
commit
a47e419168
|
@ -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" />
|
||||
|
|
|
@ -69,7 +69,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
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,17 +256,8 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if (frame.syncShouldWarpCursor() && mouse_queue != null) {
|
||||
mouse_queue.warpCursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -286,8 +277,6 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
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 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import java.awt.event.MouseMotionListener;
|
|||
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 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
|
|||
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 @@ final class MacOSXMouseEventQueue extends MouseEventQueue {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -56,7 +56,6 @@ class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionLi
|
|||
|
||||
private boolean grabbed;
|
||||
|
||||
|
||||
/** The accumulated mouse deltas returned by poll() */
|
||||
private int accum_dx;
|
||||
private int accum_dy;
|
||||
|
@ -93,6 +92,10 @@ class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionLi
|
|||
component.removeMouseWheelListener(this);
|
||||
}
|
||||
|
||||
protected Component getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
public synchronized void setGrabbed(boolean grabbed) {
|
||||
this.grabbed = grabbed;
|
||||
resetCursorToCenter();
|
||||
|
|
|
@ -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_nGrabMouse(JNIEnv *en
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue