From c2e02b9964860dc59af92187ae124695e1e2f1dc Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Fri, 5 Apr 2013 19:11:38 +0200 Subject: Adds a unit test and a fix for the bug 697 --- .../newt/TestGLWindowInvisiblePointer01NEWT.java | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java diff --git a/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java new file mode 100644 index 000000000..ba69481a3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java @@ -0,0 +1,114 @@ +package com.jogamp.opengl.test.junit.newt; + +import java.io.IOException; + +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jogamp.newt.Screen; +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.jogl.demos.es1.GearsES1; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +public class TestGLWindowInvisiblePointer01NEWT extends UITestCase { + static GLProfile glp; + static int width, height; + static long durationPerTest = 4000; // ms + + @BeforeClass + public static void initClass() { + width = 640; + height = 480; + glp = GLProfile.getDefault(); + } + + static GLWindow createWindow(Screen screen, GLCapabilitiesImmutable caps) + throws InterruptedException + { + Assert.assertNotNull(caps); + // + // Create native windowing resources .. X11/Win/OSX + // + GLWindow glWindow; + if(null!=screen) { + glWindow = GLWindow.create(screen, caps); + Assert.assertNotNull(glWindow); + } else { + glWindow = GLWindow.create(caps); + Assert.assertNotNull(glWindow); + } + glWindow.setUpdateFPSFrames(1, null); + + GLEventListener demo = new GearsES1(); + glWindow.addGLEventListener(demo); + + glWindow.setSize(512, 512); + glWindow.setVisible(true); + Assert.assertEquals(true,glWindow.isVisible()); + Assert.assertEquals(true,glWindow.isNativeValid()); + + return glWindow; + } + + static void destroyWindow(GLWindow glWindow) { + if(null!=glWindow) { + glWindow.destroy(); + Assert.assertEquals(false,glWindow.isNativeValid()); + } + } + + @Test + public void testWindow00() throws InterruptedException { + GLCapabilities caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + GLWindow window1 = createWindow(null, caps); // local + Assert.assertEquals(true,window1.isNativeValid()); + Assert.assertEquals(true,window1.isVisible()); + Animator animator = new Animator(); + animator.setUpdateFPSFrames(1, null); + animator.add(window1); + animator.start(); + AbstractGraphicsDevice device1 = window1.getScreen().getDisplay().getGraphicsDevice(); + + System.err.println("GLProfiles window1: "+device1.getConnection()+": "+GLProfile.glAvailabilityToString(device1)); + + window1.warpPointer(width / 2, height / 2); + window1.requestFocus(); + while(animator.isAnimating() && animator.getTotalFPSDuration() Date: Sat, 6 Apr 2013 10:44:48 +0200 Subject: Adds the missing file --- src/newt/native/WindowsWindow.c | 82 ++++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index aeb860bbc..ae09490f8 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -141,6 +141,7 @@ static RECT* UpdateInsets(JNIEnv *env, jobject window, HWND hwnd); typedef struct { JNIEnv* jenv; jobject jinstance; + int pointerVisible; } WindowUserData; typedef struct { @@ -1033,8 +1034,26 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP useDefWindowProc = 0; res = 1; // return 1 == done, OpenGL, etc .. erases the background, hence we claim to have just done this break; - - + case WM_SETCURSOR : + if (0 != wud->pointerVisible) { + BOOL visibilityChangeSuccessful; + if (1 == wud->pointerVisible) { + visibilityChangeSuccessful = SafeShowCursor(TRUE); + } else { + if (-1 == wud->pointerVisible) { + visibilityChangeSuccessful = SafeShowCursor(FALSE); + } else { + // it should never happen + visibilityChangeSuccessful = FALSE; + } + } + useDefWindowProc = visibilityChangeSuccessful ? 1 : 0; + pointerVisible = 0; + DBG_PRINT("*** WindowsWindow: WM_SETCURSOR requested visibility: %d success: %d\n", wud->pointerVisible, visibilityChangeSuccessful); + } else { + useDefWindowProc = 0; + } + break; default: useDefWindowProc = 1; } @@ -1045,6 +1064,28 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, WPARAM wParam, LPARAM lP return res; } +static BOOL SafeShowCursor(BOOL show) { + int attempt = 0, maxAttempt, previousDisplayCount, currentDisplayCount; + currentDisplayCount = ShowCursor(show); + if (show) { + success = currentDisplayCount >= 0; + maxAttempt = -currentDisplayCount; + } else { + success = currentDisplayCount < 0; + maxAttempt = currentDisplayCount + 1; + } + while (!success && attempt < maxAttempt) { + previousDisplayCount = currentDisplayCount; + currentDisplayCount = ShowCursor(show); + success = show ? currentDisplayCount >= 0 : currentDisplayCount < 0; + attempt++; + if (previousDisplayCount == currentDisplayCount) { + break; + } + } + return success; +} + /* * Class: jogamp_newt_driver_windows_DisplayDriver * Method: DispatchMessages @@ -1456,6 +1497,7 @@ JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_windows_WindowDriver_CreateWindo WindowUserData * wud = (WindowUserData *) malloc(sizeof(WindowUserData)); wud->jinstance = (*env)->NewGlobalRef(env, obj); wud->jenv = env; + wud->pointerVisible = 0; #if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) SetWindowLong(window, GWL_USERDATA, (intptr_t) wud); #else @@ -1664,34 +1706,16 @@ JNIEXPORT jboolean JNICALL Java_jogamp_newt_driver_windows_WindowDriver_setPoint (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); + WindowUserData * wud; +#if !defined(__MINGW64__) && ( defined(UNDER_CE) || _MSC_VER <= 1200 ) + wud = (WindowUserData *) GetWindowLong(hwnd, GWL_USERDATA); +#else + wud = (WindowUserData *) GetWindowLongPtr(hwnd, GWLP_USERDATA); +#endif + wud->pointerVisible = mouseVisible ? 1 : -1; + SendMessage(hwnd, WM_SETCURSOR, 0, 0); - return b; + return JNI_TRUE; } /* -- cgit v1.2.3