Now that no native side event_queue_t type is used anymore, convert input read() semantics to use normal nio Buffer semantics - that is, move the position when writing events

This commit is contained in:
Elias Naur 2006-07-03 19:09:47 +00:00
parent b20423aa62
commit 3902c69c7a
11 changed files with 37 additions and 50 deletions

View file

@ -348,8 +348,7 @@ public class Keyboard {
private static void read() {
readBuffer.compact();
int numEvents = Display.getImplementation().readKeyboard(readBuffer);
readBuffer.position(readBuffer.position() + numEvents*EVENT_SIZE);
Display.getImplementation().readKeyboard(readBuffer);
readBuffer.flip();
}

View file

@ -306,8 +306,7 @@ public class Mouse {
private static void read() {
readBuffer.compact();
int numEvents = Display.getImplementation().readMouse(readBuffer);
readBuffer.position(readBuffer.position() + numEvents * EVENT_SIZE);
Display.getImplementation().readMouse(readBuffer);
readBuffer.flip();
}

View file

@ -150,10 +150,8 @@ public interface DisplayImplementation {
/**
* Method to read the keyboard buffer
*
* @return the total number of events read.
*/
int readMouse(IntBuffer buffer);
void readMouse(IntBuffer buffer);
void grabMouse(boolean grab);
@ -198,9 +196,8 @@ public interface DisplayImplementation {
/**
* Method to read the keyboard buffer
* @return the total number of events read.
*/
int readKeyboard(IntBuffer buffer);
void readKeyboard(IntBuffer buffer);
// int isStateKeySet(int key);

View file

@ -62,8 +62,7 @@ class EventQueue {
* the behaviour of the native event queues.
* @return the number of events copied
*/
public synchronized int copyEvents(IntBuffer dest) {
int old_position = dest.position();
public synchronized void copyEvents(IntBuffer dest) {
queue.flip();
int old_limit = queue.limit();
if (dest.remaining() < queue.remaining())
@ -71,9 +70,6 @@ class EventQueue {
dest.put(queue);
queue.limit(old_limit);
queue.compact();
int num_events = (dest.position() - old_position)/event_size;
dest.position(old_position);
return num_events;
}
/**

View file

@ -648,11 +648,11 @@ final class LinuxDisplay implements DisplayImplementation {
}
}
public int readMouse(IntBuffer buffer) {
public void readMouse(IntBuffer buffer) {
update();
lockAWT();
try {
return mouse.read(buffer);
mouse.read(buffer);
} finally {
unlockAWT();
}
@ -818,11 +818,11 @@ final class LinuxDisplay implements DisplayImplementation {
}
}
public int readKeyboard(IntBuffer buffer) {
public void readKeyboard(IntBuffer buffer) {
update();
lockAWT();
try {
return keyboard.read(buffer);
keyboard.read(buffer);
} finally {
unlockAWT();
}

View file

@ -152,8 +152,8 @@ final class LinuxKeyboard {
private static native void destroyIC(long xic);
private static native void closeIM(long xim);
public int read(IntBuffer buffer) {
return event_queue.copyEvents(buffer);
public void read(IntBuffer buffer) {
event_queue.copyEvents(buffer);
}
public void poll(ByteBuffer keyDownBuffer) {

View file

@ -86,8 +86,8 @@ final class LinuxMouse {
accum_dx = accum_dy = 0;
}
public int read(IntBuffer buffer) {
return event_queue.copyEvents(buffer);
public void read(IntBuffer buffer) {
event_queue.copyEvents(buffer);
}
public void poll(boolean grab, IntBuffer coord_buffer, ByteBuffer buttons_buffer) {

View file

@ -321,8 +321,8 @@ final class MacOSXDisplay implements DisplayImplementation {
mouse_queue.poll(coord_buffer, buttons_buffer);
}
public int readMouse(IntBuffer buffer) {
return mouse_queue.copyEvents(buffer);
public void readMouse(IntBuffer buffer) {
mouse_queue.copyEvents(buffer);
}
public void grabMouse(boolean grab) {
@ -407,8 +407,8 @@ final class MacOSXDisplay implements DisplayImplementation {
keyboard_queue.poll(keyDownBuffer);
}
public int readKeyboard(IntBuffer buffer) {
return keyboard_queue.copyEvents(buffer);
public void readKeyboard(IntBuffer buffer) {
keyboard_queue.copyEvents(buffer);
}
/* public int isStateKeySet(int key) {

View file

@ -206,9 +206,9 @@ final class Win32Display implements DisplayImplementation {
mouse.poll(coord_buffer, buttons);
}
public int readMouse(IntBuffer buffer) {
public void readMouse(IntBuffer buffer) {
update();
return mouse.read(buffer);
mouse.read(buffer);
}
public void grabMouse(boolean grab) {
@ -251,9 +251,9 @@ final class Win32Display implements DisplayImplementation {
keyboard.poll(keyDownBuffer);
}
public int readKeyboard(IntBuffer buffer) {
public void readKeyboard(IntBuffer buffer) {
update();
return keyboard.read(buffer);
keyboard.read(buffer);
}
// public native int isStateKeySet(int key);

View file

@ -103,15 +103,13 @@ final class WindowsKeyboard {
}
}
private int translateData(IntBuffer src, IntBuffer dst) {
private void translateData(IntBuffer src, IntBuffer dst) {
int dst_index = dst.position();
int num_events = 0;
while (dst_index < dst.limit() && src.hasRemaining()) {
num_events++;
while (dst.hasRemaining() && src.hasRemaining()) {
int dwOfs = src.get();
dst.put(dst_index++, dwOfs);
dst.put(dwOfs);
int dwData = src.get();
dst.put(dst_index++, dwData);
dst.put(dwData);
boolean key_down = (dwData & 0x80) != 0;
if (key_down) {
int virt_key = MapVirtualKey(dwOfs, 1);
@ -128,33 +126,31 @@ final class WindowsKeyboard {
int current_char = 0;
do {
if (current_char >= 1) {
num_events++;
dst.put(dst_index++, 0);
dst.put(dst_index++, 0);
dst.put(0);
dst.put(0);
}
int char_int = ((int)unicode_buffer.get()) & 0xFFFF;
dst.put(dst_index++, char_int);
dst.put(char_int);
current_char++;
} while (dst_index < dst.limit() && current_char < num_chars);
} while (dst.hasRemaining() && current_char < num_chars);
} else {
dst.put(dst_index++, 0);
dst.put(0);
}
} else {
dst.put(dst_index++, 0);
dst.put(0);
}
} else
dst.put(dst_index++, 0);
dst.put(0);
}
return num_events;
}
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 GetKeyboardState(ByteBuffer lpKeyState);
public int read(IntBuffer buffer) {
public void read(IntBuffer buffer) {
int ret = keyboard.acquire();
if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
return 0;
return;
keyboard.poll();
temp_data_buffer.clear();
ret = keyboard.getDeviceData(temp_data_buffer);
@ -173,6 +169,6 @@ final class WindowsKeyboard {
break;
}
temp_data_buffer.flip();
return translateData(temp_data_buffer, buffer);
translateData(temp_data_buffer, buffer);
}
}

View file

@ -261,9 +261,9 @@ final class WindowsMouse {
}
}
public int read(IntBuffer buffer) {
public void read(IntBuffer buffer) {
readDXBuffer();
return event_queue.copyEvents(buffer);
event_queue.copyEvents(buffer);
}
public void grab(boolean grab) {