rustboy_core/
input.rs

1pub enum ButtonType {
2    ACTION,
3    DIRECTION,
4}
5
6#[derive(Copy, Clone)]
7pub enum Button {
8    A,
9    B,
10    SELECT,
11    START,
12    RIGHT,
13    LEFT,
14    UP,
15    DOWN,
16}
17
18impl Button {
19    pub fn button_index(&self) -> usize {
20        match self {
21            Button::A => 0,
22            Button::B => 1,
23            Button::SELECT => 2,
24            Button::START => 3,
25            Button::RIGHT => 0,
26            Button::LEFT => 1,
27            Button::UP => 2,
28            Button::DOWN => 3,
29        }
30    }
31
32    pub fn button_type(&self) -> ButtonType {
33        match self {
34            Button::A => ButtonType::ACTION,
35            Button::B => ButtonType::ACTION,
36            Button::SELECT => ButtonType::ACTION,
37            Button::START => ButtonType::ACTION,
38            Button::RIGHT => ButtonType::DIRECTION,
39            Button::LEFT => ButtonType::DIRECTION,
40            Button::UP => ButtonType::DIRECTION,
41            Button::DOWN => ButtonType::DIRECTION
42        }
43    }
44}