diff options
author | Sven Gothel <[email protected]> | 2011-10-13 03:49:14 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-13 03:49:14 +0200 |
commit | 96c50e94f4dbc0e18762a97c026b7e6986cea8e7 (patch) | |
tree | ce42f5905af08820fdbabe74be8f31a1dbc25ccd /src | |
parent | e7329d99aa6b44b976d0a5d2dd6f0d19c25d661c (diff) |
NEWT/OSX: Fix resize behavior / Cleanup coordinate transormation (client-space/top-level, child/parent)
At resizing a perent window w/ a NEWT OSX child,
the window position needs to be updated since it's absolute.
Re-adding sending *Changed notifications via the appropriate WindowImpl methods.
Turns out they are missing in some parent/child situations (fullscreen for example).
Native getLocationOnScreen0(..) queries totalHeight by it's own to have correct values.
Diffstat (limited to 'src')
-rw-r--r-- | src/nativewindow/classes/javax/media/nativewindow/util/Point.java | 6 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java | 105 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 26 |
3 files changed, 86 insertions, 51 deletions
diff --git a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java index 0a5036eda..c53b16928 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/util/Point.java +++ b/src/nativewindow/classes/javax/media/nativewindow/util/Point.java @@ -97,4 +97,10 @@ public class Point implements Cloneable, PointImmutable { return this; } + public Point scale(int sx, int sy) { + x *= sx ; + y *= sy ; + return this; + } + } diff --git a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java index 8114e5536..d18d6b901 100644 --- a/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java +++ b/src/newt/classes/jogamp/newt/driver/macosx/MacWindow.java @@ -43,6 +43,7 @@ import jogamp.newt.*; import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; +import javax.media.nativewindow.util.PointImmutable; public class MacWindow extends WindowImpl { @@ -185,66 +186,49 @@ public class MacWindow extends WindowImpl { } protected boolean reconfigureWindowImpl(int x, int y, int width, int height, int flags) { - int _x = x, _y = y; - final InsetsImmutable insets = getInsets(); // zero if undecorated - if(0<=_x && 0<=_y) { - // client position -> top-level window position - _x -= insets.getLeftWidth() ; - _y -= insets.getTopHeight() ; - if(DEBUG_IMPLEMENTATION) { - System.err.println("MacWindow reconfig (insets: "+insets+"): "+x+"/"+y+" -> "+_x+"/"+_y); - } - } - // min val is 0 - _x=Math.max(_x, 0); - _y=Math.max(_y, 0); - { - // On MacOSX the absolute position is required to position - // a window - even a child window! - final NativeWindow parent = getParent(); - if( null != parent && 0 != parent.getWindowHandle() ) { - final Point p = parent.getLocationOnScreen(null); - _x += p.getX(); - _y += p.getY(); - if(DEBUG_IMPLEMENTATION) { - System.err.println("MacWindow reconfig (parent: "+p+"): "+x+"/"+y+" -> "+_x+"/"+_y); - } - } - } + final PointImmutable pS = position2TopLevel(new Point(x, y)); if(DEBUG_IMPLEMENTATION) { - System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+_x+"/"+_y+" - "+width+"x"+height+", "+ + System.err.println("MacWindow reconfig: "+x+"/"+y+" -> "+pS+" - "+width+"x"+height+", "+ getReconfigureFlagsAsString(null, flags)); } if( getWindowHandle() == 0 ) { if( 0 != ( FLAG_IS_VISIBLE & flags) ) { - createWindow(false, _x, _y, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); + createWindow(false, pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); makeKeyAndOrderFront0(getWindowHandle()); - visibleChanged(false, true); // no native event .. + // no native event .. + visibleChanged(true, true); + focusChanged(true, true); } /* else { ?? } */ } else { if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 == ( FLAG_IS_VISIBLE & flags) ) { orderOut0(getWindowHandle()); - visibleChanged(false, false); // no native event .. - enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_LOST_FOCUS); + // no native event .. + visibleChanged(true, false); + focusChanged(true, false); } if( 0 != ( FLAG_CHANGE_DECORATION & flags) || 0 != ( FLAG_CHANGE_PARENTING & flags) || 0 != ( FLAG_CHANGE_FULLSCREEN & flags) ) { - createWindow(true, _x, _y, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); + createWindow(true, pS, width, height, 0 != ( FLAG_IS_FULLSCREEN & flags)); if(isVisible()) { flags |= FLAG_CHANGE_VISIBILITY; } } if(x>=0 && y>=0) { - setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), _x, _y, height+insets.getTotalHeight()); + setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), pS.getX(), pS.getY()); + // no native event (fullscreen, some reparenting) + positionChanged(true, getLocationOnScreenImpl(0, 0)); // incl. validation } if(width>0 && height>0) { setContentSize0(getWindowHandle(), width, height); + // no native event (fullscreen, some reparenting) + sizeChanged(true, width, height, false); // incl. validation (incl. repositioning) } if( 0 != ( FLAG_CHANGE_VISIBILITY & flags) && 0 != ( FLAG_IS_VISIBLE & flags) ) { makeKeyAndOrderFront0(getWindowHandle()); - visibleChanged(false, true); // no native event .. - enqueueWindowEvent(false, WindowEvent.EVENT_WINDOW_GAINED_FOCUS); + // no native event .. + visibleChanged(true, true); + focusChanged(true, true); } setAlwaysOnTop0(getWindowHandle(), 0 != ( FLAG_IS_ALWAYSONTOP & flags)); } @@ -352,7 +336,7 @@ public class MacWindow extends WindowImpl { } private void createWindow(final boolean recreate, - int x, int y, int width, int height, + PointImmutable pS, int width, int height, final boolean fullscreen) { if(0!=getWindowHandle() && !recreate) { @@ -373,7 +357,7 @@ public class MacWindow extends WindowImpl { surfaceHandle = 0; } setWindowHandle(createWindow0(getParentWindowHandle(), - x, y, width, height, + pS.getX(), pS.getY(), width, height, config.getChosenCapabilities().isBackgroundOpaque(), fullscreen, (isUndecorated() ? @@ -386,20 +370,57 @@ public class MacWindow extends WindowImpl { } surfaceHandle = contentView0(getWindowHandle()); setTitle0(getWindowHandle(), getTitle()); + // need to revalidate real position + positionChanged(true, getLocationOnScreenImpl(0, 0)); // incl. validation } catch (Exception ie) { ie.printStackTrace(); } } @Override + protected void sizeChanged(boolean defer, int newWidth, int newHeight, boolean force) { + if(width != newWidth || height != newHeight) { + final Point p0S = position2TopLevel(new Point(x, y)); + setFrameTopLeftPoint0(getParentWindowHandle(), getWindowHandle(), p0S.getX(), p0S.getY()); + } + super.sizeChanged(defer, newWidth, newHeight, force); + } + + @Override protected void positionChanged(boolean defer, int newX, int newY) { + positionChanged(defer, new Point(newX, newY)); + } + + protected void positionChanged(boolean defer, Point absPos) { + position2ClientSpace(absPos); + super.positionChanged(defer, absPos.getX(), absPos.getY()); + } + + protected Point position2ClientSpace(Point absPos) { final NativeWindow parent = getParent(); if(null != parent) { - final Point p = parent.getLocationOnScreen(null); - newX -= p.getX(); - newY -= p.getY(); + return absPos.translate( parent.getLocationOnScreen(null).scale(-1, -1) ); + } + return absPos; + } + + protected Point position2TopLevel(Point clientPos) { + if(0<=clientPos.getX() && 0<=clientPos.getY()) { + final InsetsImmutable _insets = getInsets(); // zero if undecorated + // client position -> top-level window position + clientPos.setX(clientPos.getX() - _insets.getLeftWidth()) ; + clientPos.setY(clientPos.getY() - _insets.getTopHeight()) ; + } + // min val is 0 + clientPos.setX(Math.max(clientPos.getX(), 0)); + clientPos.setY(Math.max(clientPos.getY(), 0)); + // On MacOSX the absolute position is required to position + // a window - even a child window! + final NativeWindow parent = getParent(); + if( null != parent && 0 != parent.getWindowHandle() ) { + clientPos.translate(parent.getLocationOnScreen(null)); } - super.positionChanged(defer, newX, newY); + return clientPos; } protected static native boolean initIDs0(); @@ -416,7 +437,7 @@ public class MacWindow extends WindowImpl { private native long contentView0(long window); private native long changeContentView0(long parentWindowOrViewHandle, long window, long view); private native void setContentSize0(long window, int w, int h); - private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y, int totalHeight); + private native void setFrameTopLeftPoint0(long parentWindowHandle, long window, int x, int y); private native void setAlwaysOnTop0(long window, boolean atop); private static native Object getLocationOnScreen0(long windowHandle, int src_x, int src_y); } diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 4e4dc3173..670deaf1d 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -57,11 +57,15 @@ static NSString* jstringToNSString(JNIEnv* env, jstring jstr) return str; } -static void setFrameTopLeftPoint(NSWindow* pWin, NSWindow* mWin, jint x, jint y, jint totalHeight) { +static void setFrameTopLeftPoint(NSWindow* pWin, NewtMacWindow* mWin, jint x, jint y) { NSScreen* screen = [mWin screen]; NSRect screenTotal = [screen frame]; + NSView* mView = [mWin contentView]; + NSRect mViewFrame = [mView frame]; + int totalHeight = mViewFrame.size.height + mWin->cachedInsets[2] + mWin->cachedInsets[3]; // height + insets[top+bottom] + NSPoint pS = NSMakePoint(screenTotal.origin.x + x, screenTotal.origin.y + screenTotal.size.height - y - totalHeight); #ifdef VERBOSE_ON @@ -315,6 +319,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_MacWindow_createWindow0 defer: NO screen: myScreen]; [myWindow setReleasedWhenClosed: YES]; // default + [myWindow setPreservesContentDuringLiveResize: NO]; NSObject *nsParentObj = (NSObject*) ((intptr_t) parent); NSWindow* parentWindow = NULL; @@ -337,6 +342,9 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_MacWindow_createWindow0 if(opaque) { [myWindow setOpaque: YES]; + if (!fullscreen) { + [myWindow setShowsResizeIndicator: YES]; + } } else { [myWindow setOpaque: NO]; [myWindow setBackgroundColor: [NSColor clearColor]]; @@ -355,7 +363,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_MacWindow_createWindow0 (void) changeContentView(env, jthis, parentWindow, parentView, myWindow, myView); // Immediately re-position the window based on an upper-left coordinate system - setFrameTopLeftPoint(parentWindow, myWindow, x, y, h+myWindow->cachedInsets[2]+myWindow->cachedInsets[3]); // h+insets[top+bottom] + setFrameTopLeftPoint(parentWindow, myWindow, x, y); NS_DURING // Available >= 10.5 - Makes the menubar disapear @@ -390,7 +398,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_makeKeyAndOrderF DBG_PRINT( "makeKeyAndOrderFront0 - window: %p (START)\n", win); - // [win performSelectorOnMainThread:@selector(makeKeyAndOrderFront:) withObject:win waitUntilDone:NO]; + // [win performSelectorOnMainThread:@selector(makeKeyAndOrderFront:) withObject:win waitUntilDone:YES]; [win makeKeyAndOrderFront: win]; DBG_PRINT( "makeKeyAndOrderFront0 - window: %p (END)\n", win); @@ -411,7 +419,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_makeKey0 DBG_PRINT( "makeKey0 - window: %p (START)\n", win); - // [win performSelectorOnMainThread:@selector(makeKeyWindow:) withObject:nil waitUntilDone:NO]; + // [win performSelectorOnMainThread:@selector(makeKeyWindow:) withObject:nil waitUntilDone:YES]; [win makeKeyWindow]; DBG_PRINT( "makeKey0 - window: %p (END)\n", win); @@ -499,8 +507,8 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_setTitle0 NSString* str = jstringToNSString(env, title); [str autorelease]; - [win performSelectorOnMainThread:@selector(setTitle:) withObject:str waitUntilDone:NO]; - // [win setTitle: str]; + // [win performSelectorOnMainThread:@selector(setTitle:) withObject:str waitUntilDone:NO]; + [win setTitle: str]; DBG_PRINT( "setTitle0 - window: %p (END)\n", win); @@ -592,10 +600,10 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_setContentSize0 * Signature: (JJII)V */ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_setFrameTopLeftPoint0 - (JNIEnv *env, jobject unused, jlong parent, jlong window, jint x, jint y, jint totalHeight) + (JNIEnv *env, jobject unused, jlong parent, jlong window, jint x, jint y) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - NSWindow* mWin = (NSWindow*) ((intptr_t) window); + NewtMacWindow* mWin = (NewtMacWindow*) ((intptr_t) window); NSObject *nsParentObj = (NSObject*) ((intptr_t) parent); NSWindow* pWin = NULL; @@ -608,7 +616,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_setFrameTopLeftP DBG_PRINT( "setFrameTopLeftPoint0 - window: %p, parent %p (START)\n", mWin, pWin); - setFrameTopLeftPoint(pWin, mWin, x, y, totalHeight); + setFrameTopLeftPoint(pWin, mWin, x, y); DBG_PRINT( "setFrameTopLeftPoint0 - window: %p, parent %p (END)\n", mWin, pWin); |