diff --git a/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java b/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java index 17222923..ca29e725 100644 --- a/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java +++ b/src/java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java @@ -104,25 +104,37 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo { } public void componentMoved(ComponentEvent e) { - Insets insets = getWindowInsets(component); + Point componentPosition = SwingUtilities.convertPoint(component, component.getLocation(), null); + Point parentPosition = SwingUtilities.convertPoint(component.getParent(), component.getLocation(), null); - int top = insets != null ? insets.top : 0; - int left = insets != null ? insets.left : 0; - - Point p = SwingUtilities.convertPoint(component, component.getLocation(), null); - - nSetLayerPosition(getHandle(), (int)p.getX()-left, (int)p.getY()-top); + if (componentPosition.getX() == parentPosition.getX() && componentPosition.getY() == parentPosition.getY()) { + Insets insets = getWindowInsets(component); + + int top = insets != null ? insets.top : 0; + int left = insets != null ? insets.left : 0; + + nSetLayerBounds(getHandle(), (int)componentPosition.getX()-left, (int)componentPosition.getY()-top, component.getWidth(), component.getHeight()); + } + else { + nSetLayerPosition(getHandle(), component.getX(), component.getY()); + } } public void componentResized(ComponentEvent e) { - Insets insets = getWindowInsets(component); + Point componentPosition = SwingUtilities.convertPoint(component, component.getLocation(), null); + Point parentPosition = SwingUtilities.convertPoint(component.getParent(), component.getLocation(), null); - int top = insets != null ? insets.top : 0; - int left = insets != null ? insets.left : 0; - - Point p = SwingUtilities.convertPoint(component, component.getLocation(), null); - - nSetLayerPosition(getHandle(), (int)p.getX()-left, (int)p.getY()-top); + if (componentPosition.getX() == parentPosition.getX() && componentPosition.getY() == parentPosition.getY()) { + Insets insets = getWindowInsets(component); + + int top = insets != null ? insets.top : 0; + int left = insets != null ? insets.left : 0; + + nSetLayerBounds(getHandle(), (int)componentPosition.getX()-left, (int)componentPosition.getY()-top, component.getWidth(), component.getHeight()); + } + else { + nSetLayerPosition(getHandle(), component.getX(), component.getY()); + } } public void componentShown(ComponentEvent e) { @@ -137,6 +149,16 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo { component.addComponentListener(comp); } + private static native ByteBuffer nInitHandle(ByteBuffer surface_buffer, ByteBuffer peer_info_handle, ByteBuffer window_handle, boolean forceCALayer, int x, int y) throws LWJGLException; + + private static native void nSetLayerPosition(ByteBuffer peer_info_handle, int x, int y); + + private static native void nSetLayerBounds(ByteBuffer peer_info_handle, int x, int y, int width, int height); + + protected void doUnlock() throws LWJGLException { + awt_surface.unlock(); + } + /** * Return the Insets of the Window holding the Canvas */ @@ -155,14 +177,6 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo { return null; } - private static native ByteBuffer nInitHandle(ByteBuffer surface_buffer, ByteBuffer peer_info_handle, ByteBuffer window_handle, boolean forceCALayer, int x, int y) throws LWJGLException; - - private static native void nSetLayerPosition(ByteBuffer peer_info_handle, int x, int y); - - protected void doUnlock() throws LWJGLException { - awt_surface.unlock(); - } - private Insets getInsets(Canvas component) { Component parent = component.getParent(); diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m b/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m index 895f2041..0006b856 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXCanvasPeerInfo.m @@ -114,6 +114,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nSetLayerPosit } } +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nSetLayerBounds +(JNIEnv *env, jclass clazz, jobject peer_info_handle, jint x, jint y, jint width, jint height) { + MacOSXPeerInfo *peer_info = (MacOSXPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); + + if (peer_info->glLayer != nil) { + NSRect rect = NSMakeRect(x, y, width, height); + NSValue *value = [NSValue valueWithRect:rect]; + [peer_info->glLayer performSelectorOnMainThread:@selector(updateBounds:) withObject:value waitUntilDone:NO]; + } +} + @implementation GLLayer - (void) attachLayer { @@ -157,6 +168,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXCanvasPeerInfo_nSetLayerPosit self.position = CGPointMake(point.x, self.superlayer.bounds.size.height - point.y - self.bounds.size.height); } +- (void)updateBounds:(NSValue*)value { + NSRect rect = [value rectValue]; + self.frame = CGRectMake(rect.origin.x, self.superlayer.bounds.size.height - rect.origin.y - self.bounds.size.height, rect.size.width, rect.size.height); +} + - (int) getWidth { return canvasBounds.width; }