Cleaned up Mouse and Keyboard now that buffering and translation are always enabled
This commit is contained in:
parent
250a87767f
commit
f4180a214d
|
@ -247,9 +247,6 @@ public class Keyboard {
|
|||
*/
|
||||
private static IntBuffer readBuffer;
|
||||
|
||||
/** True if translation is enabled */
|
||||
private static boolean translationEnabled;
|
||||
|
||||
/** The current keyboard character being examined */
|
||||
private static char eventCharacter;
|
||||
|
||||
|
@ -293,8 +290,8 @@ public class Keyboard {
|
|||
return;
|
||||
Display.getImplementation().createKeyboard();
|
||||
created = true;
|
||||
enableBuffer();
|
||||
enableTranslation();
|
||||
readBuffer = BufferUtils.createIntBuffer(EVENT_SIZE*BUFFER_SIZE);
|
||||
readBuffer.limit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -337,8 +334,7 @@ public class Keyboard {
|
|||
if (!created)
|
||||
throw new IllegalStateException("Keyboard must be created before you can poll the device");
|
||||
Display.getImplementation().pollKeyboard(keyDownBuffer);
|
||||
if (readBuffer != null)
|
||||
read();
|
||||
read();
|
||||
}
|
||||
|
||||
private static void read() {
|
||||
|
@ -348,30 +344,6 @@ public class Keyboard {
|
|||
readBuffer.flip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable keyboard translation. Must be called after the keyboard is created,
|
||||
* and keyboard buffering must be enabled.
|
||||
*/
|
||||
private static void enableTranslation() throws LWJGLException {
|
||||
if (!created)
|
||||
throw new IllegalStateException("Keyboard must be created before you can read events");
|
||||
if (readBuffer == null)
|
||||
throw new IllegalStateException("Event buffering must be enabled before you can read events");
|
||||
Display.getImplementation().enableTranslation();
|
||||
translationEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable keyboard buffering. Must be called after the keyboard is created.
|
||||
*/
|
||||
private static void enableBuffer() throws LWJGLException {
|
||||
if (!created)
|
||||
throw new IllegalStateException("Keyboard must be created before you can enable buffering");
|
||||
readBuffer = BufferUtils.createIntBuffer(EVENT_SIZE*BUFFER_SIZE);
|
||||
readBuffer.limit(0);
|
||||
Display.getImplementation().enableKeyboardBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a key is down.
|
||||
* @param key Keycode to check
|
||||
|
@ -440,8 +412,6 @@ public class Keyboard {
|
|||
public static boolean next() {
|
||||
if (!created)
|
||||
throw new IllegalStateException("Keyboard must be created before you can read events");
|
||||
if (readBuffer == null)
|
||||
throw new IllegalStateException("Event buffering must be enabled before you can read events");
|
||||
|
||||
if (readBuffer.hasRemaining()) {
|
||||
eventKey = readBuffer.get() & 0xFF;
|
||||
|
|
|
@ -198,8 +198,7 @@ public class Mouse {
|
|||
height = Display.getDisplayMode().getHeight();
|
||||
x = width / 2;
|
||||
y = height / 2;
|
||||
if (readBuffer != null)
|
||||
readBuffer.clear();
|
||||
readBuffer.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,8 +224,9 @@ public class Mouse {
|
|||
coord_buffer = BufferUtils.createIntBuffer(3);
|
||||
if (currentCursor != null)
|
||||
setNativeCursor(currentCursor);
|
||||
readBuffer = BufferUtils.createIntBuffer(EVENT_SIZE * BUFFER_SIZE);
|
||||
readBuffer.limit(0);
|
||||
setGrabbed(isGrabbed);
|
||||
enableBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -291,8 +291,7 @@ public class Mouse {
|
|||
x = Math.min(width - 1, Math.max(0, x));
|
||||
y = Math.min(height - 1, Math.max(0, y));
|
||||
dwheel += poll_dwheel;
|
||||
if (readBuffer != null)
|
||||
read();
|
||||
read();
|
||||
}
|
||||
|
||||
private static void read() {
|
||||
|
@ -340,16 +339,6 @@ public class Mouse {
|
|||
return ret.intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable mouse button buffering. Must be called after the mouse is created.
|
||||
*/
|
||||
private static void enableBuffer() throws LWJGLException {
|
||||
if (!created) throw new IllegalStateException("Mouse must be created before you can enable buffering");
|
||||
readBuffer = BufferUtils.createIntBuffer(EVENT_SIZE * BUFFER_SIZE);
|
||||
readBuffer.limit(0);
|
||||
Display.getImplementation().enableMouseBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next mouse event. You can query which button caused the event by using
|
||||
* <code>getEventButton()</code> (if any). To get the state of that key, for that event, use
|
||||
|
@ -361,9 +350,6 @@ public class Mouse {
|
|||
*/
|
||||
public static boolean next() {
|
||||
if (!created) throw new IllegalStateException("Mouse must be created before you can read events");
|
||||
if (readBuffer == null)
|
||||
throw new IllegalStateException("Event buffering must be enabled before you can read events");
|
||||
|
||||
if (readBuffer.hasRemaining()) {
|
||||
eventButton = readBuffer.get();
|
||||
eventState = readBuffer.get() != 0;
|
||||
|
|
|
@ -159,11 +159,6 @@ public interface DisplayImplementation {
|
|||
*/
|
||||
void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
|
||||
|
||||
/**
|
||||
* Method to enable the buffer
|
||||
*/
|
||||
void enableMouseBuffer() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Method to read the keyboard buffer
|
||||
*
|
||||
|
@ -216,16 +211,6 @@ public interface DisplayImplementation {
|
|||
*/
|
||||
int readKeyboard(IntBuffer buffer, int buffer_position);
|
||||
|
||||
/**
|
||||
* Method to enable the translation buffer
|
||||
*/
|
||||
void enableTranslation() throws LWJGLException;
|
||||
|
||||
/**
|
||||
* Method to enable the buffer
|
||||
*/
|
||||
void enableKeyboardBuffer() throws LWJGLException;
|
||||
|
||||
int isStateKeySet(int key);
|
||||
|
||||
/** Native cursor handles */
|
||||
|
|
|
@ -247,13 +247,6 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
public native void nPollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
|
||||
|
||||
public void enableMouseBuffer() throws LWJGLException {
|
||||
lockAWT();
|
||||
nEnableMouseBuffer();
|
||||
unlockAWT();
|
||||
}
|
||||
public native void nEnableMouseBuffer() throws LWJGLException;
|
||||
|
||||
public int readMouse(IntBuffer buffer, int buffer_position) {
|
||||
lockAWT();
|
||||
int count = nReadMouse(buffer, buffer_position);
|
||||
|
@ -330,20 +323,6 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
public native int nReadKeyboard(IntBuffer buffer, int buffer_position);
|
||||
|
||||
public void enableTranslation() throws LWJGLException {
|
||||
lockAWT();
|
||||
nEnableTranslation();
|
||||
unlockAWT();
|
||||
}
|
||||
public native void nEnableTranslation() throws LWJGLException;
|
||||
|
||||
public void enableKeyboardBuffer() throws LWJGLException {
|
||||
lockAWT();
|
||||
nEnableKeyboardBuffer();
|
||||
unlockAWT();
|
||||
}
|
||||
public native void nEnableKeyboardBuffer() throws LWJGLException;
|
||||
|
||||
public int isStateKeySet(int key) {
|
||||
return Keyboard.STATE_UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -270,9 +270,6 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
mouse_queue.poll(coord_buffer, buttons_buffer);
|
||||
}
|
||||
|
||||
public void enableMouseBuffer() throws LWJGLException {
|
||||
}
|
||||
|
||||
public int readMouse(IntBuffer buffer, int buffer_position) {
|
||||
assert buffer_position == buffer.position();
|
||||
return mouse_queue.copyEvents(buffer);
|
||||
|
@ -349,12 +346,6 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
return keyboard_queue.copyEvents(buffer);
|
||||
}
|
||||
|
||||
public void enableTranslation() throws LWJGLException {
|
||||
}
|
||||
|
||||
public void enableKeyboardBuffer() throws LWJGLException {
|
||||
}
|
||||
|
||||
public int isStateKeySet(int key) {
|
||||
return Keyboard.STATE_UNKNOWN;
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ final class Win32Display implements DisplayImplementation {
|
|||
public native void createMouse();
|
||||
public native void destroyMouse();
|
||||
public native void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
|
||||
public native void enableMouseBuffer() throws LWJGLException;
|
||||
public native int readMouse(IntBuffer buffer, int buffer_position);
|
||||
public native void grabMouse(boolean grab);
|
||||
public int getNativeCursorCapabilities() {
|
||||
|
@ -95,8 +94,6 @@ final class Win32Display implements DisplayImplementation {
|
|||
public native void destroyKeyboard();
|
||||
public native void pollKeyboard(ByteBuffer keyDownBuffer);
|
||||
public native int readKeyboard(IntBuffer buffer, int buffer_position);
|
||||
public native void enableTranslation() throws LWJGLException;
|
||||
public native void enableKeyboardBuffer() throws LWJGLException;
|
||||
public native int isStateKeySet(int key);
|
||||
|
||||
public native void nCreateCursor(ByteBuffer handle, int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, int images_offset, IntBuffer delays, int delays_offset) throws LWJGLException;
|
||||
|
|
|
@ -61,8 +61,6 @@ static unsigned char key_map[KEYBOARD_SIZE];
|
|||
static event_queue_t event_queue;
|
||||
|
||||
static bool keyboard_grabbed;
|
||||
static bool buffer_enabled;
|
||||
static bool translation_enabled;
|
||||
static bool created = false;
|
||||
|
||||
// X input manager values
|
||||
|
@ -151,8 +149,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateKeyboard
|
|||
memset(key_buf, 0, KEYBOARD_SIZE*sizeof(unsigned char));
|
||||
created = true;
|
||||
keyboard_grabbed = false;
|
||||
translation_enabled = false;
|
||||
buffer_enabled = false;
|
||||
initEventQueue(&event_queue, 3);
|
||||
updateKeyboardGrab();
|
||||
|
||||
|
@ -244,7 +240,7 @@ static void translateEvent(XKeyEvent *event, jint keycode, jint state) {
|
|||
int num_chars, i;
|
||||
jint ch;
|
||||
|
||||
if (!translation_enabled || event->type == KeyRelease) {
|
||||
if (event->type == KeyRelease) {
|
||||
putKeyboardEvent(keycode, state, 0);
|
||||
return;
|
||||
}
|
||||
|
@ -281,8 +277,7 @@ void handleKeyEvent(XKeyEvent *event) {
|
|||
unsigned char keycode = getKeycode(event);
|
||||
unsigned char state = eventState(event);
|
||||
key_buf[keycode] = state;
|
||||
if (buffer_enabled)
|
||||
bufferEvent(event);
|
||||
bufferEvent(event);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nPollKeyboard(JNIEnv * env, jobject this, jobject buffer) {
|
||||
|
@ -297,11 +292,3 @@ JNIEXPORT int JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nReadKeyboard(JNIEnv *
|
|||
int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer))/sizeof(jint) - buffer_position;
|
||||
return copyEvents(&event_queue, buffer_ptr + buffer_position, buffer_size);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nEnableTranslation(JNIEnv *env, jobject this) {
|
||||
translation_enabled = true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nEnableKeyboardBuffer(JNIEnv * env, jobject this) {
|
||||
buffer_enabled = true;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,6 @@ static int last_x;
|
|||
static int last_y;
|
||||
static jbyte buttons[NUM_BUTTONS];
|
||||
static event_queue_t event_queue;
|
||||
static bool buffer_enabled;
|
||||
|
||||
static Cursor blank_cursor;
|
||||
static Cursor current_cursor;
|
||||
|
@ -228,7 +227,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nCreateMouse
|
|||
current_cursor = None;
|
||||
created = true;
|
||||
pointer_grabbed = false;
|
||||
buffer_enabled = false;
|
||||
updatePointerGrab();
|
||||
initEventQueue(&event_queue, EVENT_SIZE);
|
||||
}
|
||||
|
@ -348,10 +346,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nPollMouse(JNIEnv * en
|
|||
buttons_buffer[i] = buttons[i];
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nEnableMouseBuffer(JNIEnv *env, jobject this) {
|
||||
buffer_enabled = true;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nReadMouse(JNIEnv *env, jobject this, jobject buffer, jint buffer_position) {
|
||||
jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer);
|
||||
int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer))/sizeof(jint) - buffer_position;
|
||||
|
|
|
@ -173,7 +173,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
|
|||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyCursor
|
||||
(JNIEnv *env, jobject self, jobject handle_buffer)
|
||||
{
|
||||
// HCURSOR cursor = (HCURSOR)cursor_handle;
|
||||
HCURSOR *cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
|
||||
HCURSOR *cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
|
||||
DestroyCursor(*cursor_handle);
|
||||
}
|
||||
|
|
|
@ -54,13 +54,13 @@ extern HINSTANCE dll_handle; // Handle to the LWJGL dll
|
|||
|
||||
static LPDIRECTINPUT lpdi = NULL; // DirectInput
|
||||
static LPDIRECTINPUTDEVICE lpdiKeyboard = NULL;
|
||||
static bool translationEnabled;
|
||||
|
||||
static bool useUnicode;
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
|
||||
(JNIEnv * env, jobject self)
|
||||
{
|
||||
OSVERSIONINFO osvi;
|
||||
DIPROPDWORD dipropdw;
|
||||
// Create input
|
||||
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
||||
|
@ -69,7 +69,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
|
|||
return;
|
||||
}
|
||||
|
||||
translationEnabled = false;
|
||||
// Check to see if we're already initialized
|
||||
if (lpdiKeyboard != NULL) {
|
||||
throwException(env, "Keyboard already created.");
|
||||
|
@ -101,6 +100,16 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
|
|||
if(FAILED(ret)) {
|
||||
printfDebug("Failed to acquire keyboard\n");
|
||||
}
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
GetVersionEx(&osvi);
|
||||
|
||||
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
useUnicode = true;
|
||||
} else {
|
||||
useUnicode = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -205,7 +214,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
|
|||
buf[index++] = (unsigned char) rgdod[current_di_event].dwOfs;
|
||||
buf[index++] = (unsigned char) rgdod[current_di_event].dwData;
|
||||
key_down = (rgdod[current_di_event].dwData & 0x80) != 0;
|
||||
if (translationEnabled && key_down) {
|
||||
if (key_down) {
|
||||
scan_code = rgdod[current_di_event].dwOfs;
|
||||
virt_key = MapVirtualKey(scan_code, 1);
|
||||
if (virt_key != 0 && GetKeyboardState(state)) {
|
||||
|
@ -270,34 +279,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
|
|||
return num_events;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_input_Keyboard
|
||||
* Method: nEnableTranslation
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_enableTranslation
|
||||
(JNIEnv *env, jobject self)
|
||||
{
|
||||
// We can't do translation on DOS boxes it seems so we'll have to throw a wobbler
|
||||
// here:
|
||||
OSVERSIONINFO osvi;
|
||||
|
||||
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
||||
GetVersionEx(&osvi);
|
||||
|
||||
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
useUnicode = true;
|
||||
} else {
|
||||
useUnicode = false;
|
||||
}
|
||||
translationEnabled = true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_enableKeyboardBuffer
|
||||
(JNIEnv * env, jobject self)
|
||||
{
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_isStateKeySet(JNIEnv *env, jobject self, jint key)
|
||||
{
|
||||
int state = org_lwjgl_input_Keyboard_STATE_UNKNOWN;
|
||||
|
|
|
@ -72,7 +72,6 @@ static int last_x;
|
|||
static int last_y;
|
||||
|
||||
static event_queue_t event_queue;
|
||||
static bool buffer_enabled;
|
||||
|
||||
// Function prototypes (defined in the cpp file, since header file is generic across platforms
|
||||
BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef);
|
||||
|
@ -178,7 +177,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en
|
|||
initEventQueue(&event_queue, EVENT_SIZE);
|
||||
|
||||
last_x = last_y = accum_dx = accum_dy = accum_dwheel = 0;
|
||||
buffer_enabled = false;
|
||||
mouse_grabbed = false;
|
||||
|
||||
// Create input
|
||||
|
@ -209,10 +207,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en
|
|||
created = true;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_enableMouseBuffer(JNIEnv * env, jobject self) {
|
||||
buffer_enabled = true;
|
||||
}
|
||||
|
||||
void handleMouseScrolled(int event_dwheel) {
|
||||
if(created) {
|
||||
accum_dwheel += event_dwheel;
|
||||
|
|
Loading…
Reference in New Issue