Skip to content

Commit

Permalink
Merge pull request Noxime#162 from FreddieGilbraith/master
Browse files Browse the repository at this point in the history
Add controler helper bindings
  • Loading branch information
Noxime authored Apr 26, 2024
2 parents 96b0c95 + 5c5595b commit 2041f33
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ pub struct Input<Manager> {
pub(crate) _inner: Arc<Inner<Manager>>,
}

pub enum InputType {
Unknown,
SteamController,
XBox360Controller,
XBoxOneController,
GenericGamepad,
PS4Controller,
AppleMFiController,
AndroidController,
SwitchJoyConPair,
SwitchJoyConSingle,
SwitchProController,
MobileTouch,
PS3Controller,
PS5Controller,
SteamDeckController,
}

impl<Manager> Input<Manager> {
/// Init must be called when starting use of this interface.
/// if explicitly_call_run_frame is called then you will need to manually call RunFrame
Expand Down Expand Up @@ -61,6 +79,64 @@ impl<Manager> Input<Manager> {
unsafe { sys::SteamAPI_ISteamInput_GetActionSetHandle(self.input, name.as_ptr()) }
}

/// Returns the input type for a controler
pub fn get_input_type_for_handle(&self, input_handle: sys::InputHandle_t) -> InputType {
let input_type: sys::ESteamInputType =
unsafe { sys::SteamAPI_ISteamInput_GetInputTypeForHandle(self.input, input_handle) };

match input_type {
sys::ESteamInputType::k_ESteamInputType_SteamController => InputType::SteamController,
sys::ESteamInputType::k_ESteamInputType_GenericGamepad => InputType::GenericGamepad,
sys::ESteamInputType::k_ESteamInputType_PS4Controller => InputType::PS4Controller,
sys::ESteamInputType::k_ESteamInputType_SwitchJoyConPair => InputType::SwitchJoyConPair,
sys::ESteamInputType::k_ESteamInputType_MobileTouch => InputType::MobileTouch,
sys::ESteamInputType::k_ESteamInputType_PS3Controller => InputType::PS3Controller,
sys::ESteamInputType::k_ESteamInputType_PS5Controller => InputType::PS5Controller,
sys::ESteamInputType::k_ESteamInputType_XBox360Controller => {
InputType::XBox360Controller
}
sys::ESteamInputType::k_ESteamInputType_XBoxOneController => {
InputType::XBoxOneController
}
sys::ESteamInputType::k_ESteamInputType_AppleMFiController => {
InputType::AppleMFiController
}
sys::ESteamInputType::k_ESteamInputType_AndroidController => {
InputType::AndroidController
}
sys::ESteamInputType::k_ESteamInputType_SwitchJoyConSingle => {
InputType::SwitchJoyConSingle
}
sys::ESteamInputType::k_ESteamInputType_SwitchProController => {
InputType::SwitchProController
}
sys::ESteamInputType::k_ESteamInputType_SteamDeckController => {
InputType::SteamDeckController
}
_ => InputType::Unknown,
}
}

/// Returns the glyph for an input action
pub fn get_glyph_for_action_origin(&self, action_origin: sys::EInputActionOrigin) -> String {
unsafe {
let glyph_path =
sys::SteamAPI_ISteamInput_GetGlyphForActionOrigin_Legacy(self.input, action_origin);
let glyph_path = CStr::from_ptr(glyph_path);
glyph_path.to_string_lossy().into_owned()
}
}

/// Returns the name of an input action
pub fn get_string_for_action_origin(&self, action_origin: sys::EInputActionOrigin) -> String {
unsafe {
let name_path =
sys::SteamAPI_ISteamInput_GetStringForActionOrigin(self.input, action_origin);
let name_path = CStr::from_ptr(name_path);
name_path.to_string_lossy().into_owned()
}
}

/// Reconfigure the controller to use the specified action set
/// This is cheap, and can be safely called repeatedly.
pub fn activate_action_set_handle(
Expand Down

0 comments on commit 2041f33

Please sign in to comment.