Fixed touch normalized coordinates

When converting normalized coordinates to pixel coordinates, the valid range is 0 to (width or height) - 1, and the pixel coordinate of width or height is past the edge of the window.

Fixes https://github.com/libsdl-org/SDL/issues/2913
This commit is contained in:
Sam Lantinga
2023-11-05 00:03:23 -07:00
parent ff3c20a799
commit 9302d7732d
6 changed files with 72 additions and 16 deletions

View File

@@ -759,8 +759,16 @@ static EM_BOOL Emscripten_HandleTouch(int eventType, const EmscriptenTouchEvent
}
id = touchEvent->touches[i].identifier;
x = touchEvent->touches[i].targetX / client_w;
y = touchEvent->touches[i].targetY / client_h;
if (client_w <= 1) {
x = 0.5f;
} else {
x = touchEvent->touches[i].targetX / (client_w - 1);
}
if (client_h <= 1) {
y = 0.5f;
} else {
y = touchEvent->touches[i].targetY / (client_h - 1);
}
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) {
SDL_SendTouch(0, deviceId, id, window_data->window, SDL_TRUE, x, y, 1.0f);