mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 18:32:44 +00:00
Introduce video_driver_translate_coord_viewport_wrap clamping variant. (#17196)
Add another version of the coordinate translation that will not report -0x8000 for offscreen values, but instead map the position to the respective edge (0x7fff/-0x7fff). Not yet in use. Udev driver updated to use the wrapper, as all other input drivers do.
This commit is contained in:
parent
8d640fc048
commit
30a656738b
@ -681,9 +681,12 @@ struct string_list* video_driver_get_gpu_api_devices(enum gfx_ctx_api api)
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
* @report_oob : Out-of-bounds report mode
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
* coordinates based on viewport info. If report_oob is true,
|
||||
* -0x8000 will be returned for the coordinate which is offscreen,
|
||||
* otherwise offscreen coordinate is clamped to 0x7fff / -0x7fff.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
@ -692,7 +695,8 @@ bool video_driver_translate_coord_viewport(
|
||||
struct video_viewport *vp,
|
||||
int mouse_x, int mouse_y,
|
||||
int16_t *res_x, int16_t *res_y,
|
||||
int16_t *res_screen_x, int16_t *res_screen_y)
|
||||
int16_t *res_screen_x, int16_t *res_screen_y,
|
||||
bool report_oob)
|
||||
{
|
||||
int norm_vp_width = (int)vp->width;
|
||||
int norm_vp_height = (int)vp->height;
|
||||
@ -722,12 +726,24 @@ bool video_driver_translate_coord_viewport(
|
||||
if (mouse_x >= 0 && mouse_x <= norm_vp_width)
|
||||
scaled_x = ((2 * mouse_x * 0x7fff)
|
||||
/ norm_vp_width) - 0x7fff;
|
||||
else
|
||||
scaled_x = -0x8000; /* OOB */
|
||||
else if (!report_oob)
|
||||
{
|
||||
if (mouse_x < 0)
|
||||
scaled_x = -0x7fff;
|
||||
else
|
||||
scaled_x = 0x7fff;
|
||||
}
|
||||
|
||||
if (mouse_y >= 0 && mouse_y <= norm_vp_height)
|
||||
scaled_y = ((2 * mouse_y * 0x7fff)
|
||||
/ norm_vp_height) - 0x7fff;
|
||||
else if (!report_oob)
|
||||
{
|
||||
if (mouse_y < 0)
|
||||
scaled_y = -0x7fff;
|
||||
else
|
||||
scaled_y = 0x7fff;
|
||||
}
|
||||
|
||||
*res_x = scaled_x;
|
||||
*res_y = scaled_y;
|
||||
|
@ -1071,7 +1071,10 @@ bool video_monitor_fps_statistics(double *refresh_rate,
|
||||
double *deviation, unsigned *sample_points);
|
||||
|
||||
#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_get_viewport_info(vp) ? video_driver_translate_coord_viewport(vp, mouse_x, mouse_y, res_x, res_y, res_screen_x, res_screen_y, true) : false)
|
||||
|
||||
#define video_driver_translate_coord_viewport_confined_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) : false)
|
||||
|
||||
/**
|
||||
* video_driver_translate_coord_viewport:
|
||||
@ -1081,9 +1084,12 @@ bool video_monitor_fps_statistics(double *refresh_rate,
|
||||
* @res_y : Scaled Y coordinate.
|
||||
* @res_screen_x : Scaled screen X coordinate.
|
||||
* @res_screen_y : Scaled screen Y coordinate.
|
||||
* @report_oob : Out-of-bounds report mode
|
||||
*
|
||||
* Translates pointer [X,Y] coordinates into scaled screen
|
||||
* coordinates based on viewport info.
|
||||
* coordinates based on viewport info. If report_oob is true,
|
||||
* -0x8000 will be returned for the coordinate which is offscreen,
|
||||
* otherwise offscreen coordinate is clamped to 0x7fff / -0x7fff.
|
||||
*
|
||||
* Returns: true (1) if successful, false if video driver doesn't support
|
||||
* viewport info.
|
||||
@ -1092,7 +1098,7 @@ bool video_driver_translate_coord_viewport(
|
||||
struct video_viewport *vp,
|
||||
int mouse_x, int mouse_y,
|
||||
int16_t *res_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y);
|
||||
int16_t *res_screen_y, bool report_oob);
|
||||
|
||||
uintptr_t video_driver_display_userdata_get(void);
|
||||
|
||||
|
@ -1900,7 +1900,7 @@ static bool udev_translate_touch_pos(
|
||||
*pointer_ma_pos_y = ma_pos_y;
|
||||
|
||||
/* Main panel -> Screen and Viewport */
|
||||
return video_driver_translate_coord_viewport(
|
||||
return video_driver_translate_coord_viewport_wrap(
|
||||
target_vp,
|
||||
*pointer_ma_pos_x,
|
||||
*pointer_ma_pos_y,
|
||||
@ -2571,7 +2571,7 @@ static void udev_report_touch(udev_input_t *udev, udev_input_device_t *dev)
|
||||
touch->mouse_pos_y = (int32_t) touch->touchpad_pos_y;
|
||||
|
||||
/* Translate the panel coordinates into normalized coordinates. */
|
||||
video_driver_translate_coord_viewport(
|
||||
video_driver_translate_coord_viewport_wrap(
|
||||
&vp, touch->mouse_pos_x, touch->mouse_pos_y,
|
||||
&touch->mouse_vp_pos_x, &touch->mouse_vp_pos_y,
|
||||
&touch->mouse_scr_pos_x, &touch->mouse_scr_pos_y
|
||||
@ -2875,7 +2875,7 @@ static void udev_input_touch_state_trackball(
|
||||
/* Get current viewport information */
|
||||
video_driver_get_viewport_info(&vp);
|
||||
/* Translate the raw coordinates into normalized coordinates. */
|
||||
video_driver_translate_coord_viewport(
|
||||
video_driver_translate_coord_viewport_wrap(
|
||||
&vp, touch->mouse_pos_x, touch->mouse_pos_y,
|
||||
&touch->mouse_vp_pos_x, &touch->mouse_vp_pos_y,
|
||||
&touch->mouse_scr_pos_x, &touch->mouse_scr_pos_y
|
||||
|
Loading…
x
Reference in New Issue
Block a user