Added some isCreated() methods to input classes and keyboard key name mapping
This commit is contained in:
parent
5da72080f0
commit
99588933cf
|
@ -158,6 +158,13 @@ public class Controller {
|
||||||
created = true;
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the controller has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Destroy" the controller
|
* "Destroy" the controller
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
package org.lwjgl.input;
|
package org.lwjgl.input;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
|
@ -185,6 +187,27 @@ public class Keyboard {
|
||||||
public static final int KEY_POWER = 0xDE;
|
public static final int KEY_POWER = 0xDE;
|
||||||
public static final int KEY_SLEEP = 0xDF;
|
public static final int KEY_SLEEP = 0xDF;
|
||||||
|
|
||||||
|
/** Key names */
|
||||||
|
private static final String[] keyName = new String[255];
|
||||||
|
static {
|
||||||
|
// Use reflection to find out key names
|
||||||
|
Field[] field = Keyboard.class.getFields();
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < field.length; i++) {
|
||||||
|
if (Modifier.isStatic(field[i].getModifiers())
|
||||||
|
&& Modifier.isPublic(field[i].getModifiers())
|
||||||
|
&& Modifier.isFinal(field[i].getModifiers())
|
||||||
|
&& field[i].getType() == int.class
|
||||||
|
&& field[i].getName().startsWith("KEY_")) {
|
||||||
|
keyName[field[i].getInt(null)] = field[i].getName().substring(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** Has the keyboard been created? */
|
/** Has the keyboard been created? */
|
||||||
private static boolean created;
|
private static boolean created;
|
||||||
|
|
||||||
|
@ -260,6 +283,13 @@ public class Keyboard {
|
||||||
*/
|
*/
|
||||||
private static native boolean nCreate();
|
private static native boolean nCreate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the keyboard has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Destroy" the keyboard
|
* "Destroy" the keyboard
|
||||||
*/
|
*/
|
||||||
|
@ -357,6 +387,15 @@ public class Keyboard {
|
||||||
return keyDownBuffer.get(key) != 0;
|
return keyDownBuffer.get(key) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a key's name
|
||||||
|
* @param key The key
|
||||||
|
* @return a String with the key's human readable name in it or null if the key is unnamed
|
||||||
|
*/
|
||||||
|
public static String getKeyName(int key) {
|
||||||
|
return keyName[key];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the number of keyboard events waiting after doing a read().
|
* Gets the number of keyboard events waiting after doing a read().
|
||||||
* @return the number of keyboard events
|
* @return the number of keyboard events
|
||||||
|
|
|
@ -116,6 +116,13 @@ public class Mouse {
|
||||||
*/
|
*/
|
||||||
private static native boolean nCreate();
|
private static native boolean nCreate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if the mouse has been created
|
||||||
|
*/
|
||||||
|
public static boolean isCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "Destroy" the mouse
|
* "Destroy" the mouse
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package org.lwjgl.openal;
|
package org.lwjgl.openal;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -57,7 +57,7 @@ public abstract class BaseAL {
|
||||||
/**
|
/**
|
||||||
* Override to provide any initialization code after creation.
|
* Override to provide any initialization code after creation.
|
||||||
*/
|
*/
|
||||||
protected void init() {
|
protected void init() throws Exception {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,27 +83,25 @@ public abstract class BaseAL {
|
||||||
String libname;
|
String libname;
|
||||||
|
|
||||||
// libname is hardcoded atm - this will change in a near future...
|
// libname is hardcoded atm - this will change in a near future...
|
||||||
libname = (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1)
|
libname = (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) ? "libopenal.so" : "OpenAL32.dll";
|
||||||
? "libopenal.so"
|
|
||||||
: "OpenAL32.dll";
|
|
||||||
|
|
||||||
StringTokenizer st = new StringTokenizer(libpath, seperator);
|
StringTokenizer st = new StringTokenizer(libpath, seperator);
|
||||||
|
|
||||||
//create needed string array
|
//create needed string array
|
||||||
String[] oalPaths = new String[st.countTokens()+1];
|
String[] oalPaths = new String[st.countTokens() + 1];
|
||||||
|
|
||||||
//build paths
|
//build paths
|
||||||
for(int i=0;i<oalPaths.length - 1;i++) {
|
for (int i = 0; i < oalPaths.length - 1; i++) {
|
||||||
oalPaths[i] = st.nextToken() + File.separator + libname;
|
oalPaths[i] = st.nextToken() + File.separator + libname;
|
||||||
}
|
}
|
||||||
|
|
||||||
//add cwd path
|
//add cwd path
|
||||||
oalPaths[oalPaths.length-1] = libname;
|
oalPaths[oalPaths.length - 1] = libname;
|
||||||
if (!nCreate(oalPaths)) {
|
if (!nCreate(oalPaths)) {
|
||||||
throw new Exception("AL instance could not be created.");
|
throw new Exception("AL instance could not be created.");
|
||||||
}
|
}
|
||||||
created = true;
|
|
||||||
init();
|
init();
|
||||||
|
created = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue