aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native
diff options
context:
space:
mode:
Diffstat (limited to 'src/newt/native')
-rw-r--r--src/newt/native/MacWindow.m74
-rw-r--r--src/newt/native/NewtMacWindow.h5
-rw-r--r--src/newt/native/NewtMacWindow.m21
3 files changed, 56 insertions, 44 deletions
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m
index 94363624f..1895b98a5 100644
--- a/src/newt/native/MacWindow.m
+++ b/src/newt/native/MacWindow.m
@@ -62,14 +62,25 @@ static NSString* jstringToNSString(JNIEnv* env, jstring jstr)
return str;
}
-static void setFrameTopLeftPoint(NSWindow* pWin, NewtMacWindow* mWin, jint x, jint y) {
- NSPoint pS = [mWin newtScreenWinPos2OSXScreenPos: NSMakePoint(x, y)];
+static void setWindowClientTopLeftPoint(NewtMacWindow* mWin, jint x, jint y) {
+ NSPoint pS = [mWin newtAbsClientTLWinPos2AbsBLScreenPos: NSMakePoint(x, y)];
[mWin setFrameOrigin: pS];
NSView* mView = [mWin contentView];
[mWin invalidateCursorRectsForView: mView];
}
+static void setWindowClientTopLeftPointAndSize(NewtMacWindow* mWin, jint x, jint y, jint width, jint height) {
+ NSSize sz = NSMakeSize(width, height);
+ NSPoint pS = [mWin newtAbsClientTLWinPos2AbsBLScreenPos: NSMakePoint(x, y) size: sz];
+ NSRect rect = { pS, sz };
+ [mWin setFrame: rect display:YES];
+
+ // -> display:YES
+ // NSView* mView = [mWin contentView];
+ // [mWin invalidateCursorRectsForView: mView];
+}
+
#ifdef VERBOSE_ON
static int getRetainCount(NSObject * obj) {
return ( NULL == obj ) ? -1 : (int)([obj retainCount]) ;
@@ -575,21 +586,21 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_createWindow
if(screen_idx<0) screen_idx=0;
if(screen_idx>=[screens count]) screen_idx=0;
NSScreen *myScreen = (NSScreen *) [screens objectAtIndex: screen_idx];
- NSRect rect;
+ NSRect rectWin;
if (fullscreen) {
styleMask = NSBorderlessWindowMask;
- rect = [myScreen frame];
+ rectWin = [myScreen frame];
x = 0;
y = 0;
- w = (jint) (rect.size.width);
- h = (jint) (rect.size.height);
+ w = (jint) (rectWin.size.width);
+ h = (jint) (rectWin.size.height);
} else {
- rect = NSMakeRect(x, y, w, h);
+ rectWin = NSMakeRect(x, y, w, h);
}
// Allocate the window
- NewtMacWindow* myWindow = [[NewtMacWindow alloc] initWithContentRect: rect
+ NewtMacWindow* myWindow = [[NewtMacWindow alloc] initWithContentRect: rectWin
styleMask: (NSUInteger) styleMask
backing: (NSBackingStoreType) bufferingType
defer: NO
@@ -646,7 +657,8 @@ NS_ENDHANDLER
// Use given NewtView or allocate an NewtView if NULL
if(NULL == myView) {
- myView = [[NewtView alloc] initWithFrame: rect] ;
+ NSRect rectView = NSMakeRect(0, 0, w, h);
+ myView = [[NewtView alloc] initWithFrame: rectView] ;
DBG_PRINT( "createWindow0.%d - use new view: %p,%d\n", dbgIdx++, myView, getRetainCount(myView));
} else {
DBG_PRINT( "createWindow0.%d - use given view: %p,%d\n", dbgIdx++, myView, getRetainCount(myView));
@@ -666,7 +678,7 @@ NS_ENDHANDLER
}
// Immediately re-position the window based on an upper-left coordinate system
- setFrameTopLeftPoint(parentWindow, myWindow, x, y);
+ setWindowClientTopLeftPoint(myWindow, x, y);
// force surface creation
[myView lockFocus];
@@ -1000,50 +1012,40 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_changeConten
/*
* Class: jogamp_newt_driver_macosx_WindowDriver
- * Method: setContentSize
- * Signature: (JII)V
+ * Method: setWindowClientTopLeftPointAndSize0
+ * Signature: (JIIII)V
*/
-JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_setContentSize0
- (JNIEnv *env, jobject unused, jlong window, jint w, jint h)
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_setWindowClientTopLeftPointAndSize0
+ (JNIEnv *env, jobject unused, jlong window, jint x, jint y, jint w, jint h)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- NSWindow* win = (NSWindow*) ((intptr_t) window);
+ NewtMacWindow* mWin = (NewtMacWindow*) ((intptr_t) window);
- DBG_PRINT( "setContentSize0 - window: %p (START)\n", win);
+ DBG_PRINT( "setWindowClientTopLeftPointAndSize - window: %p (START)\n", mWin);
- NSSize sz = NSMakeSize(w, h);
- [win setContentSize: sz];
+ setWindowClientTopLeftPointAndSize(mWin, x, y, w, h);
- DBG_PRINT( "setContentSize0 - window: %p (END)\n", win);
+ DBG_PRINT( "setWindowClientTopLeftPointAndSize - window: %p (END)\n", mWin);
[pool release];
}
/*
* Class: jogamp_newt_driver_macosx_WindowDriver
- * Method: setFrameTopLeftPoint
- * Signature: (JJII)V
+ * Method: setWindowClientTopLeftPoint0
+ * Signature: (JII)V
*/
-JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_setFrameTopLeftPoint0
- (JNIEnv *env, jobject unused, jlong parent, jlong window, jint x, jint y)
+JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_setWindowClientTopLeftPoint0
+ (JNIEnv *env, jobject unused, jlong window, jint x, jint y)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NewtMacWindow* mWin = (NewtMacWindow*) ((intptr_t) window);
- NSObject *nsParentObj = (NSObject*) ((intptr_t) parent);
- NSWindow* pWin = NULL;
- if( nsParentObj != NULL && [nsParentObj isKindOfClass:[NSWindow class]] ) {
- pWin = (NSWindow*) nsParentObj;
- } else if( nsParentObj != NULL && [nsParentObj isKindOfClass:[NSView class]] ) {
- NSView* pView = (NSView*) nsParentObj;
- pWin = [pView window];
- }
-
- DBG_PRINT( "setFrameTopLeftPoint0 - window: %p, parent %p (START)\n", mWin, pWin);
+ DBG_PRINT( "setWindowClientTopLeftPoint - window: %p (START)\n", mWin);
- setFrameTopLeftPoint(pWin, mWin, x, y);
+ setWindowClientTopLeftPoint(mWin, x, y);
- DBG_PRINT( "setFrameTopLeftPoint0 - window: %p, parent %p (END)\n", mWin, pWin);
+ DBG_PRINT( "setWindowClientTopLeftPoint - window: %p (END)\n", mWin);
[pool release];
}
@@ -1129,6 +1131,6 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_WindowDriver_warpPointer0
(JNIEnv *env, jclass clazz, jlong window, jint x, jint y)
{
NewtMacWindow *mWin = (NewtMacWindow*) ((intptr_t) window);
- [mWin setMousePosition: [mWin newtClientWinPos2OSXScreenPos: NSMakePoint(x, y)]];
+ [mWin setMousePosition: [mWin newtRelClientTLWinPos2AbsBLScreenPos: NSMakePoint(x, y)]];
}
diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h
index 1e4f0c3ba..6d1bcca00 100644
--- a/src/newt/native/NewtMacWindow.h
+++ b/src/newt/native/NewtMacWindow.h
@@ -134,8 +134,9 @@
- (void) attachToParent: (NSWindow*) parent;
- (void) detachFromParent: (NSWindow*) parent;
-- (NSPoint) newtScreenWinPos2OSXScreenPos: (NSPoint) p;
-- (NSPoint) newtClientWinPos2OSXScreenPos: (NSPoint) p;
+- (NSPoint) newtAbsClientTLWinPos2AbsBLScreenPos: (NSPoint) p;
+- (NSPoint) newtAbsClientTLWinPos2AbsBLScreenPos: (NSPoint) p size: (NSSize) nsz;
+- (NSPoint) newtRelClientTLWinPos2AbsBLScreenPos: (NSPoint) p;
- (NSPoint) getLocationOnScreen: (NSPoint) p;
- (NSPoint) screenPos2NewtClientWinPos: (NSPoint) p;
diff --git a/src/newt/native/NewtMacWindow.m b/src/newt/native/NewtMacWindow.m
index 66d68d9d2..282c13fd3 100644
--- a/src/newt/native/NewtMacWindow.m
+++ b/src/newt/native/NewtMacWindow.m
@@ -356,7 +356,7 @@ static jmethodID windowRepaintID = NULL;
sizeChangedID = (*env)->GetMethodID(env, clazz, "sizeChanged", "(ZIIZ)V");
visibleChangedID = (*env)->GetMethodID(env, clazz, "visibleChanged", "(ZZ)V");
insetsChangedID = (*env)->GetMethodID(env, clazz, "insetsChanged", "(ZIIII)V");
- positionChangedID = (*env)->GetMethodID(env, clazz, "positionChanged", "(ZII)V");
+ positionChangedID = (*env)->GetMethodID(env, clazz, "screenPositionChanged", "(ZII)V");
focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(ZZ)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "(Z)Z");
windowRepaintID = (*env)->GetMethodID(env, clazz, "windowRepaint", "(ZIIII)V");
@@ -484,19 +484,28 @@ static jmethodID windowRepaintID = NULL;
}
/**
- * p abs screen position w/ top-left origin
+ * p abs screen position of client-area pos w/ top-left origin, using contentView's client NSSize
* returns: abs screen position w/ bottom-left origin
*/
-- (NSPoint) newtScreenWinPos2OSXScreenPos: (NSPoint) p
+- (NSPoint) newtAbsClientTLWinPos2AbsBLScreenPos: (NSPoint) p
{
NSView* mView = [self contentView];
NSRect mViewFrame = [mView frame];
- int totalHeight = mViewFrame.size.height + cachedInsets[2] + cachedInsets[3]; // height + insets[top+bottom]
+ return [self newtAbsClientTLWinPos2AbsBLScreenPos: p size: mViewFrame.size];
+}
+
+/**
+ * p abs screen position of client-area pos w/ top-left origin, using given client NSSize
+ * returns: abs screen position w/ bottom-left origin
+ */
+- (NSPoint) newtAbsClientTLWinPos2AbsBLScreenPos: (NSPoint) p size: (NSSize) nsz
+{
+ int totalHeight = nsz.height + cachedInsets[3]; // height + insets.bottom
NSScreen* screen = [self screen];
NSRect screenFrame = [screen frame];
- return NSMakePoint(screenFrame.origin.x + p.x + cachedInsets[0],
+ return NSMakePoint(screenFrame.origin.x + p.x,
screenFrame.origin.y + screenFrame.size.height - p.y - totalHeight);
}
@@ -504,7 +513,7 @@ static jmethodID windowRepaintID = NULL;
* p rel client window position w/ top-left origin
* returns: abs screen position w/ bottom-left origin
*/
-- (NSPoint) newtClientWinPos2OSXScreenPos: (NSPoint) p
+- (NSPoint) newtRelClientTLWinPos2AbsBLScreenPos: (NSPoint) p
{
NSRect winFrame = [self frame];