diff options
author | Sven Gothel <[email protected]> | 2020-01-13 06:52:22 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-01-13 06:52:22 +0100 |
commit | 12bbb049b716282321c979ae78918801ef071884 (patch) | |
tree | 39693b99cb6506603fb90dc7c04c6484cc3c1b2b /src/nativewindow/native/macosx | |
parent | e3e671e3ca63235830a2ebf7875650a4c86ce18e (diff) |
Bug 1421, Bug 1358, Bug 969, Bug 672: Fix NEWT's coordinate conversion on MacOS (fixes NewtCanvasSWT on SWT positioning)
Newt's OSX Window consist out of NSView wrapped up within its own NSWindow.
It's position is being set via its NSWindow's client-area position on screen (frame),
which we derive from NSView's client-area position.
When NEWT reparents into a new 'window',
on OSX it uses the parent's NSView and its NSWindow
to attach its own NSView and NSWindow as a subview and childwindow.
SWT's OSX implementation uses NSView's for each Compositor,
but an individual NSWindow is only established for the Shell (Window).
An oversight in Nativewindow and NEWT's coordinate translation:
'top-left view <-> top-left screen'
by missing the 'view <-> window' translation caused this whole issue.
The oversight occured as NEWT's 'view <-> window' translation
had no impact due to its 1-view to 1-window mapping.
Fixing the coordinate translation resolves the mess
for SWT and for potential other toolkits on OSX.
NewtCanvasSWT behaves same on OSX as on X11 etc finally.
Diffstat (limited to 'src/nativewindow/native/macosx')
-rw-r--r-- | src/nativewindow/native/macosx/OSXmisc.m | 50 |
1 files changed, 7 insertions, 43 deletions
diff --git a/src/nativewindow/native/macosx/OSXmisc.m b/src/nativewindow/native/macosx/OSXmisc.m index 6c13d9c05..f5991b1b5 100644 --- a/src/nativewindow/native/macosx/OSXmisc.m +++ b/src/nativewindow/native/macosx/OSXmisc.m @@ -180,42 +180,6 @@ static NSScreen * OSXUtil_getNSScreenByCGDirectDisplayID(CGDirectDisplayID displ /* * Class: Java_jogamp_nativewindow_macosx_OSXUtil - * Method: getLocation0 - * Signature: (J)Lcom/jogamp/nativewindow/util/Point; - */ -JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocation0 - (JNIEnv *env, jclass unused, jlong winOrView) -{ - NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; - - /** - * return location in 0/0 top-left space, - * OSX is 0/0 bottom-left space naturally - */ - 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]] ) { - view = (NSView*) nsObj; - win = [view window]; - } else { - NativewindowCommon_throwNewRuntimeException(env, "neither win nor view %p\n", nsObj); - } - NSRect viewFrame = [view frame]; - - jobject res = (*env)->NewObject(env, pointClz, pointCstr, (jint)viewFrame.origin.x, (jint)viewFrame.origin.y); - - [pool release]; - - return res; -} - -/* - * Class: Java_jogamp_nativewindow_macosx_OSXUtil * Method: getLocationOnScreen0 * Signature: (JII)Lcom/jogamp/nativewindow/util/Point; */ @@ -243,13 +207,13 @@ JNIEXPORT jobject JNICALL Java_jogamp_nativewindow_macosx_OSXUtil_GetLocationOnS } NSRect viewFrame = [view frame]; - NSRect r; - r.origin.x = 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]; // BL-screen + NSPoint oS = NSMakePoint(src_x, src_y); + if( ![view isFlipped] ) { + // y-flip for 0/0 top-left: TL-view -> BL-view + oS.y = viewFrame.size.height - oS.y; + } + oS = [view convertPoint: oS toView:nil]; // BL-view -> BL-window + oS = [win convertBaseToScreen: oS]; // BL-window -> BL-screen NSScreen* screen = [win screen]; CGDirectDisplayID display = OSXUtil_getCGDirectDisplayIDByNSScreen(screen); |