listen for mouse buttons/wheel when binding input

This commit is contained in:
David Walters 2017-11-26 15:42:47 +00:00
parent cdb5a656f2
commit c733f96a16
3 changed files with 82 additions and 2 deletions

View File

@ -1745,6 +1745,41 @@ bool input_joypad_hat_raw(const input_device_driver_t *drv,
return drv->button(port, HAT_MAP(hat, hat_dir));
}
/**
* input_mouse_button_raw:
* @port : Mouse number.
* @button : Identifier of key (libretro mouse constant).
*
* Checks if key (@button) was being pressed by user
* with mouse number @port.
*
* Returns: true (1) if key was pressed, otherwise
* false (0).
**/
bool input_mouse_button_raw(unsigned port, unsigned id)
{
int16_t res;
rarch_joypad_info_t joypad_info;
settings_t *settings = config_get_ptr();
/*ignore axes*/
if ( id == RETRO_DEVICE_ID_MOUSE_X || id == RETRO_DEVICE_ID_MOUSE_Y ) {
return false;
}
joypad_info.axis_threshold = input_driver_axis_threshold;
joypad_info.joy_idx = settings->uints.input_joypad_map[port];
joypad_info.auto_binds = input_autoconf_binds[joypad_info.joy_idx];
res = current_input->input_state(current_input_data,
joypad_info, libretro_input_binds, port, RETRO_DEVICE_MOUSE, 0, id);
if ( res ) {
return true;
}
return false;
}
/**
* input_conv_analog_id_to_bind_id:
* @idx : Analog key index.

View File

@ -608,7 +608,20 @@ bool input_joypad_hat_raw(const input_device_driver_t *driver,
unsigned joypad, unsigned hat_dir, unsigned hat);
/**
* input_joypad_name:
* input_mouse_button_raw:
* @port : Mouse number.
* @button : Identifier of key (libretro mouse constant).
*
* Checks if key (@button) was being pressed by user
* with mouse number @port.
*
* Returns: true (1) if key was pressed, otherwise
* false (0).
**/
bool input_mouse_button_raw(unsigned port, unsigned button);
/**
* input_joypad_name:
* @drv : Input device driver handle.
* @port : Joystick number.
*

View File

@ -30,9 +30,11 @@
#define MENU_MAX_BUTTONS 219
#define MENU_MAX_AXES 32
#define MENU_MAX_HATS 4
#define MENU_MAX_MBUTTONS 32 /*enough to cover largest libretro constant*/
struct menu_bind_state_port
{
bool mbuttons[MENU_MAX_MBUTTONS];
bool buttons[MENU_MAX_BUTTONS];
int16_t axes[MENU_MAX_AXES];
uint16_t hats[MENU_MAX_HATS];
@ -206,6 +208,7 @@ static void menu_input_key_bind_poll_bind_state(
unsigned port,
bool timed_out)
{
unsigned b;
rarch_joypad_info_t joypad_info;
const input_device_driver_t *joypad =
input_driver_get_joypad_driver();
@ -217,6 +220,11 @@ static void menu_input_key_bind_poll_bind_state(
memset(state->state, 0, sizeof(state->state));
/* poll mouse (on the relevant port) */
for (b = 0; b < MENU_MAX_MBUTTONS; b++)
state->state[port].mbuttons[b] =
input_mouse_button_raw(port, b);
joypad_info.joy_idx = 0;
joypad_info.auto_binds = NULL;
joypad_info.axis_threshold = 0.0f;
@ -277,6 +285,30 @@ static bool menu_input_key_bind_poll_find_trigger_pad(
const struct menu_bind_state_port *o = (const struct menu_bind_state_port*)
&state->state[p];
for (b = 0; b < MENU_MAX_MBUTTONS; b++)
{
bool iterate = n->mbuttons[b] && !o->mbuttons[b];
if (!iterate)
continue;
switch ( b )
{
case RETRO_DEVICE_ID_MOUSE_LEFT:
case RETRO_DEVICE_ID_MOUSE_RIGHT:
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
state->target->mbutton = b;
return true;
}
}
for (b = 0; b < MENU_MAX_BUTTONS; b++)
{
bool iterate = n->buttons[b] && !o->buttons[b];
@ -398,7 +430,7 @@ bool menu_input_key_bind_iterate(menu_input_ctx_bind_t *bind)
}
snprintf(bind->s, bind->len,
"[%s]\npress keyboard or joypad\n(timeout %d %s)",
"[%s]\npress keyboard, mouse or joypad\n(timeout %d %s)",
input_config_bind_map_get_desc(
menu_input_binds.begin - MENU_SETTINGS_BIND_BEGIN),
rarch_timer_get_timeout(&menu_input_binds.timer),