4 Commits

Author SHA1 Message Date
Ray
de7fc12be0 REVIEWED: IsGamepadButton*() for consistency with key and mouse equivalents 2026-01-28 19:35:54 +01:00
Ray
8a2da96eed Reviewed formating and spacing 2026-01-28 19:34:55 +01:00
af37fa2a96 Refactoring based on Coding Style Conventions (#5517)
Co-authored-by: maiconpintoabreu <maicon@thinkpad02.exads.com>
2026-01-28 19:27:03 +01:00
d0a6892989 [rcore] IsMouseButton*(), random key codes return unexpected results (#5516)
* update

* update

* stuff

* update

* move headerfile to root

* delete .h

* update ignore

* fix IsMouseButtonDown\Pressed\Released\Up will get randomly returned to true when the button code is outside the range of mouse button

* remove unessary macro

* refactor IsMouseButton*() early returns
2026-01-28 19:26:07 +01:00
6 changed files with 59 additions and 38 deletions

View File

@ -3831,7 +3831,6 @@ void PlayAutomationEvent(AutomationEvent event)
// Check if a key has been pressed once // Check if a key has been pressed once
bool IsKeyPressed(int key) bool IsKeyPressed(int key)
{ {
bool pressed = false; bool pressed = false;
if ((key > 0) && (key < MAX_KEYBOARD_KEYS)) if ((key > 0) && (key < MAX_KEYBOARD_KEYS))
@ -3973,8 +3972,10 @@ bool IsGamepadButtonPressed(int gamepad, int button)
{ {
bool pressed = false; bool pressed = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
(CORE.Input.Gamepad.previousButtonState[gamepad][button] == 0) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1)) pressed = true; {
if ((CORE.Input.Gamepad.previousButtonState[gamepad][button] == 0) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1)) pressed = true;
}
return pressed; return pressed;
} }
@ -3984,8 +3985,10 @@ bool IsGamepadButtonDown(int gamepad, int button)
{ {
bool down = false; bool down = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
(CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1)) down = true; {
if (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 1) down = true;
}
return down; return down;
} }
@ -3995,8 +3998,10 @@ bool IsGamepadButtonReleased(int gamepad, int button)
{ {
bool released = false; bool released = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
(CORE.Input.Gamepad.previousButtonState[gamepad][button] == 1) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0)) released = true; {
if ((CORE.Input.Gamepad.previousButtonState[gamepad][button] == 1) && (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0)) released = true;
}
return released; return released;
} }
@ -4006,8 +4011,10 @@ bool IsGamepadButtonUp(int gamepad, int button)
{ {
bool up = false; bool up = false;
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS) && if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (button < MAX_GAMEPAD_BUTTONS))
(CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0)) up = true; {
if (CORE.Input.Gamepad.currentButtonState[gamepad][button] == 0) up = true;
}
return up; return up;
} }
@ -4053,10 +4060,13 @@ bool IsMouseButtonPressed(int button)
{ {
bool pressed = false; bool pressed = false;
if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) pressed = true; if ((CORE.Input.Mouse.currentButtonState[button] == 1) && (CORE.Input.Mouse.previousButtonState[button] == 0)) pressed = true;
// Map touches to mouse buttons checking // Map touches to mouse buttons checking
if ((CORE.Input.Touch.currentTouchState[button] == 1) && (CORE.Input.Touch.previousTouchState[button] == 0)) pressed = true; if ((CORE.Input.Touch.currentTouchState[button] == 1) && (CORE.Input.Touch.previousTouchState[button] == 0)) pressed = true;
}
return pressed; return pressed;
} }
@ -4066,10 +4076,13 @@ bool IsMouseButtonDown(int button)
{ {
bool down = false; bool down = false;
if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true; if (CORE.Input.Mouse.currentButtonState[button] == 1) down = true;
// NOTE: Touches are considered like mouse buttons // NOTE: Touches are considered like mouse buttons
if (CORE.Input.Touch.currentTouchState[button] == 1) down = true; if (CORE.Input.Touch.currentTouchState[button] == 1) down = true;
}
return down; return down;
} }
@ -4079,10 +4092,13 @@ bool IsMouseButtonReleased(int button)
{ {
bool released = false; bool released = false;
if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) released = true; if ((CORE.Input.Mouse.currentButtonState[button] == 0) && (CORE.Input.Mouse.previousButtonState[button] == 1)) released = true;
// Map touches to mouse buttons checking // Map touches to mouse buttons checking
if ((CORE.Input.Touch.currentTouchState[button] == 0) && (CORE.Input.Touch.previousTouchState[button] == 1)) released = true; if ((CORE.Input.Touch.currentTouchState[button] == 0) && (CORE.Input.Touch.previousTouchState[button] == 1)) released = true;
}
return released; return released;
} }
@ -4092,10 +4108,13 @@ bool IsMouseButtonUp(int button)
{ {
bool up = false; bool up = false;
if ((button >= 0) && (button <= MOUSE_BUTTON_BACK))
{
if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true; if (CORE.Input.Mouse.currentButtonState[button] == 0) up = true;
// NOTE: Touches are considered like mouse buttons // NOTE: Touches are considered like mouse buttons
if (CORE.Input.Touch.currentTouchState[button] == 0) up = true; if (CORE.Input.Touch.currentTouchState[button] == 0) up = true;
}
return up; return up;
} }
@ -4104,6 +4123,7 @@ bool IsMouseButtonUp(int button)
int GetMouseX(void) int GetMouseX(void)
{ {
int mouseX = (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x); int mouseX = (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x);
return mouseX; return mouseX;
} }
@ -4111,6 +4131,7 @@ int GetMouseX(void)
int GetMouseY(void) int GetMouseY(void)
{ {
int mouseY = (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y); int mouseY = (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y);
return mouseY; return mouseY;
} }