-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
GamepadContext
and event handling for gamepads
- Loading branch information
Showing
8 changed files
with
80 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// TODO: Documentation | ||
//! Gamepad utility functions. | ||
use std::fmt; | ||
|
||
use gilrs::{Gamepad, Gilrs}; | ||
|
||
use context::Context; | ||
use GameResult; | ||
|
||
/// A structure that contains gamepad state. | ||
pub struct GamepadContext { | ||
pub(crate) gilrs: Gilrs, | ||
} | ||
|
||
impl fmt::Debug for GamepadContext { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "<GamepadContext: {:p}>", self) | ||
} | ||
} | ||
|
||
impl GamepadContext { | ||
pub(crate) fn new() -> GameResult<GamepadContext> { | ||
let gilrs = Gilrs::new()?; | ||
Ok(GamepadContext { gilrs }) | ||
} | ||
} | ||
|
||
/// returns the `Gamepad` associated with an id. | ||
pub fn get_gamepad(ctx: &Context, id: usize) -> Option<&Gamepad> { | ||
ctx.gamepad_context.gilrs.get(id) | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters