diff options
| author | Ray <[email protected]> | 2023-10-11 11:36:44 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-10-11 11:36:44 +0200 |
| commit | 0d175a69ae1e7072e05587b5f7505bac0c07b4ce (patch) | |
| tree | 22fd3a8073105e223d76beb6980a806e13e6ed65 /src/rcore.c | |
| parent | 6ebfec99c50ef0b00bb693ac25ddebc01457153a (diff) | |
| download | raylib-0d175a69ae1e7072e05587b5f7505bac0c07b4ce.tar.gz raylib-0d175a69ae1e7072e05587b5f7505bac0c07b4ce.zip | |
REVIEWED: Mouse and Touch functions generic to all platforms #3313
Diffstat (limited to 'src/rcore.c')
| -rw-r--r-- | src/rcore.c | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/src/rcore.c b/src/rcore.c index 2e6d3213..595cbfe0 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -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) |
