Merge pull request #5806 from hiddenasbestos/input_driver_winraw_2

winraw input driver update for new lightgun/mouse changes
This commit is contained in:
Twinaphex 2017-11-27 17:01:52 +01:00 committed by GitHub
commit d4d935ce28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,6 +241,65 @@ static bool winraw_set_mouse_input(HWND window, bool grab)
return true;
}
static int16_t winraw_lightgun_aiming_state(winraw_input_t *wr,
unsigned port, unsigned id)
{
const int edge_detect = 32700;
struct video_viewport vp;
bool inside = false;
unsigned i;
settings_t *settings = config_get_ptr();
winraw_mouse_t *mouse = NULL;
int16_t res_x = 0;
int16_t res_y = 0;
int16_t res_screen_x = 0;
int16_t res_screen_y = 0;
if (port >= MAX_USERS)
return 0;
for (i = 0; i < g_mouse_cnt; ++i)
{
if (i == settings->uints.input_mouse_index[port])
{
mouse = &wr->mice[i];
break;
}
}
if (!mouse)
return 0;
vp.x = 0;
vp.y = 0;
vp.width = 0;
vp.height = 0;
vp.full_width = 0;
vp.full_height = 0;
if ( !( video_driver_translate_coord_viewport_wrap(
&vp, mouse->x, mouse->y, &res_x, &res_y, &res_screen_x, &res_screen_y ) ) )
{
return 0;
}
inside = (res_x >= -edge_detect) && (res_y >= -edge_detect) && (res_x <= edge_detect) && (res_y <= edge_detect);
switch ( id )
{
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
return inside ? res_x : 0;
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
return inside ? res_y : 0;
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return !inside;
default:
break;
}
return 0;
}
static int16_t winraw_mouse_state(winraw_input_t *wr,
unsigned port, bool abs, unsigned id)
{
@ -288,6 +347,12 @@ static int16_t winraw_mouse_state(winraw_input_t *wr,
return 0;
}
static bool winraw_keyboard_pressed(winraw_input_t *wr, unsigned key)
{
unsigned k = rarch_keysym_lut[(enum retro_key)key];
return wr->keyboard.keys[k];
}
static bool winraw_mbutton_pressed(winraw_input_t *wr, unsigned port, unsigned key)
{
unsigned i;
@ -332,21 +397,24 @@ static bool winraw_mbutton_pressed(winraw_input_t *wr, unsigned port, unsigned k
return false;
}
static int16_t winraw_joypad_state(winraw_input_t *wr,
static bool winraw_is_pressed(winraw_input_t *wr,
rarch_joypad_info_t joypad_info,
const struct retro_keybind *binds,
unsigned port, unsigned id)
{
const struct retro_keybind *bind = &binds[id];
unsigned key = rarch_keysym_lut[(enum retro_key)bind->key];
if (!wr->kbd_mapp_block && (bind->key < RETROK_LAST) && wr->keyboard.keys[key])
return 1;
if (!wr->kbd_mapp_block && (bind->key < RETROK_LAST) && winraw_keyboard_pressed(wr, bind->key))
return true;
if (binds && binds[id].valid)
{
if (winraw_mbutton_pressed(wr, port, bind->mbutton))
return true;
if (input_joypad_pressed(wr->joypad, joypad_info, port, binds, id))
return true;
}
if (binds && binds[id].valid && winraw_mbutton_pressed(wr, port, bind->mbutton))
return 1;
return input_joypad_pressed(wr->joypad, joypad_info, port, binds, id);
return false;
}
static void winraw_init_mouse_xy_mapping()
@ -374,7 +442,7 @@ static void winraw_init_mouse_xy_mapping()
}
}
static int16_t winraw_lightgun_state(winraw_input_t *wr,
static int16_t winraw_deprecated_lightgun_state(winraw_input_t *wr,
unsigned port, unsigned id)
{
unsigned i;
@ -402,16 +470,6 @@ static int16_t winraw_lightgun_state(winraw_input_t *wr,
return mouse->dlt_x;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return mouse->dlt_y;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return mouse->btn_l ? 1 : 0;
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
return mouse->btn_m ? 1 : 0;
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
return mouse->btn_r ? 1 : 0;
case RETRO_DEVICE_ID_LIGHTGUN_START:
return (mouse->btn_m && mouse->btn_r) ? 1 : 0;
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return mouse->btn_m && mouse->btn_l ? 1 : 0;
}
return 0;
@ -644,26 +702,62 @@ static int16_t winraw_input_state(void *d,
switch (device)
{
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
unsigned key = rarch_keysym_lut[(enum retro_key)id];
return wr->keyboard.keys[key];
}
case RETRO_DEVICE_JOYPAD:
if (id < RARCH_BIND_LIST_END)
return winraw_is_pressed(wr, joypad_info, binds[port], port, id);
break;
case RETRO_DEVICE_KEYBOARD:
return (id < RETROK_LAST) && winraw_keyboard_pressed(wr, id);
case RETRO_DEVICE_MOUSE:
return winraw_mouse_state(wr, port, false, id);
case RARCH_DEVICE_MOUSE_SCREEN:
return winraw_mouse_state(wr, port, true, id);
case RETRO_DEVICE_JOYPAD:
return winraw_joypad_state(wr, joypad_info, binds[port], port, id);
case RETRO_DEVICE_ANALOG:
if (binds[port])
return input_joypad_analog(wr->joypad, joypad_info,
port, index, id, binds[port]);
break;
case RETRO_DEVICE_LIGHTGUN:
return winraw_lightgun_state(wr, port, id);
switch ( id )
{
/*aiming*/
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
return winraw_lightgun_aiming_state( wr, port, id );
/*buttons*/
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_TRIGGER);
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_RELOAD);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_A);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_B);
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_AUX_C);
case RETRO_DEVICE_ID_LIGHTGUN_START:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_START);
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_SELECT);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_UP);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_DOWN);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_LEFT);
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_DPAD_RIGHT);
/*deprecated*/
case RETRO_DEVICE_ID_LIGHTGUN_X:
case RETRO_DEVICE_ID_LIGHTGUN_Y:
return winraw_deprecated_lightgun_state(wr, port, id);
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
return winraw_is_pressed(wr, joypad_info, binds[port], port, RARCH_LIGHTGUN_START);
}
break;
}
return 0;