* Javadocs for com.jme3.input

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7587 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent 58626202f0
commit 913d3ec963
  1. 4
      engine/src/core/com/jme3/input/ChaseCamera.java
  2. 6
      engine/src/core/com/jme3/input/FlyByCamera.java
  3. 248
      engine/src/core/com/jme3/input/InputManager.java
  4. 21
      engine/src/core/com/jme3/input/JoyInput.java
  5. 64
      engine/src/core/com/jme3/input/Joystick.java
  6. 12
      engine/src/core/com/jme3/input/KeyInput.java
  7. 40
      engine/src/core/com/jme3/input/MouseInput.java
  8. 49
      engine/src/core/com/jme3/input/RawInputListener.java
  9. 4
      engine/src/core/com/jme3/input/TouchInput.java
  10. 11
      engine/src/core/com/jme3/input/controls/ActionListener.java
  11. 10
      engine/src/core/com/jme3/input/controls/AnalogListener.java
  12. 11
      engine/src/core/com/jme3/input/controls/JoyAxisTrigger.java
  13. 13
      engine/src/core/com/jme3/input/controls/JoyButtonTrigger.java
  14. 12
      engine/src/core/com/jme3/input/controls/KeyTrigger.java
  15. 14
      engine/src/core/com/jme3/input/controls/MouseAxisTrigger.java
  16. 6
      engine/src/core/com/jme3/input/controls/MouseButtonTrigger.java
  17. 6
      engine/src/core/com/jme3/input/controls/TouchListener.java
  18. 8
      engine/src/core/com/jme3/input/controls/Trigger.java
  19. 6
      engine/src/core/com/jme3/input/dummy/DummyInput.java
  20. 6
      engine/src/core/com/jme3/input/dummy/DummyKeyInput.java
  21. 6
      engine/src/core/com/jme3/input/dummy/DummyMouseInput.java
  22. 31
      engine/src/core/com/jme3/input/event/InputEvent.java
  23. 30
      engine/src/core/com/jme3/input/event/JoyAxisEvent.java
  24. 28
      engine/src/core/com/jme3/input/event/JoyButtonEvent.java
  25. 35
      engine/src/core/com/jme3/input/event/KeyInputEvent.java
  26. 39
      engine/src/core/com/jme3/input/event/MouseButtonEvent.java
  27. 35
      engine/src/core/com/jme3/input/event/MouseMotionEvent.java
  28. 98
      engine/src/core/com/jme3/input/event/TouchEvent.java
  29. 38
      engine/src/core/com/jme3/input/package.html

@ -541,7 +541,7 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
}
/**
* update the camera control, should on ly be used internally
* update the camera control, should only be used internally
* @param tpf
*/
public void update(float tpf) {
@ -549,7 +549,7 @@ public class ChaseCamera implements ActionListener, AnalogListener, Control {
}
/**
* renders the camera control, should on ly be used internally
* renders the camera control, should only be used internally
* @param rm
* @param vp
*/

@ -135,11 +135,15 @@ public class FlyByCamera implements AnalogListener, ActionListener {
}
/**
* @param dragToRotate When true, the user must hold the mouse button
* Set if drag to rotate mode is enabled.
*
* When true, the user must hold the mouse button
* and drag over the screen to rotate the camera, and the cursor is
* visible until dragged. Otherwise, the cursor is invisible at all times
* and holding the mouse button is not needed to rotate the camera.
* This feature is disabled by default.
*
* @param dragToRotate True if drag to rotate mode is enabled.
*/
public void setDragToRotate(boolean dragToRotate) {
this.dragToRotate = dragToRotate;

@ -31,6 +31,7 @@
*/
package com.jme3.input;
import com.jme3.app.Application;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.InputListener;
@ -62,10 +63,38 @@ import java.util.logging.Logger;
* The <code>InputManager</code> is responsible for converting input events
* received from the Key, Mouse and Joy Input implementations into an
* abstract, input device independent representation that user code can use.
*
* By default a dispatcher is included with every Application instance for use
* <p>
* By default an <code>InputManager</code> is included with every Application instance for use
* in user code to query input, unless the Application is created as headless
* or with input explicitly disabled.
* <p>
* The input manager has two concepts, a {@link Trigger} and a mapping.
* A trigger represents a specific input trigger, such as a key button,
* or a mouse axis. A mapping represents a link onto one or several triggers,
* when the appropriate trigger is activated (e.g. a key is pressed), the
* mapping will be invoked. Any listeners registered to receive an event
* from the mapping will have an event raised.
* <p>
* There are two types of events that {@link InputListener input listeners}
* can receive, one is {@link ActionListener#onAction(java.lang.String, boolean, float) action}
* events and another is {@link AnalogListener#onAnalog(java.lang.String, float, float) analog}
* events.
* <p>
* <code>onAction</code> events are raised when the specific input
* activates or deactivates. For a digital input such as key press, the <code>onAction()</code>
* event will be raised with the <code>isPressed</code> argument equal to true,
* when the key is released, <code>onAction</code> is called again but this time
* with the <code>isPressed</code> argument set to false.
* For analog inputs, the <code>onAction</code> method will be called any time
* the input is non-zero, however an exception to this is for joystick axis inputs,
* which are only called when the input is above the {@link InputManager#setAxisDeadZone(float) dead zone}.
* <p>
* <code>onAnalog</code> events are raised every frame while the input is activated.
* For digital inputs, every frame that the input is active will cause the
* <code>onAnalog</code> method to be called, the argument <code>value</code>
* argument will equal to the frame's time per frame (TPF) value but only
* for digital inputs. For analog inputs however, the <code>value</code> argument
* will equal the actual analog value.
*/
public class InputManager implements RawInputListener {
@ -106,6 +135,8 @@ public class InputManager implements RawInputListener {
/**
* Initializes the InputManager.
*
* <p>This should only be called internally in {@link Application}.
*
* @param mouseInput
* @param keyInput
@ -267,9 +298,15 @@ public class InputManager implements RawInputListener {
}
}
/**
* Callback from RawInputListener. Do not use.
*/
public void beginInput() {
}
/**
* Callback from RawInputListener. Do not use.
*/
public void endInput() {
}
@ -309,6 +346,9 @@ public class InputManager implements RawInputListener {
}
}
/**
* Callback from RawInputListener. Do not use.
*/
public void onJoyAxisEvent(JoyAxisEvent evt) {
if (!eventsPermitted) {
throw new UnsupportedOperationException("JoyInput has raised an event at an illegal time.");
@ -327,6 +367,9 @@ public class InputManager implements RawInputListener {
invokeTimedActions(hash, evt.getTime(), evt.isPressed());
}
/**
* Callback from RawInputListener. Do not use.
*/
public void onJoyButtonEvent(JoyButtonEvent evt) {
if (!eventsPermitted) {
throw new UnsupportedOperationException("JoyInput has raised an event at an illegal time.");
@ -354,6 +397,9 @@ public class InputManager implements RawInputListener {
}
}
/**
* Callback from RawInputListener. Do not use.
*/
public void onMouseMotionEvent(MouseMotionEvent evt) {
if (!eventsPermitted) {
throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time.");
@ -364,15 +410,14 @@ public class InputManager implements RawInputListener {
}
private void onMouseButtonEventQueued(MouseButtonEvent evt) {
// for (int i = 0; i < rawListeners.size(); i++){
// rawListeners.get(i).onMouseButtonEvent(evt);
// }
int hash = MouseButtonTrigger.mouseButtonHash(evt.getButtonIndex());
invokeActions(hash, evt.isPressed());
invokeTimedActions(hash, evt.getTime(), evt.isPressed());
}
/**
* Callback from RawInputListener. Do not use.
*/
public void onMouseButtonEvent(MouseButtonEvent evt) {
if (!eventsPermitted) {
throw new UnsupportedOperationException("MouseInput has raised an event at an illegal time.");
@ -382,18 +427,18 @@ public class InputManager implements RawInputListener {
}
private void onKeyEventQueued(KeyInputEvent evt) {
// for (int i = 0; i < rawListeners.size(); i++){
// rawListeners.get(i).onKeyEvent(evt);
// }
if (evt.isRepeating()) {
return; // repeat events not used for bindings
}
int hash = KeyTrigger.keyHash(evt.getKeyCode());
invokeActions(hash, evt.isPressed());
invokeTimedActions(hash, evt.getTime(), evt.isPressed());
}
/**
* Callback from RawInputListener. Do not use.
*/
public void onKeyEvent(KeyInputEvent evt) {
if (!eventsPermitted) {
throw new UnsupportedOperationException("KeyInput has raised an event at an illegal time.");
@ -401,11 +446,69 @@ public class InputManager implements RawInputListener {
inputQueue.add(evt);
}
private void onTouchEventQueued(TouchEvent evt) {
for (Mapping mapping : mappings.values()) {
for (InputListener listener : mapping.listeners) {
if (listener instanceof TouchListener) {
((TouchListener) listener).onTouch(mapping.name, evt, frameTPF);
}
}
}
}
/**
* Callback from RawInputListener. Do not use.
*/
@Override
public void onTouchEvent(TouchEvent evt) {
if (!eventsPermitted) {
throw new UnsupportedOperationException("TouchInput has raised an event at an illegal time.");
}
inputQueue.add(evt);
}
/**
* Set the deadzone for joystick axes.
*
* <p>{@link ActionListener#onAction(java.lang.String, boolean, float) }
* events will only be raised if the joystick axis value is greater than
* the <code>deadZone</code>.
*
* @param deadZone the deadzone for joystick axes.
*/
public void setAxisDeadZone(float deadZone) {
this.axisDeadZone = deadZone;
}
/**
* Returns the deadzone for joystick axes.
*
* @return the deadzone for joystick axes.
*/
public float getAxisDeadZone() {
return axisDeadZone;
}
/**
* Adds a new listener to receive events on the given mappings.
*
* <p>The given InputListener will be registered to receive events
* on the specified mapping names. When a mapping raises an event, the
* listener will have its appropriate method invoked, either
* {@link ActionListener#onAction(java.lang.String, boolean, float) }
* or {@link AnalogListener#onAnalog(java.lang.String, float, float) }
* depending on which interface the <code>listener</code> implements.
* If the listener implements both interfaces, then it will receive the
* appropriate event for each method.
*
* @param listener The listener to register to receive input events.
* @param mappingNames The mapping names which the listener will receive
* events from.
*
* @see InputManager#removeListener(com.jme3.input.controls.InputListener)
*/
public void addListener(InputListener listener, String... mappingNames) {
for (String mappingName : mappingNames) {
Mapping mapping = mappings.get(mappingName);
@ -419,12 +522,36 @@ public class InputManager implements RawInputListener {
}
}
/**
* Removes a listener from receiving events.
*
* <p>This will unregister the listener from any mappings that it
* was previously registered with via
* {@link InputManager#addListener(com.jme3.input.controls.InputListener, java.lang.String[]) }.
*
* @param listener The listener to unregister.
*
* @see InputManager#addListener(com.jme3.input.controls.InputListener, java.lang.String[])
*/
public void removeListener(InputListener listener) {
for (Mapping mapping : mappings.values()) {
mapping.listeners.remove(listener);
}
}
/**
* Create a new mapping to the given triggers.
*
* <p>
* The given mapping will be assigned to the given triggers, when
* any of the triggers given raise an event, the listeners
* registered to the mappings will receive appropriate events.
*
* @param mappingName The mapping name to assign.
* @param triggers The triggers to which the mapping is to be registered.
*
* @see InputManager#deleteMapping(java.lang.String)
*/
public void addMapping(String mappingName, Trigger... triggers) {
Mapping mapping = mappings.get(mappingName);
if (mapping == null) {
@ -448,6 +575,17 @@ public class InputManager implements RawInputListener {
}
}
/**
* Deletes a mapping from receiving trigger events.
*
* <p>
* The given mapping will no longer be assigned to receive trigger
* events.
*
* @param mappingName The mapping name to unregister.
*
* @see InputManager#addMapping(java.lang.String, com.jme3.input.controls.Trigger[])
*/
public void deleteMapping(String mappingName) {
Mapping mapping = mappings.remove(mappingName);
if (mapping == null) {
@ -462,6 +600,17 @@ public class InputManager implements RawInputListener {
}
}
/**
* Deletes a specific trigger registered to a mapping.
*
* <p>
* The given mapping will no longer receive events raised by the
* trigger.
*
* @param mappingName The mapping name to cease receiving events from the
* trigger.
* @param trigger The trigger to no longer invoke events on the mapping.
*/
public void deleteTrigger(String mappingName, Trigger trigger) {
Mapping mapping = mappings.get(mappingName);
if (mapping == null) {
@ -474,7 +623,8 @@ public class InputManager implements RawInputListener {
}
/**
* Clears all the input mappings from this InputManager. Consequently, also clears all of the
* Clears all the input mappings from this InputManager.
* Consequently, also clears all of the
* InputListeners as well.
*/
public void clearMappings() {
@ -484,6 +634,7 @@ public class InputManager implements RawInputListener {
}
/**
* Do not use.
* Called to reset pressed keys or buttons when focus is restored.
*/
public void reset() {
@ -492,13 +643,21 @@ public class InputManager implements RawInputListener {
}
/**
* Returns whether the mouse cursor is visible or not.
*
* <p>By default the cursor is visible.
*
* @param visible whether the mouse cursor is visible or not.
*
* @see InputManager#setCursorVisible(boolean)
*/
public boolean isCursorVisible() {
return mouseVisible;
}
/**
* Set whether the mouse cursor should be visible or not.
*
* @param visible whether the mouse cursor should be visible or not.
*/
public void setCursorVisible(boolean visible) {
@ -508,24 +667,68 @@ public class InputManager implements RawInputListener {
}
}
/**
* Returns the current cursor position. The position is relative to the
* bottom-left of the screen and is in pixels.
*
* @return the current cursor position
*/
public Vector2f getCursorPosition() {
return cursorPos;
}
/**
* Returns an array of all joysticks installed on the system.
*
* @return an array of all joysticks installed on the system.
*/
public Joystick[] getJoysticks() {
return joysticks;
}
/**
* Adds a {@link RawInputListener} to receive raw input events.
*
* <p>
* Any raw input listeners registered to this <code>InputManager</code>
* will receive raw input events first, before they get handled
* by the <code>InputManager</code> itself. The listeners are
* each processed in the order they were added, e.g. FIFO.
* <p>
* If a raw input listener has handled the event and does not wish
* other listeners down the list to process the event, it may set the
* {@link InputEvent#setConsumed() consumed flag} to indicate the
* event was consumed and shouldn't be processed any further.
* The listener may do this either at each of the event callbacks
* or at the {@link RawInputListener#endInput() } method.
*
* @param listener A listener to receive raw input events.
*
* @see RawInputListener
*/
public void addRawInputListener(RawInputListener listener) {
rawListeners.add(listener);
rawListenerArray = null;
}
/**
* Removes a {@link RawInputListener} so that it no longer
* receives raw input events.
*
* @param listener The listener to cease receiving raw input events.
*
* @see InputManager#addRawInputListener(com.jme3.input.RawInputListener)
*/
public void removeRawInputListener(RawInputListener listener) {
rawListeners.remove(listener);
rawListenerArray = null;
}
/**
* Clears all {@link RawInputListener}s.
*
* @see InputManager#addRawInputListener(com.jme3.input.RawInputListener)
*/
public void clearRawInputListeners() {
rawListeners.clear();
rawListenerArray = null;
@ -537,16 +740,22 @@ public class InputManager implements RawInputListener {
return rawListenerArray;
}
public TouchInput getTouchInput() {
return touch;
}
/**
* Enable simulation of mouse events. Used for touchscreen input only.
*
* @param value True to enable simulation of mouse events
*/
public void setSimulateMouse(boolean value) {
if (touch != null) {
touch.setSimulateMouse(value);
}
}
/**
* Enable simulation of keyboard events. Used for touchscreen input only.
*
* @param value True to enable simulation of keyboard events
*/
public void setSimulateKeyboard(boolean value) {
if (touch != null) {
touch.setSimulateKeyboard(value);
@ -557,7 +766,7 @@ public class InputManager implements RawInputListener {
int queueSize = inputQueue.size();
RawInputListener[] array = getRawListenerArray();
for (RawInputListener listener : array) {
for (RawInputListener listener : array) {
listener.beginInput();
for (int j = 0; j < queueSize; j++) {
@ -618,14 +827,19 @@ public class InputManager implements RawInputListener {
}
/**
* Updates the Dispatcher. This will query current input devices and send
* Updates the <code>InputManager</code>.
* This will query current input devices and send
* appropriate events to registered listeners.
*
* @param tpf Time per frame value.
*/
public void update(float tpf) {
frameTPF = tpf;
// Activate safemode if the TPF value is so small
// that rounding errors are inevitable
safeMode = tpf < 0.015f;
long currentTime = keys.getInputTimeNanos();
frameDelta = currentTime - lastUpdateTime;

@ -37,9 +37,30 @@ package com.jme3.input;
*/
public interface JoyInput extends Input {
/**
* The X axis for POV (point of view hat).
*/
public static final int AXIS_POV_X = 254;
/**
* The Y axis for POV (point of view hat).
*/
public static final int AXIS_POV_Y = 255;
/**
* Causes the joystick at <code>joyId</code> index to rumble with
* the given amount.
*
* @param joyId The joystick index
* @param amount Rumble amount. Should be between 0 and 1.
*/
public void setJoyRumble(int joyId, float amount);
/**
* Loads a list of joysticks from the system.
*
* @param inputManager The input manager requesting to load joysticks
* @return A list of joysticks that are installed.
*/
public Joystick[] loadJoysticks(InputManager inputManager);
}

@ -3,6 +3,11 @@ package com.jme3.input;
import com.jme3.input.controls.JoyAxisTrigger;
import com.jme3.input.controls.JoyButtonTrigger;
/**
* A joystick represents a single joystick that is installed in the system.
*
* @author Kirill Vainer
*/
public final class Joystick {
private InputManager inputManager;
@ -13,6 +18,9 @@ public final class Joystick {
private int axisXIndex, axisYIndex;
private String name;
/**
* Creates a new joystick instance. Only used internally.
*/
public Joystick(InputManager inputManager, JoyInput joyInput,
int joyId, String name, int buttonCount, int axisCount,
int xAxis, int yAxis){
@ -27,10 +35,24 @@ public final class Joystick {
this.axisYIndex = yAxis;
}
/**
* Rumbles the joystick for the given amount/magnitude.
*
* @param amount The amount to rumble. Should be between 0 and 1.
*/
public void rumble(float amount){
joyInput.setJoyRumble(joyId, amount);
}
/**
* Assign the mapping name to receive events from the given button index
* on the joystick.
*
* @param mappingName The mapping to receive joystick button events.
* @param buttonId The button index.
*
* @see Joystick#getButtonCount()
*/
public void assignButton(String mappingName, int buttonId){
if (buttonId < 0 || buttonId >= buttonCount)
throw new IllegalArgumentException();
@ -38,27 +60,69 @@ public final class Joystick {
inputManager.addMapping(mappingName, new JoyButtonTrigger(joyId, buttonId));
}
/**
* Assign the mappings to receive events from the given joystick axis.
*
* @param positiveMapping The mapping to receive events when the axis is negative
* @param negativeMapping The mapping to receive events when the axis is positive
* @param axisId The axis index.
*
* @see Joystick#getAxisCount()
*/
public void assignAxis(String positiveMapping, String negativeMapping, int axisId){
inputManager.addMapping(positiveMapping, new JoyAxisTrigger(joyId, axisId, false));
inputManager.addMapping(negativeMapping, new JoyAxisTrigger(joyId, axisId, true));
}
/**
* Gets the index number for the X axis on the joystick.
*
* <p>E.g. for most gamepads, the left control stick X axis will be returned.
*
* @return The axis index for the X axis for this joystick.
*
* @see Joystick#assignAxis(java.lang.String, java.lang.String, int)
*/
public int getXAxisIndex(){
return axisXIndex;
}
/**
* Gets the index number for the Y axis on the joystick.
*
* <p>E.g. for most gamepads, the left control stick Y axis will be returned.
*
* @return The axis index for the Y axis for this joystick.
*
* @see Joystick#assignAxis(java.lang.String, java.lang.String, int)
*/
public int getYAxisIndex(){
return axisYIndex;
}
/**
* Returns the number of axes on this joystick.
*
* @return the number of axes on this joystick.
*/
public int getAxisCount() {
return axisCount;
}
/**
* Returns the number of buttons on this joystick.
*
* @return the number of buttons on this joystick.
*/
public int getButtonCount() {
return buttonCount;
}
/**
* Returns the name of this joystick.
*
* @return the name of this joystick.
*/
public String getName() {
return name;
}

@ -519,9 +519,17 @@ public interface KeyInput extends Input {
* delete key.
*/
public static final int KEY_DELETE = 0xD3;
public static final int KEY_LMETA = 0xDB; /* Left Windows/Option key */
public static final int KEY_RMETA = 0xDC; /* Right Windows/Option key */
/**
* Left "Windows" key on PC keyboards, left "Option" key on Mac keyboards.
*/
public static final int KEY_LMETA = 0xDB;
/**
* Right "Windows" key on PC keyboards, right "Option" key on Mac keyboards.
*/
public static final int KEY_RMETA = 0xDC;
public static final int KEY_APPS = 0xDD;
/**
* power key.

@ -37,21 +37,47 @@ package com.jme3.input;
*/
public interface MouseInput extends Input {
public static final int AXIS_X = 0,
AXIS_Y = 1,
AXIS_WHEEL = 2;
/**
* Mouse X axis.
*/
public static final int AXIS_X = 0;
/**
* Mouse Y axis.
*/
public static final int AXIS_Y = 1;
/**
* Mouse wheel axis.
*/
public static final int AXIS_WHEEL = 2;
public static final int BUTTON_LEFT = 0,
BUTTON_RIGHT = 1,
BUTTON_MIDDLE = 2;
/**
* Left mouse button.
*/
public static final int BUTTON_LEFT = 0;
/**
* Right mouse button.
*/
public static final int BUTTON_RIGHT = 1;
/**
* Middle mouse button.
*/
public static final int BUTTON_MIDDLE = 2;
/**
* Set whether the mouse cursor should be visible or not.
*
* @param visible Whether the mouse cursor should be visible or not.
*/
public void setCursorVisible(boolean visible);
/**
* @return The number of buttons the mouse has. Typically 3 for most mice.
* Returns the number of buttons the mouse has. Typically 3 for most mice.
*
* @return the number of buttons the mouse has.
*/
public int getButtonCount();
}

@ -32,6 +32,7 @@
package com.jme3.input;
import com.jme3.input.event.InputEvent;
import com.jme3.input.event.JoyAxisEvent;
import com.jme3.input.event.JoyButtonEvent;
import com.jme3.input.event.KeyInputEvent;
@ -44,15 +45,61 @@ import com.jme3.input.event.TouchEvent;
*/
public interface RawInputListener {
/**
* Called before a batch of input will be sent to this
* <code>RawInputListener</code>.
*/
public void beginInput();
/**
* Called after a batch of input was sent to this
* <code>RawInputListener</code>.
*
* The listener should set the {@link InputEvent#setConsumed() consumed flag}
* on any events that have been consumed either at this call or previous calls.
*/
public void endInput();
/**
* Invoked on joystick axis events.
*
* @param evt
*/
public void onJoyAxisEvent(JoyAxisEvent evt);
/**
* Invoked on joystick button presses.
*
* @param evt
*/
public void onJoyButtonEvent(JoyButtonEvent evt);
/**
* Invoked on mouse movement/motion events.
*
* @param evt
*/
public void onMouseMotionEvent(MouseMotionEvent evt);
/**
* Invoked on mouse button events.
*
* @param evt
*/
public void onMouseButtonEvent(MouseButtonEvent evt);
/**
* Invoked on keyboard key press or release events.
*
* @param evt
*/
public void onKeyEvent(KeyInputEvent evt);
// Generic Smartphone input event, used by the Android platform currently
/**
* Invoked on touchscreen touch events.
*
* @param evt
*/
public void onTouchEvent(TouchEvent evt);
}

@ -38,11 +38,15 @@ package com.jme3.input;
public interface TouchInput extends Input {
/**
* Set whether mouse events should be generated
*
* @param simulate Whether mouse events should be generated
*/
public void setSimulateMouse(boolean simulate);
/**
* Set whether keyboard events should be generated
*
* @param simulate Whether keyboard events should be generated
*/
public void setSimulateKeyboard(boolean simulate);

@ -34,9 +34,10 @@ package com.jme3.input.controls;
/**
* <code>ActionListener</code> is used to receive input events in "digital" style.
* <p>
* Generally all button inputs, such as keyboard, mouse button, and joystick button,
* will be represented exactly. Analog inputs will be converted into digital.
*
* <p>
* When an action listener is registered to a natively digital input, such as a button,
* the event will be invoked when the button is pressed, with <code>value</code>
* set to <code>true</code>, and will be invoked again when the button is released,
@ -45,5 +46,13 @@ package com.jme3.input.controls;
* @author Kirill Vainer
*/
public interface ActionListener extends InputListener {
/**
* Called when an input to which this listener is registered to is invoked.
*
* @param name The name of the mapping that was invoked
* @param isPressed True if the action is "pressed", false otherwise
* @param tpf The time per frame value.
*/
public void onAction(String name, boolean isPressed, float tpf);
}

@ -34,20 +34,20 @@ package com.jme3.input.controls;
/**
* <code>AnalogListener</code> is used to receive events of inputs
* in analog format. As a value from 0 to 1.
* in analog format.
*
* @author Kirill Vainer
*/
public interface AnalogListener extends InputListener {
/**
* Called to notify the implementation that an analog event has occured.
* Called to notify the implementation that an analog event has occurred.
*
* The results of KeyTrigger and MouseButtonTrigger events will have tpf
* == value.
*
* @param name - the name of the analog event
* @param value - how much the axis changed during this event
* @param tpf - how much time has passed since the last frame
* @param name The name of the mapping that was invoked
* @param value Value of the axis, from 0 to 1.
* @param tpf The time per frame value.
*/
public void onAnalog(String name, float value, float tpf);
}

@ -32,11 +32,17 @@
package com.jme3.input.controls;
import com.jme3.input.Joystick;
public class JoyAxisTrigger implements Trigger {
private final int joyId, axisId;
private final boolean negative;
/**
* Use {@link Joystick#assignAxis(java.lang.String, java.lang.String, int) }
* instead.
*/
public JoyAxisTrigger(int joyId, int axisId, boolean negative) {
this.joyId = joyId;
this.axisId = axisId;
@ -48,11 +54,6 @@ public class JoyAxisTrigger implements Trigger {
return (2048 * joyId) | (negative ? 1280 : 1024) | (joyAxis & 0xff);
}
@Override
public int hashCode(){
return joyAxisHash(joyId, axisId, negative);
}
public int getAxisId() {
return axisId;
}

@ -32,10 +32,18 @@
package com.jme3.input.controls;
import com.jme3.input.Joystick;
public class JoyButtonTrigger implements Trigger {
private final int joyId, buttonId;
/**
* Use {@link Joystick#assignButton(java.lang.String, int) } instead.
*
* @param joyId
* @param axisId
*/
public JoyButtonTrigger(int joyId, int axisId) {
this.joyId = joyId;
this.buttonId = axisId;
@ -46,11 +54,6 @@ public class JoyButtonTrigger implements Trigger {
return (2048 * joyId) | 1536 | (joyButton & 0xff);
}
@Override
public int hashCode(){
return joyButtonHash(joyId, buttonId);
}
public int getAxisId() {
return buttonId;
}

@ -32,6 +32,8 @@
package com.jme3.input.controls;
import com.jme3.input.KeyInput;
/**
* A <code>KeyTrigger</code> is used as a mapping to keyboard keys.
*
@ -41,6 +43,11 @@ public class KeyTrigger implements Trigger {
private final int keyCode;
/**
* Create a new <code>KeyTrigger</code> for the given keycode.
*
* @param keyCode the code for the key, see constants in {@link KeyInput}.
*/
public KeyTrigger(int keyCode){
this.keyCode = keyCode;
}
@ -58,9 +65,4 @@ public class KeyTrigger implements Trigger {
return keyCode & 0xff;
}
@Override
public int hashCode(){
return keyHash(keyCode);
}
}

@ -46,6 +46,13 @@ public class MouseAxisTrigger implements Trigger {
private int mouseAxis;
private boolean negative;
/**
* Create a new <code>MouseAxisTrigger</code>.
* <p>
* @param mouseAxis Mouse axis. See AXIS_*** constants in {@link MouseInput}
* @param negative True if listen to negative axis events, false if
* listen to positive axis events.
*/
public MouseAxisTrigger(int mouseAxis, boolean negative){
if (mouseAxis < 0 || mouseAxis > 2)
throw new IllegalArgumentException("Mouse Axis must be between 0 and 2");
@ -72,13 +79,8 @@ public class MouseAxisTrigger implements Trigger {
}
}
public static final int mouseAxisHash(int mouseAxis, boolean negative){
public static int mouseAxisHash(int mouseAxis, boolean negative){
assert mouseAxis >= 0 && mouseAxis <= 255;
return (negative ? 768 : 512) | (mouseAxis & 0xff);
}
@Override
public int hashCode(){
return mouseAxisHash(mouseAxis, negative);
}
}

@ -44,6 +44,12 @@ public class MouseButtonTrigger implements Trigger {
private final int mouseButton;
/**
* Create a new <code>MouseButtonTrigger</code> to receive mouse button events.
*
* @param mouseButton Mouse button index. See BUTTON_*** constants in
* {@link MouseInput}.
*/
public MouseButtonTrigger(int mouseButton) {
if (mouseButton < 0)
throw new IllegalArgumentException("Mouse Button cannot be negative");

@ -41,9 +41,9 @@ import com.jme3.input.event.TouchEvent;
*/
public interface TouchListener extends InputListener {
/**
* @param name - the name of the event
* @param event - the touch event itself
* @param tpf - how much time has passed since the last frame
* @param name the name of the event
* @param event the touch event
* @param tpf how much time has passed since the last frame
*/
public void onTouch(String name, TouchEvent event, float tpf);
}

@ -42,12 +42,4 @@ public interface Trigger {
* @return A user friendly name for the trigger.
*/
public String getName();
/**
* @return Hash-code for the trigger, can map into the entire
* 32 bit space, and there must be no two different triggers with same
* hash-code.
*/
@Override
public int hashCode();
}

@ -35,6 +35,12 @@ package com.jme3.input.dummy;
import com.jme3.input.Input;
import com.jme3.input.RawInputListener;
/**
* DummyInput as an implementation of <code>Input</code> that raises no
* input events.
*
* @author Kirill Vainer.
*/
public class DummyInput implements Input {
protected boolean inited = false;

@ -34,6 +34,12 @@ package com.jme3.input.dummy;
import com.jme3.input.KeyInput;
/**
* DummyKeyInput as an implementation of <code>KeyInput</code> that raises no
* input events.
*
* @author Kirill Vainer.
*/
public class DummyKeyInput extends DummyInput implements KeyInput {
public int getKeyCount() {

@ -34,6 +34,12 @@ package com.jme3.input.dummy;
import com.jme3.input.MouseInput;
/**
* DummyMouseInput as an implementation of <code>MouseInput</code> that raises no
* input events.
*
* @author Kirill Vainer.
*/
public class DummyMouseInput extends DummyInput implements MouseInput {
public void setCursorVisible(boolean visible) {

@ -32,34 +32,51 @@
package com.jme3.input.event;
import com.jme3.input.Input;
/**
* An abstract input event.
*/
public abstract class InputEvent {
/**
* Time in ticks when the event occured.
*/
protected long time;
/**
* If the input event has been consumed, meaning it is no longer valid
* and should not be forwarded to input listeners.
*/
protected boolean consumed = false;
/**
* The time when the event occurred. This is relative to
* {@link Input#getInputTimeNanos() }.
*
* @return time when the event occured
*/
public long getTime(){
return time;
}
/**
* Set the time when the event occurred.
*
* @param time time when the event occurred.
*/
public void setTime(long time){
this.time = time;
}
/**
* Returns true if the input event has been consumed, meaning it is no longer valid
* and should not be forwarded to input listeners.
*
* @return true if the input event has been consumed
*/
public boolean isConsumed() {
return consumed;
}
/**
* Call to mark this input event as consumed, meaning it is no longer valid
* and should not be forwarded to input listeners.
*/
public void setConsumed() {
this.consumed = true;
}

@ -32,6 +32,14 @@
package com.jme3.input.event;
import com.jme3.input.InputManager;
import com.jme3.input.Joystick;
/**
* Joystick axis event.
*
* @author Kirill Vainer
*/
public class JoyAxisEvent extends InputEvent {
private int joyIdx;
@ -44,18 +52,34 @@ public class JoyAxisEvent extends InputEvent {
this.value = value;
}
/**
* Returns the joystick axis index.
*
* @return joystick axis index.
*
* @see Joystick#assignAxis(java.lang.String, java.lang.String, int)
*/
public int getAxisIndex() {
return axisIdx;
}
/**
* The joystick index.
*
* @return joystick index.
*
* @see InputManager#getJoysticks()
*/
public int getJoyIndex() {
return joyIdx;
}
/**
* The value of the axis.
*
* @return value of the axis.
*/
public float getValue() {
return value;
}
}

@ -32,6 +32,13 @@
package com.jme3.input.event;
import com.jme3.input.Joystick;
/**
* Joystick button event.
*
* @author Kirill Vainer
*/
public class JoyButtonEvent extends InputEvent {
private int joyIdx;
@ -44,14 +51,35 @@ public class JoyButtonEvent extends InputEvent {
this.pressed = pressed;
}
/**
* The button index.
*
* @return button index.
*
* @see Joystick#assignButton(java.lang.String, int)
*/
public int getButtonIndex() {
return btnIdx;
}
/**
* The joystick index.
*
* @return joystick index.
*
* @see InputManager#getJoysticks()
*/
public int getJoyIndex() {
return joyIdx;
}
/**
* Returns true if the event was a button press,
* returns false if the event was a button release.
*
* @return true if the event was a button press,
* false if the event was a button release.
*/
public boolean isPressed() {
return pressed;
}

@ -32,6 +32,13 @@
package com.jme3.input.event;
import com.jme3.input.KeyInput;
/**
* Keyboard key event.
*
* @author Kirill Vainer
*/
public class KeyInputEvent extends InputEvent {
private int keyCode;
@ -46,26 +53,54 @@ public class KeyInputEvent extends InputEvent {
this.repeating = repeating;
}
/**
* Returns the key character. Returns 0 if the key has no character.
*
* @return the key character. 0 if the key has no character.
*/
public char getKeyChar() {
return keyChar;
}
/**
* The key code.
* <p>
* See KEY_*** constants in {@link KeyInput}.
*
* @return key code.
*/
public int getKeyCode() {
return keyCode;
}
/**
* Returns true if this event is key press, false is it was a key release.
*
* @return true if this event is key press, false is it was a key release.
*/
public boolean isPressed() {
return pressed;
}
/**
* Returns true if this event is a repeat event. Not used anymore.
*
* @return true if this event is a repeat event
*/
public boolean isRepeating() {
return repeating;
}
/**
* Returns true if this event is a key release, false if it was a key press.
*
* @return true if this event is a key release, false if it was a key press.
*/
public boolean isReleased() {
return !pressed;
}
@Override
public String toString(){
String str = "Key(CODE="+keyCode;
if (keyChar != '\0')

@ -32,12 +32,17 @@
package com.jme3.input.event;
/**
* Mouse button press/release event.
*
* @author Kirill Vainer
*/
public class MouseButtonEvent extends InputEvent {
int x;
int y;
int btnIndex;
boolean pressed;
private int x;
private int y;
private int btnIndex;
private boolean pressed;
public MouseButtonEvent(int btnIndex, boolean pressed, int x, int y) {
this.btnIndex = btnIndex;
@ -46,26 +51,52 @@ public class MouseButtonEvent extends InputEvent {
this.y = y;
}
/**
* Returns the mouse button index.
* <p>
* See constants in {@link MouseInput}.
*
* @return the mouse button index.
*/
public int getButtonIndex() {
return btnIndex;
}
/**
* Returns true if the mouse button was pressed, false if it was released.
*
* @return true if the mouse button was pressed, false if it was released.
*/
public boolean isPressed() {
return pressed;
}
/**
* Returns true if the mouse button was released, false if it was pressed.
*
* @return true if the mouse button was released, false if it was pressed.
*/
public boolean isReleased() {
return !pressed;
}
/**
* The X coordinate of the mouse when the event was generated.
* @return X coordinate of the mouse when the event was generated.
*/
public int getX() {
return x;
}
/**
* The Y coordinate of the mouse when the event was generated.
* @return Y coordinate of the mouse when the event was generated.
*/
public int getY() {
return y;
}
@Override
public String toString(){
String str = "MouseButton(BTN="+btnIndex;
if (pressed){

@ -32,8 +32,13 @@
package com.jme3.input.event;
import com.jme3.input.*;
/**
* Mouse movement event.
* <p>
* Movement events are only generated if the mouse is on-screen.
*
* @author Kirill Vainer
*/
public class MouseMotionEvent extends InputEvent {
private int x, y, dx, dy, wheel, deltaWheel;
@ -47,26 +52,52 @@ public class MouseMotionEvent extends InputEvent {
this.deltaWheel = deltaWheel;
}
/**
* The change in wheel rotation.
*
* @return change in wheel rotation.
*/
public int getDeltaWheel() {
return deltaWheel;
}
/**
* The change in X coordinate
* @return change in X coordinate
*/
public int getDX() {
return dx;
}
/**
* The change in Y coordinate
*
* @return change in Y coordinate
*/
public int getDY() {
return dy;
}
/**
* Current mouse wheel value
* @return Current mouse wheel value
*/
public int getWheel() {
return wheel;
}
/**
* Current X coordinate
* @return Current X coordinate
*/
public int getX() {
return x;
}
/**
* Current Y coordinate
* @return Current Y coordinate
*/
public int getY() {
return y;
}

@ -29,51 +29,43 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.input.event;
import com.jme3.input.event.InputEvent;
import com.jme3.math.Vector2f;
/**
* <code>TouchEvent</code> represents a single event from multi-touch input devices
* @author larynx
*/
public class TouchEvent extends InputEvent
{
public static enum Type
{
public class TouchEvent extends InputEvent {
public enum Type {
/**
* Touch down event, fields: posX, posY, pressure
*/
DOWN,
/**
* Move/Drag event, fields: posX, posY, deltaX, deltaY, pressure
*/
MOVE,
/**
* Touch up event, fields: posX, posY, pressure
*/
UP,
/**
* Virtual keyboard or hardware key event down, fields: keyCode, characters
*/
KEY_DOWN,
/**
* Virtual keyboard or hardware key event up, fields: keyCode, characters
*/
KEY_UP,
// Single finger gestures
FLING,
TAP,
DOUBLETAP,
LONGPRESSED,
// Two finger scale events
/**
* Two finger scale event start, fields: posX/posY = getFocusX/Y, scaleFactor, scaleSpan
@ -87,24 +79,19 @@ public class TouchEvent extends InputEvent
* Two finger scale event end, fields: posX/posY = getFocusX/Y, scaleFactor, scaleSpan
*/
SCALE_END,
/**
* Scroll event
*/
SCROLL,
/**
* The user has performed a down MotionEvent and not performed a move or up yet. This event is commonly used to provide visual feedback to the user to let them know that their action has been recognized i.e. highlight an element.
*/
SHOWPRESS,
// Others
OUTSIDE,
IDLE}
IDLE
}
private Type type = Type.IDLE;
private int pointerId;
private float posX;
private float posY;
@ -115,28 +102,23 @@ public class TouchEvent extends InputEvent
// Used only with KEY* events
private int keyCode;
private String characters;
// Used only with SCALE* events
private float scaleFactor;
private float scaleSpan;
public TouchEvent()
{
public TouchEvent() {
set(Type.IDLE, 0f, 0f, 0f, 0f);
}
public TouchEvent(Type type, float x, float y, float deltax, float deltay)
{
public TouchEvent(Type type, float x, float y, float deltax, float deltay) {
set(type, x, y, deltax, deltay);
}
public void set(Type type)
{
public void set(Type type) {
set(type, 0f, 0f, 0f, 0f);
}
public void set(Type type, float x, float y, float deltax, float deltay)
{
public void set(Type type, float x, float y, float deltax, float deltay) {
this.type = type;
this.posX = x;
this.posY = y;
@ -145,29 +127,28 @@ public class TouchEvent extends InputEvent
consumed = false;
}
public Type getType()
{
/**
* Returns the type of touch event.
*
* @return the type of touch event.
*/
public Type getType() {
return type;
}
public float getX()
{
public float getX() {
return posX;
}
public float getY()
{
public float getY() {
return posY;
}
public float getDeltaX()
{
public float getDeltaX() {
return deltaX;
}
public float getDeltaY()
{
public float getDeltaY() {
return deltaY;
}
@ -186,48 +167,39 @@ public class TouchEvent extends InputEvent
return pointerId;
}
public void setPointerId(int pointerId)
{
public void setPointerId(int pointerId) {
this.pointerId = pointerId;
}
public int getKeyCode()
{
public int getKeyCode() {
return keyCode;
}
public void setKeyCode(int keyCode)
{
public void setKeyCode(int keyCode) {
this.keyCode = keyCode;
}
public String getCharacters()
{
public String getCharacters() {
return characters;
}
public void setCharacters(String characters)
{
public void setCharacters(String characters) {
this.characters = characters;
}
public float getScaleFactor()
{
public float getScaleFactor() {
return scaleFactor;
}
public void setScaleFactor(float scaleFactor)
{
public void setScaleFactor(float scaleFactor) {
this.scaleFactor = scaleFactor;
}
public float getScaleSpan()
{
public float getScaleSpan() {
return scaleSpan;
}
public void setScaleSpan(float scaleSpan)
{
public void setScaleSpan(float scaleSpan) {
this.scaleSpan = scaleSpan;
}
}

@ -0,0 +1,38 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
The <code>com.jme3.input</code> package is used for all input handling in
jMonkeyEngine. User code should use the {@link com.jme3.input.InputManager} to register
for and receive input events. The <code>InputManager</code> can be
retrieved for an application by using {@link com.jme3.app.Application#getInputManager()}.
<h3>Usage</h3>
<p>
Using ActionListener:<br>
<code>
// Retrieve an input manager for the application "app"<br>
InputManager inputManager = app.getInputManager();<br>
<br>
// Adds a new mapping "PrintHello" that will be invoked when the Return/Enter key is pressed<br>
inputManager.addMapping("PrintHello", new KeyTrigger(KeyInput.KEY_RETURN));<br>
// Adds a new ActionListener to get an event when enter is pressed.<br>
inputManager.addListener(new ActionListener() {<br>
public void onAction(String name, boolean isPressed, float tpf) {<br>
// Only invoke the event when the mapping is "PrintHello" <br>
// and isPressed is true, meaning it was a key press and not release.<br>
if (name.equals("PrintHello") && isPressed){<br>
System.out.println("Hello!");<br>
}<br>
}<br>
}, "PrintHello");<br>
</code>
</body>
</html>
Loading…
Cancel
Save