From f0219aed1aa481fa05989b4ad935adff1745e796 Mon Sep 17 00:00:00 2001 From: kappaOne Date: Sat, 26 Jan 2013 22:47:36 +0000 Subject: [PATCH] Fix native cursor global handle passing --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 11 ++++++--- .../org/lwjgl/opengl/MacOSXNativeMouse.java | 12 +++++----- .../org_lwjgl_opengl_MacOSXNativeMouse.m | 24 +++++++------------ 3 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 47ab8494..832055f1 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -401,7 +401,7 @@ final class MacOSXDisplay implements DisplayImplementation { public void setNativeCursor(Object handle) throws LWJGLException { if (native_mode) { - MacOSXNativeMouse.setCursor(handle); + MacOSXNativeMouse.setCursor(getCursorHandle(handle)); } } @@ -457,11 +457,12 @@ final class MacOSXDisplay implements DisplayImplementation { keyboard_queue.copyEvents(buffer); } } - + /** Native cursor handles */ public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { if (native_mode) { - return MacOSXNativeMouse.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays); + long cursor = MacOSXNativeMouse.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays); + return cursor; } else { return AWTUtil.createCursor(width, height, xHotspot, yHotspot, numImages, images, delays); @@ -471,6 +472,10 @@ final class MacOSXDisplay implements DisplayImplementation { public void destroyCursor(Object cursor_handle) { } + + private static long getCursorHandle(Object cursor_handle) { + return cursor_handle != null ? (Long)cursor_handle : 0; + } public int getPbufferCapabilities() { return Pbuffer.PBUFFER_SUPPORTED; diff --git a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java index 4de64693..013fcd56 100644 --- a/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java +++ b/src/java/org/lwjgl/opengl/MacOSXNativeMouse.java @@ -89,17 +89,17 @@ final class MacOSXNativeMouse extends EventQueue { private native void nUnregisterMouseListener(ByteBuffer window_handle); - private static native Object nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; + private static native long nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException; - private static native void nDestroyCursor(Object handle) throws LWJGLException; + private static native void nDestroyCursor(long handle) throws LWJGLException; - private static native void nSetCursor(Object handle) throws LWJGLException; + private static native void nSetCursor(long handle) throws LWJGLException; public synchronized void register() { nRegisterMouseListener(window_handle); } - public static Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { + public static long createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { try { return nCreateCursor(width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1); } catch (LWJGLException e) { @@ -107,7 +107,7 @@ final class MacOSXNativeMouse extends EventQueue { } } - public static void destroyCursor(Object handle) throws LWJGLException { + public static void destroyCursor(long handle) throws LWJGLException { try { nDestroyCursor(handle); } catch (LWJGLException e) { @@ -115,7 +115,7 @@ final class MacOSXNativeMouse extends EventQueue { } } - public static void setCursor(Object handle) throws LWJGLException { + public static void setCursor(long handle) throws LWJGLException { try { nSetCursor(handle); } catch (LWJGLException e) { diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m b/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m index bc625600..1a8e69a4 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXNativeMouse.m @@ -100,13 +100,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nUnregisterMouseL window_info->jmouse = nil; } -JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor(JNIEnv *env, jobject _this, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) { - NSLog(@"nCreateCursor"); - - char *bytes = (char *)(*env)->GetDirectBufferAddress(env, image_buffer); +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor(JNIEnv *env, jobject _this, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset) { + jint *bytes = (jint *)(*env)->GetDirectBufferAddress(env, image_buffer); NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] - initWithBitmapDataPlanes:(char *)&bytes + initWithBitmapDataPlanes:(jint *)&bytes pixelsWide:width pixelsHigh:height bitsPerSample:8 samplesPerPixel:4 @@ -124,20 +122,14 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nCreateCursor( NSCursor *cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x_hotspot, y_hotspot)]; - [cursor set]; // temporarily set the cursor here as returning the handle doesn't work yet - - return cursor; + return (jlong)cursor; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nDestroyCursor(JNIEnv *env, jobject _this, jobject handle) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nDestroyCursor(JNIEnv *env, jobject _this, jlong handle) { // TODO } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nSetCursor(JNIEnv *env, jobject _this, jobject handle) { - NSLog(@"nSetCursor"); - - // TODO - this method should get the cursor from the handle and set it - - //NSCursor *cursor = (NSCursor *)(*env)->GetDirectBufferAddress(env, handle); - //[cursor set]; +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXNativeMouse_nSetCursor(JNIEnv *env, jobject _this, jlong cursor_pointer) { + NSCursor *cursor = (NSCursor *)cursor_pointer; + [cursor set]; }