REVIEWED: Mouse and Touch functions generic to all platforms #3313

This commit is contained in:
Ray
2023-10-11 11:36:44 +02:00
parent 6ebfec99c5
commit 0d175a69ae
6 changed files with 68 additions and 288 deletions

View File

@ -2113,11 +2113,7 @@ float GetGamepadAxisMovement(int gamepad, int axis)
//----------------------------------------------------------------------------------
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
//int GetMouseX(void) **
//int GetMouseY(void) **
//Vector2 GetMousePosition(void) **
//void SetMousePosition(int x, int y)
//float GetMouseWheelMove(void) **
//void SetMouseCursor(int cursor)
// Check if a mouse button has been pressed once
@ -2172,6 +2168,29 @@ bool IsMouseButtonUp(int button)
return up;
}
// Get mouse position X
int GetMouseX(void)
{
return (int)((CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x);
}
// Get mouse position Y
int GetMouseY(void)
{
return (int)((CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y);
}
// Get mouse position XY
Vector2 GetMousePosition(void)
{
Vector2 position = { 0 };
position.x = (CORE.Input.Mouse.currentPosition.x + CORE.Input.Mouse.offset.x)*CORE.Input.Mouse.scale.x;
position.y = (CORE.Input.Mouse.currentPosition.y + CORE.Input.Mouse.offset.y)*CORE.Input.Mouse.scale.y;
return position;
}
// Get mouse delta between frames
Vector2 GetMouseDelta(void)
{
@ -2197,6 +2216,17 @@ void SetMouseScale(float scaleX, float scaleY)
CORE.Input.Mouse.scale = (Vector2){ scaleX, scaleY };
}
// Get mouse wheel movement Y
float GetMouseWheelMove(void)
{
float result = 0.0f;
if (fabsf(CORE.Input.Mouse.currentWheelMove.x) > fabsf(CORE.Input.Mouse.currentWheelMove.y)) result = (float)CORE.Input.Mouse.currentWheelMove.x;
else result = (float)CORE.Input.Mouse.currentWheelMove.y;
return result;
}
// Get mouse wheel movement X/Y as a vector
Vector2 GetMouseWheelMoveV(void)
{
@ -2211,10 +2241,29 @@ Vector2 GetMouseWheelMoveV(void)
// Module Functions Definition: Input Handling: Touch
//----------------------------------------------------------------------------------
// NOTE: Functions with a platform-specific implementation on rcore_<platform>.c
//int GetTouchX(void)
//int GetTouchY(void)
//Vector2 GetTouchPosition(int index)
// Get touch position X for touch point 0 (relative to screen size)
int GetTouchX(void)
{
return (int)CORE.Input.Touch.position[0].x;
}
// Get touch position Y for touch point 0 (relative to screen size)
int GetTouchY(void)
{
return (int)CORE.Input.Touch.position[0].y;
}
// Get touch position XY for a touch point index (relative to screen size)
// TODO: Touch position should be scaled depending on display size and render size
Vector2 GetTouchPosition(int index)
{
Vector2 position = { -1.0f, -1.0f };
if (index < MAX_TOUCH_POINTS) position = CORE.Input.Touch.position[index];
else TRACELOG(LOG_WARNING, "INPUT: Required touch point out of range (Max touch points: %i)", MAX_TOUCH_POINTS);
return position;
}
// Get touch point identifier for given index
int GetTouchPointId(int index)