Simplify input_translate_coord_viewport

This commit is contained in:
twinaphex 2016-12-05 05:18:36 +01:00
parent 4d23ba91fc
commit 2ba311274e
9 changed files with 73 additions and 68 deletions

View File

@ -525,15 +525,17 @@ static INLINE int android_input_poll_event_type_motion(
}
else
{
float x, y;
int pointer_max = MIN(AMotionEvent_getPointerCount(event), MAX_TOUCH);
for (motion_ptr = 0; motion_ptr < pointer_max; motion_ptr++)
{
x = AMotionEvent_getX(event, motion_ptr);
y = AMotionEvent_getY(event, motion_ptr);
struct video_viewport vp = {0};
float x = AMotionEvent_getX(event, motion_ptr);
float y = AMotionEvent_getY(event, motion_ptr);
input_translate_coord_viewport(x, y,
input_translate_coord_viewport_wrap(
&vp,
x, y,
&android_data->pointer[motion_ptr].x,
&android_data->pointer[motion_ptr].y,
&android_data->pointer[motion_ptr].full_x,

View File

@ -156,11 +156,13 @@ static void cocoa_input_poll(void *data)
for (i = 0; i < apple->touch_count; i++)
{
struct video_viewport vp = {0};
#ifndef IOS
apple->touches[i].screen_x *= backing_scale_factor;
apple->touches[i].screen_y *= backing_scale_factor;
#endif
input_translate_coord_viewport(
input_translate_coord_viewport_wrap(
&vp,
apple->touches[i].screen_x,
apple->touches[i].screen_y,
&apple->touches[i].fixed_x,

View File

@ -401,10 +401,11 @@ static int16_t dinput_mouse_state_screen(struct dinput_input *di, unsigned id)
static int16_t dinput_pointer_state(struct dinput_input *di,
unsigned idx, unsigned id, bool screen)
{
bool pointer_down, valid, inside;
bool pointer_down, inside;
int x, y;
struct video_viewport vp = {0};
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
unsigned num = 0;
unsigned num = 0;
struct pointer_status *check_pos = di->pointer_head.next;
while (check_pos && num < idx)
@ -426,10 +427,8 @@ static int16_t dinput_pointer_state(struct dinput_input *di,
pointer_down = true;
}
valid = input_translate_coord_viewport(x, y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
if (!(input_translate_coord_viewport_wrap(&vp, x, y,
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
if (screen)

View File

@ -423,8 +423,12 @@ static void qnx_process_touch_event(
{
if(qnx->pointer[i].contact_id == -1)
{
struct video_viewport vp = {0};
qnx->pointer[i].contact_id = contact_id;
input_translate_coord_viewport(pos[0], pos[1],
input_translate_coord_viewport_wrap(&vp,
pos[0], pos[1],
&qnx->pointer[i].x, &qnx->pointer[i].y,
&qnx->pointer[i].full_x, &qnx->pointer[i].full_y);
@ -482,6 +486,7 @@ static void qnx_process_touch_event(
{
if(qnx->pointer[i].contact_id == contact_id)
{
struct video_viewport vp = {0};
#if 0
gl_t *gl = (gl_t*)video_driver_get_ptr(false);
@ -501,7 +506,8 @@ static void qnx_process_touch_event(
pos[1] = gl->full_y;
#endif
input_translate_coord_viewport(pos[0], pos[1],
input_translate_coord_viewport_wrap(&vp,
pos[0], pos[1],
&qnx->pointer[i].x, &qnx->pointer[i].y,
&qnx->pointer[i].full_x, &qnx->pointer[i].full_y);
#if 0

View File

@ -172,16 +172,12 @@ static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id)
static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
unsigned idx, unsigned id, bool screen)
{
bool valid, inside;
bool inside = false;
struct video_viewport vp = {0};
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
if (idx != 0)
return 0;
valid = input_translate_coord_viewport(sdl->mouse_abs_x, sdl->mouse_abs_y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
if (!(input_translate_coord_viewport_wrap(&vp, sdl->mouse_abs_x, sdl->mouse_abs_y,
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
if (screen)
@ -247,7 +243,9 @@ static int16_t sdl_input_state(void *data_, const struct retro_keybind **binds,
return sdl_mouse_device_state(data, id);
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
return sdl_pointer_device_state(data, idx, id, device == RARCH_DEVICE_POINTER_SCREEN);
if (idx == 0)
return sdl_pointer_device_state(data, idx, id, device == RARCH_DEVICE_POINTER_SCREEN);
break;
case RETRO_DEVICE_KEYBOARD:
return sdl_keyboard_device_state(data, id);
case RETRO_DEVICE_LIGHTGUN:

View File

@ -459,12 +459,12 @@ static int16_t udev_analog_pressed(const struct retro_keybind *binds, unsigned i
static int16_t udev_pointer_state(udev_input_t *udev,
unsigned idx, unsigned id, bool screen)
{
bool inside = false;
bool inside = false;
struct video_viewport vp = {0};
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
bool valid = input_translate_coord_viewport(udev->mouse_x, udev->mouse_y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
if (!(input_translate_coord_viewport_wrap(&vp, udev->mouse_x, udev->mouse_y,
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
if (screen)
@ -520,11 +520,10 @@ static int16_t udev_input_state(void *data, const struct retro_keybind **binds,
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
if (idx != 0)
return 0;
return udev_pointer_state(udev, idx, id,
device == RARCH_DEVICE_POINTER_SCREEN);
if (idx == 0)
return udev_pointer_state(udev, idx, id,
device == RARCH_DEVICE_POINTER_SCREEN);
break;
case RETRO_DEVICE_LIGHTGUN:
return udev_lightgun_state(udev, id);
}

View File

@ -164,16 +164,12 @@ static int16_t x_mouse_state_screen(x11_input_t *x11, unsigned id)
static int16_t x_pointer_state(x11_input_t *x11,
unsigned idx, unsigned id, bool screen)
{
bool valid, inside;
bool inside;
struct video_viewport vp = {0};
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
if (idx != 0)
return 0;
valid = input_translate_coord_viewport(x11->mouse_x, x11->mouse_y,
&res_x, &res_y, &res_screen_x, &res_screen_y);
if (!valid)
if (!(input_translate_coord_viewport_wrap(&vp, x11->mouse_x, x11->mouse_y,
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
if (screen)
@ -254,9 +250,10 @@ static int16_t x_input_state(void *data,
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
return x_pointer_state(x11, idx, id,
device == RARCH_DEVICE_POINTER_SCREEN);
if (idx == 0)
return x_pointer_state(x11, idx, id,
device == RARCH_DEVICE_POINTER_SCREEN);
break;
case RETRO_DEVICE_LIGHTGUN:
return x_lightgun_state(x11, id);
}

View File

@ -267,44 +267,41 @@ float input_sensor_get_input(unsigned port, unsigned id)
* Returns: true (1) if successful, false if video driver doesn't support
* viewport info.
**/
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
int16_t *res_screen_y)
bool input_translate_coord_viewport(
void *data,
int mouse_x, int mouse_y,
int16_t *res_x, int16_t *res_y,
int16_t *res_screen_x, int16_t *res_screen_y)
{
int scaled_screen_x, scaled_screen_y, scaled_x, scaled_y;
int norm_full_vp_width, norm_full_vp_height;
struct video_viewport vp = {0};
if (!video_driver_get_viewport_info(&vp))
return false;
norm_full_vp_width = (int)vp.full_width;
norm_full_vp_height = (int)vp.full_height;
struct video_viewport *vp = (struct video_viewport*)data;
int norm_full_vp_width = (int)vp->full_width;
int norm_full_vp_height = (int)vp->full_height;
if (norm_full_vp_width <= 0 || norm_full_vp_height <= 0)
return false;
scaled_screen_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
scaled_screen_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
scaled_screen_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
scaled_screen_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
scaled_screen_x = -0x8000; /* OOB */
scaled_screen_x = -0x8000; /* OOB */
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
scaled_screen_y = -0x8000; /* OOB */
scaled_screen_y = -0x8000; /* OOB */
mouse_x -= vp.x;
mouse_y -= vp.y;
mouse_x -= vp->x;
mouse_y -= vp->y;
scaled_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
scaled_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
scaled_x = (2 * mouse_x * 0x7fff) / norm_full_vp_width - 0x7fff;
scaled_y = (2 * mouse_y * 0x7fff) / norm_full_vp_height - 0x7fff;
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
scaled_x = -0x8000; /* OOB */
scaled_x = -0x8000; /* OOB */
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
scaled_y = -0x8000; /* OOB */
scaled_y = -0x8000; /* OOB */
*res_x = scaled_x;
*res_y = scaled_y;
*res_screen_x = scaled_screen_x;
*res_screen_y = scaled_screen_y;
*res_x = scaled_x;
*res_y = scaled_y;
*res_screen_x = scaled_screen_x;
*res_screen_y = scaled_screen_y;
return true;
}

View File

@ -160,6 +160,9 @@ bool input_sensor_set_state(unsigned port,
float input_sensor_get_input(unsigned port, unsigned id);
#define input_translate_coord_viewport_wrap(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y) \
(video_driver_get_viewport_info(vp) ? input_translate_coord_viewport(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y) : false)
/**
* input_translate_coord_viewport:
* @mouse_x : Pointer X coordinate.
@ -175,7 +178,9 @@ float input_sensor_get_input(unsigned port, unsigned id);
* Returns: true (1) if successful, false if video driver doesn't support
* viewport info.
**/
bool input_translate_coord_viewport(int mouse_x, int mouse_y,
bool input_translate_coord_viewport(
void *data,
int mouse_x, int mouse_y,
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
int16_t *res_screen_y);