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