mirror of
https://github.com/libretro/RetroArch
synced 2025-01-31 06:32:48 +00:00
convert abs mouse from screen to viewport coordinates; fix relative m… (#13258)
* convert abs mouse from screen to viewport coordinates; fix relative mouse code to work in screen mode * C89 compatibility * revert accidental include
This commit is contained in:
parent
698ab4729a
commit
e5e6f343ac
@ -385,19 +385,29 @@ static int16_t udev_mouse_get_pointer_x(const udev_input_mouse_t *mouse, bool sc
|
||||
|
||||
if (mouse->abs) /* mouse coords are absolute */
|
||||
{
|
||||
/* mouse coordinates are relative to the screen; convert them
|
||||
* to be relative to the viewport */
|
||||
double scaled_x;
|
||||
src_min = mouse->x_min;
|
||||
src_width = mouse->x_max - mouse->x_min + 1;
|
||||
scaled_x = vp.full_width * (mouse->x_abs - src_min) / src_width;
|
||||
x = -32767.0 + 65535.0 / vp.width * (scaled_x - vp.x);
|
||||
}
|
||||
else /* mouse coords are viewport relative */
|
||||
{
|
||||
src_min = vp.x;
|
||||
if (screen)
|
||||
if (screen)
|
||||
{
|
||||
src_min = 0.0;
|
||||
src_width = vp.full_width;
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
src_min = vp.x;
|
||||
src_width = vp.width;
|
||||
}
|
||||
x = -32767.0 + 65535.0 / src_width * (mouse->x_abs - src_min);
|
||||
}
|
||||
|
||||
x = -32767.0 + 65535.0 / src_width * (mouse->x_abs - src_min);
|
||||
x += (x < 0 ? -0.5 : 0.5);
|
||||
|
||||
if (x < -0x7fff)
|
||||
@ -420,16 +430,26 @@ static int16_t udev_mouse_get_pointer_y(const udev_input_mouse_t *mouse, bool sc
|
||||
|
||||
if (mouse->abs) /* mouse coords are absolute */
|
||||
{
|
||||
double scaled_y;
|
||||
/* mouse coordinates are relative to the screen; convert them
|
||||
* to be relative to the viewport */
|
||||
src_min = mouse->y_min;
|
||||
src_height = mouse->y_max - mouse->y_min + 1;
|
||||
scaled_y = vp.full_height * (mouse->y_abs - src_min) / src_height;
|
||||
y = -32767.0 + 65535.0 / vp.height * (scaled_y - vp.y);
|
||||
}
|
||||
else /* mouse coords are viewport relative */
|
||||
{
|
||||
src_min = vp.y;
|
||||
if (screen)
|
||||
{
|
||||
src_min = 0.0;
|
||||
src_height = vp.full_height;
|
||||
}
|
||||
else
|
||||
{
|
||||
src_min = vp.y;
|
||||
src_height = vp.height;
|
||||
}
|
||||
}
|
||||
|
||||
y = -32767.0 + 65535.0 / src_height * (mouse->y_abs - src_min);
|
||||
|
Loading…
x
Reference in New Issue
Block a user