|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jme.input.InputHandler
public class InputHandler
InputHandler
handles mouse, key and other inputs. Actions can be subscribed for specific event triggers.
InputActionInterface.performAction(InputActionEvent)
is invoked within the update(float)
method whenever the
trigger criterias match. For a usage example see TestInputHandler. InputHandler is also used to decouple event
occurence and action invocation (see ActionTrigger
) - an event may occur in another thread (e.g. polling
thread) but the action is still invoked in the thread that is calling the update(float)
method.
You can add custom devices via the addDevice(InputHandlerDevice)
method.
Field Summary | |
---|---|
(package private) ActionTrigger |
activeTriggers
Stores first active trigger that is invoked upon next update. |
(package private) java.util.ArrayList<ActionTrigger> |
allTriggers
list of all ActionTrigger s of this input handler (triggers add themselves). |
static int |
AXIS_ALL
int value for representing all axes (wildcard). |
static int |
AXIS_NONE
int value for representing no axis. |
static int |
BUTTON_ALL
int value for representing all buttons/keys (wildcard). |
static int |
BUTTON_NONE
int value for representing no button/key. |
static java.lang.String |
DEVICE_ALL
Wildcard device name for all devices. |
static java.lang.String |
DEVICE_KEYBOARD
Device name of the keyboard. |
static java.lang.String |
DEVICE_MOUSE
Device name of the mouse. |
protected InputActionEvent |
event
event that will be used to call each action this frame. |
protected Mouse |
mouse
Not used any more. |
Constructor Summary | |
---|---|
InputHandler()
Creates a new input handler. |
Method Summary | |
---|---|
void |
addAction(InputActionInterface inputAction,
java.lang.String triggerCommand,
boolean allowRepeats)
Adds an input action to be invoked by this handler during update. |
void |
addAction(InputActionInterface inputAction,
java.lang.String triggerCommand,
int keyCode,
boolean allowRepeats)
Registeres a single key as command in KeyBindingManager and adds an input
action to be invoked by this handler during update. |
void |
addAction(InputActionInterface action,
java.lang.String deviceName,
int button,
int axis,
boolean allowRepeats)
Adds an input action to be invoked on deviceName button or axis events. |
void |
addAction(InputAction action,
SyntheticAxis eventHandler,
boolean allowRepeats)
Adds an input action to be invoked on events for the given synthetic axis. |
void |
addAction(InputAction action,
SyntheticButton eventHandler,
boolean allowRepeats)
Adds an input action to be invoked on events for the given synthetic button. |
void |
addAction(MouseInputAction mouseAction)
Adds a mouse input action to be invoked each frame. |
static void |
addDevice(InputHandlerDevice device)
Add a device to the InputHandlers. |
boolean |
addToAttachedHandlers(InputHandler value)
Attach a handler which should be updated in this handlers update method. |
void |
clearActions()
Clears all actions currently registered. |
static boolean |
getBooleanProp(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String key,
boolean defaultVal)
|
static java.util.Collection<InputHandlerDevice> |
getDevices()
|
static float |
getFloatProp(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String key,
float defaultVal)
|
InputHandler |
getFromAttachedHandlers(int index)
Get an element from the attachedHandlers association. |
static int |
getIntProp(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String key,
int defaultVal)
|
static java.lang.Object |
getObjectProp(java.util.Map<java.lang.String,java.lang.Object> props,
java.lang.String key,
java.lang.Object defaultVal)
|
InputHandler |
getParent()
Query parent handler. |
boolean |
isEnabled()
|
protected void |
processTriggers(float time)
Process triggers and call ActionTrigger.performAction(com.jme.input.action.InputActionEvent) if appropriate. |
void |
removeAction(InputActionInterface inputAction)
Removes a keyboard input action from the list of keyActions that are polled during update. |
void |
removeAction(java.lang.String triggerCommand)
Removes a keyboard input action from the list of keyActions that are polled during update. |
void |
removeAllActions()
Removes all actions and triggers from this handler. |
void |
removeAllFromAttachedHandlers()
|
boolean |
removeFromAttachedHandlers(InputHandler value)
|
void |
setActionSpeed(float speed)
Sets the speed of all actions currently registered with this handler to the given value. |
void |
setActionSpeed(float speed,
java.lang.String trigger)
|
void |
setEnabled(boolean value)
Enable/disable the handler: disabled handler do not invoke actions and do not update attached handlers. |
void |
setEnabledOfAttachedHandlers(boolean enabled)
enabled/disables all attached handlers but this handler keeps its status. |
protected boolean |
setParent(InputHandler value)
|
int |
sizeOfAttachedHandlers()
|
void |
update(float time)
Checks all actions to see if they should be invoked. |
protected void |
updateAttachedHandlers(float time)
Update attached handlers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
ActionTrigger activeTriggers
ActionTrigger.getNext()
(linked list).
java.util.ArrayList<ActionTrigger> allTriggers
ActionTrigger
s of this input handler (triggers add themselves).
public static final java.lang.String DEVICE_MOUSE
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuespublic static final java.lang.String DEVICE_KEYBOARD
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuespublic static final java.lang.String DEVICE_ALL
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuespublic static final int BUTTON_NONE
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuespublic static final int BUTTON_ALL
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuespublic static final int AXIS_NONE
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuespublic static final int AXIS_ALL
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
,
Constant Field Valuesprotected Mouse mouse
protected InputActionEvent event
Constructor Detail |
---|
public InputHandler()
Method Detail |
---|
public void setActionSpeed(float speed)
speed
- The new speed for all currently registered actions.InputAction.setSpeed(float)
public void setActionSpeed(float speed, java.lang.String trigger)
public void addAction(InputActionInterface inputAction, java.lang.String triggerCommand, boolean allowRepeats)
inputAction
- the input action to be addedtriggerCommand
- the command to trigger this action (registered with KeyBindingManager
), if null
the action is invoked on each call of update(float)
allowRepeats
- true to invoke the action every call of update the trigger is lit, false to invokepublic void addAction(InputActionInterface inputAction, java.lang.String triggerCommand, int keyCode, boolean allowRepeats)
KeyBindingManager
and adds an input
action to be invoked by this handler during update.
inputAction
- the input action to be addedtriggerCommand
- the command to trigger this action, may not be null (unlike in
addAction(com.jme.input.action.InputActionInterface,String,boolean)
)keyCode
- the keyCode to register at KeyBindingManager
for the commandallowRepeats
- true to invoke the action every call of update the trigger is lit, false to invokepublic void addAction(InputAction action, SyntheticButton eventHandler, boolean allowRepeats)
InputActionEvent
.getTrigger* methods.
action
- the input action to be addedallowRepeats
- false to invoke action once for each button down, true to invoke each frame while theeventHandler
- buttonpublic void addAction(InputAction action, SyntheticAxis eventHandler, boolean allowRepeats)
InputActionEvent
.getTrigger* methods.
action
- the input action to be addedallowRepeats
- false to invoke action once for each button down, true to invoke each frame while theeventHandler
- axispublic void addAction(MouseInputAction mouseAction)
addAction(com.jme.input.action.InputActionInterface,String,int,int,boolean)
to add actions that
are invoked on mouse events.
mouseAction
- The input action to be addedpublic static java.util.Collection<InputHandlerDevice> getDevices()
public static void addDevice(InputHandlerDevice device)
DEVICE_ALL
before device was added will not receive device events).
device
- new deviceInputHandlerDevice
public void addAction(InputActionInterface action, java.lang.String deviceName, int button, int axis, boolean allowRepeats)
InputActionEvent
.getTrigger* methods.
action
- the input action to be addeddeviceName
- name of the deviceName: DEVICE_MOUSE
, DEVICE_KEYBOARD
,
a joystick name or DEVICE_ALL
button
- index of the button that triggers this event, BUTTON_NONE
for no button,
BUTTON_ALL
for all buttons. (for keyboad deviceName this is a key code).
If DEVICE_ALL is specified button will not be interpreted as key code, thus
keyboard input is only regarded if BUTTON_ALL is specified inthis case.axis
- index of the axis that triggers this event, AXIS_NONE
for no axis,
AXIS_ALL
for all axesallowRepeats
- false to invoke action once for each button down, true to invoke each frame while thepublic void removeAction(InputActionInterface inputAction)
inputAction
- The action to remove.public void removeAction(java.lang.String triggerCommand)
triggerCommand
- the command that should be removedpublic void removeAllActions()
public void clearActions()
public void update(float time)
InputActionInterface.performAction(InputActionEvent)
is called on the action with the given time.
isEnabled()
and return immediately if it evaluates to false.
InputHandlerDevice
s.
time
- The time to pass to every action that is active.addAction(com.jme.input.action.InputActionInterface,String,boolean)
protected void processTriggers(float time)
ActionTrigger.performAction(com.jme.input.action.InputActionEvent)
if appropriate.
time
- The time to pass to every trigger that is called.protected void updateAttachedHandlers(float time)
time
- The time to pass to every action that is active.public static float getFloatProp(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String key, float defaultVal)
public static int getIntProp(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String key, int defaultVal)
public static boolean getBooleanProp(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String key, boolean defaultVal)
public static java.lang.Object getObjectProp(java.util.Map<java.lang.String,java.lang.Object> props, java.lang.String key, java.lang.Object defaultVal)
public boolean isEnabled()
public void setEnabled(boolean value)
value
- true to enable the handler, false to disable the handlerpublic void setEnabledOfAttachedHandlers(boolean enabled)
enabled
- true to enable all attached handlers, false to disable thempublic boolean addToAttachedHandlers(InputHandler value)
value
- handler to attach
public InputHandler getFromAttachedHandlers(int index)
index
- index of element to be retrieved
public void removeAllFromAttachedHandlers()
public boolean removeFromAttachedHandlers(InputHandler value)
public int sizeOfAttachedHandlers()
public InputHandler getParent()
protected boolean setParent(InputHandler value)
value
- new value for field parent
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |