mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-02-20 06:34:14 +01:00
Initial checkin
This commit is contained in:
parent
9741fccdfa
commit
e312d8dd34
58
plugins/awt/build.xml
Normal file
58
plugins/awt/build.xml
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project basedir="." default="all" name="AWT Plugin">
|
||||
|
||||
<target name="init">
|
||||
<mkdir dir="classes"/>
|
||||
<mkdir dir="bin"/>
|
||||
</target>
|
||||
|
||||
<target depends="init" name="compile">
|
||||
<javac debug="true" deprecation="true" destdir="classes" source="1.4" srcdir="src">
|
||||
<classpath>
|
||||
<pathelement location="../../coreAPI/bin/jinput.jar"/>
|
||||
<pathelement location="../../coreAPI/lib/jutils.jar"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target depends="init,compile" name="jar">
|
||||
<jar jarfile="bin/awtinput.jar" compress="true" basedir="classes">
|
||||
<exclude name="**/*.java"/>
|
||||
<exclude name="awtinput.jar"/>
|
||||
<exclude name="apidoc"/>
|
||||
</jar>
|
||||
<copy file="bin/awtinput.jar" todir="../../coreAPI/src/tests/controller" />
|
||||
</target>
|
||||
|
||||
<target depends="jar" description="Build everything." name="all">
|
||||
<echo message="Application built."/>
|
||||
</target>
|
||||
|
||||
<target name="javadoc" depends="init" description="Javadoc for AWT plugin for JInput.">
|
||||
<mkdir dir="apidocs"/>
|
||||
<javadoc packagenames="net.java.games.input.*"
|
||||
destdir="apidocs"
|
||||
additionalparam="-source 1.4"
|
||||
link="../../../coreAPI/apidocs">
|
||||
<sourcepath>
|
||||
<pathelement location="src"/>
|
||||
</sourcepath>
|
||||
<classpath>
|
||||
<pathelement location="../../coreAPI/bin/jinput.jar"/>
|
||||
<pathelement location="../../coreAPI/lib/jutils.jar"/>
|
||||
</classpath>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<target description="Clean all build products." name="clean">
|
||||
<delete failonerror="no">
|
||||
<fileset dir="classes">
|
||||
<include name="**/*.class"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
<delete file="bin/awtinput.jar" failonerror="no"/>
|
||||
<delete file="../../coreAPI/src/tests/controller/awtinput.jar" failonerror="no" />
|
||||
<delete file="apidoc" failonerror="no"/>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
77
plugins/awt/src/net/java/games/input/AWTAxis.java
Normal file
77
plugins/awt/src/net/java/games/input/AWTAxis.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer. Redistributions in binary
|
||||
* form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* The name of the author may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
package net.java.games.input;
|
||||
|
||||
import net.java.games.input.Component.Identifier;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class AWTAxis extends AbstractComponent {
|
||||
|
||||
private float value = 0.0f;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param id
|
||||
*/
|
||||
protected AWTAxis(String name, Identifier id) {
|
||||
super(name, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data from the last time the control has been polled.
|
||||
* If this axis is a button, the value returned will be either 0.0f or 1.0f.
|
||||
* If this axis is normalized, the value returned will be between -1.0f and
|
||||
* 1.0f.
|
||||
* @return 0.0f by default, can be overridden
|
||||
*/
|
||||
public float getPollData() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.java.games.input.Component#isRelative()
|
||||
*/
|
||||
public boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the axis is analog, or false if it is digital.
|
||||
* @return false by default, can be overridden
|
||||
*/
|
||||
public boolean isAnalog() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void setValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
81
plugins/awt/src/net/java/games/input/AWTButton.java
Normal file
81
plugins/awt/src/net/java/games/input/AWTButton.java
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer. Redistributions in binary
|
||||
* form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* The name of the author may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
package net.java.games.input;
|
||||
|
||||
import net.java.games.input.Component.Identifier;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class AWTButton extends AbstractComponent {
|
||||
|
||||
private boolean value = false;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param id
|
||||
*/
|
||||
protected AWTButton(String name, Identifier id) {
|
||||
super(name, id);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.java.games.input.Component#isRelative()
|
||||
*/
|
||||
public boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the axis is analog, or false if it is digital.
|
||||
* @return false by default, can be overridden
|
||||
*/
|
||||
public boolean isAnalog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the data from the last time the control has been polled.
|
||||
* If this axis is a button, the value returned will be either 0.0f or 1.0f.
|
||||
* If this axis is normalized, the value returned will be between -1.0f and
|
||||
* 1.0f.
|
||||
* @return 0.0f by default, can be overridden
|
||||
*/
|
||||
public float getPollData() {
|
||||
if(value) {
|
||||
return 1.0f;
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void setValue(boolean value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer. Redistributions in binary
|
||||
* form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* The name of the author may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
package net.java.games.input;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import net.java.games.input.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.util.plugins.Plugin;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class AWTEnvironmentPlugin extends ControllerEnvironment implements Plugin {
|
||||
|
||||
/** The two controllers */
|
||||
private Controller[] controllers = new Controller[2];
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.java.games.input.ControllerEnvironment#getControllers()
|
||||
*/
|
||||
public Controller[] getControllers() {
|
||||
if((controllers[0] == null) && (controllers[1] == null)) {
|
||||
controllers[0] = new AWTKeyboard("AWTKeyboard");
|
||||
controllers[1] = new AWTMouse("AWTMouse");
|
||||
}
|
||||
return controllers;
|
||||
}
|
||||
|
||||
}
|
||||
264
plugins/awt/src/net/java/games/input/AWTKeyboard.java
Normal file
264
plugins/awt/src/net/java/games/input/AWTKeyboard.java
Normal file
|
|
@ -0,0 +1,264 @@
|
|||
/**
|
||||
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer. Redistributions in binary
|
||||
* form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* The name of the author may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
package net.java.games.input;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.AWTEventListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import net.java.games.input.Keyboard.Key;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class AWTKeyboard extends StandardKeyboard implements AWTEventListener {
|
||||
|
||||
private boolean[] buttonValues;
|
||||
|
||||
private int[] buttonMap;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
protected AWTKeyboard(String name) {
|
||||
super(name);
|
||||
|
||||
buttonValues = new boolean[getAxes().length];
|
||||
buttonMap = new int[65535]; //has to be this big, as the values of KeyEvent keys are large
|
||||
|
||||
buttonMap[KeyEvent.VK_0] = Component.Identifier.Key._0.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_1] = Component.Identifier.Key._1.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_2] = Component.Identifier.Key._2.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_3] = Component.Identifier.Key._3.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_4] = Component.Identifier.Key._4.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_5] = Component.Identifier.Key._5.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_6] = Component.Identifier.Key._6.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_7] = Component.Identifier.Key._7.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_8] = Component.Identifier.Key._8.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_9] = Component.Identifier.Key._9.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_Q] = Component.Identifier.Key.Q.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_W] = Component.Identifier.Key.W.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_E] = Component.Identifier.Key.E.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_R] = Component.Identifier.Key.R.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_T] = Component.Identifier.Key.T.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_Y] = Component.Identifier.Key.Y.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_U] = Component.Identifier.Key.U.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_I] = Component.Identifier.Key.I.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_O] = Component.Identifier.Key.O.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_P] = Component.Identifier.Key.P.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_A] = Component.Identifier.Key.A.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_S] = Component.Identifier.Key.S.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_D] = Component.Identifier.Key.D.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F] = Component.Identifier.Key.F.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_G] = Component.Identifier.Key.G.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_H] = Component.Identifier.Key.H.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_J] = Component.Identifier.Key.J.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_K] = Component.Identifier.Key.K.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_L] = Component.Identifier.Key.L.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_Z] = Component.Identifier.Key.Z.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_X] = Component.Identifier.Key.X.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_C] = Component.Identifier.Key.C.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_V] = Component.Identifier.Key.V.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_B] = Component.Identifier.Key.B.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_N] = Component.Identifier.Key.N.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_M] = Component.Identifier.Key.M.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_F1] = Component.Identifier.Key.F1.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F2] = Component.Identifier.Key.F2.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F3] = Component.Identifier.Key.F3.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F4] = Component.Identifier.Key.F4.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F5] = Component.Identifier.Key.F5.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F6] = Component.Identifier.Key.F6.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F7] = Component.Identifier.Key.F7.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F8] = Component.Identifier.Key.F8.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F9] = Component.Identifier.Key.F9.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F10] = Component.Identifier.Key.F10.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F11] = Component.Identifier.Key.F11.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_F12] = Component.Identifier.Key.F12.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_ESCAPE] = Component.Identifier.Key.ESCAPE.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_MINUS] = Component.Identifier.Key.MINUS.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_EQUALS] = Component.Identifier.Key.EQUALS.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_BACK_SPACE] = Component.Identifier.Key.BACKSLASH.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_TAB] = Component.Identifier.Key.TAB.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_OPEN_BRACKET] = Component.Identifier.Key.LBRACKET.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_CLOSE_BRACKET] = Component.Identifier.Key.RBRACKET.getKeyIndex();
|
||||
//Enter is a special one
|
||||
//Control is a special one
|
||||
buttonMap[KeyEvent.VK_SEMICOLON] = Component.Identifier.Key.SEMICOLON.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_QUOTE] = Component.Identifier.Key.APOSTROPHE.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMBER_SIGN] = Component.Identifier.Key.GRAVE.getKeyIndex();
|
||||
//Shift is a special one
|
||||
buttonMap[KeyEvent.VK_BACK_SLASH] = Component.Identifier.Key.BACKSLASH.getKeyIndex();
|
||||
//Comma is special
|
||||
buttonMap[KeyEvent.VK_PERIOD] = Component.Identifier.Key.PERIOD.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_SLASH] = Component.Identifier.Key.SLASH.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_MULTIPLY] = Component.Identifier.Key.MULTIPLY.getKeyIndex();
|
||||
//Alt is a special one
|
||||
buttonMap[KeyEvent.VK_SPACE] = Component.Identifier.Key.SPACE.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_CAPS_LOCK] = Component.Identifier.Key.CAPITAL.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUM_LOCK] = Component.Identifier.Key.NUMLOCK.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_SCROLL_LOCK] = Component.Identifier.Key.SCROLL.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD7] = Component.Identifier.Key.NUMPAD7.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD8] = Component.Identifier.Key.NUMPAD8.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD9] = Component.Identifier.Key.NUMPAD9.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_SUBTRACT] = Component.Identifier.Key.SUBTRACT.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD4] = Component.Identifier.Key.NUMPAD4.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD5] = Component.Identifier.Key.NUMPAD5.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD6] = Component.Identifier.Key.NUMPAD6.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_ADD] = Component.Identifier.Key.ADD.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD1] = Component.Identifier.Key.NUMPAD1.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD2] = Component.Identifier.Key.NUMPAD2.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD3] = Component.Identifier.Key.NUMPAD3.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NUMPAD0] = Component.Identifier.Key.NUMPAD0.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_DECIMAL] = Component.Identifier.Key.DECIMAL.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_KANA] = Component.Identifier.Key.KANA.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_CONVERT] = Component.Identifier.Key.CONVERT.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_NONCONVERT] = Component.Identifier.Key.NOCONVERT.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_CIRCUMFLEX] = Component.Identifier.Key.CIRCUMFLEX.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_AT] = Component.Identifier.Key.AT.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_COLON] = Component.Identifier.Key.COLON.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_UNDERSCORE] = Component.Identifier.Key.UNDERLINE.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_KANJI] = Component.Identifier.Key.KANJI.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_STOP] = Component.Identifier.Key.STOP.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_DIVIDE] = Component.Identifier.Key.DIVIDE.getKeyIndex();
|
||||
|
||||
buttonMap[KeyEvent.VK_PAUSE] = Component.Identifier.Key.PAUSE.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_HOME] = Component.Identifier.Key.HOME.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_UP] = Component.Identifier.Key.UP.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_PAGE_UP] = Component.Identifier.Key.PAGEUP.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_LEFT] = Component.Identifier.Key.LEFT.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_RIGHT] = Component.Identifier.Key.RIGHT.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_END] = Component.Identifier.Key.END.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_DOWN] = Component.Identifier.Key.DOWN.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_PAGE_DOWN] = Component.Identifier.Key.PAGEDOWN.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_INSERT] = Component.Identifier.Key.INSERT.getKeyIndex();
|
||||
buttonMap[KeyEvent.VK_DELETE] = Component.Identifier.Key.DELETE.getKeyIndex();
|
||||
|
||||
//Windows key is a special one
|
||||
|
||||
// start working
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.java.games.input.Keyboard#isKeyPressed(net.java.games.input.Keyboard.Key)
|
||||
*/
|
||||
protected boolean isKeyPressed(Key key) {
|
||||
int keyId = ((Component.Identifier.Key)key.getIdentifier()).getKeyIndex();
|
||||
return buttonValues[keyId];
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.java.games.input.Controller#poll()
|
||||
*/
|
||||
public boolean poll() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
|
||||
*/
|
||||
public void eventDispatched(AWTEvent event) {
|
||||
if(event instanceof KeyEvent) {
|
||||
KeyEvent keyEvent = (KeyEvent)event;
|
||||
if(keyEvent.getID() == KeyEvent.KEY_PRESSED) {
|
||||
//the key was pressed
|
||||
//System.out.println("Key pressed KeyCode: " + keyEvent.getKeyCode() + " KeyChar: " + keyEvent.getKeyChar());
|
||||
buttonValues[findKeyIndex(keyEvent)] = true;
|
||||
} else if(keyEvent.getID() == KeyEvent.KEY_RELEASED) {
|
||||
KeyEvent nextPress = (KeyEvent)Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(KeyEvent.KEY_PRESSED);
|
||||
|
||||
if ((nextPress == null) || (nextPress.getWhen() != keyEvent.getWhen())) {
|
||||
//the key came really came up
|
||||
//System.out.println("Key released KeyCode: " + keyEvent.getKeyCode() + " KeyChar: " + keyEvent.getKeyChar());
|
||||
buttonValues[findKeyIndex(keyEvent)] = false;
|
||||
}
|
||||
} else {
|
||||
//System.out.println("AWTKeyboard: Ignoring event " + keyEvent.getID());
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("AWTKeyboard not expecting event of type " + event.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private int findKeyIndex(KeyEvent keyEvent) {
|
||||
int buttonIndex = 0;
|
||||
if(keyEvent.getKeyCode() == KeyEvent.VK_CONTROL) {
|
||||
if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
|
||||
buttonIndex = Component.Identifier.Key.LCONTROL.getKeyIndex();
|
||||
} else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
|
||||
buttonIndex = Component.Identifier.Key.RCONTROL.getKeyIndex();
|
||||
}
|
||||
} else if(keyEvent.getKeyCode() == KeyEvent.VK_SHIFT) {
|
||||
if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
|
||||
buttonIndex = Component.Identifier.Key.LSHIFT.getKeyIndex();
|
||||
} else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
|
||||
buttonIndex = Component.Identifier.Key.RSHIFT.getKeyIndex();
|
||||
}
|
||||
} else if(keyEvent.getKeyCode() == KeyEvent.VK_ALT) {
|
||||
if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
|
||||
buttonIndex = Component.Identifier.Key.LALT.getKeyIndex();
|
||||
} else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
|
||||
buttonIndex = Component.Identifier.Key.RALT.getKeyIndex();
|
||||
}
|
||||
//this is 1.5 only
|
||||
/* } else if(keyEvent.getKeyCode() == KeyEvent.VK_WINDOWS) {
|
||||
if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_LEFT) {
|
||||
buttonIndex = Component.Identifier.Key.LWIN.getKeyIndex();
|
||||
} else if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_RIGHT) {
|
||||
buttonIndex = Component.Identifier.Key.RWIN.getKeyIndex();
|
||||
}*/
|
||||
} else if(keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD) {
|
||||
buttonIndex = Component.Identifier.Key.NUMPADENTER.getKeyIndex();
|
||||
} else {
|
||||
buttonIndex = Component.Identifier.Key.RETURN.getKeyIndex();
|
||||
}
|
||||
} else if(keyEvent.getKeyCode() == KeyEvent.VK_COMMA) {
|
||||
if(keyEvent.getKeyLocation() == KeyEvent.KEY_LOCATION_NUMPAD) {
|
||||
buttonIndex = Component.Identifier.Key.NUMPADCOMMA.getKeyIndex();
|
||||
} else {
|
||||
buttonIndex = Component.Identifier.Key.COMMA.getKeyIndex();
|
||||
}
|
||||
} else {
|
||||
buttonIndex = buttonMap[keyEvent.getKeyCode()];
|
||||
}
|
||||
if(buttonIndex == 0 ) {
|
||||
System.out.println("Unrecognised key: " + keyEvent.getKeyCode() + " (" + keyEvent.getKeyLocation() + " " + keyEvent.getKeyChar() + ")");
|
||||
}
|
||||
return buttonIndex;
|
||||
}
|
||||
}
|
||||
198
plugins/awt/src/net/java/games/input/AWTMouse.java
Normal file
198
plugins/awt/src/net/java/games/input/AWTMouse.java
Normal file
|
|
@ -0,0 +1,198 @@
|
|||
/**
|
||||
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer. Redistributions in binary
|
||||
* form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
* The name of the author may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*/
|
||||
|
||||
package net.java.games.input;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.AWTEventListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
*
|
||||
* TODO To change the template for this generated type comment go to
|
||||
* Window - Preferences - Java - Code Style - Code Templates
|
||||
*/
|
||||
public class AWTMouse extends Mouse implements AWTEventListener {
|
||||
|
||||
private AWTAxis xMove = new AWTAxis("X", Component.Identifier.Axis.X);
|
||||
private AWTAxis yMove = new AWTAxis("Y", Component.Identifier.Axis.Y);
|
||||
private AWTAxis zMove = new AWTAxis("Wheel", Component.Identifier.Axis.SLIDER);
|
||||
|
||||
private AWTButton button1 = new AWTButton("Left", Component.Identifier.Button.LEFT);
|
||||
private AWTButton button2 = new AWTButton("Middle", Component.Identifier.Button.MIDDLE);
|
||||
private AWTButton button3 = new AWTButton("Right", Component.Identifier.Button.RIGHT);
|
||||
|
||||
private Point oldMouseLocation = new Point(0,0);
|
||||
private Point newMouseLocation = new Point(0,0);
|
||||
private int scrollAmount = 0;
|
||||
private boolean button1Value = false;
|
||||
private boolean button2Value = false;
|
||||
private boolean button3Value = false;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
protected AWTMouse(String name) {
|
||||
super(name);
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
|
||||
this.ball = new AWTMouseBall(xMove, yMove, zMove);
|
||||
this.buttons = new AWTMouseButtons(new AWTMouseButton(button1), new AWTMouseButton(button2), new AWTMouseButton(button3));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.java.games.input.Controller#poll()
|
||||
*/
|
||||
public boolean poll() {
|
||||
button1.setValue(button1Value);
|
||||
button2.setValue(button2Value);
|
||||
button3.setValue(button3Value);
|
||||
|
||||
zMove.setValue(scrollAmount);
|
||||
scrollAmount = 0;
|
||||
|
||||
//System.out.println("old mouse location " + oldMouseLocation);
|
||||
//System.out.println("new mouse location " + newMouseLocation);
|
||||
yMove.setValue((float)(newMouseLocation.getY() - oldMouseLocation.getY()));
|
||||
xMove.setValue((float)(newMouseLocation.getX() - oldMouseLocation.getX()));
|
||||
oldMouseLocation.setLocation(newMouseLocation.getLocation());
|
||||
//newMouseLocation.setLocation(0,0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.awt.event.AWTEventListener#eventDispatched(java.awt.AWTEvent)
|
||||
*/
|
||||
public void eventDispatched(AWTEvent event) {
|
||||
//System.out.println("AWTMouse: From: " + arg0.getSource() + " - " + arg0);
|
||||
if(event instanceof MouseWheelEvent) {
|
||||
MouseWheelEvent mwe = (MouseWheelEvent)event;
|
||||
scrollAmount += mwe.getWheelRotation();
|
||||
//System.out.println("New scroll amount: " + scrollAmount);
|
||||
}
|
||||
if(event instanceof MouseEvent) {
|
||||
MouseEvent me = (MouseEvent)event;
|
||||
newMouseLocation.setLocation(me.getPoint());
|
||||
//System.out.println("Mouse moved to " + newMouseLocation);
|
||||
if(me.getID() == MouseEvent.MOUSE_PRESSED) {
|
||||
//System.out.println("Button was pressed");
|
||||
if(me.getButton() == MouseEvent.BUTTON1) {
|
||||
//System.out.println("Button 1 was pressed");
|
||||
button1Value = true;
|
||||
} else if(me.getButton() == MouseEvent.BUTTON2) {
|
||||
//System.out.println("Button 2 was pressed");
|
||||
button2Value = true;
|
||||
} else if(me.getButton() == MouseEvent.BUTTON3) {
|
||||
//System.out.println("Button 3 was pressed");
|
||||
button3Value = true;
|
||||
}
|
||||
} else if(me.getID() == MouseEvent.MOUSE_RELEASED) {
|
||||
//ystem.out.println("Button was released");
|
||||
if(me.getButton() == MouseEvent.BUTTON1) {
|
||||
//System.out.println("Button 1 was released");
|
||||
button1Value = false;
|
||||
} else if(me.getButton() == MouseEvent.BUTTON2) {
|
||||
//System.out.println("Button 2 was released");
|
||||
button2Value = false;
|
||||
} else if(me.getButton() == MouseEvent.BUTTON3) {
|
||||
//System.out.println("Button 3 was released");
|
||||
button3Value = false;
|
||||
}
|
||||
} else {
|
||||
//System.out.println("Mouse event ID " + me.getID() + " (" + me.getClass().getName() + ")");
|
||||
}
|
||||
} else {
|
||||
System.out.println("AWTMouse got an event of type " + event.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/** Mouse ball under AWT
|
||||
*/
|
||||
private class AWTMouseBall extends Ball {
|
||||
/** Constructs the new mouse ball
|
||||
* @param x The x axis
|
||||
* @param y The y axis
|
||||
* @param wheel The mouse wheel axis
|
||||
*/
|
||||
public AWTMouseBall(Component x, Component y, Component wheel) {
|
||||
super(AWTMouse.this.getName() + " ball");
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.wheel = wheel;
|
||||
}
|
||||
}
|
||||
|
||||
/** Mouse buttons under AWT
|
||||
*/
|
||||
private class AWTMouseButtons extends Buttons {
|
||||
/** Creates the new mouse's buttons
|
||||
* @param left Left mouse button
|
||||
* @param right Right mouse button
|
||||
* @param middle Middle mouse button
|
||||
*/
|
||||
public AWTMouseButtons(Button left, Button right, Button middle) {
|
||||
super(AWTMouse.this.getName() + " buttons");
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.middle = middle;
|
||||
}
|
||||
}
|
||||
|
||||
/** AWT specific mouse buttons
|
||||
*/
|
||||
private class AWTMouseButton extends Mouse.Button {
|
||||
/** The real Axis
|
||||
*/
|
||||
private Component realAxis;
|
||||
|
||||
/** Construct an AWT mouse button from the given axis
|
||||
* @param axis The axis that holds the data
|
||||
*/
|
||||
public AWTMouseButton(Component axis) {
|
||||
super(axis.getName(), (Component.Identifier.Button)axis.getIdentifier());
|
||||
this.realAxis = axis;
|
||||
}
|
||||
|
||||
/** Returns true f this axis is relative
|
||||
* @return Always returns false for a mouse button
|
||||
*/
|
||||
public boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns the data for this mouse button
|
||||
* @return Retursn this mouse buttons value
|
||||
*/
|
||||
public float getPollData(){
|
||||
return realAxis.getPollData();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue