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 classprotected classstatic interfaceRepresents a specific control mapping such that it can be reconfigured.protected classprotected class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidactivateGroup(String group) Activates the specified function group, allowing those function IDs to receive input.voidaddAnalogListener(AnalogFunctionListener l, FunctionId... functions) voidaddDelegate(FunctionId func, Object target, String methodName) voidaddDelegate(FunctionId func, Object target, String methodName, boolean passArgument) voidAdds a listener that will be notified when input mappings are added, changed, or removed.protected InputMapper.MappingaddMapping(FunctionId function, double scale, Object primary, Object... modifiers) voidaddStateListener(StateFunctionListener l, FunctionId... functions) protected voidvoiddeactivateGroup(String group) Deactivates the specified function group, preventing those function IDs from receiving input.protected InputMapper.StateGroupfindMapping(FunctionId function, Object primary, Object... modifiers) protected voidprotected voidprotected voidReturns a list of all FunctionIds that have listeners registered or inputs mapped.protected InputMapper.FunctionListenersgetFunctionListeners(FunctionId f, boolean create) protected InputMapper.StateGroupIndexgetMapping(FunctionId function, Object primary, Object... modifiers) getMappings(FunctionId function) Returns all of the different input mappings for a particular function ID.booleanhasMappings(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 voidmapGamepad(InputDevice device, Joystick j) protected voidprotected voidnotifyStateChanged(FunctionId function, InputState value) protected voidnotifyValueActive(FunctionId function, double value) voidregisterProvider(InputProvider provider) Registers an alternate InputProvider that can be used to supply events to this InputMapper and call its addRawInputListener() method.voidrelease()voidremoveAnalogListener(AnalogFunctionListener l, FunctionId... functions) voidremoveDelegate(FunctionId func, Object target, String methodName) voidRemoves a previously registered input config listener.voidremoveMapping(FunctionId function, Object primary, Object... modifiers) voidremoveMapping(InputMapper.Mapping mapping) voidremoveStateListener(StateFunctionListener l, FunctionId... functions) voidunregisterProvider(InputProvider provider) Removes a previously registered alternate InputProvider and calls its removeRawInputListener() method.voidupdate()protected InputStatevalueToState(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
-