Class InputMapper
The design of InputMapper is setup to better handle the case where an application wants to allow the user to configure their own input mappings through a GUI... and specifically where the application may allow multiple separately configured inputs to trigger the same set of functions. For example, an application may map a joystick axis, the mouse wheel, and/or one or two keys to a specific function.
Also, any logical FunctionId can be treated as both an analog input or a trinary state input. Key inputs can trigger analog functions and analog axes can trigger Positive, Off, Negative state transitions. For example, the key 'A' can be mapped to a "move" function and 'S' can be mapped to the "move" function as being inverted. 'A' and 'S' will then trigger analog values of 1.0 and -1.0 respectively. The "move" function can then also be mapped to an analog joystick axis and the code remains the same. On the other end, if a StateFunctionListener is registered with to a logical FunctionId being fed by an analog Axis then it will see Positive, Negative, and Off as the axis transitions from greater than 0, less than 0, and 0, respectively. (A small neutrality threshold is effected to make extremely small analog values operate as 0.)
When registering inputs, a series of combinations can be included that must all be present to invoke the function. As an example, "mouse wheel" and "ctrl + mouse wheel" can be treated as two separate function triggers.
Entire groups of logical functions can be enabled and disabled by their groups. Multiple groups can be active at any given time and only active groups are elegible to receive input.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
protected class
static interface
Represents a specific control mapping such that it can be reconfigured.protected class
protected class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
void
activateGroup
(String group) Activates the specified function group, allowing those function IDs to receive input.void
addAnalogListener
(AnalogFunctionListener l, FunctionId... functions) void
addDelegate
(FunctionId func, Object target, String methodName) void
addDelegate
(FunctionId func, Object target, String methodName, boolean passArgument) void
Adds a listener that will be notified when input mappings are added, changed, or removed.protected InputMapper.Mapping
addMapping
(FunctionId function, double scale, Object primary, Object... modifiers) void
addStateListener
(StateFunctionListener l, FunctionId... functions) protected void
void
deactivateGroup
(String group) Deactivates the specified function group, preventing those function IDs from receiving input.protected InputMapper.StateGroup
findMapping
(FunctionId function, Object primary, Object... modifiers) protected void
protected void
protected void
Returns a list of all FunctionIds that have listeners registered or inputs mapped.protected InputMapper.FunctionListeners
getFunctionListeners
(FunctionId f, boolean create) protected InputMapper.StateGroupIndex
getMapping
(FunctionId function, Object primary, Object... modifiers) getMappings
(FunctionId function) Returns all of the different input mappings for a particular function ID.boolean
hasMappings
(FunctionId function) Returns true if the specified function has any input mappings.map
(FunctionId function, int mainKeyCode, Object... pressed) map
(FunctionId function, Axis axis, Object... pressed) map
(FunctionId function, Button button, Object... pressed) map
(FunctionId function, InputState bias, int mainKeyCode, Object... pressed) map
(FunctionId function, InputState bias, Axis axis, Object... pressed) map
(FunctionId function, InputState bias, Button button, Object... pressed) protected void
mapGamepad
(InputDevice device, Joystick j) protected void
protected void
notifyStateChanged
(FunctionId function, InputState value) protected void
notifyValueActive
(FunctionId function, double value) void
registerProvider
(InputProvider provider) Registers an alternate InputProvider that can be used to supply events to this InputMapper and call its addRawInputListener() method.void
release()
void
removeAnalogListener
(AnalogFunctionListener l, FunctionId... functions) void
removeDelegate
(FunctionId func, Object target, String methodName) void
Removes a previously registered input config listener.void
removeMapping
(FunctionId function, Object primary, Object... modifiers) void
removeMapping
(InputMapper.Mapping mapping) void
removeStateListener
(StateFunctionListener l, FunctionId... functions) void
unregisterProvider
(InputProvider provider) Removes a previously registered alternate InputProvider and calls its removeRawInputListener() method.void
update()
protected InputState
valueToState
(double val)
-
Constructor Details
-
InputMapper
-
-
Method Details
-
registerProvider
Registers an alternate InputProvider that can be used to supply events to this InputMapper and call its addRawInputListener() method. If the provider is still registered when InputMapper is released then InputMapper will remove its listener during release(). -
unregisterProvider
Removes a previously registered alternate InputProvider and calls its removeRawInputListener() method. -
activateGroup
Activates the specified function group, allowing those function IDs to receive input. -
deactivateGroup
Deactivates the specified function group, preventing those function IDs from receiving input. -
release
public void release() -
mapJoystick
-
mapGamepad
-
getIndex
-
getFunctionListeners
-
map
-
map
-
map
-
map
public InputMapper.Mapping map(FunctionId function, InputState bias, Button button, Object... pressed) -
map
-
map
public InputMapper.Mapping map(FunctionId function, InputState bias, int mainKeyCode, Object... pressed) -
addMapping
protected InputMapper.Mapping addMapping(FunctionId function, double scale, Object primary, Object... modifiers) -
findMapping
protected InputMapper.StateGroup findMapping(FunctionId function, Object primary, Object... modifiers) -
getMapping
-
removeMapping
-
removeMapping
-
hasMappings
Returns true if the specified function has any input mappings. -
getFunctionIds
Returns a list of all FunctionIds that have listeners registered or inputs mapped. -
getMappings
Returns all of the different input mappings for a particular function ID. -
addStateListener
-
removeStateListener
-
addAnalogListener
-
removeAnalogListener
-
addDelegate
-
addDelegate
-
removeDelegate
-
activate
-
deactivate
-
update
public void update() -
notifyStateChanged
-
notifyValueActive
-
valueToState
-
addInputConfigListener
Adds a listener that will be notified when input mappings are added, changed, or removed. -
removeInputConfigListener
Removes a previously registered input config listener. -
fireMappingAdded
-
fireMappingRemoved
-
fireMappingChanged
-