diff options
| author | Denis Pobedrya <[email protected]> | 2022-09-18 00:15:11 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-09-17 23:15:11 +0200 |
| commit | 8e57c8ace389135d1f4b92ced0bfb79920ed359e (patch) | |
| tree | 76464ecf6c0c3d92b1bca10eb19b5a082c6e42d4 /src | |
| parent | 494a581339721f5693654281b19d2b2e69dfd9df (diff) | |
| download | raylib-8e57c8ace389135d1f4b92ced0bfb79920ed359e.tar.gz raylib-8e57c8ace389135d1f4b92ced0bfb79920ed359e.zip | |
Fix touchscreen input related functions on Android (#2702)
Fix display -> screen coordinate conversion for android platform and
move it to the platform event handling code, simplifying
GetTouchPosition() function implementation.
Co-authored-by: Denis Pobedrya <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/rcore.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/rcore.c b/src/rcore.c index 40581415..daf39a93 100644 --- a/src/rcore.c +++ b/src/rcore.c @@ -3835,22 +3835,7 @@ Vector2 GetTouchPosition(int index) // https://docs.microsoft.com/en-us/windows/win32/wintouch/getting-started-with-multi-touch-messages if (index == 0) position = GetMousePosition(); #endif -#if defined(PLATFORM_ANDROID) - 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); - - if ((CORE.Window.screen.width > CORE.Window.display.width) || (CORE.Window.screen.height > CORE.Window.display.height)) - { - position.x = position.x*((float)CORE.Window.screen.width/(float)(CORE.Window.display.width - CORE.Window.renderOffset.x)) - CORE.Window.renderOffset.x/2; - position.y = position.y*((float)CORE.Window.screen.height/(float)(CORE.Window.display.height - CORE.Window.renderOffset.y)) - CORE.Window.renderOffset.y/2; - } - else - { - position.x = position.x*((float)CORE.Window.render.width/(float)CORE.Window.display.width) - CORE.Window.renderOffset.x/2; - position.y = position.y*((float)CORE.Window.render.height/(float)CORE.Window.display.height) - CORE.Window.renderOffset.y/2; - } -#endif -#if defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) +#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB) || defined(PLATFORM_RPI) || defined(PLATFORM_DRM) 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); #endif @@ -5675,9 +5660,11 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event) // Register touch points position CORE.Input.Touch.position[i] = (Vector2){ AMotionEvent_getX(event, i), AMotionEvent_getY(event, i) }; - // Normalize CORE.Input.Touch.position[x] for screenWidth and screenHeight - CORE.Input.Touch.position[i].x /= (float)GetScreenWidth(); - CORE.Input.Touch.position[i].y /= (float)GetScreenHeight(); + // Normalize CORE.Input.Touch.position[i] for CORE.Window.screen.width and CORE.Window.screen.height + float widthRatio = (float)(CORE.Window.screen.width + CORE.Window.renderOffset.x) / (float)CORE.Window.display.width; + float heightRatio = (float)(CORE.Window.screen.height + CORE.Window.renderOffset.y) / (float)CORE.Window.display.height; + CORE.Input.Touch.position[i].x = CORE.Input.Touch.position[i].x * widthRatio - (float)CORE.Window.renderOffset.x / 2; + CORE.Input.Touch.position[i].y = CORE.Input.Touch.position[i].y * heightRatio - (float)CORE.Window.renderOffset.y / 2; } int32_t action = AMotionEvent_getAction(event); |
