mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-13 21:35:59 +00:00
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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user