From fff12c5e34d788cc9e32471cd96cdcbe473c46ee Mon Sep 17 00:00:00 2001 From: Ian Rash Date: Sun, 10 Nov 2024 18:40:41 -0800 Subject: [PATCH] Added helper methods to enums used for input polling --- src/raylib-cr/raylib.cr | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/raylib-cr/raylib.cr b/src/raylib-cr/raylib.cr index 2545f70..1b94f38 100644 --- a/src/raylib-cr/raylib.cr +++ b/src/raylib-cr/raylib.cr @@ -156,6 +156,22 @@ lib Raylib Menu = 82 VolumeUp = 24 VolumeDown = 25 + + def up? + Raylib.key_up?(self.to_i) + end + + def down? + Raylib.key_down?(self.to_i) + end + + def pressed? + Raylib.key_pressed?(self.to_i) + end + + def released? + Raylib.key_released?(self.to_i) + end end enum MouseButton @@ -166,6 +182,22 @@ lib Raylib Extra = 4 Forward = 5 Back = 6 + + def up? + Raylib.mouse_button_up?(self.to_i) + end + + def released? + Raylib.mouse_button_released?(self.to_i) + end + + def down? + Raylib.mouse_button_down?(self.to_i) + end + + def pressed? + Raylib.mouse_button_pressed?(self.to_i) + end end enum MouseCursor @@ -182,6 +214,17 @@ lib Raylib NotAllowed = 10 end + enum Crixel::Gamepad::Player + One = 0 + Two = 1 + Three = 2 + Four = 3 + + def available? + Raylib.gamepad_available?(self.value) + end + end + enum GamepadButton Unknown = 0 LeftFaceUp = 1 @@ -201,6 +244,22 @@ lib Raylib MiddleRight = 15 LeftThumb = 16 RightThumb = 17 + + def up?(player : Player) + Raylib.gamepad_button_up?(player.to_i, self.to_i) + end + + def down?(player : Player) + Raylib.gamepad_button_down?(player.to_i, self.to_i) + end + + def pressed?(player : Player) + Raylib.gamepad_button_pressed?(player.to_i, self.to_i) + end + + def released?(player : Player) + Raylib.gamepad_button_released?(player.to_i, self.to_i) + end end enum GamepadAxis