pub struct InputProcessor { /* private fields */ }Expand description
Parse input events, particularly key-down/up pairs, into character control and such.
This is designed to be a leaf of the dependency graph: it does not own or send messages to any other elements of the application. Instead, the following steps must occur in the given order.
- The platform-specific code should call
InputProcessor::key_downand such to to provide input information. - The game loop should call
InputProcessor::apply_inputto apply the effects of input on the relevantCharacter. (This is currently only possible viaSession.) - The game loop should call
InputProcessor::stepto apply the effects of time on the input processor. (This is currently only possible viaSession.)
TODO: Refactor APIs till this can be explained more cleanly without reference to private items.
Implementations§
Source§impl InputProcessor
impl InputProcessor
Sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new InputProcessor.
Consider using Session instead of directly calling this.
Sourcepub fn key_down(&mut self, key: Key) -> bool
pub fn key_down(&mut self, key: Key) -> bool
Handles incoming key-down events. Returns whether the key was unbound.
Sourcepub fn key_momentary(&mut self, key: Key) -> bool
pub fn key_momentary(&mut self, key: Key) -> bool
Handles incoming key events in the case where key-up events are not available, such that an assumption about equivalent press duration must be made.
Sourcepub fn key_focus(&mut self, has_focus: bool)
pub fn key_focus(&mut self, has_focus: bool)
Handles the keyboard focus being gained or lost. If the platform does not have
a concept of focus, you need not call this method, but may call it with true.
InputProcessor will assume that if focus is lost, key-up events may be lost and
so currently held keys should stop taking effect.
Sourcepub fn wants_pointer_lock(&self) -> bool
pub fn wants_pointer_lock(&self) -> bool
True when the UI is in a state which should have mouse pointer
lock/capture/disable. This is not the same as actually having it since the window
may lack focus, the application may lack permission, etc.; use
InputProcessor::has_pointer_lock to report that state.
Sourcepub fn has_pointer_lock(&mut self, value: bool)
pub fn has_pointer_lock(&mut self, value: bool)
Use this method to report whether mouse mouse pointer lock/capture/disable is
known to be successfully enabled, after InputProcessor::wants_pointer_lock
requests it or it is disabled for any reason.
Sourcepub fn mouselook_delta(&mut self, delta: Vector2D<FreeCoordinate, NominalPixel>)
pub fn mouselook_delta(&mut self, delta: Vector2D<FreeCoordinate, NominalPixel>)
Provide relative movement information for mouselook.
This value is an accumulated displacement, not an angular velocity, so it is not suitable for joystick-type input.
Note that absolute cursor positions must be provided separately.
Sourcepub fn mouse_ndc_position(&mut self, position: Option<NdcPoint2>)
pub fn mouse_ndc_position(&mut self, position: Option<NdcPoint2>)
Provide position of mouse pointer or other input device in normalized device
coordinates (range -1 to 1 upward and rightward).
None denotes the cursor being outside the viewport, and out-of-range
coordinates will be treated the same.
Pixel coordinates may be converted to NDC using Viewport::normalize_nominal_point
or by using InputProcessor::mouse_pixel_position.
If this is never called, the default value is (0, 0) which corresponds to the center of the screen.
Sourcepub fn mouse_pixel_position(
&mut self,
viewport: Viewport,
position: Option<Point2D<f64, NominalPixel>>,
derive_movement: bool,
)
pub fn mouse_pixel_position( &mut self, viewport: Viewport, position: Option<Point2D<f64, NominalPixel>>, derive_movement: bool, )
Provide position of mouse pointer or other input device in pixel coordinates
framed by the given Viewport’s nominal_size.
None denotes the cursor being outside the viewport, and out-of-range
coordinates will be treated the same.
This is equivalent to converting the coordinates and calling
InputProcessor::mouse_ndc_position.
If this is never called, the default mouse_ndc_position value is (0, 0), which
corresponds to the center of the screen.
TODO: this should take float input, probably
Sourcepub fn movement(&self) -> FreeVector
pub fn movement(&self) -> FreeVector
Returns the character movement direction that input is currently requesting.
This is always a vector of length at most 1.
Sourcepub fn mouselook_mode(&self) -> DynSource<bool>
pub fn mouselook_mode(&self) -> DynSource<bool>
Returns a source which reports whether the mouselook mode (mouse movement is interpreted as view rotation) is currently active.
This value may be toggled by in-game UI.
Sourcepub fn set_mouselook_mode(&mut self, active: bool)
pub fn set_mouselook_mode(&mut self, active: bool)
Activates or deactivates mouselook mode, identically to user input doing so.
Sourcepub fn cursor_ndc_position(&self) -> Option<NdcPoint2>
pub fn cursor_ndc_position(&self) -> Option<NdcPoint2>
Returns the position which should be used for click/cursor raycasting. This is not necessarily equal to the tracked mouse position.
Returns None if the mouse position is out of bounds, the window has lost
focus, or similar conditions under which no cursor should be shown.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for InputProcessor
impl !RefUnwindSafe for InputProcessor
impl Send for InputProcessor
impl Sync for InputProcessor
impl Unpin for InputProcessor
impl !UnwindSafe for InputProcessor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more