Skip to main content

forge/
input.rs

1pub use sys::input::{Button, Key};
2
3pub struct Input;
4
5impl Input {
6    pub fn is_button_down(button: Button) -> bool {
7        unsafe { sys::input::forge_input_isDown(button) }
8    }
9
10    pub fn is_button_pressed(button: Button) -> bool {
11        unsafe { sys::input::forge_input_isPressed(button) }
12    }
13
14    pub fn is_button_released(button: Button) -> bool {
15        unsafe { sys::input::forge_input_isReleased(button) }
16    }
17
18    pub fn get_stick_l() -> (f32, f32) {
19        let mut x = 0.0;
20        let mut y = 0.0;
21        unsafe { sys::input::forge_input_getStickL(&mut x, &mut y) };
22        (x, y)
23    }
24
25    pub fn get_stick_r() -> (f32, f32) {
26        let mut x = 0.0;
27        let mut y = 0.0;
28        unsafe { sys::input::forge_input_getStickR(&mut x, &mut y) };
29        (x, y)
30    }
31
32    pub fn is_connected() -> bool {
33        unsafe { sys::input::forge_input_isConnected() }
34    }
35
36    pub fn get_touch() -> Option<(f32, f32)> {
37        let mut x = 0.0;
38        let mut y = 0.0;
39        if unsafe { sys::input::forge_input_getTouch(&mut x, &mut y) } {
40            Some((x, y))
41        } else {
42            None
43        }
44    }
45
46    pub fn is_key_down(key: Key) -> bool {
47        unsafe { sys::input::forge_input_isKeyDown(key) }
48    }
49
50    pub fn is_key_pressed(key: Key) -> bool {
51        unsafe { sys::input::forge_input_isKeyPressed(key) }
52    }
53
54    pub fn is_key_released(key: Key) -> bool {
55        unsafe { sys::input::forge_input_isKeyReleased(key) }
56    }
57
58    pub fn is_shift_down() -> bool {
59        unsafe { sys::input::forge_input_isShiftDown() }
60    }
61
62    pub fn is_ctrl_down() -> bool {
63        unsafe { sys::input::forge_input_isCtrlDown() }
64    }
65
66    pub fn is_alt_down() -> bool {
67        unsafe { sys::input::forge_input_isAltDown() }
68    }
69}