mirror of
https://github.com/shadowfacts/jinput-arm64.git
synced 2026-04-21 06:14:11 +00:00
Linux building under maven
This commit is contained in:
parent
294629a312
commit
b2fd759065
78 changed files with 418 additions and 297 deletions
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* 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.Controller;
|
||||
import net.java.games.input.ControllerEnvironment;
|
||||
import net.java.games.util.plugins.Plugin;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
* @author elias
|
||||
*/
|
||||
public class AWTEnvironmentPlugin extends ControllerEnvironment implements Plugin {
|
||||
|
||||
private final Controller[] controllers;
|
||||
|
||||
public AWTEnvironmentPlugin() {
|
||||
this.controllers = new Controller[]{new AWTKeyboard(), new AWTMouse()};
|
||||
}
|
||||
|
||||
public Controller[] getControllers() {
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public boolean isSupported() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
289
plugins/awt/src/main/java/net/java/games/input/AWTKeyMap.java
Normal file
289
plugins/awt/src/main/java/net/java/games/input/AWTKeyMap.java
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
/**
|
||||
* 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.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
* @author elias
|
||||
*/
|
||||
final class AWTKeyMap {
|
||||
public final static Component.Identifier.Key mapKeyCode(int key_code) {
|
||||
switch (key_code) {
|
||||
case KeyEvent.VK_0:
|
||||
return Component.Identifier.Key._0;
|
||||
case KeyEvent.VK_1:
|
||||
return Component.Identifier.Key._1;
|
||||
case KeyEvent.VK_2:
|
||||
return Component.Identifier.Key._2;
|
||||
case KeyEvent.VK_3:
|
||||
return Component.Identifier.Key._3;
|
||||
case KeyEvent.VK_4:
|
||||
return Component.Identifier.Key._4;
|
||||
case KeyEvent.VK_5:
|
||||
return Component.Identifier.Key._5;
|
||||
case KeyEvent.VK_6:
|
||||
return Component.Identifier.Key._6;
|
||||
case KeyEvent.VK_7:
|
||||
return Component.Identifier.Key._7;
|
||||
case KeyEvent.VK_8:
|
||||
return Component.Identifier.Key._8;
|
||||
case KeyEvent.VK_9:
|
||||
return Component.Identifier.Key._9;
|
||||
|
||||
case KeyEvent.VK_Q:
|
||||
return Component.Identifier.Key.Q;
|
||||
case KeyEvent.VK_W:
|
||||
return Component.Identifier.Key.W;
|
||||
case KeyEvent.VK_E:
|
||||
return Component.Identifier.Key.E;
|
||||
case KeyEvent.VK_R:
|
||||
return Component.Identifier.Key.R;
|
||||
case KeyEvent.VK_T:
|
||||
return Component.Identifier.Key.T;
|
||||
case KeyEvent.VK_Y:
|
||||
return Component.Identifier.Key.Y;
|
||||
case KeyEvent.VK_U:
|
||||
return Component.Identifier.Key.U;
|
||||
case KeyEvent.VK_I:
|
||||
return Component.Identifier.Key.I;
|
||||
case KeyEvent.VK_O:
|
||||
return Component.Identifier.Key.O;
|
||||
case KeyEvent.VK_P:
|
||||
return Component.Identifier.Key.P;
|
||||
case KeyEvent.VK_A:
|
||||
return Component.Identifier.Key.A;
|
||||
case KeyEvent.VK_S:
|
||||
return Component.Identifier.Key.S;
|
||||
case KeyEvent.VK_D:
|
||||
return Component.Identifier.Key.D;
|
||||
case KeyEvent.VK_F:
|
||||
return Component.Identifier.Key.F;
|
||||
case KeyEvent.VK_G:
|
||||
return Component.Identifier.Key.G;
|
||||
case KeyEvent.VK_H:
|
||||
return Component.Identifier.Key.H;
|
||||
case KeyEvent.VK_J:
|
||||
return Component.Identifier.Key.J;
|
||||
case KeyEvent.VK_K:
|
||||
return Component.Identifier.Key.K;
|
||||
case KeyEvent.VK_L:
|
||||
return Component.Identifier.Key.L;
|
||||
case KeyEvent.VK_Z:
|
||||
return Component.Identifier.Key.Z;
|
||||
case KeyEvent.VK_X:
|
||||
return Component.Identifier.Key.X;
|
||||
case KeyEvent.VK_C:
|
||||
return Component.Identifier.Key.C;
|
||||
case KeyEvent.VK_V:
|
||||
return Component.Identifier.Key.V;
|
||||
case KeyEvent.VK_B:
|
||||
return Component.Identifier.Key.B;
|
||||
case KeyEvent.VK_N:
|
||||
return Component.Identifier.Key.N;
|
||||
case KeyEvent.VK_M:
|
||||
return Component.Identifier.Key.M;
|
||||
|
||||
case KeyEvent.VK_F1:
|
||||
return Component.Identifier.Key.F1;
|
||||
case KeyEvent.VK_F2:
|
||||
return Component.Identifier.Key.F2;
|
||||
case KeyEvent.VK_F3:
|
||||
return Component.Identifier.Key.F3;
|
||||
case KeyEvent.VK_F4:
|
||||
return Component.Identifier.Key.F4;
|
||||
case KeyEvent.VK_F5:
|
||||
return Component.Identifier.Key.F5;
|
||||
case KeyEvent.VK_F6:
|
||||
return Component.Identifier.Key.F6;
|
||||
case KeyEvent.VK_F7:
|
||||
return Component.Identifier.Key.F7;
|
||||
case KeyEvent.VK_F8:
|
||||
return Component.Identifier.Key.F8;
|
||||
case KeyEvent.VK_F9:
|
||||
return Component.Identifier.Key.F9;
|
||||
case KeyEvent.VK_F10:
|
||||
return Component.Identifier.Key.F10;
|
||||
case KeyEvent.VK_F11:
|
||||
return Component.Identifier.Key.F11;
|
||||
case KeyEvent.VK_F12:
|
||||
return Component.Identifier.Key.F12;
|
||||
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
return Component.Identifier.Key.ESCAPE;
|
||||
case KeyEvent.VK_MINUS:
|
||||
return Component.Identifier.Key.MINUS;
|
||||
case KeyEvent.VK_EQUALS:
|
||||
return Component.Identifier.Key.EQUALS;
|
||||
case KeyEvent.VK_BACK_SPACE:
|
||||
return Component.Identifier.Key.BACKSLASH;
|
||||
case KeyEvent.VK_TAB:
|
||||
return Component.Identifier.Key.TAB;
|
||||
case KeyEvent.VK_OPEN_BRACKET:
|
||||
return Component.Identifier.Key.LBRACKET;
|
||||
case KeyEvent.VK_CLOSE_BRACKET:
|
||||
return Component.Identifier.Key.RBRACKET;
|
||||
case KeyEvent.VK_SEMICOLON:
|
||||
return Component.Identifier.Key.SEMICOLON;
|
||||
case KeyEvent.VK_QUOTE:
|
||||
return Component.Identifier.Key.APOSTROPHE;
|
||||
case KeyEvent.VK_NUMBER_SIGN:
|
||||
return Component.Identifier.Key.GRAVE;
|
||||
case KeyEvent.VK_BACK_SLASH:
|
||||
return Component.Identifier.Key.BACKSLASH;
|
||||
case KeyEvent.VK_PERIOD:
|
||||
return Component.Identifier.Key.PERIOD;
|
||||
case KeyEvent.VK_SLASH:
|
||||
return Component.Identifier.Key.SLASH;
|
||||
case KeyEvent.VK_MULTIPLY:
|
||||
return Component.Identifier.Key.MULTIPLY;
|
||||
case KeyEvent.VK_SPACE:
|
||||
return Component.Identifier.Key.SPACE;
|
||||
case KeyEvent.VK_CAPS_LOCK:
|
||||
return Component.Identifier.Key.CAPITAL;
|
||||
case KeyEvent.VK_NUM_LOCK:
|
||||
return Component.Identifier.Key.NUMLOCK;
|
||||
case KeyEvent.VK_SCROLL_LOCK:
|
||||
return Component.Identifier.Key.SCROLL;
|
||||
case KeyEvent.VK_NUMPAD7:
|
||||
return Component.Identifier.Key.NUMPAD7;
|
||||
case KeyEvent.VK_NUMPAD8:
|
||||
return Component.Identifier.Key.NUMPAD8;
|
||||
case KeyEvent.VK_NUMPAD9:
|
||||
return Component.Identifier.Key.NUMPAD9;
|
||||
case KeyEvent.VK_SUBTRACT:
|
||||
return Component.Identifier.Key.SUBTRACT;
|
||||
case KeyEvent.VK_NUMPAD4:
|
||||
return Component.Identifier.Key.NUMPAD4;
|
||||
case KeyEvent.VK_NUMPAD5:
|
||||
return Component.Identifier.Key.NUMPAD5;
|
||||
case KeyEvent.VK_NUMPAD6:
|
||||
return Component.Identifier.Key.NUMPAD6;
|
||||
case KeyEvent.VK_ADD:
|
||||
return Component.Identifier.Key.ADD;
|
||||
case KeyEvent.VK_NUMPAD1:
|
||||
return Component.Identifier.Key.NUMPAD1;
|
||||
case KeyEvent.VK_NUMPAD2:
|
||||
return Component.Identifier.Key.NUMPAD2;
|
||||
case KeyEvent.VK_NUMPAD3:
|
||||
return Component.Identifier.Key.NUMPAD3;
|
||||
case KeyEvent.VK_NUMPAD0:
|
||||
return Component.Identifier.Key.NUMPAD0;
|
||||
case KeyEvent.VK_DECIMAL:
|
||||
return Component.Identifier.Key.DECIMAL;
|
||||
|
||||
case KeyEvent.VK_KANA:
|
||||
return Component.Identifier.Key.KANA;
|
||||
case KeyEvent.VK_CONVERT:
|
||||
return Component.Identifier.Key.CONVERT;
|
||||
case KeyEvent.VK_NONCONVERT:
|
||||
return Component.Identifier.Key.NOCONVERT;
|
||||
|
||||
case KeyEvent.VK_CIRCUMFLEX:
|
||||
return Component.Identifier.Key.CIRCUMFLEX;
|
||||
case KeyEvent.VK_AT:
|
||||
return Component.Identifier.Key.AT;
|
||||
case KeyEvent.VK_COLON:
|
||||
return Component.Identifier.Key.COLON;
|
||||
case KeyEvent.VK_UNDERSCORE:
|
||||
return Component.Identifier.Key.UNDERLINE;
|
||||
case KeyEvent.VK_KANJI:
|
||||
return Component.Identifier.Key.KANJI;
|
||||
|
||||
case KeyEvent.VK_STOP:
|
||||
return Component.Identifier.Key.STOP;
|
||||
|
||||
case KeyEvent.VK_DIVIDE:
|
||||
return Component.Identifier.Key.DIVIDE;
|
||||
|
||||
case KeyEvent.VK_PAUSE:
|
||||
return Component.Identifier.Key.PAUSE;
|
||||
case KeyEvent.VK_HOME:
|
||||
return Component.Identifier.Key.HOME;
|
||||
case KeyEvent.VK_UP:
|
||||
return Component.Identifier.Key.UP;
|
||||
case KeyEvent.VK_PAGE_UP:
|
||||
return Component.Identifier.Key.PAGEUP;
|
||||
case KeyEvent.VK_LEFT:
|
||||
return Component.Identifier.Key.LEFT;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
return Component.Identifier.Key.RIGHT;
|
||||
case KeyEvent.VK_END:
|
||||
return Component.Identifier.Key.END;
|
||||
case KeyEvent.VK_DOWN:
|
||||
return Component.Identifier.Key.DOWN;
|
||||
case KeyEvent.VK_PAGE_DOWN:
|
||||
return Component.Identifier.Key.PAGEDOWN;
|
||||
case KeyEvent.VK_INSERT:
|
||||
return Component.Identifier.Key.INSERT;
|
||||
case KeyEvent.VK_DELETE:
|
||||
return Component.Identifier.Key.DELETE;
|
||||
default:
|
||||
return Component.Identifier.Key.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public final static Component.Identifier.Key map(KeyEvent event) {
|
||||
int key_code = event.getKeyCode();
|
||||
int key_location = event.getKeyLocation();
|
||||
switch (key_code) {
|
||||
case KeyEvent.VK_CONTROL:
|
||||
if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
|
||||
return Component.Identifier.Key.RCONTROL;
|
||||
else
|
||||
return Component.Identifier.Key.LCONTROL;
|
||||
case KeyEvent.VK_SHIFT:
|
||||
if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
|
||||
return Component.Identifier.Key.RSHIFT;
|
||||
else
|
||||
return Component.Identifier.Key.LSHIFT;
|
||||
case KeyEvent.VK_ALT:
|
||||
if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
|
||||
return Component.Identifier.Key.RALT;
|
||||
else
|
||||
return Component.Identifier.Key.LALT;
|
||||
//this is 1.5 only
|
||||
/* case KeyEvent.VK_WINDOWS:
|
||||
if (key_location == KeyEvent.KEY_LOCATION_RIGHT)
|
||||
return Component.Identifier.Key.RWIN;
|
||||
else
|
||||
return Component.Identifier.Key.LWIN;*/
|
||||
case KeyEvent.VK_ENTER:
|
||||
if (key_location == KeyEvent.KEY_LOCATION_NUMPAD)
|
||||
return Component.Identifier.Key.NUMPADENTER;
|
||||
else
|
||||
return Component.Identifier.Key.RETURN;
|
||||
case KeyEvent.VK_COMMA:
|
||||
if (key_location == KeyEvent.KEY_LOCATION_NUMPAD)
|
||||
return Component.Identifier.Key.NUMPADCOMMA;
|
||||
else
|
||||
return Component.Identifier.Key.COMMA;
|
||||
default:
|
||||
return mapKeyCode(key_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
171
plugins/awt/src/main/java/net/java/games/input/AWTKeyboard.java
Normal file
171
plugins/awt/src/main/java/net/java/games/input/AWTKeyboard.java
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/**
|
||||
* 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 java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
* @author elias
|
||||
*/
|
||||
final class AWTKeyboard extends Keyboard implements AWTEventListener {
|
||||
private final List awt_events = new ArrayList();
|
||||
private Event[] processed_events;
|
||||
private int processed_events_index;
|
||||
|
||||
protected AWTKeyboard() {
|
||||
super("AWTKeyboard", createComponents(), new Controller[]{}, new Rumbler[]{});
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
|
||||
resizeEventQueue(EVENT_QUEUE_DEPTH);
|
||||
}
|
||||
|
||||
private final static Component[] createComponents() {
|
||||
List components = new ArrayList();
|
||||
Field[] vkey_fields = KeyEvent.class.getFields();
|
||||
for (int i = 0; i < vkey_fields.length; i++) {
|
||||
Field vkey_field = vkey_fields[i];
|
||||
try {
|
||||
if (Modifier.isStatic(vkey_field.getModifiers()) && vkey_field.getType() == int.class &&
|
||||
vkey_field.getName().startsWith("VK_")) {
|
||||
int vkey_code = vkey_field.getInt(null);
|
||||
Component.Identifier.Key key_id = AWTKeyMap.mapKeyCode(vkey_code);
|
||||
if (key_id != Component.Identifier.Key.UNKNOWN)
|
||||
components.add(new Key(key_id));
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
components.add(new Key(Component.Identifier.Key.RCONTROL));
|
||||
components.add(new Key(Component.Identifier.Key.LCONTROL));
|
||||
components.add(new Key(Component.Identifier.Key.RSHIFT));
|
||||
components.add(new Key(Component.Identifier.Key.LSHIFT));
|
||||
components.add(new Key(Component.Identifier.Key.RALT));
|
||||
components.add(new Key(Component.Identifier.Key.LALT));
|
||||
components.add(new Key(Component.Identifier.Key.NUMPADENTER));
|
||||
components.add(new Key(Component.Identifier.Key.RETURN));
|
||||
components.add(new Key(Component.Identifier.Key.NUMPADCOMMA));
|
||||
components.add(new Key(Component.Identifier.Key.COMMA));
|
||||
return (Component[])components.toArray(new Component[]{});
|
||||
}
|
||||
|
||||
private final void resizeEventQueue(int size) {
|
||||
processed_events = new Event[size];
|
||||
for (int i = 0; i < processed_events.length; i++)
|
||||
processed_events[i] = new Event();
|
||||
processed_events_index = 0;
|
||||
}
|
||||
|
||||
protected final void setDeviceEventQueueSize(int size) throws IOException {
|
||||
resizeEventQueue(size);
|
||||
}
|
||||
|
||||
public final synchronized void eventDispatched(AWTEvent event) {
|
||||
if (event instanceof KeyEvent)
|
||||
awt_events.add(event);
|
||||
}
|
||||
|
||||
public final synchronized void pollDevice() throws IOException {
|
||||
for (int i = 0; i < awt_events.size(); i++) {
|
||||
KeyEvent event = (KeyEvent)awt_events.get(i);
|
||||
processEvent(event);
|
||||
}
|
||||
awt_events.clear();
|
||||
}
|
||||
|
||||
private final void processEvent(KeyEvent event) {
|
||||
Component.Identifier.Key key_id = AWTKeyMap.map(event);
|
||||
if (key_id == null)
|
||||
return;
|
||||
Key key = (Key)getComponent(key_id);
|
||||
if (key == null)
|
||||
return;
|
||||
long nanos = event.getWhen()*1000000L;
|
||||
if (event.getID() == KeyEvent.KEY_PRESSED) {
|
||||
//the key was pressed
|
||||
addEvent(key, 1, nanos);
|
||||
} else if (event.getID() == KeyEvent.KEY_RELEASED) {
|
||||
KeyEvent nextPress = (KeyEvent)Toolkit.getDefaultToolkit().getSystemEventQueue().peekEvent(KeyEvent.KEY_PRESSED);
|
||||
if ((nextPress == null) || (nextPress.getWhen() != event.getWhen())) {
|
||||
//the key came really came up
|
||||
addEvent(key, 0, nanos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final void addEvent(Key key, float value, long nanos) {
|
||||
key.setValue(value);
|
||||
if (processed_events_index < processed_events.length)
|
||||
processed_events[processed_events_index++].set(key, value, nanos);
|
||||
}
|
||||
|
||||
protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
|
||||
if (processed_events_index == 0)
|
||||
return false;
|
||||
processed_events_index--;
|
||||
event.set(processed_events[0]);
|
||||
Event tmp = processed_events[0];
|
||||
processed_events[0] = processed_events[processed_events_index];
|
||||
processed_events[processed_events_index] = tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private final static class Key extends AbstractComponent {
|
||||
private float value;
|
||||
|
||||
public Key(Component.Identifier.Key key_id) {
|
||||
super(key_id.getName(), key_id);
|
||||
}
|
||||
|
||||
public final void setValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected final float poll() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public final boolean isAnalog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
222
plugins/awt/src/main/java/net/java/games/input/AWTMouse.java
Normal file
222
plugins/awt/src/main/java/net/java/games/input/AWTMouse.java
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
/**
|
||||
* 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.MouseWheelEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Jeremy
|
||||
* @author elias
|
||||
*/
|
||||
final class AWTMouse extends Mouse implements AWTEventListener {
|
||||
private final static int EVENT_X = 1;
|
||||
private final static int EVENT_Y = 2;
|
||||
private final static int EVENT_BUTTON = 4;
|
||||
|
||||
private final List awt_events = new ArrayList();
|
||||
private final List processed_awt_events = new ArrayList();
|
||||
|
||||
private int event_state = EVENT_X;
|
||||
|
||||
protected AWTMouse() {
|
||||
super("AWTMouse", createComponents(), new Controller[]{}, new Rumbler[]{});
|
||||
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK);
|
||||
}
|
||||
|
||||
private final static Component[] createComponents() {
|
||||
return new Component[]{new Axis(Component.Identifier.Axis.X),
|
||||
new Axis(Component.Identifier.Axis.Y),
|
||||
new Axis(Component.Identifier.Axis.Z),
|
||||
new Button(Component.Identifier.Button.LEFT),
|
||||
new Button(Component.Identifier.Button.MIDDLE),
|
||||
new Button(Component.Identifier.Button.RIGHT)};
|
||||
}
|
||||
|
||||
private final void processButtons(int button_enum, float value) {
|
||||
Button button = getButton(button_enum);
|
||||
if (button != null)
|
||||
button.setValue(value);
|
||||
}
|
||||
|
||||
private final Button getButton(int button_enum) {
|
||||
switch (button_enum) {
|
||||
case MouseEvent.BUTTON1:
|
||||
return (Button)getLeft();
|
||||
case MouseEvent.BUTTON2:
|
||||
return (Button)getMiddle();
|
||||
case MouseEvent.BUTTON3:
|
||||
return (Button)getRight();
|
||||
case MouseEvent.NOBUTTON:
|
||||
default:
|
||||
// Unknown button
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final void processEvent(AWTEvent event) throws IOException {
|
||||
if (event instanceof MouseWheelEvent) {
|
||||
MouseWheelEvent mwe = (MouseWheelEvent)event;
|
||||
Axis wheel = (Axis)getWheel();
|
||||
wheel.setValue(wheel.poll() + mwe.getWheelRotation());
|
||||
} else if (event instanceof MouseEvent) {
|
||||
MouseEvent me = (MouseEvent)event;
|
||||
Axis x = (Axis)getX();
|
||||
Axis y = (Axis)getY();
|
||||
x.setValue(me.getX());
|
||||
y.setValue(me.getY());
|
||||
switch (me.getID()) {
|
||||
case MouseEvent.MOUSE_PRESSED:
|
||||
processButtons(me.getButton(), 1f);
|
||||
break;
|
||||
case MouseEvent.MOUSE_RELEASED:
|
||||
processButtons(me.getButton(), 0f);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized void pollDevice() throws IOException {
|
||||
Axis wheel = (Axis)getWheel();
|
||||
wheel.setValue(0);
|
||||
for (int i = 0; i < awt_events.size(); i++) {
|
||||
AWTEvent event = (AWTEvent)awt_events.get(i);
|
||||
processEvent(event);
|
||||
processed_awt_events.add(event);
|
||||
}
|
||||
awt_events.clear();
|
||||
}
|
||||
|
||||
protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {
|
||||
while (true) {
|
||||
if (processed_awt_events.isEmpty())
|
||||
return false;
|
||||
AWTEvent awt_event = (AWTEvent)processed_awt_events.get(0);
|
||||
if (awt_event instanceof MouseWheelEvent) {
|
||||
MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event;
|
||||
long nanos = awt_wheel_event.getWhen()*1000000L;
|
||||
event.set(getWheel(), awt_wheel_event.getWheelRotation(), nanos);
|
||||
processed_awt_events.remove(0);
|
||||
} else if (awt_event instanceof MouseEvent) {
|
||||
MouseEvent mouse_event = (MouseEvent)awt_event;
|
||||
long nanos = mouse_event.getWhen()*1000000L;
|
||||
switch (event_state) {
|
||||
case EVENT_X:
|
||||
event_state = EVENT_Y;
|
||||
event.set(getX(), mouse_event.getX(), nanos);
|
||||
return true;
|
||||
case EVENT_Y:
|
||||
event_state = EVENT_BUTTON;
|
||||
event.set(getY(), mouse_event.getY(), nanos);
|
||||
return true;
|
||||
case EVENT_BUTTON:
|
||||
processed_awt_events.remove(0);
|
||||
event_state = EVENT_X;
|
||||
Button button = getButton(mouse_event.getButton());
|
||||
if (button != null) {
|
||||
switch (mouse_event.getID()) {
|
||||
case MouseEvent.MOUSE_PRESSED:
|
||||
event.set(button, 1f, nanos);
|
||||
return true;
|
||||
case MouseEvent.MOUSE_RELEASED:
|
||||
event.set(button, 0f, nanos);
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unknown event state: " + event_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized void eventDispatched(AWTEvent event) {
|
||||
awt_events.add(event);
|
||||
}
|
||||
|
||||
final static class Axis extends AbstractComponent {
|
||||
private float value;
|
||||
|
||||
public Axis(Component.Identifier.Axis axis_id) {
|
||||
super(axis_id.getName(), axis_id);
|
||||
}
|
||||
|
||||
public final boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isAnalog() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected final void setValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected final float poll() throws IOException {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
final static class Button extends AbstractComponent {
|
||||
private float value;
|
||||
|
||||
public Button(Component.Identifier.Button button_id) {
|
||||
super(button_id.getName(), button_id);
|
||||
}
|
||||
|
||||
protected final void setValue(float value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
protected final float poll() throws IOException {
|
||||
return value;
|
||||
}
|
||||
|
||||
public final boolean isAnalog() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isRelative() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue