Implemented variable sized events in preparation of timestamped input events
This commit is contained in:
parent
25a953bbdc
commit
26c6de6363
|
@ -55,6 +55,9 @@ import org.lwjgl.opengl.Display;
|
||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
public class Keyboard {
|
public class Keyboard {
|
||||||
|
/** Internal use - event size in bytes */
|
||||||
|
public static final int EVENT_SIZE = 4 + 1 + 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The special character meaning that no
|
* The special character meaning that no
|
||||||
* character was translated for the event.
|
* character was translated for the event.
|
||||||
|
@ -199,8 +202,6 @@ public class Keyboard {
|
||||||
|
|
||||||
/** Buffer size in events */
|
/** Buffer size in events */
|
||||||
private static final int BUFFER_SIZE = 50;
|
private static final int BUFFER_SIZE = 50;
|
||||||
/** Event size in elements */
|
|
||||||
private static final int EVENT_SIZE = 3;
|
|
||||||
|
|
||||||
/** Key names */
|
/** Key names */
|
||||||
private static final String[] keyName = new String[255];
|
private static final String[] keyName = new String[255];
|
||||||
|
@ -245,7 +246,7 @@ public class Keyboard {
|
||||||
* followed by state. The state is followed by
|
* followed by state. The state is followed by
|
||||||
* a 4 byte code point representing the translated character.
|
* a 4 byte code point representing the translated character.
|
||||||
*/
|
*/
|
||||||
private static IntBuffer readBuffer;
|
private static ByteBuffer readBuffer;
|
||||||
|
|
||||||
/** The current keyboard character being examined */
|
/** The current keyboard character being examined */
|
||||||
private static int eventCharacter;
|
private static int eventCharacter;
|
||||||
|
@ -290,7 +291,7 @@ public class Keyboard {
|
||||||
return;
|
return;
|
||||||
Display.getImplementation().createKeyboard();
|
Display.getImplementation().createKeyboard();
|
||||||
created = true;
|
created = true;
|
||||||
readBuffer = BufferUtils.createIntBuffer(EVENT_SIZE*BUFFER_SIZE);
|
readBuffer = ByteBuffer.allocate(EVENT_SIZE*BUFFER_SIZE);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,9 +423,9 @@ public class Keyboard {
|
||||||
throw new IllegalStateException("Keyboard must be created before you can read events");
|
throw new IllegalStateException("Keyboard must be created before you can read events");
|
||||||
|
|
||||||
if (readBuffer.hasRemaining()) {
|
if (readBuffer.hasRemaining()) {
|
||||||
eventKey = readBuffer.get() & 0xFF;
|
eventKey = readBuffer.getInt() & 0xFF;
|
||||||
eventState = readBuffer.get() != 0;
|
eventState = readBuffer.get() != 0;
|
||||||
eventCharacter = readBuffer.get();
|
eventCharacter = readBuffer.getInt();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -59,6 +59,9 @@ import org.lwjgl.opengl.Display;
|
||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
public class Mouse {
|
public class Mouse {
|
||||||
|
/** Internal use - event size in bytes */
|
||||||
|
public static final int EVENT_SIZE = 1 + 1 + 4 + 4 + 4;
|
||||||
|
|
||||||
/** Has the mouse been created? */
|
/** Has the mouse been created? */
|
||||||
private static boolean created;
|
private static boolean created;
|
||||||
|
|
||||||
|
@ -102,7 +105,7 @@ public class Mouse {
|
||||||
private static boolean initialized;
|
private static boolean initialized;
|
||||||
|
|
||||||
/** The mouse button events from the last read */
|
/** The mouse button events from the last read */
|
||||||
private static IntBuffer readBuffer;
|
private static ByteBuffer readBuffer;
|
||||||
|
|
||||||
/** The current mouse event button being examined */
|
/** The current mouse event button being examined */
|
||||||
private static int eventButton;
|
private static int eventButton;
|
||||||
|
@ -120,8 +123,6 @@ public class Mouse {
|
||||||
|
|
||||||
/** Buffer size in events */
|
/** Buffer size in events */
|
||||||
private static final int BUFFER_SIZE = 50;
|
private static final int BUFFER_SIZE = 50;
|
||||||
/** Event size in elements */
|
|
||||||
private static final int EVENT_SIZE = 5;
|
|
||||||
|
|
||||||
private static boolean isGrabbed;
|
private static boolean isGrabbed;
|
||||||
|
|
||||||
|
@ -232,7 +233,7 @@ public class Mouse {
|
||||||
coord_buffer = BufferUtils.createIntBuffer(3);
|
coord_buffer = BufferUtils.createIntBuffer(3);
|
||||||
if (currentCursor != null)
|
if (currentCursor != null)
|
||||||
setNativeCursor(currentCursor);
|
setNativeCursor(currentCursor);
|
||||||
readBuffer = BufferUtils.createIntBuffer(EVENT_SIZE * BUFFER_SIZE);
|
readBuffer = ByteBuffer.allocate(EVENT_SIZE * BUFFER_SIZE);
|
||||||
readBuffer.limit(0);
|
readBuffer.limit(0);
|
||||||
setGrabbed(isGrabbed);
|
setGrabbed(isGrabbed);
|
||||||
}
|
}
|
||||||
|
@ -363,13 +364,13 @@ public class Mouse {
|
||||||
eventButton = readBuffer.get();
|
eventButton = readBuffer.get();
|
||||||
eventState = readBuffer.get() != 0;
|
eventState = readBuffer.get() != 0;
|
||||||
if (isGrabbed()) {
|
if (isGrabbed()) {
|
||||||
event_dx = readBuffer.get();
|
event_dx = readBuffer.getInt();
|
||||||
event_dy = readBuffer.get();
|
event_dy = readBuffer.getInt();
|
||||||
event_x += event_dx;
|
event_x += event_dx;
|
||||||
event_y += event_dy;
|
event_y += event_dy;
|
||||||
} else {
|
} else {
|
||||||
int new_event_x = readBuffer.get();
|
int new_event_x = readBuffer.getInt();
|
||||||
int new_event_y = readBuffer.get();
|
int new_event_y = readBuffer.getInt();
|
||||||
event_dx = new_event_x - event_x;
|
event_dx = new_event_x - event_x;
|
||||||
event_dy = new_event_y - event_y;
|
event_dy = new_event_y - event_y;
|
||||||
event_x = new_event_x;
|
event_x = new_event_x;
|
||||||
|
@ -377,7 +378,7 @@ public class Mouse {
|
||||||
}
|
}
|
||||||
event_x = Math.min(Display.getDisplayMode().getWidth() - 1, Math.max(0, event_x));
|
event_x = Math.min(Display.getDisplayMode().getWidth() - 1, Math.max(0, event_x));
|
||||||
event_y = Math.min(Display.getDisplayMode().getHeight() - 1, Math.max(0, event_y));
|
event_y = Math.min(Display.getDisplayMode().getHeight() - 1, Math.max(0, event_y));
|
||||||
event_dwheel = readBuffer.get();
|
event_dwheel = readBuffer.getInt();
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -151,7 +151,7 @@ public interface DisplayImplementation {
|
||||||
/**
|
/**
|
||||||
* Method to read the keyboard buffer
|
* Method to read the keyboard buffer
|
||||||
*/
|
*/
|
||||||
void readMouse(IntBuffer buffer);
|
void readMouse(ByteBuffer buffer);
|
||||||
|
|
||||||
void grabMouse(boolean grab);
|
void grabMouse(boolean grab);
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ public interface DisplayImplementation {
|
||||||
/**
|
/**
|
||||||
* Method to read the keyboard buffer
|
* Method to read the keyboard buffer
|
||||||
*/
|
*/
|
||||||
void readKeyboard(IntBuffer buffer);
|
void readKeyboard(ByteBuffer buffer);
|
||||||
|
|
||||||
// int isStateKeySet(int key);
|
// int isStateKeySet(int key);
|
||||||
|
|
||||||
|
|
|
@ -40,16 +40,15 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
class EventQueue {
|
class EventQueue {
|
||||||
|
|
||||||
private static final int QUEUE_SIZE = 200;
|
private static final int QUEUE_SIZE = 200;
|
||||||
|
|
||||||
private final int event_size;
|
private final int event_size;
|
||||||
|
|
||||||
private final IntBuffer queue;
|
private final ByteBuffer queue;
|
||||||
|
|
||||||
protected EventQueue(int event_size) {
|
protected EventQueue(int event_size) {
|
||||||
this.event_size = event_size;
|
this.event_size = event_size;
|
||||||
this.queue = ByteBuffer.allocateDirect(QUEUE_SIZE*event_size).asIntBuffer();
|
this.queue = ByteBuffer.allocate(QUEUE_SIZE*event_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void clearEvents() {
|
protected synchronized void clearEvents() {
|
||||||
|
@ -59,7 +58,7 @@ class EventQueue {
|
||||||
/**
|
/**
|
||||||
* Copy available events into the specified buffer.
|
* Copy available events into the specified buffer.
|
||||||
*/
|
*/
|
||||||
public synchronized void copyEvents(IntBuffer dest) {
|
public synchronized void copyEvents(ByteBuffer dest) {
|
||||||
queue.flip();
|
queue.flip();
|
||||||
int old_limit = queue.limit();
|
int old_limit = queue.limit();
|
||||||
if (dest.remaining() < queue.remaining())
|
if (dest.remaining() < queue.remaining())
|
||||||
|
@ -73,10 +72,10 @@ class EventQueue {
|
||||||
* Put an event into the queue.
|
* Put an event into the queue.
|
||||||
* @return true if the event fitted into the queue, false otherwise
|
* @return true if the event fitted into the queue, false otherwise
|
||||||
*/
|
*/
|
||||||
public synchronized boolean putEvent(int[] event) {
|
public synchronized boolean putEvent(ByteBuffer event) {
|
||||||
if (event.length != event_size)
|
if (event.remaining() != event_size)
|
||||||
throw new IllegalArgumentException("Internal error: event size " + event_size + " does not equals the given event size " + event.length);
|
throw new IllegalArgumentException("Internal error: event size " + event_size + " does not equal the given event size " + event.remaining());
|
||||||
if (queue.remaining() >= event.length) {
|
if (queue.remaining() >= event.remaining()) {
|
||||||
queue.put(event);
|
queue.put(event);
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -44,14 +44,12 @@ import java.nio.ByteBuffer;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
final class KeyboardEventQueue extends EventQueue implements KeyListener {
|
final class KeyboardEventQueue extends EventQueue implements KeyListener {
|
||||||
|
|
||||||
private static final int[] KEY_MAP = new int[0xffff];
|
private static final int[] KEY_MAP = new int[0xffff];
|
||||||
private static final int EVENT_SIZE = 3;
|
|
||||||
|
|
||||||
private final byte[] key_states = new byte[Keyboard.KEYBOARD_SIZE];
|
private final byte[] key_states = new byte[Keyboard.KEYBOARD_SIZE];
|
||||||
|
|
||||||
/** Event scratch array */
|
/** Event scratch array */
|
||||||
private final int[] event = new int[EVENT_SIZE];
|
private final ByteBuffer event = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
KEY_MAP[KeyEvent.VK_0] = Keyboard.KEY_0;
|
KEY_MAP[KeyEvent.VK_0] = Keyboard.KEY_0;
|
||||||
|
@ -241,14 +239,14 @@ final class KeyboardEventQueue extends EventQueue implements KeyListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyboardEventQueue() {
|
public KeyboardEventQueue() {
|
||||||
super(EVENT_SIZE);
|
super(Keyboard.EVENT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putKeyboardEvent(int key_code, int state, int character) {
|
private void putKeyboardEvent(int key_code, byte state, int character) {
|
||||||
event[0] = key_code;
|
event.putInt(key_code).put(state).putInt(character);
|
||||||
event[1] = state;
|
event.flip();
|
||||||
event[2] = character;
|
|
||||||
putEvent(event);
|
putEvent(event);
|
||||||
|
event.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void poll(ByteBuffer key_down_buffer) {
|
public synchronized void poll(ByteBuffer key_down_buffer) {
|
||||||
|
|
|
@ -648,7 +648,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readMouse(IntBuffer buffer) {
|
public void readMouse(ByteBuffer buffer) {
|
||||||
update();
|
update();
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
|
@ -818,7 +818,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readKeyboard(IntBuffer buffer) {
|
public void readKeyboard(ByteBuffer buffer) {
|
||||||
update();
|
update();
|
||||||
lockAWT();
|
lockAWT();
|
||||||
try {
|
try {
|
||||||
|
@ -972,7 +972,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
||||||
/* Callbacks from nUpdate() */
|
/* Callbacks from nUpdate() */
|
||||||
private static void handleButtonEvent(long millis, int type, int button, int state) {
|
private static void handleButtonEvent(long millis, int type, int button, int state) {
|
||||||
if (mouse != null)
|
if (mouse != null)
|
||||||
mouse.handleButtonEvent(grab, type, button);
|
mouse.handleButtonEvent(grab, type, (byte)button);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleKeyEvent(long event_ptr, long millis, int type, int keycode, int state) {
|
private static void handleKeyEvent(long event_ptr, long millis, int type, int keycode, int state) {
|
||||||
|
|
|
@ -55,8 +55,6 @@ final class LinuxKeyboard {
|
||||||
private static final int XLookupChars = 2;
|
private static final int XLookupChars = 2;
|
||||||
private static final int XLookupBoth = 4;
|
private static final int XLookupBoth = 4;
|
||||||
|
|
||||||
|
|
||||||
private static final int EVENT_SIZE = 3;
|
|
||||||
private static final int KEYBOARD_BUFFER_SIZE = 50;
|
private static final int KEYBOARD_BUFFER_SIZE = 50;
|
||||||
|
|
||||||
private final long xim;
|
private final long xim;
|
||||||
|
@ -70,9 +68,9 @@ final class LinuxKeyboard {
|
||||||
private final ByteBuffer compose_status;
|
private final ByteBuffer compose_status;
|
||||||
|
|
||||||
private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
|
private final byte[] key_down_buffer = new byte[Keyboard.KEYBOARD_SIZE];
|
||||||
private final EventQueue event_queue = new EventQueue(EVENT_SIZE);
|
private final EventQueue event_queue = new EventQueue(Keyboard.EVENT_SIZE);
|
||||||
|
|
||||||
private final int[] tmp_event = new int[3];
|
private final ByteBuffer tmp_event = ByteBuffer.allocate(Keyboard.EVENT_SIZE);
|
||||||
private final int[] temp_translation_buffer = new int[KEYBOARD_BUFFER_SIZE];
|
private final int[] temp_translation_buffer = new int[KEYBOARD_BUFFER_SIZE];
|
||||||
private final ByteBuffer native_translation_buffer = BufferUtils.createByteBuffer(KEYBOARD_BUFFER_SIZE);
|
private final ByteBuffer native_translation_buffer = BufferUtils.createByteBuffer(KEYBOARD_BUFFER_SIZE);
|
||||||
private final CharsetDecoder utf8_decoder = Charset.forName("UTF-8").newDecoder();
|
private final CharsetDecoder utf8_decoder = Charset.forName("UTF-8").newDecoder();
|
||||||
|
@ -152,7 +150,7 @@ final class LinuxKeyboard {
|
||||||
private static native void destroyIC(long xic);
|
private static native void destroyIC(long xic);
|
||||||
private static native void closeIM(long xim);
|
private static native void closeIM(long xim);
|
||||||
|
|
||||||
public void read(IntBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
event_queue.copyEvents(buffer);
|
event_queue.copyEvents(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,11 +160,11 @@ final class LinuxKeyboard {
|
||||||
keyDownBuffer.position(old_position);
|
keyDownBuffer.position(old_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putKeyboardEvent(int keycode, int state, int ch) {
|
private void putKeyboardEvent(int keycode, byte state, int ch) {
|
||||||
tmp_event[0] = keycode;
|
tmp_event.putInt(keycode).put(state).putInt(ch);
|
||||||
tmp_event[1] = state;
|
tmp_event.flip();
|
||||||
tmp_event[2] = ch;
|
|
||||||
event_queue.putEvent(tmp_event);
|
event_queue.putEvent(tmp_event);
|
||||||
|
tmp_event.compact();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int lookupStringISO88591(long event_ptr, int[] translation_buffer) {
|
private int lookupStringISO88591(long event_ptr, int[] translation_buffer) {
|
||||||
|
@ -204,7 +202,7 @@ final class LinuxKeyboard {
|
||||||
return lookupStringISO88591(event_ptr, translation_buffer);
|
return lookupStringISO88591(event_ptr, translation_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void translateEvent(long event_ptr, int event_type, int keycode, int key_state) {
|
private void translateEvent(long event_ptr, int event_type, int keycode, byte key_state) {
|
||||||
int num_chars, i;
|
int num_chars, i;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
|
@ -218,7 +216,7 @@ final class LinuxKeyboard {
|
||||||
putKeyboardEvent(keycode, key_state, ch);
|
putKeyboardEvent(keycode, key_state, ch);
|
||||||
for (i = 1; i < num_chars; i++) {
|
for (i = 1; i < num_chars; i++) {
|
||||||
ch = temp_translation_buffer[i];
|
ch = temp_translation_buffer[i];
|
||||||
putKeyboardEvent(0, 0, ch);
|
putKeyboardEvent(0, (byte)0, ch);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
putKeyboardEvent(keycode, key_state, 0);
|
putKeyboardEvent(keycode, key_state, 0);
|
||||||
|
|
|
@ -46,7 +46,6 @@ import java.nio.charset.CharsetDecoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
final class LinuxMouse {
|
final class LinuxMouse {
|
||||||
private static final int EVENT_SIZE = 5;
|
|
||||||
private static final int NUM_BUTTONS = 3;
|
private static final int NUM_BUTTONS = 3;
|
||||||
private static final int POINTER_WARP_BORDER = 10;
|
private static final int POINTER_WARP_BORDER = 10;
|
||||||
// scale the mouse wheel according to DirectInput
|
// scale the mouse wheel according to DirectInput
|
||||||
|
@ -65,7 +64,7 @@ final class LinuxMouse {
|
||||||
private final long display;
|
private final long display;
|
||||||
private final long window;
|
private final long window;
|
||||||
private final IntBuffer query_pointer_buffer = BufferUtils.createIntBuffer(4);
|
private final IntBuffer query_pointer_buffer = BufferUtils.createIntBuffer(4);
|
||||||
private final int[] event_buffer = new int[EVENT_SIZE];
|
private final ByteBuffer event_buffer = ByteBuffer.allocate(Mouse.EVENT_SIZE);
|
||||||
|
|
||||||
private int last_x;
|
private int last_x;
|
||||||
private int last_y;
|
private int last_y;
|
||||||
|
@ -82,11 +81,11 @@ final class LinuxMouse {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reset() {
|
private void reset() {
|
||||||
event_queue = new EventQueue(EVENT_SIZE);
|
event_queue = new EventQueue(event_buffer.capacity());
|
||||||
accum_dx = accum_dy = 0;
|
accum_dx = accum_dy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(IntBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
event_queue.copyEvents(buffer);
|
event_queue.copyEvents(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,13 +103,11 @@ final class LinuxMouse {
|
||||||
buttons_buffer.put(i, buttons[i]);
|
buttons_buffer.put(i, buttons[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean putMouseEventWithCoords(int button, int state, int coord1, int coord2, int dz) {
|
private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz) {
|
||||||
event_buffer[0] = button;
|
event_buffer.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz);
|
||||||
event_buffer[1] = state;
|
event_buffer.flip();
|
||||||
event_buffer[2] = coord1;
|
event_queue.putEvent(event_buffer);
|
||||||
event_buffer[3] = coord2;
|
event_buffer.compact();
|
||||||
event_buffer[4] = dz;
|
|
||||||
return event_queue.putEvent(event_buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCursorPos(boolean grab, int x, int y) {
|
private void setCursorPos(boolean grab, int x, int y) {
|
||||||
|
@ -122,9 +119,9 @@ final class LinuxMouse {
|
||||||
last_x = x;
|
last_x = x;
|
||||||
last_y = y;
|
last_y = y;
|
||||||
if (grab) {
|
if (grab) {
|
||||||
putMouseEventWithCoords(-1, 0, dx, dy, 0);
|
putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0);
|
||||||
} else {
|
} else {
|
||||||
putMouseEventWithCoords(-1, 0, x, y, 0);
|
putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,16 +189,16 @@ final class LinuxMouse {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleButton(boolean grab, int button, byte state) {
|
private void handleButton(boolean grab, int button, byte state) {
|
||||||
int button_num;
|
byte button_num;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case Button1:
|
case Button1:
|
||||||
button_num = 0;
|
button_num = (byte)0;
|
||||||
break;
|
break;
|
||||||
case Button2:
|
case Button2:
|
||||||
button_num = 2;
|
button_num = (byte)2;
|
||||||
break;
|
break;
|
||||||
case Button3:
|
case Button3:
|
||||||
button_num = 1;
|
button_num = (byte)1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
@ -210,24 +207,24 @@ final class LinuxMouse {
|
||||||
putMouseEvent(grab, button_num, state, 0);
|
putMouseEvent(grab, button_num, state, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void putMouseEvent(boolean grab, int button, int state, int dz) {
|
private void putMouseEvent(boolean grab, byte button, byte state, int dz) {
|
||||||
if (grab)
|
if (grab)
|
||||||
putMouseEventWithCoords(button, state, 0, 0, dz);
|
putMouseEventWithCoords(button, state, 0, 0, dz);
|
||||||
else
|
else
|
||||||
putMouseEventWithCoords(button, state, last_x, last_y, dz);
|
putMouseEventWithCoords(button, state, last_x, last_y, dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleButtonPress(boolean grab, int button) {
|
private void handleButtonPress(boolean grab, byte button) {
|
||||||
int delta = 0;
|
int delta = 0;
|
||||||
switch (button) {
|
switch (button) {
|
||||||
case Button4:
|
case Button4:
|
||||||
delta = WHEEL_SCALE;
|
delta = WHEEL_SCALE;
|
||||||
putMouseEvent(grab, -1, 0, delta);
|
putMouseEvent(grab, (byte)-1, (byte)0, delta);
|
||||||
accum_dz += delta;
|
accum_dz += delta;
|
||||||
break;
|
break;
|
||||||
case Button5:
|
case Button5:
|
||||||
delta = -WHEEL_SCALE;
|
delta = -WHEEL_SCALE;
|
||||||
putMouseEvent(grab, -1, 0, delta);
|
putMouseEvent(grab, (byte)-1, (byte)0, delta);
|
||||||
accum_dz += delta;
|
accum_dz += delta;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -240,7 +237,7 @@ final class LinuxMouse {
|
||||||
handleButton(grab, button, (byte)0);
|
handleButton(grab, button, (byte)0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleButtonEvent(boolean grab, int type, int button) {
|
public void handleButtonEvent(boolean grab, int type, byte button) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
handleButton(grab, button, (byte)0);
|
handleButton(grab, button, (byte)0);
|
||||||
|
|
|
@ -321,7 +321,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
||||||
mouse_queue.poll(coord_buffer, buttons_buffer);
|
mouse_queue.poll(coord_buffer, buttons_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readMouse(IntBuffer buffer) {
|
public void readMouse(ByteBuffer buffer) {
|
||||||
mouse_queue.copyEvents(buffer);
|
mouse_queue.copyEvents(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +407,7 @@ final class MacOSXDisplay implements DisplayImplementation {
|
||||||
keyboard_queue.poll(keyDownBuffer);
|
keyboard_queue.poll(keyDownBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readKeyboard(IntBuffer buffer) {
|
public void readKeyboard(ByteBuffer buffer) {
|
||||||
keyboard_queue.copyEvents(buffer);
|
keyboard_queue.copyEvents(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,11 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
final class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionListener, MouseWheelListener {
|
final class MouseEventQueue extends EventQueue implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||||
|
|
||||||
private static final int WHEEL_SCALE = 120;
|
private static final int WHEEL_SCALE = 120;
|
||||||
public static final int NUM_BUTTONS = 3;
|
public static final int NUM_BUTTONS = 3;
|
||||||
private static final int EVENT_SIZE = 5;
|
|
||||||
|
|
||||||
private final int width;
|
private final int width;
|
||||||
private final int height;
|
private final int height;
|
||||||
|
@ -73,13 +72,13 @@ final class MouseEventQueue extends EventQueue implements MouseListener, MouseMo
|
||||||
private boolean saved_control_state;
|
private boolean saved_control_state;
|
||||||
|
|
||||||
/** Event scratch array */
|
/** Event scratch array */
|
||||||
private final int[] event = new int[EVENT_SIZE];
|
private final ByteBuffer event = ByteBuffer.allocate(Mouse.EVENT_SIZE);
|
||||||
|
|
||||||
/** Buttons array */
|
/** Buttons array */
|
||||||
private final byte[] buttons = new byte[NUM_BUTTONS];
|
private final byte[] buttons = new byte[NUM_BUTTONS];
|
||||||
|
|
||||||
MouseEventQueue(int width, int height) {
|
MouseEventQueue(int width, int height) {
|
||||||
super(EVENT_SIZE);
|
super(Mouse.EVENT_SIZE);
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
resetCursorToCenter();
|
resetCursorToCenter();
|
||||||
|
@ -105,20 +104,18 @@ final class MouseEventQueue extends EventQueue implements MouseListener, MouseMo
|
||||||
((MacOSXDisplay)Display.getImplementation()).getMouseDeltas(delta_buffer);
|
((MacOSXDisplay)Display.getImplementation()).getMouseDeltas(delta_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean putMouseEvent(int button, int state, int dz) {
|
private void putMouseEvent(byte button, byte state, int dz) {
|
||||||
if ( grabbed )
|
if (grabbed)
|
||||||
return putMouseEventWithCoords(button, state, 0, 0, dz);
|
putMouseEventWithCoords(button, state, 0, 0, dz);
|
||||||
else
|
else
|
||||||
return putMouseEventWithCoords(button, state, last_x, last_y, dz);
|
putMouseEventWithCoords(button, state, last_x, last_y, dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean putMouseEventWithCoords(int button, int state, int coord1, int coord2, int dz) {
|
private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz) {
|
||||||
event[0] = button;
|
event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz);
|
||||||
event[1] = state;
|
event.flip();
|
||||||
event[2] = coord1;
|
putEvent(event);
|
||||||
event[3] = coord2;
|
event.compact();
|
||||||
event[4] = dz;
|
|
||||||
return putEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void poll(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
|
public synchronized void poll(IntBuffer coord_buffer, ByteBuffer buttons_buffer) {
|
||||||
|
@ -146,7 +143,7 @@ final class MouseEventQueue extends EventQueue implements MouseListener, MouseMo
|
||||||
accum_dy += dy;
|
accum_dy += dy;
|
||||||
last_x = x;
|
last_x = x;
|
||||||
last_y = y;
|
last_y = y;
|
||||||
putMouseEventWithCoords(-1, 0, x, y, 0);
|
putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
@ -232,7 +229,7 @@ final class MouseEventQueue extends EventQueue implements MouseListener, MouseMo
|
||||||
|
|
||||||
private synchronized void handleWheel(int amount) {
|
private synchronized void handleWheel(int amount) {
|
||||||
accum_dz += amount;
|
accum_dz += amount;
|
||||||
putMouseEvent(-1, 0, amount);
|
putMouseEvent((byte)-1, (byte)0, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDeltas() {
|
private void updateDeltas() {
|
||||||
|
@ -243,7 +240,7 @@ final class MouseEventQueue extends EventQueue implements MouseListener, MouseMo
|
||||||
int dx = delta_buffer.get(0);
|
int dx = delta_buffer.get(0);
|
||||||
int dy = -delta_buffer.get(1);
|
int dy = -delta_buffer.get(1);
|
||||||
if ( dx != 0 || dy != 0 ) {
|
if ( dx != 0 || dy != 0 ) {
|
||||||
putMouseEventWithCoords(-1, 0, dx, dy, 0);
|
putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0);
|
||||||
accum_dx += dx;
|
accum_dx += dx;
|
||||||
accum_dy += dy;
|
accum_dy += dy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ final class Win32Display implements DisplayImplementation {
|
||||||
mouse.poll(coord_buffer, buttons);
|
mouse.poll(coord_buffer, buttons);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readMouse(IntBuffer buffer) {
|
public void readMouse(ByteBuffer buffer) {
|
||||||
update();
|
update();
|
||||||
mouse.read(buffer);
|
mouse.read(buffer);
|
||||||
}
|
}
|
||||||
|
@ -251,7 +251,7 @@ final class Win32Display implements DisplayImplementation {
|
||||||
keyboard.poll(keyDownBuffer);
|
keyboard.poll(keyDownBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readKeyboard(IntBuffer buffer) {
|
public void readKeyboard(ByteBuffer buffer) {
|
||||||
update();
|
update();
|
||||||
keyboard.read(buffer);
|
keyboard.read(buffer);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ final class Win32Display implements DisplayImplementation {
|
||||||
|
|
||||||
private static void handleMouseButton(int button, int state) {
|
private static void handleMouseButton(int button, int state) {
|
||||||
if (mouse != null)
|
if (mouse != null)
|
||||||
mouse.handleMouseButton(button, state);
|
mouse.handleMouseButton((byte)button, (byte)state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleMouseMoved(int x, int y) {
|
private static void handleMouseMoved(int x, int y) {
|
||||||
|
|
|
@ -103,14 +103,13 @@ final class WindowsKeyboard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void translateData(IntBuffer src, IntBuffer dst) {
|
private void translateData(IntBuffer src, ByteBuffer dst) {
|
||||||
int dst_index = dst.position();
|
|
||||||
while (dst.hasRemaining() && src.hasRemaining()) {
|
while (dst.hasRemaining() && src.hasRemaining()) {
|
||||||
int dwOfs = src.get();
|
int dwOfs = src.get();
|
||||||
dst.put(dwOfs);
|
dst.putInt(dwOfs);
|
||||||
int dwData = src.get();
|
byte dwData = (byte)src.get();
|
||||||
dst.put(dwData);
|
|
||||||
boolean key_down = (dwData & 0x80) != 0;
|
boolean key_down = (dwData & 0x80) != 0;
|
||||||
|
dst.put(key_down ? (byte)1 : (byte)0);
|
||||||
if (key_down) {
|
if (key_down) {
|
||||||
int virt_key = MapVirtualKey(dwOfs, 1);
|
int virt_key = MapVirtualKey(dwOfs, 1);
|
||||||
if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) {
|
if (virt_key != 0 && GetKeyboardState(keyboard_state) != 0) {
|
||||||
|
@ -126,28 +125,28 @@ final class WindowsKeyboard {
|
||||||
int current_char = 0;
|
int current_char = 0;
|
||||||
do {
|
do {
|
||||||
if (current_char >= 1) {
|
if (current_char >= 1) {
|
||||||
dst.put(0);
|
dst.putInt(0);
|
||||||
dst.put(0);
|
dst.put((byte)0);
|
||||||
}
|
}
|
||||||
int char_int = ((int)unicode_buffer.get()) & 0xFFFF;
|
int char_int = ((int)unicode_buffer.get()) & 0xFFFF;
|
||||||
dst.put(char_int);
|
dst.putInt(char_int);
|
||||||
current_char++;
|
current_char++;
|
||||||
} while (dst.hasRemaining() && current_char < num_chars);
|
} while (dst.hasRemaining() && current_char < num_chars);
|
||||||
} else {
|
} else {
|
||||||
dst.put(0);
|
dst.putInt(0);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dst.put(0);
|
dst.putInt(0);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
dst.put(0);
|
dst.putInt(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static native int MapVirtualKey(int uCode, int uMapType);
|
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 ToUnicode(int wVirtKey, int wScanCode, ByteBuffer lpKeyState, CharBuffer pwszBuff, int cchBuff, int flags);
|
||||||
private static native int GetKeyboardState(ByteBuffer lpKeyState);
|
private static native int GetKeyboardState(ByteBuffer lpKeyState);
|
||||||
|
|
||||||
public void read(IntBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
int ret = keyboard.acquire();
|
int ret = keyboard.acquire();
|
||||||
if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
|
if (ret != WindowsDirectInput.DI_OK && ret != WindowsDirectInput.DI_NOEFFECT)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -43,11 +43,11 @@ import java.nio.CharBuffer;
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.LWJGLUtil;
|
import org.lwjgl.LWJGLUtil;
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
final class WindowsMouse {
|
final class WindowsMouse {
|
||||||
private final static int BUFFER_SIZE = 50;
|
private final static int BUFFER_SIZE = 50;
|
||||||
private final static int BUTTON_STATES_SIZE = 7;
|
private final static int BUTTON_STATES_SIZE = 7;
|
||||||
private final static int MOUSE_EVENT_SIZE = 5;
|
|
||||||
|
|
||||||
private final static int DIMOFS_X = 0;
|
private final static int DIMOFS_X = 0;
|
||||||
private final static int DIMOFS_Y = 4;
|
private final static int DIMOFS_Y = 4;
|
||||||
|
@ -64,12 +64,12 @@ final class WindowsMouse {
|
||||||
private final int mouse_button_count;
|
private final int mouse_button_count;
|
||||||
private final boolean has_wheel;
|
private final boolean has_wheel;
|
||||||
|
|
||||||
private final EventQueue event_queue = new EventQueue(MOUSE_EVENT_SIZE);
|
private final EventQueue event_queue = new EventQueue(Mouse.EVENT_SIZE);
|
||||||
/* Buffer to hold a DIMOUSESTATE */
|
/* Buffer to hold a DIMOUSESTATE */
|
||||||
private final ByteBuffer mouse_state;
|
private final ByteBuffer mouse_state;
|
||||||
private final IntBuffer temp_data_buffer;
|
private final IntBuffer temp_data_buffer;
|
||||||
|
|
||||||
private final int[] mouse_event = new int[MOUSE_EVENT_SIZE];
|
private final ByteBuffer mouse_event = ByteBuffer.allocate(Mouse.EVENT_SIZE);
|
||||||
|
|
||||||
private boolean mouse_grabbed;
|
private boolean mouse_grabbed;
|
||||||
private byte[] win32_message_button_states = new byte[BUTTON_STATES_SIZE];
|
private byte[] win32_message_button_states = new byte[BUTTON_STATES_SIZE];
|
||||||
|
@ -180,46 +180,44 @@ final class WindowsMouse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean putMouseEventWithCoords(int button, int state, int coord1, int coord2, int dz) {
|
private void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz) {
|
||||||
mouse_event[0] = button;
|
mouse_event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz);
|
||||||
mouse_event[1] = state;
|
mouse_event.flip();
|
||||||
mouse_event[2] = coord1;
|
event_queue.putEvent(mouse_event);
|
||||||
mouse_event[3] = coord2;
|
mouse_event.compact();
|
||||||
mouse_event[4] = dz;
|
|
||||||
return event_queue.putEvent(mouse_event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean putMouseEvent(int button, int state, int dz) {
|
private void putMouseEvent(byte button, byte state, int dz) {
|
||||||
if (mouse_grabbed)
|
if (mouse_grabbed)
|
||||||
return putMouseEventWithCoords(button, state, 0, 0, dz);
|
putMouseEventWithCoords(button, state, 0, 0, dz);
|
||||||
else
|
else
|
||||||
return putMouseEventWithCoords(button, state, last_x, last_y, dz);
|
putMouseEventWithCoords(button, state, last_x, last_y, dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyDXEvents(IntBuffer buffer) {
|
private void copyDXEvents(IntBuffer buffer) {
|
||||||
int buffer_index = 0;
|
int buffer_index = 0;
|
||||||
int dx = 0, dy = 0, dwheel = 0;
|
int dx = 0, dy = 0, dwheel = 0;
|
||||||
int button_state;
|
byte button_state;
|
||||||
int i;
|
int i;
|
||||||
while (buffer.hasRemaining()) {
|
while (buffer.hasRemaining()) {
|
||||||
int dwOfs = buffer.get();
|
int dwOfs = buffer.get();
|
||||||
int dwData = buffer.get();
|
int dwData = buffer.get();
|
||||||
button_state = (dwData & 0x80) != 0 ? 1 : 0;
|
button_state = (dwData & 0x80) != 0 ? (byte)1 : (byte)0;
|
||||||
switch (dwOfs) {
|
switch (dwOfs) {
|
||||||
case DIMOFS_BUTTON0:
|
case DIMOFS_BUTTON0:
|
||||||
putMouseEventWithCoords(0, button_state, dx, -dy, dwheel);
|
putMouseEventWithCoords((byte)0, button_state, dx, -dy, dwheel);
|
||||||
dx = dy = dwheel = 0;
|
dx = dy = dwheel = 0;
|
||||||
break;
|
break;
|
||||||
case DIMOFS_BUTTON1:
|
case DIMOFS_BUTTON1:
|
||||||
putMouseEventWithCoords(1, button_state, dx, -dy, dwheel);
|
putMouseEventWithCoords((byte)1, button_state, dx, -dy, dwheel);
|
||||||
dx = dy = dwheel = 0;
|
dx = dy = dwheel = 0;
|
||||||
break;
|
break;
|
||||||
case DIMOFS_BUTTON2:
|
case DIMOFS_BUTTON2:
|
||||||
putMouseEventWithCoords(2, button_state, dx, -dy, dwheel);
|
putMouseEventWithCoords((byte)2, button_state, dx, -dy, dwheel);
|
||||||
dx = dy = dwheel = 0;
|
dx = dy = dwheel = 0;
|
||||||
break;
|
break;
|
||||||
case DIMOFS_BUTTON3:
|
case DIMOFS_BUTTON3:
|
||||||
putMouseEventWithCoords(3, button_state, dx, -dy, dwheel);
|
putMouseEventWithCoords((byte)3, button_state, dx, -dy, dwheel);
|
||||||
dx = dy = dwheel = 0;
|
dx = dy = dwheel = 0;
|
||||||
break;
|
break;
|
||||||
case DIMOFS_X:
|
case DIMOFS_X:
|
||||||
|
@ -234,7 +232,7 @@ final class WindowsMouse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dx != 0 || dy != 0 || dwheel != 0)
|
if (dx != 0 || dy != 0 || dwheel != 0)
|
||||||
putMouseEventWithCoords(-1, 0, dx, -dy, dwheel);
|
putMouseEventWithCoords((byte)-1, (byte)0, dx, -dy, dwheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readDXBuffer() {
|
private void readDXBuffer() {
|
||||||
|
@ -261,7 +259,7 @@ final class WindowsMouse {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(IntBuffer buffer) {
|
public void read(ByteBuffer buffer) {
|
||||||
readDXBuffer();
|
readDXBuffer();
|
||||||
event_queue.copyEvents(buffer);
|
event_queue.copyEvents(buffer);
|
||||||
}
|
}
|
||||||
|
@ -288,7 +286,7 @@ final class WindowsMouse {
|
||||||
|
|
||||||
public void handleMouseScrolled(int event_dwheel) {
|
public void handleMouseScrolled(int event_dwheel) {
|
||||||
accum_dwheel += event_dwheel;
|
accum_dwheel += event_dwheel;
|
||||||
putMouseEvent(-1, 0, event_dwheel);
|
putMouseEvent((byte)-1, (byte)0, event_dwheel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMouseMoved(int x, int y) {
|
public void handleMouseMoved(int x, int y) {
|
||||||
|
@ -299,13 +297,13 @@ final class WindowsMouse {
|
||||||
last_x = x;
|
last_x = x;
|
||||||
last_y = y;
|
last_y = y;
|
||||||
if (mouse_grabbed) {
|
if (mouse_grabbed) {
|
||||||
putMouseEventWithCoords(-1, 0, dx, dy, 0);
|
putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0);
|
||||||
} else {
|
} else {
|
||||||
putMouseEventWithCoords(-1, 0, x, y, 0);
|
putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleMouseButton(int button, int state) {
|
public void handleMouseButton(byte button, byte state) {
|
||||||
putMouseEvent(button, state, 0);
|
putMouseEvent(button, state, 0);
|
||||||
if (button < BUTTON_STATES_SIZE)
|
if (button < BUTTON_STATES_SIZE)
|
||||||
win32_message_button_states[button] = state != 0 ? (byte)1 : (byte)0;
|
win32_message_button_states[button] = state != 0 ? (byte)1 : (byte)0;
|
||||||
|
|
Loading…
Reference in New Issue