Cleaned up Mouse and Keyboard now that buffering and translation are always enabled

This commit is contained in:
Elias Naur 2005-01-18 16:42:31 +00:00
parent 250a87767f
commit f4180a214d
11 changed files with 22 additions and 159 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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 */

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;