Struct rusty_xinput::XInputState
source · pub struct XInputState {
pub raw: XINPUT_STATE,
}
Expand description
This wraps an XINPUT_STATE
value and provides a more rusty (read-only)
interface to the data it contains.
All three major game companies use different names for most of the buttons, so the docs for each button method list out what each of the major companies call that button. To the driver it’s all the same, it’s just however you want to think of them.
If sequential calls to xinput_get_state
for a given controller slot have
the same packet number then the controller state has not changed since the
last call. The PartialEq
and Eq
implementations for this wrapper type
reflect that. The exact value of the packet number is unimportant.
If you want to do something that the rust wrapper doesn’t support, just use the raw field to get at the inner value.
Fields§
§raw: XINPUT_STATE
The raw value we’re wrapping.
Implementations§
source§impl XInputState
impl XInputState
The north button of the action button group.
- Nintendo: X
- Playstation: Triangle
- XBox: Y
The south button of the action button group.
- Nintendo: B
- Playstation: X
- XBox: A
The east button of the action button group.
- Nintendo: A
- Playstation: Circle
- XBox: B
The west button of the action button group.
- Nintendo: Y
- Playstation: Square
- XBox: X
sourcepub fn arrow_down(&self) -> bool
pub fn arrow_down(&self) -> bool
The down button on the directional pad.
sourcepub fn arrow_left(&self) -> bool
pub fn arrow_left(&self) -> bool
The left button on the directional pad.
sourcepub fn arrow_right(&self) -> bool
pub fn arrow_right(&self) -> bool
The right button on the directional pad.
The “start” button.
- Nintendo: Start (NES / SNES), ‘+’ (Pro Controller)
- Playstation: Start
- XBox: Start
The “not start” button.
- Nintendo: Select (NES / NES), ‘-’ (Pro Controller)
- Playstation: Select
- XBox: Back
The “guide” button.
- Nintendo: Home
- Playstation: PS
- XBox: Guide
sourcepub fn left_shoulder(&self) -> bool
pub fn left_shoulder(&self) -> bool
The upper left shoulder button.
- Nintendo: L
- Playstation: L1
- XBox: LB
sourcepub fn right_shoulder(&self) -> bool
pub fn right_shoulder(&self) -> bool
The upper right shoulder button.
- Nintendo: R
- Playstation: R1
- XBox: RB
sourcepub const TRIGGER_THRESHOLD: u8 = 30u8
pub const TRIGGER_THRESHOLD: u8 = 30u8
The default threshold to count a trigger as being “pressed”.
sourcepub fn left_trigger(&self) -> u8
pub fn left_trigger(&self) -> u8
The lower left shoulder trigger. If you want to use this as a simple
boolean it is suggested that you compare it to the TRIGGER_THRESHOLD
constant.
- Nintendo: ZL
- Playstation: L2
- XBox: LT
sourcepub fn right_trigger(&self) -> u8
pub fn right_trigger(&self) -> u8
The lower right shoulder trigger. If you want to use this as a simple
boolean it is suggested that you compare it to the TRIGGER_THRESHOLD
constant.
- Nintendo: ZR
- Playstation: R2
- XBox: RT
sourcepub fn left_trigger_bool(&self) -> bool
pub fn left_trigger_bool(&self) -> bool
The lower left shoulder trigger as a bool using the default threshold.
- Nintendo: ZL
- Playstation: L2
- XBox: LT
sourcepub fn right_trigger_bool(&self) -> bool
pub fn right_trigger_bool(&self) -> bool
The lower right shoulder trigger as a bool using the default threshold.
- Nintendo: ZR
- Playstation: R2
- XBox: RT
The left thumb stick being pressed inward.
- Nintendo: (L)
- Playstation: L3
- XBox: (L)
The right thumb stick being pressed inward.
- Nintendo: (R)
- Playstation: R3
- XBox: (R)
sourcepub const LEFT_STICK_DEADZONE: i16 = 7_849i16
pub const LEFT_STICK_DEADZONE: i16 = 7_849i16
The suggested default deadzone for use with the left thumb stick.
sourcepub const RIGHT_STICK_DEADZONE: i16 = 8_689i16
pub const RIGHT_STICK_DEADZONE: i16 = 8_689i16
The suggested default deadzone for use with the right thumb stick.
sourcepub fn left_stick_raw(&self) -> (i16, i16)
pub fn left_stick_raw(&self) -> (i16, i16)
The left stick raw value.
Positive values are to the right (X-axis) or up (Y-axis).
sourcepub fn right_stick_raw(&self) -> (i16, i16)
pub fn right_stick_raw(&self) -> (i16, i16)
The right stick raw value.
Positive values are to the right (X-axis) or up (Y-axis).
sourcepub fn left_stick_normalized(&self) -> (f32, f32)
pub fn left_stick_normalized(&self) -> (f32, f32)
The left stick value normalized with the default dead-zone.
See normalize_raw_stick_value
for more.
sourcepub fn right_stick_normalized(&self) -> (f32, f32)
pub fn right_stick_normalized(&self) -> (f32, f32)
The right stick value normalized with the default dead-zone.
See normalize_raw_stick_value
for more.
sourcepub fn normalize_raw_stick_value(
raw_stick: (i16, i16),
deadzone: i16
) -> (f32, f32)
pub fn normalize_raw_stick_value( raw_stick: (i16, i16), deadzone: i16 ) -> (f32, f32)
This helper normalizes a raw stick value using the given deadzone.
If the raw value’s 2d length is less than the deadzone the result will be
(0.0,0.0)
, otherwise the result is normalized across the range from the
deadzone point to the maximum value.
The deadzone
value is clamped to the range 0 to 32,766 (inclusive)
before use. Negative inputs or maximum value inputs make the normalization
just work improperly.
Trait Implementations§
source§impl Clone for XInputState
impl Clone for XInputState
source§fn clone(&self) -> XInputState
fn clone(&self) -> XInputState
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for XInputState
impl Debug for XInputState
source§impl Default for XInputState
impl Default for XInputState
source§impl PartialEq for XInputState
impl PartialEq for XInputState
source§fn eq(&self, other: &XInputState) -> bool
fn eq(&self, other: &XInputState) -> bool
Equality for XInputState
values is based only on the
dwPacketNumber
of the wrapped XINPUT_STATE
value. This is entirely
correct for values obtained from the xinput system, but if you make your
own XInputState
values for some reason you can confuse it.