You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(134) |
Sep
(52) |
Oct
(13) |
Nov
(342) |
Dec
(163) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(44) |
Feb
(62) |
Mar
(158) |
Apr
(38) |
May
(70) |
Jun
(58) |
Jul
(104) |
Aug
(207) |
Sep
(83) |
Oct
(122) |
Nov
(23) |
Dec
(49) |
| 2004 |
Jan
(119) |
Feb
(132) |
Mar
(192) |
Apr
(140) |
May
(77) |
Jun
(74) |
Jul
(201) |
Aug
(63) |
Sep
(102) |
Oct
(70) |
Nov
(173) |
Dec
(78) |
| 2005 |
Jan
(174) |
Feb
(197) |
Mar
(105) |
Apr
(59) |
May
(77) |
Jun
(43) |
Jul
(21) |
Aug
(18) |
Sep
(47) |
Oct
(37) |
Nov
(74) |
Dec
(50) |
| 2006 |
Jan
(44) |
Feb
(19) |
Mar
(32) |
Apr
(24) |
May
(31) |
Jun
(55) |
Jul
(138) |
Aug
(28) |
Sep
(12) |
Oct
(41) |
Nov
(58) |
Dec
(24) |
| 2007 |
Jan
(28) |
Feb
(14) |
Mar
(10) |
Apr
(68) |
May
(30) |
Jun
(26) |
Jul
(18) |
Aug
(63) |
Sep
(19) |
Oct
(29) |
Nov
(20) |
Dec
(10) |
| 2008 |
Jan
(38) |
Feb
(7) |
Mar
(37) |
Apr
(120) |
May
(41) |
Jun
(36) |
Jul
(39) |
Aug
(24) |
Sep
(28) |
Oct
(30) |
Nov
(36) |
Dec
(75) |
| 2009 |
Jan
(46) |
Feb
(22) |
Mar
(50) |
Apr
(70) |
May
(134) |
Jun
(105) |
Jul
(75) |
Aug
(34) |
Sep
(38) |
Oct
(34) |
Nov
(19) |
Dec
(20) |
| 2010 |
Jan
(11) |
Feb
(20) |
Mar
(65) |
Apr
(83) |
May
(104) |
Jun
(73) |
Jul
(78) |
Aug
(57) |
Sep
(43) |
Oct
(35) |
Nov
(9) |
Dec
(4) |
| 2011 |
Jan
(21) |
Feb
(11) |
Mar
(18) |
Apr
(10) |
May
(18) |
Jun
(15) |
Jul
(48) |
Aug
(25) |
Sep
(17) |
Oct
(45) |
Nov
(15) |
Dec
(12) |
| 2012 |
Jan
(21) |
Feb
(9) |
Mar
(12) |
Apr
(9) |
May
(9) |
Jun
(5) |
Jul
(1) |
Aug
(10) |
Sep
(12) |
Oct
(1) |
Nov
(28) |
Dec
(5) |
| 2013 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
| 2016 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
|
1
|
2
(2) |
3
(3) |
4
|
5
|
6
|
7
(4) |
|
8
(1) |
9
|
10
|
11
(5) |
12
|
13
|
14
(1) |
|
15
(2) |
16
|
17
|
18
|
19
(26) |
20
|
21
|
|
22
(1) |
23
(3) |
24
(6) |
25
(1) |
26
(3) |
27
(1) |
28
(2) |
|
29
(5) |
30
(2) |
|
|
|
|
|
|
From: <eli...@us...> - 2007-04-24 14:41:20
|
Revision: 2804
http://svn.sourceforge.net/java-game-lib/?rev=2804&view=rev
Author: elias_naur
Date: 2007-04-24 07:41:17 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Windows: Use TranslateMessage and WM_CHAR to receive character input instead of manual translation. This change fixes composed characters.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.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 2007-04-24 14:13:42 UTC (rev 2803)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-24 14:41:17 UTC (rev 2804)
@@ -62,8 +62,9 @@
private final static int WM_MOUSEWHEEL = 0x020A;
private final static int WM_KEYDOWN = 256;
private final static int WM_KEYUP = 257;
- private final static int WM_SYSKEYUP = 261;
- private final static int WM_SYSKEYDOWN = 260;
+ private final static int WM_SYSKEYUP = 261;
+ private final static int WM_SYSKEYDOWN = 260;
+ private final static int WM_CHAR = 258;
private final static int WM_QUIT = 0x0012;
private final static int WM_SYSCOMMAND = 0x0112;
@@ -595,6 +596,15 @@
private static native void getClientRect(long hwnd, IntBuffer rect);
+ private void handleChar(long wParam, long lParam, long millis) {
+ byte previous_state = (byte)((lParam >>> 30) & 0x1);
+ byte state = (byte)(1 - ((lParam >>> 31) & 0x1));
+ if (state == previous_state)
+ return; // Auto-repeat message
+ if (keyboard != null)
+ keyboard.handleChar((int)(wParam & 0xFF), millis);
+ }
+
private void handleKeyButton(long wParam, long lParam, long millis) {
byte previous_state = (byte)((lParam >>> 30) & 0x1);
byte state = (byte)(1 - ((lParam >>> 31) & 0x1));
@@ -682,6 +692,9 @@
case WM_MBUTTONUP:
handleMouseButton(2, 0, millis);
return true;
+ case WM_CHAR:
+ handleChar(wParam, lParam, millis);
+ return true;
case WM_SYSKEYDOWN: /* Fall through */
case WM_SYSKEYUP: /* Fall through */
case WM_KEYUP: /* Fall through */
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-04-24 14:13:42 UTC (rev 2803)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-04-24 14:41:17 UTC (rev 2804)
@@ -55,24 +55,18 @@
private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
private final EventQueue event_queue = new EventQueue(Keyboard.EVENT_SIZE);
private final ByteBuffer tmp_event = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
- private final boolean unicode;
- private final CharBuffer unicode_buffer;
- private final ByteBuffer ascii_buffer;
private boolean grabbed;
+ private boolean has_retained_event; // Indicates if we're waiting for a WM_CHAR
+ private int retained_key_code;
+ private byte retained_state;
+ private int retained_char;
+ private long retained_millis;
+
public WindowsKeyboard(long hwnd) throws LWJGLException {
this.hwnd = hwnd;
keyboard_state = BufferUtils.createByteBuffer(256);
- unicode = isWindowsNT();
- if (unicode) {
- unicode_buffer = BufferUtils.createCharBuffer(BUFFER_SIZE);
- ascii_buffer = null;
- } else {
- unicode_buffer = null;
- // ToAscii returns at most 2 characters
- ascii_buffer = BufferUtils.createByteBuffer(2);
- }
}
private static native boolean isWindowsNT();
@@ -97,66 +91,15 @@
keyDownBuffer.position(old_position);
}
- private void translate(int virt_key, byte state, long nanos) {
- int keycode = MapVirtualKey(virt_key, MAPVK_VK_TO_VSC);
- if (state != 0) {
- if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) {
- // Mark key down in the scan code
- int key_down_code = keycode & 0x7fff;
- int num_chars;
- if (unicode) {
- unicode_buffer.clear();
- num_chars = ToUnicode(virt_key,
- key_down_code,
- keyboard_state,
- unicode_buffer,
- unicode_buffer.capacity(), 0);
- } else {
- ascii_buffer.clear();
- num_chars = ToAscii(virt_key,
- key_down_code,
- keyboard_state,
- ascii_buffer,
- 0);
- }
- if (num_chars > 0) {
- int current_char = 0;
- do {
- int char_int;
- if (unicode) {
- char_int = ((int)unicode_buffer.get()) & 0xFFFF;
- } else {
- char_int = ((int)ascii_buffer.get()) & 0xFF;
- }
- if (current_char >= 1) {
- putEvent(0, (byte)0, char_int, nanos);
- } else {
- putEvent(virt_key, state, char_int, nanos);
- }
- current_char++;
- } while (current_char < num_chars);
- } else {
- putEvent(virt_key, state, 0, nanos);
- }
- } else {
- putEvent(virt_key, state, 0, nanos);
- }
- } else {
- putEvent(virt_key, state, 0, nanos);
- }
- }
private static native int MapVirtualKey(int uCode, int uMapType);
private static native int ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags);
private static native int ToAscii(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, ByteBuffer lpChar, int flags);
private static native int GetKeyboardState(ByteBuffer lpKeyState);
private static native int GetKeyState(int virt_key);
- private void putEvent(int virt_key, byte state, int ch, long nanos) {
- int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
- if (keycode < key_down_buffer.length)
- key_down_buffer[keycode] = state;
+ private void putEvent(int keycode, byte state, int ch, long millis) {
tmp_event.clear();
- tmp_event.putInt(keycode).put(state).putInt(ch).putLong(nanos);
+ tmp_event.putInt(keycode).put(state).putInt(ch).putLong(millis*1000000);
tmp_event.flip();
event_queue.putEvent(tmp_event);
}
@@ -198,13 +141,36 @@
}
}
+ private void flushRetained() {
+ if (has_retained_event) {
+ has_retained_event = false;
+ putEvent(retained_key_code, retained_state, retained_char, retained_millis);
+ }
+ }
+
public void handleKey(int virt_key, int scan_code, boolean extended, byte event_state, long millis) {
- if (isWindowsNT())
- virt_key = translateExtended(virt_key, scan_code, event_state, extended);
- translate(virt_key, event_state, millis*1000000);
+ virt_key = translateExtended(virt_key, scan_code, event_state, extended);
+ flushRetained();
+ has_retained_event = true;
+ int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
+ if (keycode < key_down_buffer.length)
+ key_down_buffer[keycode] = event_state;
+ retained_key_code = keycode;
+ retained_state = event_state;
+ retained_millis = millis;
+ retained_char = 0;
+// translate(virt_key, event_state, millis*1000000);
}
+ public void handleChar(int event_char, long millis) {
+ if (!has_retained_event) {
+ putEvent(0, (byte)0, event_char, millis);
+ } else
+ retained_char = event_char;
+ }
+
public void read(ByteBuffer buffer) {
+ flushRetained();
event_queue.copyEvents(buffer);
}
}
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2007-04-24 14:13:42 UTC (rev 2803)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2007-04-24 14:41:17 UTC (rev 2804)
@@ -148,6 +148,7 @@
))
{
DispatchMessage(&msg);
+ TranslateMessage(&msg);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <eli...@us...> - 2007-04-24 14:13:43
|
Revision: 2803
http://svn.sourceforge.net/java-game-lib/?rev=2803&view=rev
Author: elias_naur
Date: 2007-04-24 07:13:42 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Windows: Call default handler on key events
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-24 13:41:31 UTC (rev 2802)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-24 14:13:42 UTC (rev 2803)
@@ -687,7 +687,7 @@
case WM_KEYUP: /* Fall through */
case WM_KEYDOWN:
handleKeyButton(wParam, lParam, millis);
- return true;
+ return false;
case WM_QUIT:
close_requested = true;
return true;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <eli...@us...> - 2007-04-24 13:41:32
|
Revision: 2802
http://svn.sourceforge.net/java-game-lib/?rev=2802&view=rev
Author: elias_naur
Date: 2007-04-24 06:41:31 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Removed debug output
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2007-04-24 13:40:13 UTC (rev 2801)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2007-04-24 13:41:31 UTC (rev 2802)
@@ -297,7 +297,7 @@
private static void switchDisplayMode() throws LWJGLException {
if (!current_mode.isFullscreen()) {
- System.out.println("Switching to "+initial_mode);
+ LWJGLUtil.log("Switching to "+initial_mode);
setDisplayMode(initial_mode);
}
display_impl.switchDisplayMode(current_mode);
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-04-24 13:40:13 UTC (rev 2801)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-04-24 13:41:31 UTC (rev 2802)
@@ -153,7 +153,6 @@
private void putEvent(int virt_key, byte state, int ch, long nanos) {
int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
-System.out.println("virt_key = " + Integer.toHexString(virt_key) + " = " + virt_key + " | keycode = " + Keyboard.getKeyName(keycode));
if (keycode < key_down_buffer.length)
key_down_buffer[keycode] = state;
tmp_event.clear();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <eli...@us...> - 2007-04-24 13:40:16
|
Revision: 2801
http://svn.sourceforge.net/java-game-lib/?rev=2801&view=rev
Author: elias_naur
Date: 2007-04-24 06:40:13 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Windows: Convert WindowsKeyboard to use windows messages instead of DirectInput.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c
Added Paths:
-----------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeycodes.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-24 13:22:35 UTC (rev 2800)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-24 13:40:13 UTC (rev 2801)
@@ -60,6 +60,10 @@
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_KEYDOWN = 256;
+ private final static int WM_KEYUP = 257;
+ private final static int WM_SYSKEYUP = 261;
+ private final static int WM_SYSKEYDOWN = 260;
private final static int WM_QUIT = 0x0012;
private final static int WM_SYSCOMMAND = 0x0112;
@@ -174,6 +178,15 @@
rect.offset(offset_x, offset_y);
}
+ static WindowsDirectInput createDirectInput() throws LWJGLException {
+ try {
+ return new WindowsDirectInput8(getDllInstance());
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to create DirectInput 8 interface, falling back to DirectInput 3");
+ return new WindowsDirectInput3(getDllInstance());
+ }
+ }
+
static void setupCursorClipping(long hwnd) throws LWJGLException {
cursor_clipped = true;
getGlobalClientRect(hwnd, rect);
@@ -453,7 +466,7 @@
/* Keyboard */
public void createKeyboard() throws LWJGLException {
- keyboard = new WindowsKeyboard(createDirectInput(), getHwnd());
+ keyboard = new WindowsKeyboard(getHwnd());
}
public void destroyKeyboard() {
@@ -582,6 +595,17 @@
private static native void getClientRect(long hwnd, IntBuffer rect);
+ private void handleKeyButton(long wParam, long lParam, long millis) {
+ byte previous_state = (byte)((lParam >>> 30) & 0x1);
+ byte state = (byte)(1 - ((lParam >>> 31) & 0x1));
+ if (state == previous_state)
+ return; // Auto-repeat message
+ byte extended = (byte)((lParam >>> 24) & 0x1);
+ int scan_code = (int)((lParam >>> 16) & 0xFF);
+ if (keyboard != null)
+ keyboard.handleKey((int)wParam, scan_code, extended != 0, state, millis);
+ }
+
private static int transformY(long hwnd, int y) {
getClientRect(hwnd, rect_buffer);
rect.copyFromBuffer(rect_buffer);
@@ -658,6 +682,12 @@
case WM_MBUTTONUP:
handleMouseButton(2, 0, millis);
return true;
+ case WM_SYSKEYDOWN: /* Fall through */
+ case WM_SYSKEYUP: /* Fall through */
+ case WM_KEYUP: /* Fall through */
+ case WM_KEYDOWN:
+ handleKeyButton(wParam, lParam, millis);
+ return true;
case WM_QUIT:
close_requested = true;
return true;
@@ -683,15 +713,6 @@
}
}
- static WindowsDirectInput createDirectInput() throws LWJGLException {
- try {
- return new WindowsDirectInput8(getDllInstance());
- } catch (LWJGLException e) {
- LWJGLUtil.log("Failed to create DirectInput 8 interface, falling back to DirectInput 3");
- return new WindowsDirectInput3(getDllInstance());
- }
- }
-
public int getWidth() {
return Display.getDisplayMode().getWidth();
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-04-24 13:22:35 UTC (rev 2800)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeyboard.java 2007-04-24 13:40:13 UTC (rev 2801)
@@ -43,40 +43,26 @@
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.BufferUtils;
+import org.lwjgl.input.Keyboard;
final class WindowsKeyboard {
+ private final static int MAPVK_VK_TO_VSC = 0;
+
private final static int BUFFER_SIZE = 50;
private final long hwnd;
- private final WindowsDirectInput dinput;
- private final WindowsDirectInputDevice keyboard;
- private final IntBuffer temp_data_buffer;
private final ByteBuffer keyboard_state;
+ private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
+ private final EventQueue event_queue = new EventQueue(Keyboard.EVENT_SIZE);
+ private final ByteBuffer tmp_event = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
private final boolean unicode;
private final CharBuffer unicode_buffer;
private final ByteBuffer ascii_buffer;
private boolean grabbed;
- public WindowsKeyboard(WindowsDirectInput dinput, long hwnd) throws LWJGLException {
+ public WindowsKeyboard(long hwnd) throws LWJGLException {
this.hwnd = hwnd;
- this.dinput = dinput;
- try {
- keyboard = dinput.createDevice(WindowsDirectInput.KEYBOARD_TYPE);
- try {
- keyboard.setDataFormat(WindowsDirectInput.KEYBOARD_TYPE);
- keyboard.setBufferSize(BUFFER_SIZE);
- acquireNonExclusive();
- } catch (LWJGLException e) {
- keyboard.release();
- throw e;
- }
- } catch (LWJGLException e) {
- dinput.release();
- throw e;
- }
- keyboard.acquire();
- temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*WindowsDirectInputDevice.DATA_SIZE);
keyboard_state = BufferUtils.createByteBuffer(256);
unicode = isWindowsNT();
if (unicode) {
@@ -90,165 +76,136 @@
}
private static native boolean isWindowsNT();
- private boolean acquire(int flags) {
- try {
- keyboard.setCooperateLevel(hwnd, flags);
- keyboard.acquire();
- return true;
- } catch (LWJGLException e) {
- LWJGLUtil.log("Failed to acquire keyboard: " + e);
- return false;
- }
- }
-
- private boolean acquireNonExclusive() {
- return acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND) ||
- acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_BACKGROUND);
- }
-
public void destroy() {
- keyboard.unacquire();
- keyboard.release();
- dinput.release();
}
public void grab(boolean grab) {
if(grab) {
if (!grabbed) {
- flush();
grabbed = true;
- keyboard.unacquire();
- if (!acquire(WindowsDirectInputDevice.DISCL_EXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND))
- LWJGLUtil.log("Failed to reset cooperative mode");
}
} else {
if (grabbed) {
grabbed = false;
- keyboard.unacquire();
- acquireNonExclusive();
}
}
}
public void poll(ByteBuffer keyDownBuffer) {
- int ret = keyboard.acquire();
- if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
- return;
- keyboard.poll();
- ret = keyboard.getDeviceState(keyDownBuffer);
- switch (ret) {
- case WindowsDirectInput.DI_OK:
- break;
- case WindowsDirectInput.DI_BUFFEROVERFLOW:
- LWJGLUtil.log("Keyboard buffer overflow");
- break;
- case WindowsDirectInput.DIERR_INPUTLOST:
- break;
- case WindowsDirectInput.DIERR_NOTACQUIRED:
- break;
- default:
- LWJGLUtil.log("Failed to poll keyboard (0x" + Integer.toHexString(ret) + ")");
- break;
- }
+ int old_position = keyDownBuffer.position();
+ keyDownBuffer.put(key_down_buffer);
+ keyDownBuffer.position(old_position);
}
- private void translateData(IntBuffer src, ByteBuffer dst) {
- while (dst.hasRemaining() && src.hasRemaining()) {
- int dwOfs = src.get();
- dst.putInt(dwOfs);
- byte dwData = (byte)src.get();
- boolean key_down = (dwData & 0x80) != 0;
- dst.put(key_down ? (byte)1 : (byte)0);
- long dwTimeStamp = ((long)src.get()) & 0xFFFFFFFF;
- long nanos = dwTimeStamp*1000000;
- if (key_down) {
- int virt_key = MapVirtualKey(dwOfs, 1);
- if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) {
- // Mark key down in the scan code
- dwOfs = dwOfs & 0x7fff;
- int num_chars;
- if (unicode) {
- unicode_buffer.clear();
- num_chars = ToUnicode(virt_key,
- dwOfs,
+ private void translate(int virt_key, byte state, long nanos) {
+ int keycode = MapVirtualKey(virt_key, MAPVK_VK_TO_VSC);
+ if (state != 0) {
+ if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) {
+ // Mark key down in the scan code
+ int key_down_code = keycode & 0x7fff;
+ int num_chars;
+ if (unicode) {
+ unicode_buffer.clear();
+ num_chars = ToUnicode(virt_key,
+ key_down_code,
keyboard_state,
unicode_buffer,
unicode_buffer.capacity(), 0);
- } else {
- ascii_buffer.clear();
- num_chars = ToAscii(virt_key,
- dwOfs,
+ } else {
+ ascii_buffer.clear();
+ num_chars = ToAscii(virt_key,
+ key_down_code,
keyboard_state,
ascii_buffer,
0);
- }
- if (num_chars > 0) {
- int current_char = 0;
- do {
- if (current_char >= 1) {
- dst.putInt(0);
- dst.put((byte)0);
- }
- int char_int;
- if (unicode) {
- char_int = ((int)unicode_buffer.get()) & 0xFFFF;
- } else {
- char_int = ((int)ascii_buffer.get()) & 0xFF;
- }
- dst.putInt(char_int);
- dst.putLong(nanos);
- current_char++;
- } while (dst.hasRemaining() && current_char < num_chars);
- } else {
- dst.putInt(0);
- dst.putLong(nanos);
- }
+ }
+ if (num_chars > 0) {
+ int current_char = 0;
+ do {
+ int char_int;
+ if (unicode) {
+ char_int = ((int)unicode_buffer.get()) & 0xFFFF;
+ } else {
+ char_int = ((int)ascii_buffer.get()) & 0xFF;
+ }
+ if (current_char >= 1) {
+ putEvent(0, (byte)0, char_int, nanos);
+ } else {
+ putEvent(virt_key, state, char_int, nanos);
+ }
+ current_char++;
+ } while (current_char < num_chars);
} else {
- dst.putInt(0);
- dst.putLong(nanos);
+ putEvent(virt_key, state, 0, nanos);
}
} else {
- dst.putInt(0);
- dst.putLong(nanos);
+ putEvent(virt_key, state, 0, nanos);
}
+ } else {
+ putEvent(virt_key, state, 0, nanos);
}
}
private static native int MapVirtualKey(int uCode, int uMapType);
private static native int ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags);
private static native int ToAscii(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, ByteBuffer lpChar, int flags);
private static native int GetKeyboardState(ByteBuffer lpKeyState);
+ private static native int GetKeyState(int virt_key);
- public void flush() {
- processEvents();
- temp_data_buffer.clear();
+ private void putEvent(int virt_key, byte state, int ch, long nanos) {
+ int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
+System.out.println("virt_key = " + Integer.toHexString(virt_key) + " = " + virt_key + " | keycode = " + Keyboard.getKeyName(keycode));
+ if (keycode < key_down_buffer.length)
+ key_down_buffer[keycode] = state;
+ tmp_event.clear();
+ tmp_event.putInt(keycode).put(state).putInt(ch).putLong(nanos);
+ tmp_event.flip();
+ event_queue.putEvent(tmp_event);
}
- private void processEvents() {
- int ret = keyboard.acquire();
- if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
- return;
- keyboard.poll();
- temp_data_buffer.clear();
- ret = keyboard.getDeviceData(temp_data_buffer);
- switch (ret) {
- case WindowsDirectInput.DI_OK:
- break;
- case WindowsDirectInput.DI_BUFFEROVERFLOW:
- LWJGLUtil.log("Keyboard buffer overflow");
- break;
- case WindowsDirectInput.DIERR_INPUTLOST:
- break;
- case WindowsDirectInput.DIERR_NOTACQUIRED:
- break;
+ private boolean checkShiftKey(int virt_key, byte state) {
+ int key_state = (GetKeyState(virt_key) >>> 15) & 0x1;
+ int lwjgl_code = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
+ return (key_down_buffer[lwjgl_code] == 1 - state) && (key_state == state);
+ }
+
+ private int translateShift(int scan_code, byte state) {
+ int state_mask = state != 0 ? 0x8000 : 0x0000;
+ if (checkShiftKey(WindowsKeycodes.VK_LSHIFT, state)) {
+ return WindowsKeycodes.VK_LSHIFT;
+ } else if (checkShiftKey(WindowsKeycodes.VK_RSHIFT, state)) {
+ return WindowsKeycodes.VK_RSHIFT;
+ } else {
+ if (scan_code== 0x2A)
+ return WindowsKeycodes.VK_LSHIFT;
+ else {
+ if (scan_code == 0x36)
+ return WindowsKeycodes.VK_RSHIFT;
+ else
+ return WindowsKeycodes.VK_LSHIFT;
+ }
+ }
+ }
+
+ private int translateExtended(int virt_key, int scan_code, byte state, boolean extended) {
+ switch (virt_key) {
+ case WindowsKeycodes.VK_SHIFT:
+ return translateShift(scan_code, state);
+ case WindowsKeycodes.VK_CONTROL:
+ return extended ? WindowsKeycodes.VK_RCONTROL : WindowsKeycodes.VK_LCONTROL;
+ case WindowsKeycodes.VK_MENU:
+ return extended ? WindowsKeycodes.VK_RMENU : WindowsKeycodes.VK_LMENU;
default:
- LWJGLUtil.log("Failed to read keyboard (0x" + Integer.toHexString(ret) + ")");
- break;
+ return virt_key;
}
}
+ public void handleKey(int virt_key, int scan_code, boolean extended, byte event_state, long millis) {
+ if (isWindowsNT())
+ virt_key = translateExtended(virt_key, scan_code, event_state, extended);
+ translate(virt_key, event_state, millis*1000000);
+ }
+
public void read(ByteBuffer buffer) {
- processEvents();
- temp_data_buffer.flip();
- translateData(temp_data_buffer, buffer);
+ event_queue.copyEvents(buffer);
}
}
Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeycodes.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeycodes.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeycodes.java 2007-04-24 13:40:13 UTC (rev 2801)
@@ -0,0 +1,577 @@
+/*
+ * Copyright (c) 2002-2004 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opengl;
+
+/**
+ * @author elias_naur
+ */
+
+import org.lwjgl.input.Keyboard;
+
+final class WindowsKeycodes {
+ public final static int VK_LBUTTON = 0x01;
+ public final static int VK_RBUTTON = 0x02;
+ public final static int VK_CANCEL = 0x03;
+ public final static int VK_MBUTTON = 0x04; /* NOT contiguous with L & RBUTTON */
+
+ public final static int VK_XBUTTON1 = 0x05; /* NOT contiguous with L & RBUTTON */
+ public final static int VK_XBUTTON2 = 0x06; /* NOT contiguous with L & RBUTTON */
+
+/*
+ * 0x07 : unassigned
+ */
+
+ public final static int VK_BACK = 0x08;
+ public final static int VK_TAB = 0x09;
+
+/*
+ * 0x0A - 0x0B : reserved
+ */
+
+ public final static int VK_CLEAR = 0x0C;
+ public final static int VK_RETURN = 0x0D;
+
+ public final static int VK_SHIFT = 0x10;
+ public final static int VK_CONTROL = 0x11;
+ public final static int VK_MENU = 0x12;
+ public final static int VK_PAUSE = 0x13;
+ public final static int VK_CAPITAL = 0x14;
+
+ public final static int VK_KANA = 0x15;
+ public final static int VK_HANGEUL = 0x15; /* old name - should be here for compatibility */
+ public final static int VK_HANGUL = 0x15;
+ public final static int VK_JUNJA = 0x17;
+ public final static int VK_FINAL = 0x18;
+ public final static int VK_HANJA = 0x19;
+ public final static int VK_KANJI = 0x19;
+
+ public final static int VK_ESCAPE = 0x1B;
+
+ public final static int VK_CONVERT = 0x1C;
+ public final static int VK_NONCONVERT = 0x1D;
+ public final static int VK_ACCEPT = 0x1E;
+ public final static int VK_MODECHANGE = 0x1F;
+
+ public final static int VK_SPACE = 0x20;
+ public final static int VK_PRIOR = 0x21;
+ public final static int VK_NEXT = 0x22;
+ public final static int VK_END = 0x23;
+ public final static int VK_HOME = 0x24;
+ public final static int VK_LEFT = 0x25;
+ public final static int VK_UP = 0x26;
+ public final static int VK_RIGHT = 0x27;
+ public final static int VK_DOWN = 0x28;
+ public final static int VK_SELECT = 0x29;
+ public final static int VK_PRINT = 0x2A;
+ public final static int VK_EXECUTE = 0x2B;
+ public final static int VK_SNAPSHOT = 0x2C;
+ public final static int VK_INSERT = 0x2D;
+ public final static int VK_DELETE = 0x2E;
+ public final static int VK_HELP = 0x2F;
+/*
+ * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39)
+ * 0x40 : unassigned
+ * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A)
+ */
+ public final static int VK_0 = 0x30;
+ public final static int VK_1 = 0x31;
+ public final static int VK_2 = 0x32;
+ public final static int VK_3 = 0x33;
+ public final static int VK_4 = 0x34;
+ public final static int VK_5 = 0x35;
+ public final static int VK_6 = 0x36;
+ public final static int VK_7 = 0x37;
+ public final static int VK_8 = 0x38;
+ public final static int VK_9 = 0x39;
+
+ public final static int VK_A = 0x41;
+ public final static int VK_B = 0x42;
+ public final static int VK_C = 0x43;
+ public final static int VK_D = 0x44;
+ public final static int VK_E = 0x45;
+ public final static int VK_F = 0x46;
+ public final static int VK_G = 0x47;
+ public final static int VK_H = 0x48;
+ public final static int VK_I = 0x49;
+ public final static int VK_J = 0x4A;
+ public final static int VK_K = 0x4B;
+ public final static int VK_L = 0x4C;
+ public final static int VK_M = 0x4D;
+ public final static int VK_N = 0x4E;
+ public final static int VK_O = 0x4F;
+ public final static int VK_P = 0x50;
+ public final static int VK_Q = 0x51;
+ public final static int VK_R = 0x52;
+ public final static int VK_S = 0x53;
+ public final static int VK_T = 0x54;
+ public final static int VK_U = 0x55;
+ public final static int VK_V = 0x56;
+ public final static int VK_W = 0x57;
+ public final static int VK_X = 0x58;
+ public final static int VK_Y = 0x59;
+ public final static int VK_Z = 0x5A;
+
+ public final static int VK_LWIN = 0x5B;
+ public final static int VK_RWIN = 0x5C;
+ public final static int VK_APPS = 0x5D;
+/*
+ * 0x5E : reserved;
+ */
+
+ public final static int VK_SLEEP = 0x5F;
+
+ public final static int VK_NUMPAD0 = 0x60;
+ public final static int VK_NUMPAD1 = 0x61;
+ public final static int VK_NUMPAD2 = 0x62;
+ public final static int VK_NUMPAD3 = 0x63;
+ public final static int VK_NUMPAD4 = 0x64;
+ public final static int VK_NUMPAD5 = 0x65;
+ public final static int VK_NUMPAD6 = 0x66;
+ public final static int VK_NUMPAD7 = 0x67;
+ public final static int VK_NUMPAD8 = 0x68;
+ public final static int VK_NUMPAD9 = 0x69;
+ public final static int VK_MULTIPLY = 0x6A;
+ public final static int VK_ADD = 0x6B;
+ public final static int VK_SEPARATOR = 0x6C;
+ public final static int VK_SUBTRACT = 0x6D;
+ public final static int VK_DECIMAL = 0x6E;
+ public final static int VK_DIVIDE = 0x6F;
+ public final static int VK_F1 = 0x70;
+ public final static int VK_F2 = 0x71;
+ public final static int VK_F3 = 0x72;
+ public final static int VK_F4 = 0x73;
+ public final static int VK_F5 = 0x74;
+ public final static int VK_F6 = 0x75;
+ public final static int VK_F7 = 0x76;
+ public final static int VK_F8 = 0x77;
+ public final static int VK_F9 = 0x78;
+ public final static int VK_F10 = 0x79;
+ public final static int VK_F11 = 0x7A;
+ public final static int VK_F12 = 0x7B;
+ public final static int VK_F13 = 0x7C;
+ public final static int VK_F14 = 0x7D;
+ public final static int VK_F15 = 0x7E;
+ public final static int VK_F16 = 0x7F;
+ public final static int VK_F17 = 0x80;
+ public final static int VK_F18 = 0x81;
+ public final static int VK_F19 = 0x82;
+ public final static int VK_F20 = 0x83;
+ public final static int VK_F21 = 0x84;
+ public final static int VK_F22 = 0x85;
+ public final static int VK_F23 = 0x86;
+ public final static int VK_F24 = 0x87;
+
+/*
+ * 0x88 - 0x8F : unassigned;
+ */
+
+ public final static int VK_NUMLOCK = 0x90;
+ public final static int VK_SCROLL = 0x91;
+
+/*
+ * NEC PC-9800 kbd definitions
+ */
+ public final static int VK_OEM_NEC_EQUAL = 0x92; // '=' key on numpad
+/*
+ * Fujitsu/OASYS kbd definitions
+ */
+ public final static int VK_OEM_FJ_JISHO = 0x92; // 'Dictionary' key
+ public final static int VK_OEM_FJ_MASSHOU = 0x93; // 'Unregister word' key
+ public final static int VK_OEM_FJ_TOUROKU = 0x94; // 'Register word' key
+ public final static int VK_OEM_FJ_LOYA = 0x95; // 'Left OYAYUBI' key
+ public final static int VK_OEM_FJ_ROYA = 0x96; // 'Right OYAYUBI' key
+
+/*
+ * 0x97 - 0x9F : unassigned
+ */
+
+/*
+ * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys.
+ * Used only as parameters to GetAsyncKeyState() and GetKeyState().
+ * No other API or message will distinguish left and right keys in this way.
+ */
+ public final static int VK_LSHIFT = 0xA0;
+ public final static int VK_RSHIFT = 0xA1;
+ public final static int VK_LCONTROL = 0xA2;
+ public final static int VK_RCONTROL = 0xA3;
+ public final static int VK_LMENU = 0xA4;
+ public final static int VK_RMENU = 0xA5;
+
+ public final static int VK_BROWSER_BACK = 0xA6;
+ public final static int VK_BROWSER_FORWARD = 0xA7;
+ public final static int VK_BROWSER_REFRESH = 0xA8;
+ public final static int VK_BROWSER_STOP = 0xA9;
+ public final static int VK_BROWSER_SEARCH = 0xAA;
+ public final static int VK_BROWSER_FAVORITES = 0xAB;
+ public final static int VK_BROWSER_HOME = 0xAC;
+
+ public final static int VK_VOLUME_MUTE = 0xAD;
+ public final static int VK_VOLUME_DOWN = 0xAE;
+ public final static int VK_VOLUME_UP = 0xAF;
+ public final static int VK_MEDIA_NEXT_TRACK = 0xB0;
+ public final static int VK_MEDIA_PREV_TRACK = 0xB1;
+ public final static int VK_MEDIA_STOP = 0xB2;
+ public final static int VK_MEDIA_PLAY_PAUSE = 0xB3;
+ public final static int VK_LAUNCH_MAIL = 0xB4;
+ public final static int VK_LAUNCH_MEDIA_SELECT = 0xB5;
+ public final static int VK_LAUNCH_APP1 = 0xB6;
+ public final static int VK_LAUNCH_APP2 = 0xB7;
+
+/*
+ * 0xB8 - 0xB9 : reserved
+ */
+
+ public final static int VK_OEM_1 = 0xBA; // ';:' for US
+ public final static int VK_OEM_PLUS = 0xBB; // '+' any country
+ public final static int VK_OEM_COMMA = 0xBC; // ',' any country
+ public final static int VK_OEM_MINUS = 0xBD; // '-' any country
+ public final static int VK_OEM_PERIOD = 0xBE; // '.' any country
+ public final static int VK_OEM_2 = 0xBF; // '/?' for US
+ public final static int VK_OEM_3 = 0xC0; // '`~' for US
+
+/*
+ * 0xC1 - 0xD7 : reserved
+ */
+
+/*
+ * 0xD8 - 0xDA : unassigned
+ */
+
+ public final static int VK_OEM_4 = 0xDB; // '[{' for US
+ public final static int VK_OEM_5 = 0xDC; // '\|' for US
+ public final static int VK_OEM_6 = 0xDD; // ']}' for US
+ public final static int VK_OEM_7 = 0xDE; // ''"' for US
+ public final static int VK_OEM_8 = 0xDF;
+
+/*
+ * 0xE0 : reserved
+ */
+
+/*
+ * Various extended or enhanced keyboards
+ */
+ public final static int VK_OEM_AX = 0xE1; // 'AX' key on Japanese AX kbd
+ public final static int VK_OEM_102 = 0xE2; // "<>" or "\|" on RT 102-key kbd.
+ public final static int VK_ICO_HELP = 0xE3; // Help key on ICO
+ public final static int VK_ICO_00 = 0xE4; // 00 key on ICO
+
+ public final static int VK_PROCESSKEY = 0xE5;
+
+ public final static int VK_ICO_CLEAR = 0xE6;
+
+
+ public final static int VK_PACKET = 0xE7;
+
+/*
+ * 0xE8 : unassigned
+ */
+
+/*
+ * Nokia/Ericsson definitions
+ */
+ public final static int VK_OEM_RESET = 0xE9;
+ public final static int VK_OEM_JUMP = 0xEA;
+ public final static int VK_OEM_PA1 = 0xEB;
+ public final static int VK_OEM_PA2 = 0xEC;
+ public final static int VK_OEM_PA3 = 0xED;
+ public final static int VK_OEM_WSCTRL = 0xEE;
+ public final static int VK_OEM_CUSEL = 0xEF;
+ public final static int VK_OEM_ATTN = 0xF0;
+ public final static int VK_OEM_FINISH = 0xF1;
+ public final static int VK_OEM_COPY = 0xF2;
+ public final static int VK_OEM_AUTO = 0xF3;
+ public final static int VK_OEM_ENLW = 0xF4;
+ public final static int VK_OEM_BACKTAB = 0xF5;
+
+ public final static int VK_ATTN = 0xF6;
+ public final static int VK_CRSEL = 0xF7;
+ public final static int VK_EXSEL = 0xF8;
+ public final static int VK_EREOF = 0xF9;
+ public final static int VK_PLAY = 0xFA;
+ public final static int VK_ZOOM = 0xFB;
+ public final static int VK_NONAME = 0xFC;
+ public final static int VK_PA1 = 0xFD;
+ public final static int VK_OEM_CLEAR = 0xFE;
+
+ public static int mapVirtualKeyToLWJGLCode(int virt_key) {
+ switch (virt_key) {
+ case VK_ESCAPE:
+ return Keyboard.KEY_ESCAPE;
+ case VK_1:
+ return Keyboard.KEY_1;
+ case VK_2:
+ return Keyboard.KEY_2;
+ case VK_3:
+ return Keyboard.KEY_3;
+ case VK_4:
+ return Keyboard.KEY_4;
+ case VK_5:
+ return Keyboard.KEY_5;
+ case VK_6:
+ return Keyboard.KEY_6;
+ case VK_7:
+ return Keyboard.KEY_7;
+ case VK_8:
+ return Keyboard.KEY_8;
+ case VK_9:
+ return Keyboard.KEY_9;
+ case VK_0:
+ return Keyboard.KEY_0;
+ case VK_OEM_MINUS:
+ return Keyboard.KEY_MINUS;
+/* case VK_EQUALS:
+ return Keyboard.KEY_EQUALS;*/
+ case VK_BACK:
+ return Keyboard.KEY_BACK;
+ case VK_TAB:
+ return Keyboard.KEY_TAB;
+ case VK_Q:
+ return Keyboard.KEY_Q;
+ case VK_W:
+ return Keyboard.KEY_W;
+ case VK_E:
+ return Keyboard.KEY_E;
+ case VK_R:
+ return Keyboard.KEY_R;
+ case VK_T:
+ return Keyboard.KEY_T;
+ case VK_Y:
+ return Keyboard.KEY_Y;
+ case VK_U:
+ return Keyboard.KEY_U;
+ case VK_I:
+ return Keyboard.KEY_I;
+ case VK_O:
+ return Keyboard.KEY_O;
+ case VK_P:
+ return Keyboard.KEY_P;
+ case VK_OEM_4:
+ return Keyboard.KEY_LBRACKET;
+ case VK_OEM_6:
+ return Keyboard.KEY_RBRACKET;
+ case VK_RETURN:
+ return Keyboard.KEY_RETURN;
+ case VK_LCONTROL:
+ return Keyboard.KEY_LCONTROL;
+ case VK_A:
+ return Keyboard.KEY_A;
+ case VK_S:
+ return Keyboard.KEY_S;
+ case VK_D:
+ return Keyboard.KEY_D;
+ case VK_F:
+ return Keyboard.KEY_F;
+ case VK_G:
+ return Keyboard.KEY_G;
+ case VK_H:
+ return Keyboard.KEY_H;
+ case VK_J:
+ return Keyboard.KEY_J;
+ case VK_K:
+ return Keyboard.KEY_K;
+ case VK_L:
+ return Keyboard.KEY_L;
+ case VK_OEM_1:
+ return Keyboard.KEY_SEMICOLON;
+ case VK_OEM_7:
+ return Keyboard.KEY_APOSTROPHE;
+ case VK_OEM_3:
+ return Keyboard.KEY_GRAVE;
+ case VK_LSHIFT:
+ return Keyboard.KEY_LSHIFT;
+ case VK_OEM_5:
+ return Keyboard.KEY_BACKSLASH;
+ case VK_Z:
+ return Keyboard.KEY_Z;
+ case VK_X:
+ return Keyboard.KEY_X;
+ case VK_C:
+ return Keyboard.KEY_C;
+ case VK_V:
+ return Keyboard.KEY_V;
+ case VK_B:
+ return Keyboard.KEY_B;
+ case VK_N:
+ return Keyboard.KEY_N;
+ case VK_M:
+ return Keyboard.KEY_M;
+ case VK_OEM_COMMA:
+ return Keyboard.KEY_COMMA;
+ case VK_OEM_PERIOD:
+ return Keyboard.KEY_PERIOD;
+ case VK_OEM_2:
+ return Keyboard.KEY_SLASH;
+ case VK_RSHIFT:
+ return Keyboard.KEY_RSHIFT;
+ case VK_MULTIPLY:
+ return Keyboard.KEY_MULTIPLY;
+ case VK_LMENU:
+ return Keyboard.KEY_LMENU;
+ case VK_SPACE:
+ return Keyboard.KEY_SPACE;
+ case VK_CAPITAL:
+ return Keyboard.KEY_CAPITAL;
+ case VK_F1:
+ return Keyboard.KEY_F1;
+ case VK_F2:
+ return Keyboard.KEY_F2;
+ case VK_F3:
+ return Keyboard.KEY_F3;
+ case VK_F4:
+ return Keyboard.KEY_F4;
+ case VK_F5:
+ return Keyboard.KEY_F5;
+ case VK_F6:
+ return Keyboard.KEY_F6;
+ case VK_F7:
+ return Keyboard.KEY_F7;
+ case VK_F8:
+ return Keyboard.KEY_F8;
+ case VK_F9:
+ return Keyboard.KEY_F9;
+ case VK_F10:
+ return Keyboard.KEY_F10;
+ case VK_NUMLOCK:
+ return Keyboard.KEY_NUMLOCK;
+ case VK_SCROLL:
+ return Keyboard.KEY_SCROLL;
+ case VK_NUMPAD7:
+ return Keyboard.KEY_NUMPAD7;
+ case VK_NUMPAD8:
+ return Keyboard.KEY_NUMPAD8;
+ case VK_NUMPAD9:
+ return Keyboard.KEY_NUMPAD9;
+ case VK_SUBTRACT:
+ return Keyboard.KEY_SUBTRACT;
+ case VK_NUMPAD4:
+ return Keyboard.KEY_NUMPAD4;
+ case VK_NUMPAD5:
+ return Keyboard.KEY_NUMPAD5;
+ case VK_NUMPAD6:
+ return Keyboard.KEY_NUMPAD6;
+ case VK_ADD:
+ return Keyboard.KEY_ADD;
+ case VK_NUMPAD1:
+ return Keyboard.KEY_NUMPAD1;
+ case VK_NUMPAD2:
+ return Keyboard.KEY_NUMPAD2;
+ case VK_NUMPAD3:
+ return Keyboard.KEY_NUMPAD3;
+ case VK_NUMPAD0:
+ return Keyboard.KEY_NUMPAD0;
+ case VK_DECIMAL:
+ return Keyboard.KEY_DECIMAL;
+ case VK_F11:
+ return Keyboard.KEY_F11;
+ case VK_F12:
+ return Keyboard.KEY_F12;
+ case VK_F13:
+ return Keyboard.KEY_F13;
+ case VK_F14:
+ return Keyboard.KEY_F14;
+ case VK_F15:
+ return Keyboard.KEY_F15;
+ case VK_KANA:
+ return Keyboard.KEY_KANA;
+ case VK_CONVERT:
+ return Keyboard.KEY_CONVERT;
+ case VK_NONCONVERT:
+ return Keyboard.KEY_NOCONVERT;
+/* case VK_YEN:
+ return Keyboard.KEY_YEN;
+ case VK_NUMPADEQUALS:
+ return Keyboard.KEY_NUMPADEQUALS;
+ case VK_CIRCUMFLEX:
+ return Keyboard.KEY_CIRCUMFLEX;
+ case VK_AT:
+ return Keyboard.KEY_AT;
+ case VK_COLON:
+ return Keyboard.KEY_COLON;
+ case VK_UNDERLINE:
+ return Keyboard.KEY_UNDERLINE;*/
+ case VK_KANJI:
+ return Keyboard.KEY_KANJI;
+/* case VK_STOP:
+ return Keyboard.KEY_STOP;
+ case VK_AX:
+ return Keyboard.KEY_AX;
+ case VK_UNLABELED:
+ return Keyboard.KEY_UNLABELED;
+ case VK_NUMPADENTER:
+ return Keyboard.KEY_NUMPADENTER;*/
+ case VK_RCONTROL:
+ return Keyboard.KEY_RCONTROL;
+ case VK_SEPARATOR:
+ return Keyboard.KEY_NUMPADCOMMA;
+ case VK_DIVIDE:
+ return Keyboard.KEY_DIVIDE;
+ case VK_PRINT:
+ return Keyboard.KEY_SYSRQ;
+ case VK_RMENU:
+ return Keyboard.KEY_RMENU;
+ case VK_PAUSE:
+ return Keyboard.KEY_PAUSE;
+ case VK_HOME:
+ return Keyboard.KEY_HOME;
+ case VK_UP:
+ return Keyboard.KEY_UP;
+ case VK_PRIOR:
+ return Keyboard.KEY_PRIOR;
+ case VK_LEFT:
+ return Keyboard.KEY_LEFT;
+ case VK_RIGHT:
+ return Keyboard.KEY_RIGHT;
+ case VK_END:
+ return Keyboard.KEY_END;
+ case VK_DOWN:
+ return Keyboard.KEY_DOWN;
+ case VK_NEXT:
+ return Keyboard.KEY_NEXT;
+ case VK_INSERT:
+ return Keyboard.KEY_INSERT;
+ case VK_DELETE:
+ return Keyboard.KEY_DELETE;
+ case VK_LWIN:
+ return Keyboard.KEY_LWIN;
+ case VK_RWIN:
+ return Keyboard.KEY_RWIN;
+ case VK_APPS:
+ return Keyboard.KEY_APPS;
+/* case VK_POWER:
+ return Keyboard.KEY_POWER;*/
+ case VK_SLEEP:
+ return Keyboard.KEY_SLEEP;
+ default:
+ return Keyboard.KEY_NONE;
+ }
+ }
+}
Property changes on: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsKeycodes.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c 2007-04-24 13:22:35 UTC (rev 2800)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsKeyboard.c 2007-04-24 13:40:13 UTC (rev 2801)
@@ -41,6 +41,10 @@
#include <jni.h>
#include "org_lwjgl_opengl_WindowsKeyboard.h"
+JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_GetKeyState(JNIEnv *env, jclass unused, jint virt_key) {
+ return GetKeyState(virt_key);
+}
+
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsKeyboard_MapVirtualKey(JNIEnv *env, jclass unused, jint uCode, jint uMapType) {
return MapVirtualKey(uCode, uMapType);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <eli...@us...> - 2007-04-24 13:22:52
|
Revision: 2800
http://svn.sourceforge.net/java-game-lib/?rev=2800&view=rev
Author: elias_naur
Date: 2007-04-24 06:22:35 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Compile fix
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2007-04-24 09:30:03 UTC (rev 2799)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2007-04-24 13:22:35 UTC (rev 2800)
@@ -105,7 +105,7 @@
* task bar and clicking on it. So we'll use ClipCursor to
* contain it while the cursor is grabbed.
*/
- WindowsDisplay.setupCursorClipping(hwnd, true); // Just clip it to a fullscreen window
+ WindowsDisplay.setupCursorClipping(hwnd); // Just clip it to a fullscreen window
if (getCanvas().getCursor() != blank_cursor) {
cached_cursor = getCanvas().getCursor();
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <eli...@us...> - 2007-04-24 09:30:08
|
Revision: 2799
http://svn.sourceforge.net/java-game-lib/?rev=2799&view=rev
Author: elias_naur
Date: 2007-04-24 02:30:03 -0700 (Tue, 24 Apr 2007)
Log Message:
-----------
Windows: Remove dependency on DirectInput for WindowsMouse used by WindowsDisplay. Keyboard conversion coming up. Reasons:
1. DirectInput is deprecated (http://en.wikipedia.org/wiki/DirectInput). Specifically, Microsoft recommends using regular windows messages for keyboard and mouse input.
2. Not using DirectInput enable us to use the Raw Input JInput plugin to access multiple mice (and keyboards).
3. We're already using windows messages for features DirectInput never supported, so by removing DirectInput dependency, we get rid of some special case code.
4. When we're only using windows messages for input, we're (theoretically) more compatible than with a dependency on a properly working DirectInput.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/Sys.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java
trunk/LWJGL/src/native/common/common_tools.c
trunk/LWJGL/src/native/common/common_tools.h
trunk/LWJGL/src/native/windows/org_lwjgl_input_Cursor.c
trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
Added Paths:
-----------
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputMouse.java
Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2007-04-24 09:30:03 UTC (rev 2799)
@@ -57,7 +57,7 @@
private static final String VERSION = "1.1";
/** Current version of the JNI library */
- static final int JNI_VERSION = 8;
+ static final int JNI_VERSION = 9;
/** The implementation instance to delegate platform specific behavior to */
private final static SysImplementation implementation;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsAWTInput.java 2007-04-24 09:30:03 UTC (rev 2799)
@@ -53,7 +53,7 @@
private Cursor cached_cursor;
private long cached_hwnd;
- private WindowsMouse cached_mouse;
+ private WindowsDirectInputMouse cached_mouse;
// private WindowsKeyboard cached_keyboard;
private boolean has_grabbed;
@@ -96,7 +96,7 @@
cached_keyboard.destroy();
}*/
WindowsDirectInput dinput = WindowsDisplay.createDirectInput();
- cached_mouse = new WindowsMouse(dinput, hwnd);
+ cached_mouse = new WindowsDirectInputMouse(dinput, hwnd);
// cached_keyboard = new WindowsKeyboard(dinput, hwnd);
}
if (isGrabbed()) {
@@ -105,7 +105,7 @@
* task bar and clicking on it. So we'll use ClipCursor to
* contain it while the cursor is grabbed.
*/
- WindowsDisplay.setupCursorClipping(hwnd);
+ WindowsDisplay.setupCursorClipping(hwnd, true); // Just clip it to a fullscreen window
if (getCanvas().getCursor() != blank_cursor) {
cached_cursor = getCanvas().getCursor();
/**
Added: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputMouse.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputMouse.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDirectInputMouse.java 2007-04-24 09:30:03 UTC (rev 2799)
@@ -0,0 +1,353 @@
+/*
+ * Copyright (c) 2002-2004 LWJGL Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'LWJGL' nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.lwjgl.opengl;
+
+/**
+ * This is the Windows implementation of the Mouse.
+ * @author elias_naur
+ */
+
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.nio.CharBuffer;
+
+import org.lwjgl.LWJGLException;
+import org.lwjgl.LWJGLUtil;
+import org.lwjgl.BufferUtils;
+import org.lwjgl.input.Mouse;
+
+final class WindowsDirectInputMouse {
+ private final static int BUFFER_SIZE = 50;
+ private final static int BUTTON_STATES_SIZE = 7;
+
+ private final static int DIMOFS_X = 0;
+ private final static int DIMOFS_Y = 4;
+ private final static int DIMOFS_Z = 8;
+ private final static int DIMOFS_BUTTON0 = 12;
+ private final static int DIMOFS_BUTTON1 = 13;
+ private final static int DIMOFS_BUTTON2 = 14;
+ private final static int DIMOFS_BUTTON3 = 15;
+
+ private final long hwnd;
+ private final WindowsDirectInput dinput;
+ private final WindowsDirectInputDevice mouse;
+
+ private final int mouse_button_count;
+ private final boolean has_wheel;
+
+ private final EventQueue event_queue = new EventQueue(Mouse.EVENT_SIZE);
+ /* Buffer to hold a DIMOUSESTATE */
+ private final ByteBuffer mouse_state;
+ private final IntBuffer temp_data_buffer;
+
+ private final ByteBuffer mouse_event = ByteBuffer.allocate(Mouse.EVENT_SIZE);
+
+ private boolean mouse_grabbed;
+ private byte[] win32_message_button_states = new byte[BUTTON_STATES_SIZE];
+ private int accum_dwheel;
+ private int last_x;
+ private int last_y;
+
+ public WindowsDirectInputMouse(WindowsDirectInput dinput, long hwnd) throws LWJGLException {
+ this.hwnd = hwnd;
+ this.dinput = dinput;
+ try {
+ mouse = dinput.createDevice(WindowsDirectInput.MOUSE_TYPE);
+ try {
+ mouse.setDataFormat(WindowsDirectInput.MOUSE_TYPE);
+ mouse.setBufferSize(BUFFER_SIZE);
+ if (!acquireNonExclusive())
+ throw new LWJGLException("Failed to acquire mouse non-exclusive");
+ } catch (LWJGLException e) {
+ mouse.release();
+ throw e;
+ }
+ } catch (LWJGLException e) {
+ dinput.release();
+ throw e;
+ }
+ MouseEnumerator enumerator = new MouseEnumerator();
+ mouse.enumObjects(enumerator);
+ this.mouse_button_count = Math.min(enumerator.getButtonCount(), 4);
+ this.has_wheel = enumerator.hasWheel();
+ mouse_state = BufferUtils.createByteBuffer(3*4 + 4);
+ temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*WindowsDirectInputDevice.DATA_SIZE);
+ }
+
+ public boolean hasWheel() {
+ return has_wheel;
+ }
+
+ public int getButtonCount() {
+ return mouse_button_count;
+ }
+
+ private boolean acquire(int flags) {
+ try {
+ mouse.setCooperateLevel(hwnd, flags);
+ mouse.acquire();
+ return true;
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to acquire mouse: " + e);
+ return false;
+ }
+ }
+
+ private boolean acquireNonExclusive() {
+ return acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND) ||
+ acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_BACKGROUND);
+ }
+
+ public void destroy() {
+ mouse.unacquire();
+ mouse.release();
+ dinput.release();
+ }
+
+ public void poll(IntBuffer coord_buffer, ByteBuffer buttons) {
+ int ret = mouse.acquire();
+ if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
+ return;
+ mouse.poll();
+ for (int i = 0; i < coord_buffer.remaining(); i++)
+ coord_buffer.put(coord_buffer.position() + i, 0);
+ mouse_state.clear();
+ ret = mouse.getDeviceState(mouse_state);
+ int mouse_state_lx = mouse_state.getInt();
+ int mouse_state_ly = mouse_state.getInt();
+ int mouse_state_lz = mouse_state.getInt();
+ int num_buttons = mouse_button_count;
+ if (mouse_grabbed || ret == WindowsDirectInput.DI_OK) {
+ if (ret != WindowsDirectInput.DI_OK) {
+ LWJGLUtil.log("Error getting mouse state: (0x" + Integer.toHexString(ret) + ")");
+ return;
+ }
+
+ coord_buffer.put(coord_buffer.position() + 2, mouse_state_lz);
+ if (num_buttons > buttons.remaining())
+ num_buttons = buttons.remaining();
+ for (int j = 0; j < num_buttons; j++) {
+ byte button_state = (mouse_state.get() & 0x80) != 0 ? (byte)1 : (byte)0;
+ buttons.put(buttons.position() + j, button_state);
+ // track the button state in the windows message buffer state array
+ // to get accurate button information when releasing a grab
+ win32_message_button_states[j] = button_state;
+ }
+ } else {
+ coord_buffer.put(coord_buffer.position() + 2, accum_dwheel);
+ if (num_buttons > win32_message_button_states.length)
+ num_buttons = win32_message_button_states.length;
+ for (int j = 0; j < num_buttons; j++) {
+ buttons.put(buttons.position() + j, win32_message_button_states[j]);
+ }
+ }
+ accum_dwheel = 0;
+ if (mouse_grabbed) {
+ coord_buffer.put(coord_buffer.position() + 0, mouse_state_lx);
+ coord_buffer.put(coord_buffer.position() + 1, -mouse_state_ly);
+ } else {
+ coord_buffer.put(coord_buffer.position() + 0, last_x);
+ coord_buffer.put(coord_buffer.position() + 1, last_y);
+ }
+ }
+
+ private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
+ mouse_event.clear();
+ mouse_event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz).putLong(nanos);
+ mouse_event.flip();
+ event_queue.putEvent(mouse_event);
+ }
+
+ private void putMouseEvent(byte button, byte state, int dz, long nanos) {
+ if (mouse_grabbed)
+ putMouseEventWithCoords(button, state, 0, 0, dz, nanos);
+ else
+ putMouseEventWithCoords(button, state, last_x, last_y, dz, nanos);
+ }
+
+ private void copyDXEvents(IntBuffer buffer) {
+ int buffer_index = 0;
+ int dx = 0, dy = 0, dwheel = 0;
+ byte button_state;
+ int i;
+ long nanos = 0;
+ while (buffer.hasRemaining()) {
+ int dwOfs = buffer.get();
+ int dwData = buffer.get();
+ long dwTimeStamp = ((long)buffer.get()) & 0xFFFFFFFF;
+ nanos = dwTimeStamp*1000000;
+ button_state = (dwData & 0x80) != 0 ? (byte)1 : (byte)0;
+ switch (dwOfs) {
+ case DIMOFS_BUTTON0:
+ putMouseEventWithCoords((byte)0, button_state, dx, -dy, dwheel, nanos);
+ dx = dy = dwheel = 0;
+ break;
+ case DIMOFS_BUTTON1:
+ putMouseEventWithCoords((byte)1, button_state, dx, -dy, dwheel, nanos);
+ dx = dy = dwheel = 0;
+ break;
+ case DIMOFS_BUTTON2:
+ putMouseEventWithCoords((byte)2, button_state, dx, -dy, dwheel, nanos);
+ dx = dy = dwheel = 0;
+ break;
+ case DIMOFS_BUTTON3:
+ putMouseEventWithCoords((byte)3, button_state, dx, -dy, dwheel, nanos);
+ dx = dy = dwheel = 0;
+ break;
+ case DIMOFS_X:
+ dx += dwData;
+ break;
+ case DIMOFS_Y:
+ dy += dwData;
+ break;
+ case DIMOFS_Z:
+ dwheel += dwData;
+ break;
+ }
+ }
+ if (dx != 0 || dy != 0 || dwheel != 0)
+ putMouseEventWithCoords((byte)-1, (byte)0, dx, -dy, dwheel, nanos);
+ }
+
+ private void readDXBuffer() {
+ int ret = mouse.acquire();
+ if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
+ return;
+ mouse.poll();
+ temp_data_buffer.clear();
+ ret = mouse.getDeviceData(temp_data_buffer);
+
+ switch (ret) {
+ case WindowsDirectInput.DI_OK:
+ break;
+ case WindowsDirectInput.DI_BUFFEROVERFLOW:
+ LWJGLUtil.log("Mouse buffer overflowed");
+ break;
+ case WindowsDirectInput.DIERR_INPUTLOST:
+ LWJGLUtil.log("Mouse input lost");
+ break;
+ case WindowsDirectInput.DIERR_NOTACQUIRED:
+ LWJGLUtil.log("Mouse not acquired");
+ break;
+ default:
+ LWJGLUtil.log("unknown mouse error (" + Integer.toHexString(ret) + ")");
+ break;
+ }
+ }
+
+ public final void flush() {
+ readDXBuffer();
+ temp_data_buffer.clear();
+ }
+
+ public void read(ByteBuffer buffer) {
+ readDXBuffer();
+ if (mouse_grabbed) {
+ temp_data_buffer.flip();
+ copyDXEvents(temp_data_buffer);
+ }
+ event_queue.copyEvents(buffer);
+ }
+
+ public void grab(boolean grab) {
+ if(grab) {
+ if (!mouse_grabbed) {
+ flush();
+ mouse_grabbed = true;
+ mouse.unacquire();
+ if (!acquire(WindowsDirectInputDevice.DISCL_EXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND))
+ LWJGLUtil.log("Failed to reset cooperative mode");
+ }
+ } else {
+ if (mouse_grabbed) {
+ mouse_grabbed = false;
+ mouse.unacquire();
+ acquireNonExclusive();
+ }
+ }
+ event_queue.clearEvents();
+ }
+
+ public void handleMouseScrolled(int event_dwheel, long millis) {
+ accum_dwheel += event_dwheel;
+ putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000);
+ }
+
+ public void handleMouseMoved(int x, int y, long millis) {
+ int dx;
+ int dy;
+ dx = x - last_x;
+ dy = y - last_y;
+ last_x = x;
+ last_y = y;
+ long nanos = millis*1000000;
+ if (mouse_grabbed) {
+ putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos);
+ } else {
+ putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0, nanos);
+ }
+ }
+
+ public void handleMouseButton(byte button, byte state, long millis) {
+ putMouseEvent(button, state, 0, millis*1000000);
+ if (button < BUTTON_STATES_SIZE)
+ win32_message_button_states[button] = state != 0 ? (byte)1 : (byte)0;
+ }
+
+ private static class MouseEnumerator implements WindowsDirectInputDeviceObjectCallback {
+ private int button_count;
+ private boolean has_wheel;
+
+ public int getButtonCount() {
+ return button_count;
+ }
+
+ public boolean hasWheel() {
+ return has_wheel;
+ }
+
+ public boolean nextObject(int type, String name) {
+ LWJGLUtil.log("Found mouse object: " + name);
+ switch (type) {
+ case WindowsDirectInputDevice.GUID_ZAxis:
+ has_wheel = true;
+ break;
+ case WindowsDirectInputDevice.GUID_Button:
+ button_count++;
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+ }
+}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2007-04-24 09:30:03 UTC (rev 2799)
@@ -44,6 +44,7 @@
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.BufferUtils;
import org.lwjgl.input.Cursor;
final class WindowsDisplay implements DisplayImplementation {
@@ -85,7 +86,10 @@
private final static int SC_CONTEXTHELP = 0xF180;
private final static int SC_SEPARATOR = 0xF00F;
- private final static int SM_CXCURSOR = 13;
+ final static int SM_CXCURSOR = 13;
+ final static int SM_CYCURSOR = 14;
+ final static int SM_CMOUSEBUTTONS = 43;
+ final static int SM_MOUSEWHEELPRESENT = 75;
private final static int SIZE_RESTORED = 0;
private final static int SIZE_MINIMIZED = 1;
@@ -99,9 +103,14 @@
private final static int SW_SHOWDEFAULT = 10;
private final static int SW_RESTORE = 9;
+ private final static IntBuffer rect_buffer = BufferUtils.createIntBuffer(4);
+ private final static Rect rect = new Rect();
+ private final static Rect rect2 = new Rect();
private static WindowsDisplay current_display;
+ private static boolean cursor_clipped;
private WindowsDisplayPeerInfo peer_info;
+ private Object current_cursor;
private WindowsKeyboard keyboard;
private WindowsMouse mouse;
@@ -141,13 +150,38 @@
public void destroyWindow() {
nDestroyWindow();
- if (isFullscreen)
- resetCursorClipping();
+ resetCursorClipping();
}
private static native void nDestroyWindow();
- static native void resetCursorClipping();
- static native void setupCursorClipping(long hwnd) throws LWJGLException;
+ static void resetCursorClipping() {
+ if (cursor_clipped) {
+ try {
+ clipCursor(0, null);
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to reset cursor clipping: " + e);
+ }
+ cursor_clipped = false;
+ }
+ }
+ private static void getGlobalClientRect(long hwnd, Rect rect) {
+ rect_buffer.put(0, 0).put(1, 0);
+ clientToScreen(hwnd, rect_buffer);
+ int offset_x = rect_buffer.get(0);
+ int offset_y = rect_buffer.get(1);
+ getClientRect(hwnd, rect_buffer);
+ rect.copyFromBuffer(rect_buffer);
+ rect.offset(offset_x, offset_y);
+ }
+
+ static void setupCursorClipping(long hwnd) throws LWJGLException {
+ cursor_clipped = true;
+ getGlobalClientRect(hwnd, rect);
+ rect.copyToBuffer(rect_buffer);
+ clipCursor(hwnd, rect_buffer);
+ }
+ private static native void clipCursor(long hwnd, IntBuffer rect) throws LWJGLException;
+
public void switchDisplayMode(DisplayMode mode) throws LWJGLException {
nSwitchDisplayMode(mode);
current_mode = mode;
@@ -330,11 +364,12 @@
}
public void createMouse() throws LWJGLException {
- mouse = new WindowsMouse(createDirectInput(), getHwnd());
+ mouse = new WindowsMouse(getHwnd());
}
public void destroyMouse() {
- mouse.destroy();
+ if (mouse != null)
+ mouse.destroy();
mouse = null;
}
@@ -349,7 +384,12 @@
}
public void grabMouse(boolean grab) {
- mouse.grab(grab);
+ mouse.grab(grab, shouldGrab());
+ try {
+ updateCursor();
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to update cursor: " + e);
+ }
}
public int getNativeCursorCapabilities() {
@@ -357,12 +397,27 @@
}
public void setCursorPosition(int x, int y) {
- nSetCursorPosition(x, y, isFullscreen);
+ getGlobalClientRect(getHwnd(), rect);
+ int transformed_x = rect.left + x;
+ int transformed_y = rect.bottom - 1 - y;
+ nSetCursorPosition(transformed_x, transformed_y);
+ setMousePosition(x, y);
}
- private static native void nSetCursorPosition(int x, int y, boolean fullscreen);
+ private static native void nSetCursorPosition(int x, int y);
- public native void setNativeCursor(Object handle) throws LWJGLException;
+ public void setNativeCursor(Object handle) throws LWJGLException {
+ current_cursor = handle;
+ updateCursor();
+ }
+ private void updateCursor() throws LWJGLException {
+ if (mouse != null && mouse.isGrabbed())
+ nSetNativeCursor(getHwnd(), mouse.getBlankCursor());
+ else
+ nSetNativeCursor(getHwnd(), current_cursor);
+ }
+ static native void nSetNativeCursor(long hwnd, Object handle) throws LWJGLException;
+
public int getMinCursorSize() {
return getSystemMetrics(SM_CXCURSOR);
}
@@ -371,11 +426,31 @@
return getSystemMetrics(SM_CXCURSOR);
}
- public native int getSystemMetrics(int index);
+ static native int getSystemMetrics(int index);
private static native long getDllInstance();
private static native long getHwnd();
+ private static native long getDesktopWindow();
+ static void centerCursor(long hwnd) {
+ getGlobalClientRect(getHwnd(), rect);
+ int local_offset_x = rect.left;
+ int local_offset_y = rect.top;
+ getGlobalClientRect(getDesktopWindow(), rect2);
+ Rect.intersect(rect, rect2, rect);
+ int center_x = (rect.left + rect.right)/2;
+ int center_y = (rect.top + rect.bottom)/2;
+ nSetCursorPosition(center_x, center_y);
+ int local_x = center_x - local_offset_x;
+ int local_y = center_y - local_offset_y;
+ if (current_display != null)
+ current_display.setMousePosition(local_x, transformY(getHwnd(), local_y));
+ }
+ private void setMousePosition(int x, int y) {
+ if (mouse != null)
+ mouse.setPosition(x, y);
+ }
+
/* Keyboard */
public void createKeyboard() throws LWJGLException {
keyboard = new WindowsKeyboard(createDirectInput(), getHwnd());
@@ -398,13 +473,21 @@
// public native int isStateKeySet(int key);
- public native ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
+ public static native ByteBuffer nCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
public Object createCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
+ return doCreateCursor(width, height, xHotspot, yHotspot, numImages, images, delays);
+ }
+
+ static Object doCreateCursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException {
return nCreateCursor(width, height, xHotspot, yHotspot, numImages, images, images.position(), delays, delays != null ? delays.position() : -1);
}
- public native void destroyCursor(Object cursorHandle);
+ public void destroyCursor(Object cursorHandle) {
+ doDestroyCursor(cursorHandle);
+ }
+ static native void doDestroyCursor(Object cursorHandle);
+
public int getPbufferCapabilities() {
try {
// Return the capabilities of a minimum pixel format
@@ -483,9 +566,13 @@
mouse.handleMouseButton((byte)button, (byte)state, millis);
}
+ private boolean shouldGrab() {
+ return !isMinimized && isFocused;
+ }
+
private void handleMouseMoved(int x, int y, long millis) {
if (mouse != null)
- mouse.handleMouseMoved(x, y, millis);
+ mouse.handleMouseMoved(x, y, millis, shouldGrab());
}
private void handleMouseScrolled(int amount, long millis) {
@@ -493,8 +580,16 @@
mouse.handleMouseScrolled(amount, millis);
}
- private static native int transformY(long hwnd, int y);
+ private static native void getClientRect(long hwnd, IntBuffer rect);
+ private static int transformY(long hwnd, int y) {
+ getClientRect(hwnd, rect_buffer);
+ rect.copyFromBuffer(rect_buffer);
+ return (rect.bottom - rect.top) - 1 - y;
+ }
+
+ private static native void clientToScreen(long hwnd, IntBuffer point);
+
private static boolean handleMessage(long hwnd, int msg, long wParam, long lParam, long millis) {
if (current_display != null)
return current_display.doHandleMessage(hwnd, msg, wParam, lParam, millis);
@@ -503,12 +598,14 @@
}
private boolean doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) {
- if (isFullscreen && !isMinimized && isFocused) {
+ if ((isFullscreen || (mouse != null && mouse.isGrabbed())) && !isMinimized && isFocused) {
try {
setupCursorClipping(getHwnd());
} catch (LWJGLException e) {
LWJGLUtil.log("setupCursorClipping failed: " + e.getMessage());
}
+ } else {
+ resetCursorClipping();
}
switch (msg) {
// disable screen saver and monitor power down messages which wreak havoc
@@ -602,4 +699,40 @@
public int getHeight() {
return Display.getDisplayMode().getHeight();
}
+
+ private static final class Rect {
+ public int top;
+ public int bottom;
+ public int left;
+ public int right;
+
+ public void copyToBuffer(IntBuffer buffer) {
+ buffer.put(0, top).put(1, bottom).put(2, left).put(3, right);
+ }
+
+ public void copyFromBuffer(IntBuffer buffer) {
+ top = buffer.get(0);
+ bottom = buffer.get(1);
+ left = buffer.get(2);
+ right = buffer.get(3);
+ }
+
+ public void offset(int offset_x, int offset_y) {
+ left += offset_x;
+ right += offset_x;
+ top += offset_y;
+ bottom += offset_y;
+ }
+
+ public static void intersect(Rect r1, Rect r2, Rect dst) {
+ dst.top = Math.max(r1.top, r2.top);
+ dst.bottom = Math.min(r1.bottom, r2.bottom);
+ dst.left = Math.max(r1.left, r2.left);
+ dst.right = Math.min(r1.right, r2.right);
+ }
+
+ public String toString() {
+ return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right;
+ }
+ }
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsMouse.java 2007-04-24 09:30:03 UTC (rev 2799)
@@ -44,65 +44,46 @@
import org.lwjgl.LWJGLUtil;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Mouse;
+import org.lwjgl.input.Cursor;
final class WindowsMouse {
- private final static int BUFFER_SIZE = 50;
- private final static int BUTTON_STATES_SIZE = 7;
-
- private final static int DIMOFS_X = 0;
- private final static int DIMOFS_Y = 4;
- private final static int DIMOFS_Z = 8;
- private final static int DIMOFS_BUTTON0 = 12;
- private final static int DIMOFS_BUTTON1 = 13;
- private final static int DIMOFS_BUTTON2 = 14;
- private final static int DIMOFS_BUTTON3 = 15;
-
private final long hwnd;
- private final WindowsDirectInput dinput;
- private final WindowsDirectInputDevice mouse;
private final int mouse_button_count;
private final boolean has_wheel;
private final EventQueue event_queue = new EventQueue(Mouse.EVENT_SIZE);
- /* Buffer to hold a DIMOUSESTATE */
- private final ByteBuffer mouse_state;
- private final IntBuffer temp_data_buffer;
private final ByteBuffer mouse_event = ByteBuffer.allocate(Mouse.EVENT_SIZE);
+ private final Object blank_cursor;
private boolean mouse_grabbed;
- private byte[] win32_message_button_states = new byte[BUTTON_STATES_SIZE];
+ private byte[] button_states;
+ private int accum_dx;
+ private int accum_dy;
private int accum_dwheel;
private int last_x;
private int last_y;
- public WindowsMouse(WindowsDirectInput dinput, long hwnd) throws LWJGLException {
+ public WindowsMouse(long hwnd) throws LWJGLException {
this.hwnd = hwnd;
- this.dinput = dinput;
- try {
- mouse = dinput.createDevice(WindowsDirectInput.MOUSE_TYPE);
- try {
- mouse.setDataFormat(WindowsDirectInput.MOUSE_TYPE);
- mouse.setBufferSize(BUFFER_SIZE);
- if (!acquireNonExclusive())
- throw new LWJGLException("Failed to acquire mouse non-exclusive");
- } catch (LWJGLException e) {
- mouse.release();
- throw e;
- }
- } catch (LWJGLException e) {
- dinput.release();
- throw e;
- }
- MouseEnumerator enumerator = new MouseEnumerator();
- mouse.enumObjects(enumerator);
- this.mouse_button_count = Math.min(enumerator.getButtonCount(), 4);
- this.has_wheel = enumerator.hasWheel();
- mouse_state = BufferUtils.createByteBuffer(3*4 + 4);
- temp_data_buffer = BufferUtils.createIntBuffer(BUFFER_SIZE*WindowsDirectInputDevice.DATA_SIZE);
+ this.mouse_button_count = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CMOUSEBUTTONS);
+ this.has_wheel = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_MOUSEWHEELPRESENT) != 0;
+ this.blank_cursor = createBlankCursor();
+ this.button_states = new byte[mouse_button_count];
}
+ private Object createBlankCursor() throws LWJGLException {
+ int width = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CXCURSOR);
+ int height = WindowsDisplay.getSystemMetrics(WindowsDisplay.SM_CYCURSOR);
+ IntBuffer pixels = BufferUtils.createIntBuffer(width*height);
+ return WindowsDisplay.doCreateCursor(width, height, 0, 0, 1, pixels, null);
+ }
+
+ public boolean isGrabbed() {
+ return mouse_grabbed;
+ }
+
public boolean hasWheel() {
return has_wheel;
}
@@ -111,73 +92,24 @@
return mouse_button_count;
}
- private boolean acquire(int flags) {
- try {
- mouse.setCooperateLevel(hwnd, flags);
- mouse.acquire();
- return true;
- } catch (LWJGLException e) {
- LWJGLUtil.log("Failed to acquire mouse: " + e);
- return false;
- }
- }
-
- private boolean acquireNonExclusive() {
- return acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND) ||
- acquire(WindowsDirectInputDevice.DISCL_NONEXCLUSIVE | WindowsDirectInputDevice.DISCL_BACKGROUND);
- }
-
- public void destroy() {
- mouse.unacquire();
- mouse.release();
- dinput.release();
- }
-
public void poll(IntBuffer coord_buffer, ByteBuffer buttons) {
- int ret = mouse.acquire();
- if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
- return;
- mouse.poll();
for (int i = 0; i < coord_buffer.remaining(); i++)
coord_buffer.put(coord_buffer.position() + i, 0);
- mouse_state.clear();
- ret = mouse.getDeviceState(mouse_state);
- int mouse_state_lx = mouse_state.getInt();
- int mouse_state_ly = mouse_state.getInt();
- int mouse_state_lz = mouse_state.getInt();
int num_buttons = mouse_button_count;
- if (mouse_grabbed || ret == WindowsDirectInput.DI_OK) {
- if (ret != WindowsDirectInput.DI_OK) {
- LWJGLUtil.log("Error getting mouse state: (0x" + Integer.toHexString(ret) + ")");
- return;
- }
-
- coord_buffer.put(coord_buffer.position() + 2, mouse_state_lz);
- if (num_buttons > buttons.remaining())
- num_buttons = buttons.remaining();
- for (int j = 0; j < num_buttons; j++) {
- byte button_state = (mouse_state.get() & 0x80) != 0 ? (byte)1 : (byte)0;
- buttons.put(buttons.position() + j, button_state);
- // track the button state in the windows message buffer state array
- // to get accurate button information when releasing a grab
- win32_message_button_states[j] = button_state;
- }
- } else {
- coord_buffer.put(coord_buffer.position() + 2, accum_dwheel);
- if (num_buttons > win32_message_button_states.length)
- num_buttons = win32_message_button_states.length;
- for (int j = 0; j < num_buttons; j++) {
- buttons.put(buttons.position() + j, win32_message_button_states[j]);
- }
+ coord_buffer.put(coord_buffer.position() + 2, accum_dwheel);
+ if (num_buttons > button_states.length)
+ num_buttons = button_states.length;
+ for (int j = 0; j < num_buttons; j++) {
+ buttons.put(buttons.position() + j, button_states[j]);
}
- accum_dwheel = 0;
- if (mouse_grabbed) {
- coord_buffer.put(coord_buffer.position() + 0, mouse_state_lx);
- coord_buffer.put(coord_buffer.position() + 1, -mouse_state_ly);
+ if (isGrabbed()) {
+ coord_buffer.put(coord_buffer.position() + 0, accum_dx);
+ coord_buffer.put(coord_buffer.position() + 1, accum_dy);
} else {
coord_buffer.put(coord_buffer.position() + 0, last_x);
coord_buffer.put(coord_buffer.position() + 1, last_y);
}
+ accum_dx = accum_dy = accum_dwheel = 0;
}
private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
@@ -194,104 +126,30 @@
putMouseEventWithCoords(button, state, last_x, last_y, dz, nanos);
}
- private void copyDXEvents(IntBuffer buffer) {
- int buffer_index = 0;
- int dx = 0, dy = 0, dwheel = 0;
- byte button_state;
- int i;
- long nanos = 0;
- while (buffer.hasRemaining()) {
- int dwOfs = buffer.get();
- int dwData = buffer.get();
- long dwTimeStamp = ((long)buffer.get()) & 0xFFFFFFFF;
- nanos = dwTimeStamp*1000000;
- button_state = (dwData & 0x80) != 0 ? (byte)1 : (byte)0;
- switch (dwOfs) {
- case DIMOFS_BUTTON0:
- putMouseEventWithCoords((byte)0, button_state, dx, -dy, dwheel, nanos);
- dx = dy = dwheel = 0;
- break;
- case DIMOFS_BUTTON1:
- putMouseEventWithCoords((byte)1, button_state, dx, -dy, dwheel, nanos);
- dx = dy = dwheel = 0;
- break;
- case DIMOFS_BUTTON2:
- putMouseEventWithCoords((byte)2, button_state, dx, -dy, dwheel, nanos);
- dx = dy = dwheel = 0;
- break;
- case DIMOFS_BUTTON3:
- putMouseEventWithCoords((byte)3, button_state, dx, -dy, dwheel, nanos);
- dx = dy = dwheel = 0;
- break;
- case DIMOFS_X:
- dx += dwData;
- break;
- case DIMOFS_Y:
- dy += dwData;
- break;
- case DIMOFS_Z:
- dwheel += dwData;
- break;
- }
- }
- if (dx != 0 || dy != 0 || dwheel != 0)
- putMouseEventWithCoords((byte)-1, (byte)0, dx, -dy, dwheel, nanos);
+ public void read(ByteBuffer buffer) {
+ event_queue.copyEvents(buffer);
}
- private void readDXBuffer() {
- int ret = mouse.acquire();
- if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
- return;
- mouse.poll();
- temp_data_buffer.clear();
- ret = mouse.getDeviceData(temp_data_buffer);
-
- switch (ret) {
- case WindowsDirectInput.DI_OK:
- break;
- case WindowsDirectInput.DI_BUFFEROVERFLOW:
- LWJGLUtil.log("Mouse buffer overflowed");
- break;
- case WindowsDirectInput.DIERR_INPUTLOST:
- LWJGLUtil.log("Mouse input lost");
- break;
- case WindowsDirectInput.DIERR_NOTACQUIRED:
- LWJGLUtil.log("Mouse not acquired");
- break;
- default:
- LWJGLUtil.log("unknown mouse error (" + Integer.toHexString(ret) + ")");
- break;
- }
+ public Object getBlankCursor() {
+ return blank_cursor;
}
- public final void flush() {
- readDXBuffer();
- temp_data_buffer.clear();
- }
-
- public void read(ByteBuffer buffer) {
- readDXBuffer();
- if (mouse_grabbed) {
- temp_data_buffer.flip();
- copyDXEvents(temp_data_buffer);
- }
- event_queue.copyEvents(buffer);
- }
-
- public void grab(boolean grab) {
- if(grab) {
+ public void grab(boolean grab, boolean should_center) {
+ if (grab) {
if (!mouse_grabbed) {
- flush();
mouse_grabbed = true;
- mouse.unacquire();
- if (!acquire(WindowsDirectInputDevice.DISCL_EXCLUSIVE | WindowsDirectInputDevice.DISCL_FOREGROUND))
- LWJGLUtil.log("Failed to reset cooperative mode");
+ try {
+ WindowsDisplay.setupCursorClipping(hwnd);
+ } catch (LWJGLException e) {
+ LWJGLUtil.log("Failed to setup cursor clipping: " + e);
+ }
+ if (should_center)
+ centerCursor();
}
} else {
if (mouse_grabbed) {
mouse_grabbed = false;
- mouse.unacquire();
- acquireNonExclusive();
+ WindowsDisplay.resetCursorClipping();
}
}
event_queue.clearEvents();
@@ -302,52 +160,41 @@
putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000);
}
- public void handleMouseMoved(int x, int y, long millis) {
- int dx;
- int dy;
- dx = x - last_x;
- dy = y - last_y;
- last_x = x;
- last_y = y;
- long nanos = millis*1000000;
- if (mouse_grabbed) {
- putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos);
- } else {
- putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0, nanos);
- }
+ private void centerCursor() {
+ WindowsDisplay.centerCursor(hwnd);
}
- public void handleMouseButton(byte button, byte state, long millis) {
- putMouseEvent(button, state, 0, millis*1000000);
- if (button < BUTTON_STATES_SIZE)
- win32_message_button_states[button] = state != 0 ? (byte)1 : (byte)0;
+ public void setPosition(int x, int y) {
+ this.last_x = x;
+ this.last_y = y;
}
- private static class MouseEnumerator implements WindowsDirectInputDeviceObjectCallback {
- private int button_count;
- private boolean has_wheel;
+ public void destroy() {
+ WindowsDisplay.doDestroyCursor(blank_cursor);
+ }
- public int getButtonCount() {
- return button_count;
- }
-
- public boolean hasWheel() {
- return has_wheel;
- }
-
- public boolean nextObject(int type, String name) {
- LWJGLUtil.log("Found mouse object: " + name);
- switch (type) {
- case WindowsDirectInputDevice.GUID_ZAxis:
- has_wheel = true;
- break;
- case WindowsDirectInputDevice.GUID_Button:
- button_count++;
- break;
- default:
- break;
+ public void handleMouseMoved(int x, int y, long millis, boolean should_center) {
+ int dx = x - last_x;
+ int dy = y - last_y;
+ if (dx != 0 || dy != 0) {
+ accum_dx += dx;
+ accum_dy += dy;
+ last_x = x;
+ last_y = y;
+ long nanos = millis*1000000;
+ if (mouse_grabbed) {
+ putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos);
+ if (should_center)
+ centerCursor();
+ } else {
+ putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0, nanos);
}
- return true;
}
}
+
+ public void handleMouseButton(byte button, byte state, long millis) {
+ putMouseEvent(button, state, 0, millis*1000000);
+ if (button < button_states.length)
+ button_states[button] = state != 0 ? (byte)1 : (byte)0;
+ }
}
Modified: trunk/LWJGL/src/native/common/common_tools.c
===================================================================
--- trunk/LWJGL/src/native/common/common_tools.c 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/native/common/common_tools.c 2007-04-24 09:30:03 UTC (rev 2799)
@@ -141,6 +141,13 @@
throwGeneralException(env, "org/lwjgl/fmod3/FMODException", err);
}
+void throwFormattedRuntimeException(JNIEnv * env, const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ throwFormattedGeneralException(env, "java/lang/RuntimeException", format, ap);
+ va_end(ap);
+}
+
void throwFormattedException(JNIEnv * env, const char *format, ...) {
va_list ap;
va_start(ap, format);
Modified: trunk/LWJGL/src/native/common/common_tools.h
===================================================================
--- trunk/LWJGL/src/native/common/common_tools.h 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/native/common/common_tools.h 2007-04-24 09:30:03 UTC (rev 2799)
@@ -130,6 +130,7 @@
extern bool isDebugEnabled(void);
extern jstring getVersionString(JNIEnv *env);
extern void throwGeneralException(JNIEnv * env, const char *exception_name, const char * err);
+extern void throwFormattedRuntimeException(JNIEnv * env, const char *format, ...);
extern void throwException(JNIEnv *env, const char *msg);
extern void throwFormattedException(JNIEnv * env, const char *format, ...);
extern void throwFMODException(JNIEnv * env, const char * err);
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_input_Cursor.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_input_Cursor.c 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_input_Cursor.c 2007-04-24 09:30:03 UTC (rev 2799)
@@ -45,7 +45,7 @@
#include "common_tools.h"
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nCreateCursor
-(JNIEnv *env, jobject self, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
+(JNIEnv *env, jclass unused, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
{
unsigned char col0, col1, col2, col3, col4, col5, col6, col7;
unsigned char mask;
@@ -154,8 +154,8 @@
return handle_buffer;
}
-JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_destroyCursor
-(JNIEnv *env, jobject self, jobject handle_buffer)
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_doDestroyCursor
+(JNIEnv *env, jclass unused, jobject handle_buffer)
{
HCURSOR *cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
DestroyCursor(*cursor_handle);
Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c
===================================================================
--- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2007-04-23 20:50:44 UTC (rev 2798)
+++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2007-04-24 09:30:03 UTC (rev 2799)
@@ -210,19 +210,65 @@
freeSmallIcon();
}
-JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_resetCursorClipping(JNIEnv *env, jclass unused) {
- ClipCursor(NULL);
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_clientToScreen(JNIEnv *env, jclass unused, jlong hwnd_int, jobject buffer_handle) {
+ HWND hwnd = (HWND)(INT_PTR)hwnd_int;
+ POINT point;
+ jint *buffer = (jint *)(*env)->GetDirectBufferAddress(env, buffer_handle);
+ jlong size = (*env)->GetDirectBufferCapacity(env, buffer_handle);
+ if (size < 2) {
+ throwFormattedRuntimeException(env, "Buffer size < 2", size);
+ return;
+ }
+ point.x = buffer[0];
+ point.y = buffer[1];
+ ClientToScreen(hwnd, &point);
+ buffer[0] = point.x;
+ buffer[1] = point.y;
}
-JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_setupCursorClipping(JNIEnv *env, jclass unused, jlong hwnd_ptr) {
- HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
- RECT hwnd_client;
- if (hwnd != NULL && GetWindowRect(hwnd, &hwnd_client) != 0) {
- if (ClipCursor(&hwnd_client) == 0)
- throwFormattedException(env, "ClipCursor failed (%d)", GetLastError());
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getDesktopWindow(JNIEnv *env, jclass unused) {
+ return (INT_PTR)GetDesktopWindow();
+}
+
+static void copyBufferToRect(JNIEnv *env, jobject buffer_handle, RECT *rect) {
+ jint *buffer = (jint *)(*env)->GetDirectBufferAddress(env, buffer_handle);
+ jlong size = (*env)->GetDirectBufferCapacity(env, buffer_handle);
+ if (size < 4) {
+ throwFormattedRuntimeException(env, "Buffer size < 4", size);
+ return;
}
+ rect->top = buffer[0];
+ rect->bottom = buffer[1];
+ rect->left = buffer[2];
+ rect->right = buffer[3];
}
+static void copyRectToBuffer(JNIEnv *env, RECT *rect, jobject buffer_handle) {
+ jint *buffer = (jint *)(*env)->GetDirectBufferAddress(env, buffer_handle);
+ jlong size = (*env)->GetDirectBufferCapacity(env, buffer_handle);
+ if (size < 4) {
+ throwFormattedRuntimeException(env, "Buffer size < 4", size);
+ return;
+ }
+ buffer[0] = rect->top;
+ buffer[1] = rect->bottom;
+ buffer[2] = rect->left;
+ buffer[3] = rect->right;
+}
+
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_clipCursor(JNIEnv *env, jclass unused, jlong hwnd_ptr, jobject handle_buffer) {
+ HWND hwnd = (HWND)(INT_PTR)hwnd_ptr;
+ RECT clip_rect;
+ LPRECT clip_rect_ptr;
+ if (handle_buffer != NULL) {
+ copyBufferToRect(env, handle_buffer, &clip_rect);
+ clip_rect_ptr = &clip_rect;
+ } else
+ clip_rect_ptr = NULL;
+ if (ClipCursor(clip_rect_ptr) == 0)
+ throwFormattedException(env, "ClipCursor failed (%d)", GetLastError());
+}
+
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSwitchDisplayMode(JNIEnv *env, jobject self, jobject mode) {
switchDisplayMode(env, mode);
}
@@ -452,64 +498,36 @@
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCursorPosition
-(JNIEnv * env, jclass unused, jint x, jint y, jboolean fullscreen) {
- DWORD windowflags, exstyle;
- int transformed_x, transformed_y;
- RECT window_rect;
- RECT client_rect;
- RECT adjusted_client_rect;
-
- int left_border_width;
- int bottom_border_width;
-
- getWindowFlags(&windowflags, &exstyle, fullscreen, getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated"));
- if (!GetClientRect(getCurrentHWND(), &client_rect)) {
- printfDebugJava(env, "GetClientRect failed");
- return;
- }
-
- adjusted_client_rect = client_rect;
- if (!AdjustWindowRectEx(&adjusted_client_rect, windowflags, FALSE, exstyle)) {
- printfDebugJava(env, "AdjustWindowRectEx failed");
- return;
- }
-
- if (!GetWindowRect(getCurrentHWND(), &window_rect)) {
- printfDebugJava(env, "GetWindowRect failed");
- return;
- }
- left_border_width = -adjusted_client_rect.left;
- bottom_border_width = adjusted_client_rect.bottom - client_rect.bottom;
-
- transformed_x = window_rect.left + left_border_width + x;
- transformed_y = window_rect.bottom - bottom_border_width - 1 - y;
- if (!SetCursorPos(transformed_x, transformed_y))
+(JNIEnv * env, jclass unused, jint x, jint y) {
+ if (!SetCursorPos(x, y))
printfDebugJava(env, "SetCursorPos failed");
}
-JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_setNativeCursor
- (JNIEnv *env, jobject self, jobject handle_buffer)
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getClientRect
+ (JNIEnv *env, jclass unused, jlong hwnd_int, jobject rect_buffer) {
+ HWND hwnd = (HWND)(INT_PTR)hwnd_int;
+ RECT clientRect;
+ GetClientRect(hwnd, &clientRect);
+ copyRectToBuffer(env, &clientRect, rect_buffer);
+}
+
+JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetNativeCursor
+ (JNIEnv *env, jclass unused, jlong hwnd_int, jobject handle_buffer)
{
+ HWND hwnd = (HWND)(INT_PTR)hwnd_int;
HCURSOR *cursor_handle;
HCURSOR cursor;
if (handle_buffer != NULL) {
cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
cursor = *cursor_handle;
- SetClassLongPtr(getCurrentHWND(), GCL_HCURSOR, (LONG_PTR)cursor);
+ SetClassLongPtr(hwnd, GCL_HCURSOR, (LONG_PTR)cursor);
SetCursor(cursor);
} else {
- SetClassLongPtr(getCurrentHWND(), GCL_HCURSOR, (LONG_PTR)NULL);
+ SetClassLongPtr(hwnd, GCL_HCURSOR, (LONG_PTR)NULL);
SetCursor(LoadCursor(NULL, IDC_ARROW));
}
}
-JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_transformY(JNIEnv *env, jclass unused, jlong hwnd_int, jint y) {
- HWND hwnd = (HWND)(INT_PTR)hwnd_int;
- RECT clientRect;
- GetClientRect(hwnd, &clientRect);
- return (clientRect.bottom - clientRect.top) - 1 - y;
-}
-
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getSystemMetrics(JNIEnv *env, jclass unused, jint index) {
return GetSystemMetrics(index);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|