diff options
author | Sven Gothel <[email protected]> | 2011-10-10 08:05:26 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-10 08:05:26 +0200 |
commit | 600ebcac40ee2d13947701fffc51ea93887db89c (patch) | |
tree | 448cf840e0e7bd11287437129440a4edcc7e0e2d | |
parent | 24e0591b6be036d5389cc1eb986ed5e86043ba65 (diff) |
NEWT Pointer Feature: Add Windows impl. ; Fix test (warp action) ; Minor cleanup in X11
-rwxr-xr-x | make/scripts/tests-x64.bat | 4 | ||||
-rw-r--r-- | src/newt/classes/com/jogamp/newt/Window.java | 4 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 2 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java | 40 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/x11/X11Window.java | 19 | ||||
-rw-r--r-- | src/newt/native/WindowsWindow.c | 76 | ||||
-rw-r--r-- | src/newt/native/X11Window.c | 9 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java | 1 |
8 files changed, 138 insertions, 17 deletions
diff --git a/make/scripts/tests-x64.bat b/make/scripts/tests-x64.bat index fe513da23..b45b49e89 100755 --- a/make/scripts/tests-x64.bat +++ b/make/scripts/tests-x64.bat @@ -12,7 +12,7 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.acore.TestGLPro REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNewtAWTWrapper %1 %2 %3 %4 %5 %6 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT -time 30000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT %1 %2 %3 -REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT %1 %2 %3 %4 %5 %6 +scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT %1 %2 %3 %4 %5 %6 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT -time 5000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWT -time 5000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.awt.TestAWT03GLCanvasRecreate01 @@ -24,7 +24,7 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestParenting01 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01bAWT %1 %2 %3 %4 %5 %6 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cAWT -time 50000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT -scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT %1 %2 %3 %4 %5 %6 +REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT %1 %2 %3 %4 %5 %6 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestWindows01NEWT REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.newt.TestGLWindows01NEWT diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index a69b8dbb3..a78f81668 100644 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -241,6 +241,10 @@ public interface Window extends NativeWindow, WindowClosingProtocol { /** * Confine the pointer to this window, ie. pointer jail. * <p> + * Before jailing the mouse pointer, + * the window request the focus and the pointer is centered in the window. + * </p> + * <p> * In combination w/ {@link #warpPointer(int, int)} * and maybe {@link #setPointerVisible(boolean)} a simple mouse * navigation can be realized.</p> diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 7bef0b564..b5cd3e5fd 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -1357,6 +1357,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer if(this.pointerConfined != confine) { boolean setVal = 0 == getWindowHandle(); if(!setVal) { + requestFocus(); + warpPointer(width/2, height/2); setVal = confinePointerImpl(confine); } if(setVal) { diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java index ee057fb8f..6e1444da3 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java @@ -188,6 +188,43 @@ public class WindowsWindow extends WindowImpl { setTitle0(getWindowHandle(), title); } + @Override + protected boolean setPointerVisibleImpl(final boolean pointerVisible) { + final Boolean[] res = new Boolean[] { Boolean.FALSE }; + + this.runOnEDTIfAvail(true, new Runnable() { + public void run() { + res[0] = Boolean.valueOf(setPointerVisible0(getWindowHandle(), pointerVisible)); + } + }); + return res[0].booleanValue(); + } + + @Override + protected boolean confinePointerImpl(final boolean confine) { + final Boolean[] res = new Boolean[] { Boolean.FALSE }; + + this.runOnEDTIfAvail(true, new Runnable() { + public void run() { + final Point p0 = getLocationOnScreenImpl(0, 0); + res[0] = Boolean.valueOf(confinePointer0(getWindowHandle(), confine, + p0.getX(), p0.getY(), p0.getX()+width, p0.getY()+height)); + } + }); + return res[0].booleanValue(); + } + + @Override + protected void warpPointerImpl(final int x, final int y) { + this.runOnEDTIfAvail(true, new Runnable() { + public void run() { + final Point sPos = getLocationOnScreenImpl(x, y); + warpPointer0(getWindowHandle(), sPos.getX(), sPos.getY()); + } + }); + return; + } + protected Point getLocationOnScreenImpl(int x, int y) { return GDI.GetRelativeLocation( getWindowHandle(), 0 /*root win*/, x, y); } @@ -211,4 +248,7 @@ public class WindowsWindow extends WindowImpl { private static native void setTitle0(long windowHandle, String title); private native void requestFocus0(long windowHandle, boolean force); + private static native boolean setPointerVisible0(long windowHandle, boolean visible); + private static native boolean confinePointer0(long windowHandle, boolean grab, int l, int t, int r, int b); + private static native void warpPointer0(long windowHandle, int x, int y); } diff --git a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java index c435f993c..2b6bac215 100644 --- a/src/newt/classes/jogamp/newt/driver/x11/X11Window.java +++ b/src/newt/classes/jogamp/newt/driver/x11/X11Window.java @@ -157,9 +157,10 @@ public class X11Window extends WindowImpl { @Override protected void warpPointerImpl(final int x, final int y) { - runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Boolean>() { - public Boolean run(long dpy) { - return Boolean.valueOf(warpPointer0(getDisplayEDTHandle(), getWindowHandle(), x, y)); + runWithLockedDisplayHandle( new DisplayImpl.DisplayRunnable<Object>() { + public Object run(long dpy) { + warpPointer0(getDisplayEDTHandle(), getWindowHandle(), x, y); + return null; } }); } @@ -186,18 +187,20 @@ public class X11Window extends WindowImpl { } protected static native boolean initIDs0(); + private native long CreateWindow0(long parentWindowHandle, long display, int screen_index, long visualID, long javaObjectAtom, long windowDeleteAtom, int x, int y, int width, int height, int flags); private native void CloseWindow0(long display, long windowHandle, long javaObjectAtom, long windowDeleteAtom); private native void reconfigureWindow0(long display, int screen_index, long parentWindowHandle, long windowHandle, int x, int y, int width, int height, int flags); - private native void setTitle0(long display, long windowHandle, String title); private native void requestFocus0(long display, long windowHandle, boolean force); - private native long getParentWindow0(long display, long windowHandle); - private native boolean setPointerVisible0(long display, long windowHandle, boolean visible); - private native boolean confinePointer0(long display, long windowHandle, boolean grab); - private native boolean warpPointer0(long display, long windowHandle, int x, int y); + + private static native void setTitle0(long display, long windowHandle, String title); + private static native long getParentWindow0(long display, long windowHandle); + private static native boolean setPointerVisible0(long display, long windowHandle, boolean visible); + private static native boolean confinePointer0(long display, long windowHandle, boolean grab); + private static native void warpPointer0(long display, long windowHandle, int x, int y); private long windowHandleClose; } diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 307938ac1..3eba0f345 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1574,4 +1574,80 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_requestFocu NewtWindows_requestFocus ( env, obj, (HWND) (intptr_t) window, force) ; } +/* + * Class: Java_jogamp_newt_driver_windows_WindowsWindow + * Method: setPointerVisible0 + * Signature: (JJZ)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_setPointerVisible0 + (JNIEnv *env, jclass clazz, jlong window, jboolean mouseVisible) +{ + HWND hwnd = (HWND) (intptr_t) window; + int res, resOld, i; + jboolean b; + + if(JNI_TRUE == mouseVisible) { + res = ShowCursor(TRUE); + if(res < 0) { + i=0; + do { + resOld = res; + res = ShowCursor(TRUE); + } while(res!=resOld && res<0 && ++i<10); + } + b = res>=0 ? JNI_TRUE : JNI_FALSE; + } else { + res = ShowCursor(FALSE); + if(res >= 0) { + i=0; + do { + resOld = res; + res = ShowCursor(FALSE); + } while(res!=resOld && res>=0 && ++i<10); + } + b = res<0 ? JNI_TRUE : JNI_FALSE; + } + + DBG_PRINT( "*** WindowsWindow: setPointerVisible0: %d, res %d/%d\n", mouseVisible, res, b); + + return b; +} + +/* + * Class: Java_jogamp_newt_driver_windows_WindowsWindow + * Method: confinePointer0 + * Signature: (JJZIIII)Z + */ +JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_confinePointer0 + (JNIEnv *env, jclass clazz, jlong window, jboolean confine, jint l, jint t, jint r, jint b) +{ + HWND hwnd = (HWND) (intptr_t) window; + jboolean res; + + if(JNI_TRUE == confine) { + // SetCapture(hwnd); + // res = ( GetCapture() == hwnd ) ? JNI_TRUE : JNI_FALSE; + RECT rect = { l, t, r, b }; + res = ClipCursor(&rect) ? JNI_TRUE : JNI_FALSE; + } else { + // res = ReleaseCapture() ? JNI_TRUE : JNI_FALSE; + res = ClipCursor(NULL) ? JNI_TRUE : JNI_FALSE; + } + DBG_PRINT( "*** WindowsWindow: confinePointer0: %d, [ l %d t %d r %d b %d ], res %d\n", + confine, l, t, r, b, res); + + return res; +} + +/* + * Class: Java_jogamp_newt_driver_windows_WindowsWindow + * Method: warpPointer0 + * Signature: (JJII)V + */ +JNIEXPORT void JNICALL Java_jogamp_newt_driver_windows_WindowsWindow_warpPointer0 + (JNIEnv *env, jclass clazz, jlong window, jint x, jint y) +{ + DBG_PRINT( "*** WindowsWindow: warpPointer0: %d/%d\n", x, y); + SetCursorPos(x, y); +} diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 2038237cd..c7b271188 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -1847,7 +1847,7 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Window_requestFocus0 * Signature: (JJ)J */ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_x11_X11Window_getParentWindow0 - (JNIEnv *env, jobject obj, jlong display, jlong window) + (JNIEnv *env, jclass clazz, jlong display, jlong window) { return (jlong) NewtWindows_getParent ((Display *) (intptr_t) display, (Window)window); } @@ -1947,7 +1947,6 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_confinePointer0 { Display * dpy = (Display *) (intptr_t) display; Window w = (Window)window; - int res; DBG_PRINT( "X11: confinePointer0: %d\n", confine); @@ -1964,18 +1963,16 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_confinePointer0 /* * Class: Java_jogamp_newt_driver_x11_X11Window * Method: warpPointer0 - * Signature: (JJII)Z + * Signature: (JJII)V */ -JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_x11_X11Window_warpPointer0 +JNIEXPORT void JNICALL Java_jogamp_newt_driver_x11_X11Window_warpPointer0 (JNIEnv *env, jclass clazz, jlong display, jlong window, jint x, jint y) { Display * dpy = (Display *) (intptr_t) display; Window w = (Window)window; - int res; DBG_PRINT( "X11: warpPointer0: %d/%d\n", x, y); XWarpPointer(dpy, None, w, 0, 0, 0, 0, x, y); - return JNI_TRUE; } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java index 7be31fdb7..ddba0569f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java @@ -169,7 +169,6 @@ public class TestGearsES2NEWT extends UITestCase { public void run() { System.err.println("[set mouse pos pre]"); glWindow.warpPointer(glWindow.getWidth()/2, glWindow.getHeight()/2); - glWindow.confinePointer(!glWindow.isPointerConfined()); System.err.println("[set mouse pos post]"); } }.start(); } |