1 /** provides global access to input */ 2 3 module re.input.input; 4 5 import re.core; 6 import re.math; 7 import re.input; 8 static import raylib; 9 10 alias Keys = raylib.KeyboardKey; 11 alias MouseButton = raylib.MouseButton; 12 alias GamepadButtons = raylib.GamepadButton; 13 alias Axes = raylib.GamepadAxis; 14 15 /// input helper 16 public static class Input { 17 /// global virtual input list 18 public static VirtualInput[] virtual_inputs; 19 private static Vector2 last_mouse_position; 20 public static Vector2 mouse_delta; 21 22 static this() { 23 } 24 25 public static void update() { 26 // update core input pipeline 27 immutable auto current_mouse_pos = mouse_position(); 28 mouse_delta = current_mouse_pos - last_mouse_position; 29 last_mouse_position = current_mouse_pos; 30 // update virtual inputs 31 debug { 32 // skip virtual input update if console open 33 if (Core.debugger.console.open) { 34 return; 35 } 36 } 37 foreach (input; virtual_inputs) { 38 input.update(); 39 } 40 } 41 42 // - keyboard 43 44 /// if a key was pressed this frame 45 public static bool is_key_pressed(Keys key) { 46 return raylib.IsKeyPressed(key); 47 } 48 49 /// if a key is currently down 50 public static bool is_key_down(Keys key) { 51 return raylib.IsKeyDown(key); 52 } 53 54 /// if a key was released this frame 55 public static bool is_key_released(Keys key) { 56 return raylib.IsKeyReleased(key); 57 } 58 59 /// if a key is currently up 60 public static bool is_key_up(Keys key) { 61 return raylib.IsKeyUp(key); 62 } 63 64 // - gamepad 65 // TODO 66 67 // - mouse 68 69 /// if the mouse was pressed this frame 70 public static bool is_mouse_pressed(MouseButton button) { 71 return raylib.IsMouseButtonPressed(button); 72 } 73 74 /// if the mouse is currently down 75 public static bool is_mouse_down(MouseButton button) { 76 return raylib.IsMouseButtonDown(button); 77 } 78 79 /// if the mouse was released this frame 80 public static bool is_mouse_released(MouseButton button) { 81 return raylib.IsMouseButtonReleased(button); 82 } 83 84 /// if the mouse is currently up 85 public static bool is_mouse_up(MouseButton button) { 86 return raylib.IsMouseButtonUp(button); 87 } 88 89 /// the position of the mouse as a vector 90 @property public static Vector2 mouse_position() { 91 return raylib.GetMousePosition(); 92 } 93 94 /// the mouse scroll wheel delta 95 @property public static float scroll_delta() { 96 return raylib.GetMouseWheelMove(); 97 } 98 99 private static bool _cursor_locked = false; 100 @property public static bool is_cursor_locked() { 101 return _cursor_locked; 102 } 103 104 /// lock the cursor 105 public static void lock_cursor() { 106 raylib.DisableCursor(); 107 _cursor_locked = true; 108 } 109 110 /// unlock the cursor 111 public static void unlock_cursor() { 112 raylib.EnableCursor(); 113 _cursor_locked = false; 114 } 115 }