From dde34c4961822fb5551730331dbcbe713ef73044 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 12 Oct 2011 02:58:57 +0200 Subject: Fix Nativewindow GetLocationOnScreen OSX impl. - Transform OSX origin bottom-left to our top-left origin. --- src/nativewindow/native/macosx/OSXmisc.c | 17 ++++++++++++++--- src/newt/native/MacWindow.m | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') 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); -- cgit v1.2.3