From a3d1eaf94f49114b59ea56ffd9a663275e686501 Mon Sep 17 00:00:00 2001 From: Brian Matzon Date: Wed, 4 Feb 2004 20:44:07 +0000 Subject: [PATCH] using getters --- src/java/org/lwjgl/input/Controller.java | 154 ++++++++++++++++-- src/java/org/lwjgl/input/Keyboard.java | 53 ++++-- src/java/org/lwjgl/input/Mouse.java | 98 ++++++++--- .../test/input/ControllerCreationTest.java | 8 +- .../org/lwjgl/test/input/ControllerTest.java | 12 +- .../org/lwjgl/test/input/HWCursorTest.java | 6 +- .../org/lwjgl/test/input/KeyboardTest.java | 6 +- .../lwjgl/test/input/MouseCreationTest.java | 8 +- 8 files changed, 277 insertions(+), 68 deletions(-) diff --git a/src/java/org/lwjgl/input/Controller.java b/src/java/org/lwjgl/input/Controller.java index 408c7281..b6fef124 100644 --- a/src/java/org/lwjgl/input/Controller.java +++ b/src/java/org/lwjgl/input/Controller.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Lightweight Java Game Library Project + * Copyright (c) 2002-2004 Lightweight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -63,28 +63,28 @@ public class Controller { private static boolean[] buttons; /** X position, range -1000 to 1000 */ - public static int x = 0; + private static int x = 0; /** X rotational position, range -1000 to 1000 */ - public static int rx = 0; + private static int rx = 0; /** Y position, range -1000 to 1000 */ - public static int y = 0; + private static int y = 0; /** Y rotational position, range -1000 to 1000 */ - public static int ry = 0; + private static int ry = 0; /** Z position, range -1000 to 1000 */ - public static int z = 0; + private static int z = 0; /** Z rotational position, range -1000 to 1000 */ - public static int rz = 0; + private static int rz = 0; /** Position of Point of View from -1 to 27000 (360 degrees) */ - public static int pov; + private static int pov; /** Slider position, range -1000 to 1000 */ - public static int slider = 0; + private static int slider = 0; /** Constant specifying centered POV */ public static final int POV_CENTER = -1; @@ -102,31 +102,31 @@ public class Controller { public static final int POV_WEST = 9000; /** Number of buttons on the controller */ - public static int buttonCount = -1; + private static int buttonCount = -1; /** Does this controller support a x axis */ - public static boolean hasXAxis = false; + private static boolean hasXAxis = false; /** Does this controller support a rotational x axis */ - public static boolean hasRXAxis = false; + private static boolean hasRXAxis = false; /** Does this controller support an y axis */ - public static boolean hasYAxis = false; + private static boolean hasYAxis = false; /** Does this controller support a rotational y axis */ - public static boolean hasRYAxis = false; + private static boolean hasRYAxis = false; /** Does this controller support a z axis */ - public static boolean hasZAxis = false; + private static boolean hasZAxis = false; /** Does this controller support a rotational z axis */ - public static boolean hasRZAxis = false; + private static boolean hasRZAxis = false; /** Does this controller support a Point-Of-View (hat) */ - public static boolean hasPOV = false; + private static boolean hasPOV = false; /** Does this controller support a slider */ - public static boolean hasSlider = false; + private static boolean hasSlider = false; /** Button names. These are set upon create(), to names like BUTTON0, BUTTON1, etc. */ private static String[] buttonName; @@ -258,4 +258,122 @@ public class Controller { * Register fields with the native library */ private static native void initIDs(); + /** + * @return Returns the buttonCount. + */ + public static int getButtonCount() { + return buttonCount; + } + + /** + * @return Returns whether POV is supported + */ + public static boolean hasPOV() { + return hasPOV; + } + + /** + * @return Returns whether a rotational x axis is supported + */ + public static boolean hasRXAxis() { + return hasRXAxis; + } + + /** + * @return Returns whether a rotational y axis is supported + */ + public static boolean hasRYAxis() { + return hasRYAxis; + } + + /** + * @return Returns whether a rotational z axis is supported + */ + public static boolean hasRZAxis() { + return hasRZAxis; + } + + /** + * @return Returns whether a slider is supported + */ + public static boolean hasSlider() { + return hasSlider; + } + + /** + * @return Returns whether a x axis is supported + */ + public static boolean hasXAxis() { + return hasXAxis; + } + + /** + * @return Returns whether a y axis is supported + */ + public static boolean hasYAxis() { + return hasYAxis; + } + + /** + * @return Returns whether a z axis is supported + */ + public static boolean hasZAxis() { + return hasZAxis; + } + + /** + * @return Returns the POV value + */ + public static int getPov() { + return pov; + } + + /** + * @return Returns the rotational value of the x axis + */ + public static int getRx() { + return rx; + } + + /** + * @return Returns the rotational value of the y axis + */ + public static int getRy() { + return ry; + } + + /** + * @return Returns the rotational value of the z axis + */ + public static int getRz() { + return rz; + } + + /** + * @return Returns the slider value + */ + public static int getSlider() { + return slider; + } + + /** + * @return Returns the x axis value + */ + public static int getX() { + return x; + } + + /** + * @return Returns the y axis value + */ + public static int getY() { + return y; + } + + /** + * @return Returns the z axis value + */ + public static int getZ() { + return z; + } } diff --git a/src/java/org/lwjgl/input/Keyboard.java b/src/java/org/lwjgl/input/Keyboard.java index 628a35b5..11e78660 100644 --- a/src/java/org/lwjgl/input/Keyboard.java +++ b/src/java/org/lwjgl/input/Keyboard.java @@ -222,7 +222,7 @@ public class Keyboard { } /** The number of keys supported */ - public static final int keyCount = counter; + private static final int keyCount = counter; /** Has the keyboard been created? */ private static boolean created; @@ -244,13 +244,13 @@ public class Keyboard { private static int numEvents; /** The current keyboard character being examined */ - public static char character; + private static char eventCharacter; /** The current keyboard event key being examined */ - public static int key; + private static int eventKey; /** The current state of the key being examined in the event queue */ - public static boolean state; + private static boolean eventState; /** One time initialization */ private static boolean initialized; @@ -454,12 +454,45 @@ public class Keyboard { assert readBuffer != null : "Keyboard buffering has not been enabled."; if (readBuffer.hasRemaining()) { - key = readBuffer.get() & 0xFF; - state = readBuffer.get() != 0; - if (translationEnabled) - character = readBuffer.getChar(); + eventKey = readBuffer.get() & 0xFF; + eventState = readBuffer.get() != 0; + if (translationEnabled) { + eventCharacter = readBuffer.getChar(); + } return true; - } else + } else { return false; + } } -} + + /** + * @return Number of keys on this keyboard + */ + public static int getKeyCount() { + return keyCount; + } + + /** + * @return The character from the current event + */ + public static char getCharacter() { + return eventCharacter; + } + + /** + * @return The key from the current event + */ + public static int getEventKey() { + return eventKey; + } + + /** + * Gets the state of the tkey that generated the + * current event + * + * @return True if key was down, or false if released + */ + public static boolean getEventKeyState() { + return eventState; + } +} \ No newline at end of file diff --git a/src/java/org/lwjgl/input/Mouse.java b/src/java/org/lwjgl/input/Mouse.java index aebb3ecf..c9cafb9e 100644 --- a/src/java/org/lwjgl/input/Mouse.java +++ b/src/java/org/lwjgl/input/Mouse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 Lightweight Java Game Library Project + * Copyright (c) 2002-2004 Lightweight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -50,12 +50,20 @@ import org.lwjgl.*; * last position. * * @author cix_foo + * @author elias_naur + * @author Brian Matzon * @version $Revision$ */ public class Mouse { + + /** 1 bit transparency for native cursor */ public final static int CURSOR_ONE_BIT_TRANSPARENCY = 1; + + /** 8 bit alhpa native cursor */ public final static int CURSOR_8_BIT_ALPHA = 2; - public final static int CURSOR_ANIMATION = 4; + + /** animation native cursor */ + public final static int CURSOR_ANIMATION = 4; /** Has the mouse been created? */ private static boolean created; @@ -64,41 +72,40 @@ public class Mouse { private static byte[] buttons; /** Delta X */ - public static int dx; + private static int dx; /** Delta Y */ - public static int dy; + private static int dy; /** Delta Z */ - public static int dwheel; + private static int dwheel; /** Number of buttons supported by the mouse */ - public static int buttonCount = -1; + private static int buttonCount = -1; /** Does this mouse support a scroll wheel */ - public static boolean hasWheel = false; + private static boolean hasWheel = false; /** The current native cursor, if any */ private static Cursor currentCursor; /** Button names. These are set upon create(), to names like BUTTON0, BUTTON1, etc. */ private static String[] buttonName; + + /** hashmap of button names, for fast lookup */ private static final Map buttonMap = new HashMap(16); /** Lazy initialization */ private static boolean initialized; - /** - * The mouse button events from the last read: a sequence of pairs of button number, - * followed by state. - */ - private static ByteBuffer readBuffer; + /** The mouse button events from the last read */ + private static ByteBuffer readBuffer = null; /** The current mouse event button being examined */ - public static int button; + private static int eventButton; /** The current state of the button being examined in the event queue */ - public static boolean state; + private static boolean eventState; /** * Mouse cannot be constructed. @@ -235,8 +242,10 @@ public class Mouse { buttons = new byte[buttonCount]; } + /** Native query of wheel support */ private static native boolean nHasWheel(); + /** Native query of button count */ private static native int nGetButtonCount(); /** @@ -294,10 +303,10 @@ public class Mouse { */ public static boolean isButtonDown(int button) { assert created : "The mouse has not been created."; - if (button >= buttonCount) - return false; + if (button >= buttonCount || button < 0) + return false; else - return buttons[button] == 1; + return buttons[button] == 1; } /** @@ -306,7 +315,7 @@ public class Mouse { * @return a String with the button's human readable name in it or null if the button is unnamed */ public static String getButtonName(int button) { - if (button >= buttonName.length) + if (button >= buttonName.length || button < 0) return null; else return buttonName[button]; @@ -371,10 +380,59 @@ public class Mouse { assert readBuffer != null : "Mouse buffering has not been enabled."; if (readBuffer.hasRemaining()) { - button = readBuffer.get() & 0xFF; - state = readBuffer.get() != 0; + eventButton = readBuffer.get() & 0xFF; + eventState = readBuffer.get() != 0; return true; } else return false; } + + /** + * @return Current events button + */ + public static int getEventButton() { + return eventButton; + } + + /** + * @return Current events button state + */ + public static boolean getEventButtonState() { + return eventState; + } + + /** + * @return Movement on the x axis since last poll + */ + public static int getDX() { + return dx; + } + + /** + * @return Movement on the y axis since last poll + */ + public static int getDY() { + return dy; + } + + /** + * @return Movement of the wheel since last poll + */ + public static int getDWheel() { + return dwheel; + } + + /** + * @return Number of buttons on this mouse + */ + public static int getButtonCount() { + return buttonCount; + } + + /** + * @return Whether or not this mouse has wheel support + */ + public static boolean hasWheel() { + return hasWheel; + } } diff --git a/src/java/org/lwjgl/test/input/ControllerCreationTest.java b/src/java/org/lwjgl/test/input/ControllerCreationTest.java index ef3275c2..5b63fa59 100644 --- a/src/java/org/lwjgl/test/input/ControllerCreationTest.java +++ b/src/java/org/lwjgl/test/input/ControllerCreationTest.java @@ -165,14 +165,14 @@ public class ControllerCreationTest { Controller.poll(); //controller is a bit fuzzy - if(Controller.x > 100) { + if(Controller.getX() > 100) { position.x += 1; - } else if (Controller.x < -100) { + } else if (Controller.getX() < -100) { position.x -= 1; } - if(Controller.y > 100) { + if(Controller.getY() > 100) { position.y -= 1; - } else if (Controller.y < -100) { + } else if (Controller.getY() < -100) { position.y += 1; } diff --git a/src/java/org/lwjgl/test/input/ControllerTest.java b/src/java/org/lwjgl/test/input/ControllerTest.java index 2eb12eb2..180fcede 100644 --- a/src/java/org/lwjgl/test/input/ControllerTest.java +++ b/src/java/org/lwjgl/test/input/ControllerTest.java @@ -131,19 +131,19 @@ public class ControllerTest { return; } - if (Controller.x > 200) { + if (Controller.getX() > 200) { position.x += 1; } - if (Controller.x < -200) { + if (Controller.getX() < -200) { position.x -= 1; } - if (Controller.y < -200) { + if (Controller.getY() < -200) { position.y += 1; } - if (Controller.y > 200) { + if (Controller.getY() > 200) { position.y -= 1; } @@ -174,9 +174,9 @@ public class ControllerTest { float color = 1.0f; int buttonDown = 0; - for(int i=0;i