Skip to content

Commit

Permalink
Pointer sanitization - sdl
Browse files Browse the repository at this point in the history
Adapt the sanitized pointer handling, discussed at libretro#17196 :

sdl driver specific changes:

    lightgun position handling fixed
    lightgun buttons mapped in a fixed way for now
  • Loading branch information
zoltanvb committed Dec 25, 2024
1 parent 700b136 commit 71fffce
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions input/drivers/sdl_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,39 @@ static int16_t sdl_input_state(
break;
case RETRO_DEVICE_KEYBOARD:
return (id && id < RETROK_LAST) && sdl_key_pressed(id);
/* TODO: update to match other input drivers (aiming state, button binds) */
/* TODO: update button binds to match other input drivers */
case RETRO_DEVICE_LIGHTGUN:

struct video_viewport vp = {0};
int16_t res_x = 0;
int16_t res_y = 0;
int16_t res_screen_x = 0;
int16_t res_screen_y = 0;

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))

switch (id)
{
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
return res_x;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
return res_y;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return input_driver_pointer_is_offscreen(res_x, res_y);
case RETRO_DEVICE_ID_LIGHTGUN_X:
return sdl->mouse_x;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return sdl->mouse_y;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return sdl->mouse_l;
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
return sdl->mouse_m;
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
return sdl->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_START:
return sdl->mouse_m && sdl->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return sdl->mouse_m && sdl->mouse_l;
return sdl->mouse_r;
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
return sdl->mouse_l && sdl->mouse_r;
}
break;
}
Expand Down

0 comments on commit 71fffce

Please sign in to comment.