Skip to content

Commit

Permalink
Merge pull request #1227 from Heinrich-F/master
Browse files Browse the repository at this point in the history
Support for SDL2 style controller hats
  • Loading branch information
bvssvni authored May 11, 2018
2 parents e957f4e + 4897c22 commit 14046db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/input/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ impl ControllerButton {
}
}

/// Components of a controller hat move event (d-Pad).
#[derive(Copy, Clone, Deserialize, Serialize, PartialEq, Eq, Debug, Hash)]
pub struct ControllerHat {
/// Which Controller was the button on.
pub id: i32,
/// Which button was pressed.
pub state: ::HatState,
/// Which hat on the controller was changed
pub which: u8,
}

impl ControllerHat {
/// Create a new ControllerButton object. Intended for use by backends when
/// emitting events.
pub fn new(id: i32, which: u8, state: ::HatState) -> Self {
ControllerHat {
id, state, which,
}
}
}

/// Components of a controller axis move event. Not guaranteed consistent across
/// backends.
#[derive(Copy, Clone, Deserialize, Serialize, PartialEq, Debug)]
Expand Down
18 changes: 17 additions & 1 deletion src/input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::sync::Arc;

pub use mouse::MouseButton;
pub use keyboard::Key;
pub use controller::{ControllerAxisArgs, ControllerButton};
pub use controller::{ControllerAxisArgs, ControllerButton, ControllerHat};

pub mod controller;
pub mod keyboard;
Expand Down Expand Up @@ -82,6 +82,8 @@ pub enum Button {
Mouse(MouseButton),
/// A controller button.
Controller(ControllerButton),
/// A controller hat (d-Pad)
Hat(ControllerHat),
}

/// Models different kinds of motion.
Expand All @@ -99,6 +101,20 @@ pub enum Motion {
Touch(TouchArgs),
}

#[derive(Copy, Clone, Deserialize, Serialize, PartialEq, Eq, Debug, Hash)]
#[allow(missing_docs)]
pub enum HatState {
Centered,
Up,
Right,
Down,
Left,
RightUp,
RightDown,
LeftUp,
LeftDown,
}

/// Models input events.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub enum Input {
Expand Down

0 comments on commit 14046db

Please sign in to comment.