mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-28 12:27:24 +02: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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user