using getters

This commit is contained in:
Brian Matzon 2004-02-04 20:44:07 +00:00
parent fc22c03972
commit a3d1eaf94f
8 changed files with 277 additions and 68 deletions

View file

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

View file

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

View file

@ -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 <cix_foo@users.sourceforge.net>
* @author elias_naur <elias_naur@users.sourceforge.net>
* @author Brian Matzon <brian@matzon.dk>
* @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;
}
}

View file

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

View file

@ -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<Controller.buttonCount; i++) {
for(int i=0;i<Controller.getButtonCount(); i++) {
if(Controller.isButtonDown(i)) {
color = (1.0f / Controller.buttonCount) * (i+1);
color = (1.0f / Controller.getButtonCount()) * (i+1);
System.out.println("Button " + i + " down");
}
}

View file

@ -208,9 +208,9 @@ public class HWCursorTest {
Keyboard.poll();
Mouse.poll();
if (Mouse.dx != 0 || Mouse.dy != 0) {
mouse_x += Mouse.dx;
mouse_y += Mouse.dy;
if (Mouse.getDX() != 0 || Mouse.getDY() != 0) {
mouse_x += Mouse.getDX();
mouse_y += Mouse.getDY();
System.out.println("mouse_x " + mouse_x + " mouse_y " + mouse_y);
}

View file

@ -135,9 +135,9 @@ public class KeyboardTest {
int count = Keyboard.getNumKeyboardEvents();
while(Keyboard.next()) {
System.out.println("Checking key:" + Keyboard.getKeyName(Keyboard.key));
System.out.println("Key character: " + Keyboard.character);
if(Keyboard.key == Keyboard.KEY_ESCAPE) {
System.out.println("Checking key:" + Keyboard.getKeyName(Keyboard.getEventKey()));
System.out.println("Key character: " + Keyboard.getCharacter());
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
return;
}

View file

@ -166,8 +166,8 @@ public class MouseCreationTest {
Mouse.poll();
position.x += Mouse.dx;
position.y += Mouse.dy;
position.x += Mouse.getDX();
position.y += Mouse.getDY();
if(position.x<0) {
position.x = 0;
@ -207,9 +207,9 @@ public class MouseCreationTest {
float color = 1.0f;
int buttonDown = 0;
for(int i=0;i<Mouse.buttonCount; i++) {
for(int i=0;i<Mouse.getButtonCount(); i++) {
if(Mouse.isButtonDown(i)) {
color = (1.0f / Mouse.buttonCount) * (i+1);
color = (1.0f / Mouse.getButtonCount()) * (i+1);
break;
}
}