aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-04-11 07:30:12 +0200
committerSven Gothel <[email protected]>2013-04-11 07:30:12 +0200
commitdb255a2d998ab85f4d027568509dc1028e62f604 (patch)
tree79ddcf41da5e1c020fd50ad2ebdac3128c225eb2 /src
parent294294c2317d1a22406f471c74235315afed86e4 (diff)
parent4db745e84fac610f85ab085e5c147e571e82e008 (diff)
Merge remote-tracking branch 'gouessej/master'
Diffstat (limited to 'src')
-rw-r--r--src/newt/native/WindowsWindow.c82
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/TestGLWindowInvisiblePointer01NEWT.java114
2 files changed, 167 insertions, 29 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 7426e5dfe..eecc2e075 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 {
@@ -1037,8 +1038,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;
}
@@ -1049,6 +1068,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
@@ -1460,6 +1501,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
@@ -1668,34 +1710,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;
}
/*
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()<durationPerTest) {
+ boolean pointerVisibleNewVal = (animator.getTotalFPSDuration()/100)%2==0;
+ window1.setPointerVisible(pointerVisibleNewVal);
+ Assert.assertEquals(pointerVisibleNewVal,window1.isPointerVisible());
+ Thread.sleep(100);
+ }
+
+ destroyWindow(window1);
+ }
+
+ static int atoi(String a) {
+ int i=0;
+ try {
+ i = Integer.parseInt(a);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ return i;
+ }
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ durationPerTest = atoi(args[++i]);
+ }
+ }
+ System.out.println("durationPerTest: "+durationPerTest);
+ String tstname = TestGLWindowInvisiblePointer01NEWT.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
+}