diff options
author | Sven Gothel <[email protected]> | 2011-10-12 02:58:57 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-12 02:58:57 +0200 |
commit | dde34c4961822fb5551730331dbcbe713ef73044 (patch) | |
tree | e6ab5b4b8e55f5a5d9c13e37f3e04035b2ccca48 | |
parent | f74e98c9471cd08573ac656a39eeaf09bdf4b24e (diff) |
Fix Nativewindow GetLocationOnScreen OSX impl. - Transform OSX origin bottom-left to our top-left origin.
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.c | 17 | ||||
-rw-r--r-- | src/newt/native/MacWindow.m | 2 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.c b/src/nativewindow/native/macosx/OSXmisc.c index 24cb8d48f..46a853844 100644 --- a/src/nativewindow/native/macosx/OSXmisc.c +++ b/src/nativewindow/native/macosx/OSXmisc.c @@ -76,30 +76,41 @@ Java_jogamp_nativewindow_macosx_OSXUtil_initIDs0(JNIEnv *env, jclass _unused) { JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocationOnScreen0 (JNIEnv *env, jclass unused, jlong winOrView, jint src_x, jint src_y) { + /** + * return location in 0/0 top-left space, + * OSX is 0/0 bottom-left space naturally + */ + NSScreen* screen = [NSScreen mainScreen]; + NSRect screenRect = [screen frame]; + NSRect r; int dest_x=-1; int dest_y=-1; NSObject *nsObj = (NSObject*) ((intptr_t) winOrView); NSWindow* win = NULL; + NSView* view = NULL; if( [nsObj isKindOfClass:[NSWindow class]] ) { win = (NSWindow*) nsObj; + view = [win contentView]; } else if( nsObj != NULL && [nsObj isKindOfClass:[NSView class]] ) { - NSView* view = (NSView*) nsObj; + view = (NSView*) nsObj; win = [view window]; } else { NativewindowCommon_throwNewRuntimeException(env, "neither win not view %p\n", nsObj); } + NSRect viewFrame = [view frame]; + r.origin.x = src_x; - r.origin.y = src_x; + r.origin.y = viewFrame.size.height - src_y; // y-flip for 0/0 top-left r.size.width = 0; r.size.height = 0; // NSRect rS = [win convertRectToScreen: r]; // 10.7 NSPoint oS = [win convertBaseToScreen: r.origin]; dest_x = (int) oS.x; - dest_y = (int) oS.y; + dest_y = (int) screenRect.origin.y + screenRect.size.height - oS.y; return (*env)->NewObject(env, pointClz, pointCstr, (jint)dest_x, (jint)dest_y); } diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index 8d4a5ce4b..d8839abe0 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -57,7 +57,7 @@ static void setFrameTopLeftPoint(NSWindow* pWin, NSWindow* mWin, jint x, jint y, NSRect screenRect = [screen frame]; NSPoint pS = NSMakePoint(screenRect.origin.x + x, screenRect.origin.y + screenRect.size.height - y - h); - DBG_PRINT( "setFrameTopLeftPoint screen %lf/%lf %lfx%lf, top-left %d/%d -> bottom-left %lf/%lf\n", + DBG_PRINT( "setFrameTopLeftPoint screen %lf/%lf %lfx%lf, win top-left %d/%d -> scrn bottom-left %lf/%lf\n", screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height, (int)x, (int)y, pS.x, pS.y); |