From 804f09da47f8ae8a77879bb40dee6cf02c3e92f0 Mon Sep 17 00:00:00 2001 From: kappaOne Date: Mon, 3 Dec 2012 23:04:30 +0000 Subject: [PATCH] Fixed resizing when using Display.setParent --- src/java/org/lwjgl/opengl/MacOSXDisplay.java | 5 +++-- src/native/macosx/org_lwjgl_opengl_Display.m | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 9fde3262..80f0b1eb 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -90,7 +90,7 @@ final class MacOSXDisplay implements DisplayImplementation { } - private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException; + private native ByteBuffer nCreateWindow(int x, int y, int width, int height, boolean fullscreen, boolean undecorated, boolean resizable, boolean parented, ByteBuffer peer_info_handle, ByteBuffer window_handle) throws LWJGLException; private native boolean nIsMiniaturized(ByteBuffer window_handle); @@ -113,6 +113,7 @@ final class MacOSXDisplay implements DisplayImplementation { public void createWindow(final DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException { boolean fullscreen = Display.isFullscreen(); boolean resizable = Display.isResizable(); + boolean parented = (parent != null); close_requested = false; @@ -122,7 +123,7 @@ final class MacOSXDisplay implements DisplayImplementation { try { window = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(), fullscreen, isUndecorated(), resizable, - peer_handle, window); + parented, peer_handle, window); this.x = x; this.y = y; this.width = mode.getWidth(); diff --git a/src/native/macosx/org_lwjgl_opengl_Display.m b/src/native/macosx/org_lwjgl_opengl_Display.m index a1ba898f..ea46ddec 100644 --- a/src/native/macosx/org_lwjgl_opengl_Display.m +++ b/src/native/macosx/org_lwjgl_opengl_Display.m @@ -158,10 +158,6 @@ static NSAutoreleasePool *pool; - (void)setParent:(MacOSXWindowInfo*)parent { _parent = parent; - // Set this NSView as delegate to get native window close events for windowShouldClose method - if (_parent != nil) { - [_parent->window setDelegate:self]; - } } - (void)keyDown:(NSEvent *)event { @@ -407,7 +403,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nSetTitle(JNIEnv *env [window_info->window setTitle:title]; } -JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIEnv *env, jobject this, jint x, jint y, jint width, jint height, jboolean fullscreen, jboolean undecorated, jboolean resizable, jobject peer_info_handle, jobject window_handle) { +JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIEnv *env, jobject this, jint x, jint y, jint width, jint height, jboolean fullscreen, jboolean undecorated, jboolean resizable, jboolean parented, jobject peer_info_handle, jobject window_handle) { if (window_handle == NULL) { window_handle = newJavaManagedByteBuffer(env, sizeof(MacOSXWindowInfo)); @@ -457,6 +453,11 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE [window_info->window setContentView:window_info->view]; + if (!parented) { + // set NSView as delegate of NSWindow to get windowShouldClose events + [window_info->window setDelegate:window_info->view]; + } + // disable any fixed backbuffer size to allow resizing CGLContextObj cgcontext = (CGLContextObj)[[window_info->view openGLContext] CGLContextObj]; CGLDisable(cgcontext, kCGLCESurfaceBackingSize); @@ -478,7 +479,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nCreateWindow(JNIE [window_info->view setBoundsSize:newBounds]; } - // Inform the view of its parent window info; used to register for window-close callbacks + // Inform the view of its parent window info; [window_info->view setParent:window_info]; [window_info->window performSelectorOnMainThread:@selector(makeFirstResponder:) withObject:window_info->view waitUntilDone:NO];