|
From: <ma...@us...> - 2009-06-03 11:09:09
|
Revision: 3220
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3220&view=rev
Author: matzon
Date: 2009-06-03 11:08:58 +0000 (Wed, 03 Jun 2009)
Log Message:
-----------
fixed windows click/movement detection if drag started inside display
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2009-06-02 12:40:57 UTC (rev 3219)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2009-06-03 11:08:58 UTC (rev 3220)
@@ -47,10 +47,13 @@
import org.lwjgl.LWJGLUtil;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Cursor;
+import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
final class WindowsDisplay implements DisplayImplementation {
private final static int GAMMA_LENGTH = 256;
+
+ private final static int WM_CANCELMODE = 0x001F;
private final static int WM_MOUSEMOVE = 0x0200;
private final static int WM_LBUTTONDOWN = 0x0201;
private final static int WM_LBUTTONUP = 0x0202;
@@ -62,7 +65,7 @@
private final static int WM_MBUTTONUP = 0x0208;
private final static int WM_MBUTTONDBLCLK = 0x0209;
private final static int WM_MOUSEWHEEL = 0x020A;
- private final static int WM_MOUSELEAVE = 0x02A3;
+ private final static int WM_CAPTURECHANGED = 0x0215;
private final static int WM_KEYDOWN = 256;
private final static int WM_KEYUP = 257;
private final static int WM_SYSKEYUP = 261;
@@ -150,7 +153,7 @@
private long small_icon;
private long large_icon;
- private boolean trackingMouse = false;
+ private int captureMouse = -1;
WindowsDisplay() {
current_display = this;
@@ -661,10 +664,24 @@
private static native long sendMessage(long hwnd, long msg, long wparam, long lparam);
private void handleMouseButton(int button, int state, long millis) {
- if (mouse != null)
+ if (mouse != null) {
mouse.handleMouseButton((byte)button, (byte)state, millis);
- if (parent != null && !isFocused)
+
+ // done with capture?
+ if(captureMouse != -1 && button == captureMouse && state == 0) {
+ nReleaseCapture();
+ captureMouse = -1;
+
+ // force mouse update - else we will run into an issue where the
+ // button state is "stale" while captureMouse == -1 which causes
+ // handleMouseMoved to issue a setCapture.
+ Mouse.poll();
+ }
+ }
+
+ if (parent != null && !isFocused) {
setFocus(getHwnd());
+ }
}
private boolean shouldGrab() {
@@ -673,19 +690,23 @@
private void handleMouseMoved(int x, int y, long millis) {
if (mouse != null) {
- mouse.handleMouseMoved(x, y, millis, shouldGrab());
+ mouse.handleMouseMoved(x, y, millis, shouldGrab());
- // if we're not tracking mouse and we get a mouse move event - START TRACKING!
- if(!trackingMouse && !Mouse.isGrabbed()) {
- LWJGLUtil.log("initial mouse move - need tracking");
-
- if (nTrackMouse(hwnd)) {
- trackingMouse = true;
+ // Moving - while mouse is down?
+ // need to capture
+ if(!Mouse.isGrabbed()) {
+ int button = firstMouseButtonDown();
+ if(captureMouse == -1 && button != -1) {
+ captureMouse = button;
+ nSetCapture(hwnd);
}
}
}
}
-
+
+ private static native long nSetCapture(long hwnd);
+ private static native boolean nReleaseCapture();
+
private void handleMouseScrolled(int amount, long millis) {
if (mouse != null)
mouse.handleMouseScrolled(amount, millis);
@@ -707,8 +728,14 @@
boolean repeat = state == previous_state; // Repeat message
byte extended = (byte)((lParam >>> 24) & 0x1);
int scan_code = (int)((lParam >>> 16) & 0xFF);
- if (keyboard != null)
+ if (keyboard != null) {
keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis, repeat);
+
+ if(captureMouse != -1 && keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
+ nReleaseCapture();
+ captureMouse = -1;
+ }
+ }
}
private static int transformY(long hwnd, int y) {
@@ -809,9 +836,6 @@
case WM_MBUTTONUP:
handleMouseButton(2, 0, millis);
return 0;
- case WM_MOUSELEAVE:
- handleMouseLeave(millis);
- return 0;
case WM_SYSCHAR:
case WM_CHAR:
handleChar(wParam, lParam, millis);
@@ -854,6 +878,15 @@
case WM_PAINT:
is_dirty = true;
return defWindowProc(hwnd, msg, wParam, lParam);
+ case WM_CANCELMODE:
+ nReleaseCapture();
+ /* fall through */
+ case WM_CAPTURECHANGED:
+ if(captureMouse != -1) {
+ handleMouseButton(captureMouse, 0, millis);
+ captureMouse = -1;
+ }
+ return 0;
default:
return defWindowProc(hwnd, msg, wParam, lParam);
}
@@ -866,6 +899,15 @@
public int getHeight() {
return Display.getDisplayMode().getHeight();
}
+
+ private int firstMouseButtonDown() {
+ for(int i=0; i<Mouse.getButtonCount(); i++) {
+ if(Mouse.isButtonDown(i)) {
+ return i;
+ }
+ }
+ return -1;
+ }
private static final class Rect {
public int top;
@@ -902,17 +944,4 @@
return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right;
}
}
-
-
-
-
- private static native boolean nTrackMouse(long hwnd);
-
- private void handleMouseLeave(long millis) {
- handleMouseButton(0, 0, millis);
- handleMouseButton(1, 0, millis);
- handleMouseButton(2, 0, millis);
- trackingMouse = false;
- }
-
}
Modified: trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java 2009-06-02 12:40:57 UTC (rev 3219)
+++ trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java 2009-06-03 11:08:58 UTC (rev 3220)
@@ -238,6 +238,8 @@
*/
private void handleMouse() {
readBufferedMouse();
+
+ Display.setTitle("x: " + Mouse.getX() + ", y: " + Mouse.getY() + ", [0]: " + Mouse.isButtonDown(0) + ", [1]: " + Mouse.isButtonDown(1) + ", [2]: " + Mouse.isButtonDown(2));
}
/**
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2009-06-02 12:40:57 UTC (rev 3219)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2009-06-03 11:08:58 UTC (rev 3220)
@@ -490,14 +490,11 @@
return GetSystemMetrics(index);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nTrackMouse(JNIEnv *env, jclass unused, jlong hwnd_int) {
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCapture(JNIEnv *env, jclass unused, jlong hwnd_int) {
HWND hwnd = (HWND)(INT_PTR)hwnd_int;
-
- TRACKMOUSEEVENT tme;
- tme.cbSize = sizeof(TRACKMOUSEEVENT);
- tme.dwFlags = TME_LEAVE;
- tme.hwndTrack = hwnd;
-
- return _TrackMouseEvent(&tme);
+ return (INT_PTR) SetCapture(hwnd);
}
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nReleaseCapture(JNIEnv *env, jclass unused) {
+ return ReleaseCapture();
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|