mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2025-01-03 07:29:37 +01:00
Fixed divide by zero with a 1x1 sized window
This commit is contained in:
parent
bef0fec121
commit
5bed4ca92e
@ -74,6 +74,7 @@ xinput2_version_atleast(const int version, const int wantmajor, const int wantmi
|
|||||||
return ( version >= ((wantmajor * 1000) + wantminor) );
|
return ( version >= ((wantmajor * 1000) + wantminor) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
|
||||||
static void
|
static void
|
||||||
xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
|
xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
|
||||||
double in_x, double in_y, float *out_x, float *out_y)
|
double in_x, double in_y, float *out_x, float *out_y)
|
||||||
@ -82,8 +83,16 @@ xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
|
|||||||
for (i = 0; i < videodata->numwindows; i++) {
|
for (i = 0; i < videodata->numwindows; i++) {
|
||||||
SDL_WindowData *d = videodata->windowlist[i];
|
SDL_WindowData *d = videodata->windowlist[i];
|
||||||
if (d->xwindow == window) {
|
if (d->xwindow == window) {
|
||||||
*out_x = in_x / (d->window->w-1);
|
if (d->window->w == 1) {
|
||||||
*out_y = in_y / (d->window->h-1);
|
*out_x = 0.5f;
|
||||||
|
} else {
|
||||||
|
*out_x = in_x / (d->window->w - 1);
|
||||||
|
}
|
||||||
|
if (d->window->h == 1) {
|
||||||
|
*out_y = 0.5f;
|
||||||
|
} else {
|
||||||
|
*out_y = in_y / (d->window->h - 1);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,6 +100,8 @@ xinput2_normalize_touch_coordinates(SDL_VideoData *videodata, Window window,
|
|||||||
*out_x = in_x;
|
*out_x = in_x;
|
||||||
*out_y = in_y;
|
*out_y = in_y;
|
||||||
}
|
}
|
||||||
|
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
|
#endif /* SDL_VIDEO_DRIVER_X11_XINPUT2 */
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -192,8 +203,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
|
|||||||
float x, y;
|
float x, y;
|
||||||
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
||||||
xev->event_x, xev->event_y, &x, &y);
|
xev->event_x, xev->event_y, &x, &y);
|
||||||
SDL_SendTouch(xev->sourceid,xev->detail,
|
SDL_SendTouch(xev->sourceid,xev->detail, SDL_TRUE, x, y, 1.0);
|
||||||
SDL_TRUE, x, y, 1.0);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -202,8 +212,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
|
|||||||
float x, y;
|
float x, y;
|
||||||
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
||||||
xev->event_x, xev->event_y, &x, &y);
|
xev->event_x, xev->event_y, &x, &y);
|
||||||
SDL_SendTouch(xev->sourceid,xev->detail,
|
SDL_SendTouch(xev->sourceid,xev->detail, SDL_FALSE, x, y, 1.0);
|
||||||
SDL_FALSE, x, y, 1.0);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -212,8 +221,7 @@ X11_HandleXinput2Event(SDL_VideoData *videodata,XGenericEventCookie *cookie)
|
|||||||
float x, y;
|
float x, y;
|
||||||
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
xinput2_normalize_touch_coordinates(videodata, xev->event,
|
||||||
xev->event_x, xev->event_y, &x, &y);
|
xev->event_x, xev->event_y, &x, &y);
|
||||||
SDL_SendTouchMotion(xev->sourceid,xev->detail,
|
SDL_SendTouchMotion(xev->sourceid,xev->detail, x, y, 1.0);
|
||||||
x, y, 1.0);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user