mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Move input_translate_coord_viewport to video_driver.c
This commit is contained in:
parent
e2c4c25bf5
commit
a12d0d082d
2
deps/SPIRV-Cross
vendored
2
deps/SPIRV-Cross
vendored
@ -1 +1 @@
|
||||
Subproject commit 5c24d99ff22a25ef38e9e39985f80cf57a1e7418
|
||||
Subproject commit cc207e32c8668bfe5a5cc514394e7df8f020ecf6
|
2
deps/glslang/glslang
vendored
2
deps/glslang/glslang
vendored
@ -1 +1 @@
|
||||
Subproject commit a4a4d5e22c375d37bd286106904ef819eafff29b
|
||||
Subproject commit 2eb0986f10392a4c2365869b17b59ad79226c440
|
@ -2172,3 +2172,57 @@ bool video_driver_texture_unload(uintptr_t *id)
|
||||
*id = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* video_driver_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
bool video_driver_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;
|
||||
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;
|
||||
if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
|
||||
scaled_screen_x = -0x8000; /* OOB */
|
||||
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
|
||||
scaled_screen_y = -0x8000; /* OOB */
|
||||
|
||||
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;
|
||||
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
|
||||
scaled_x = -0x8000; /* OOB */
|
||||
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
|
||||
scaled_y = -0x8000; /* OOB */
|
||||
|
||||
*res_x = scaled_x;
|
||||
*res_y = scaled_y;
|
||||
*res_screen_x = scaled_screen_x;
|
||||
*res_screen_y = scaled_screen_y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -472,6 +472,30 @@ const video_poke_interface_t *video_driver_get_poke(void);
|
||||
void video_driver_frame(const void *data, unsigned width,
|
||||
unsigned height, size_t pitch);
|
||||
|
||||
#define video_driver_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) ? video_driver_translate_coord_viewport(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y) : false)
|
||||
|
||||
/**
|
||||
* video_driver_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
bool video_driver_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);
|
||||
|
||||
uintptr_t video_driver_display_get(void);
|
||||
|
||||
enum rarch_display_type video_driver_display_type_get(void);
|
||||
|
@ -533,7 +533,7 @@ static INLINE int android_input_poll_event_type_motion(
|
||||
float x = AMotionEvent_getX(event, motion_ptr);
|
||||
float y = AMotionEvent_getY(event, motion_ptr);
|
||||
|
||||
input_translate_coord_viewport_wrap(
|
||||
video_driver_translate_coord_viewport_wrap(
|
||||
&vp,
|
||||
x, y,
|
||||
&android_data->pointer[motion_ptr].x,
|
||||
|
@ -161,7 +161,7 @@ static void cocoa_input_poll(void *data)
|
||||
apple->touches[i].screen_x *= backing_scale_factor;
|
||||
apple->touches[i].screen_y *= backing_scale_factor;
|
||||
#endif
|
||||
input_translate_coord_viewport_wrap(
|
||||
video_driver_translate_coord_viewport_wrap(
|
||||
&vp,
|
||||
apple->touches[i].screen_x,
|
||||
apple->touches[i].screen_y,
|
||||
|
@ -427,7 +427,7 @@ static int16_t dinput_pointer_state(struct dinput_input *di,
|
||||
pointer_down = true;
|
||||
}
|
||||
|
||||
if (!(input_translate_coord_viewport_wrap(&vp, x, y,
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp, x, y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
|
@ -427,7 +427,8 @@ static void qnx_process_touch_event(
|
||||
|
||||
qnx->pointer[i].contact_id = contact_id;
|
||||
|
||||
input_translate_coord_viewport_wrap(&vp,
|
||||
video_driver_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);
|
||||
@ -506,7 +507,7 @@ static void qnx_process_touch_event(
|
||||
pos[1] = gl->full_y;
|
||||
#endif
|
||||
|
||||
input_translate_coord_viewport_wrap(&vp,
|
||||
video_driver_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);
|
||||
|
@ -176,7 +176,7 @@ static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
|
||||
struct video_viewport vp = {0};
|
||||
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
|
||||
|
||||
if (!(input_translate_coord_viewport_wrap(&vp, sdl->mouse_abs_x, sdl->mouse_abs_y,
|
||||
if (!(video_driver_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;
|
||||
|
||||
|
@ -463,7 +463,7 @@ static int16_t udev_pointer_state(udev_input_t *udev,
|
||||
struct video_viewport vp = {0};
|
||||
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
|
||||
|
||||
if (!(input_translate_coord_viewport_wrap(&vp, udev->mouse_x, udev->mouse_y,
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp, udev->mouse_x, udev->mouse_y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
|
@ -168,7 +168,7 @@ static int16_t x_pointer_state(x11_input_t *x11,
|
||||
struct video_viewport vp = {0};
|
||||
int16_t res_x = 0, res_y = 0, res_screen_x = 0, res_screen_y = 0;
|
||||
|
||||
if (!(input_translate_coord_viewport_wrap(&vp, x11->mouse_x, x11->mouse_y,
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp, x11->mouse_x, x11->mouse_y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
|
@ -256,60 +256,6 @@ float input_sensor_get_input(unsigned port, unsigned id)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_translate_coord_viewport:
|
||||
* @mouse_x : Pointer X coordinate.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
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;
|
||||
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;
|
||||
if (scaled_screen_x < -0x7fff || scaled_screen_x > 0x7fff)
|
||||
scaled_screen_x = -0x8000; /* OOB */
|
||||
if (scaled_screen_y < -0x7fff || scaled_screen_y > 0x7fff)
|
||||
scaled_screen_y = -0x8000; /* OOB */
|
||||
|
||||
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;
|
||||
if (scaled_x < -0x7fff || scaled_x > 0x7fff)
|
||||
scaled_x = -0x8000; /* OOB */
|
||||
if (scaled_y < -0x7fff || scaled_y > 0x7fff)
|
||||
scaled_y = -0x8000; /* OOB */
|
||||
|
||||
*res_x = scaled_x;
|
||||
*res_y = scaled_y;
|
||||
*res_screen_x = scaled_screen_x;
|
||||
*res_screen_y = scaled_screen_y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static const struct retro_keybind *libretro_input_binds[MAX_USERS];
|
||||
|
||||
/**
|
||||
|
@ -160,30 +160,6 @@ 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.
|
||||
* @mouse_y : Pointer Y coordinate.
|
||||
* @res_x : Scaled X coordinate.
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
**/
|
||||
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);
|
||||
|
||||
#define inherit_joyaxis(binds) (((binds)[x_plus].joyaxis == (binds)[x_minus].joyaxis) || ( (binds)[y_plus].joyaxis == (binds)[y_minus].joyaxis))
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user