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

@@ -1419,6 +1419,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
for (i = 0; i < num_inputs; ++i) {
PTOUCHINPUT input = &inputs[i];
const int w = (rect.right - rect.left);
const int h = (rect.right - rect.left);
const SDL_TouchID touchId = (SDL_TouchID)((size_t)input->hSource);
@@ -1430,8 +1432,16 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
/* Get the normalized coordinates for the window */
x = (float)(input->x - rect.left) / (rect.right - rect.left);
y = (float)(input->y - rect.top) / (rect.bottom - rect.top);
if (w <= 1) {
x = 0.5f;
} else {
x = (float)(input->x - rect.left) / (w - 1);
}
if (h <= 1) {
y = 0.5f;
} else {
y = (float)(input->y - rect.top) / (h - 1);
}
/* FIXME: Should we use the input->dwTime field for the tick source of the timestamp? */
if (input->dwFlags & TOUCHEVENTF_DOWN) {