2014-03-02 04:24:57 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2014-04-13 10:12:12 +00:00
|
|
|
*
|
2014-03-02 04:24:57 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2014-03-02 10:45:41 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "../../config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-02 04:24:57 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-01-11 05:24:44 +00:00
|
|
|
#include "menu_input.h"
|
2015-01-10 03:53:37 +00:00
|
|
|
#include "menu.h"
|
2014-09-15 05:52:08 +00:00
|
|
|
#include "menu_action.h"
|
2014-10-28 20:49:50 +00:00
|
|
|
#include "menu_shader.h"
|
2015-01-19 18:00:26 +00:00
|
|
|
#include "../cheats.h"
|
2014-10-28 18:54:23 +00:00
|
|
|
#include "../performance.h"
|
|
|
|
#include "../settings_data.h"
|
2015-01-10 19:10:45 +00:00
|
|
|
#include "../input/input_joypad.h"
|
2015-01-19 17:16:34 +00:00
|
|
|
#include "../input/input_remapping.h"
|
2015-01-19 07:37:11 +00:00
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_key_start_line(void *data, const char *label,
|
2014-12-06 14:47:25 +00:00
|
|
|
const char *label_setting, unsigned type, unsigned idx,
|
|
|
|
input_keyboard_line_complete_t cb)
|
2014-03-02 10:45:41 +00:00
|
|
|
{
|
2014-06-10 00:06:10 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)data;
|
2014-04-26 00:08:03 +00:00
|
|
|
|
2014-06-10 00:06:10 +00:00
|
|
|
if (!menu)
|
2014-04-26 00:08:03 +00:00
|
|
|
return;
|
|
|
|
|
2014-08-25 12:53:03 +00:00
|
|
|
menu->keyboard.display = true;
|
|
|
|
menu->keyboard.label = label;
|
|
|
|
menu->keyboard.label_setting = label_setting;
|
2014-12-06 14:47:25 +00:00
|
|
|
menu->keyboard.type = type;
|
|
|
|
menu->keyboard.idx = idx;
|
2014-08-25 12:53:03 +00:00
|
|
|
menu->keyboard.buffer = input_keyboard_start_line(menu, cb);
|
2014-03-02 10:45:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
static void menu_input_key_end_line(void *data)
|
2014-03-02 10:45:41 +00:00
|
|
|
{
|
2014-06-10 00:06:10 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)data;
|
2014-04-26 00:08:03 +00:00
|
|
|
|
2014-06-10 00:06:10 +00:00
|
|
|
if (!menu)
|
2014-04-26 00:08:03 +00:00
|
|
|
return;
|
|
|
|
|
2014-08-25 12:53:03 +00:00
|
|
|
menu->keyboard.display = false;
|
|
|
|
menu->keyboard.label = NULL;
|
|
|
|
menu->keyboard.label_setting = NULL;
|
2014-08-20 14:26:34 +00:00
|
|
|
|
|
|
|
/* Avoid triggering states on pressing return. */
|
2014-09-29 12:55:35 +00:00
|
|
|
driver.flushing_input = true;
|
2014-03-02 10:45:41 +00:00
|
|
|
}
|
2014-03-02 04:24:57 +00:00
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
static void menu_input_search_callback(void *userdata, const char *str)
|
2014-03-02 04:24:57 +00:00
|
|
|
{
|
2014-10-20 17:18:18 +00:00
|
|
|
size_t idx;
|
2015-01-10 05:33:05 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)userdata;
|
2014-10-12 03:03:22 +00:00
|
|
|
|
2014-10-20 17:18:18 +00:00
|
|
|
if (str && *str && file_list_search(menu->menu_list->selection_buf, str, &idx))
|
2014-10-26 21:31:53 +00:00
|
|
|
menu_navigation_set(menu, idx, true);
|
2014-03-02 04:24:57 +00:00
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
menu_input_key_end_line(menu);
|
2014-03-02 10:45:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_st_uint_callback(void *userdata, const char *str)
|
2014-03-02 10:45:41 +00:00
|
|
|
{
|
2014-06-10 00:06:10 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)userdata;
|
2014-08-24 17:00:36 +00:00
|
|
|
rarch_setting_t *current_setting = NULL;
|
2014-03-02 10:45:41 +00:00
|
|
|
|
2014-10-08 22:50:35 +00:00
|
|
|
if (str && *str)
|
2014-08-24 17:00:36 +00:00
|
|
|
{
|
2014-09-03 03:10:34 +00:00
|
|
|
if ((current_setting = (rarch_setting_t*)
|
|
|
|
setting_data_find_setting(
|
2014-10-08 22:50:35 +00:00
|
|
|
menu->list_settings, menu->keyboard.label_setting)))
|
2014-08-24 17:00:36 +00:00
|
|
|
*current_setting->value.unsigned_integer = strtoul(str, NULL, 0);
|
|
|
|
}
|
2015-01-11 05:42:53 +00:00
|
|
|
menu_input_key_end_line(menu);
|
2014-03-02 10:45:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-19 07:37:11 +00:00
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_st_string_callback(void *userdata, const char *str)
|
2014-03-02 10:45:41 +00:00
|
|
|
{
|
2014-06-10 00:06:10 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)userdata;
|
2014-08-24 17:00:36 +00:00
|
|
|
rarch_setting_t *current_setting = NULL;
|
2014-08-01 05:00:32 +00:00
|
|
|
|
2014-10-08 22:50:35 +00:00
|
|
|
if (str && *str)
|
2014-08-01 05:00:32 +00:00
|
|
|
{
|
2014-09-03 03:10:34 +00:00
|
|
|
if ((current_setting = (rarch_setting_t*)
|
|
|
|
setting_data_find_setting(
|
2014-10-08 22:50:35 +00:00
|
|
|
menu->list_settings, menu->keyboard.label_setting)))
|
2014-09-15 05:52:08 +00:00
|
|
|
menu_action_setting_set_current_string(current_setting, str);
|
2014-09-05 23:34:05 +00:00
|
|
|
else
|
2014-10-28 20:49:50 +00:00
|
|
|
{
|
2015-01-05 00:25:42 +00:00
|
|
|
if (!strcmp(menu->keyboard.label_setting, "video_shader_preset_save_as"))
|
2014-10-28 20:49:50 +00:00
|
|
|
menu_shader_manager_save_preset(str, false);
|
2015-01-19 07:37:11 +00:00
|
|
|
else if (!strcmp(menu->keyboard.label_setting, "remap_file_save_as"))
|
2015-01-19 17:16:34 +00:00
|
|
|
input_remapping_save_file(str);
|
2015-01-19 18:00:26 +00:00
|
|
|
else if (!strcmp(menu->keyboard.label_setting, "cheat_file_save_as"))
|
|
|
|
cheat_manager_save(g_extern.cheat, str);
|
2014-10-28 20:49:50 +00:00
|
|
|
}
|
2014-08-01 05:00:32 +00:00
|
|
|
}
|
2015-01-11 05:42:53 +00:00
|
|
|
|
|
|
|
menu_input_key_end_line(menu);
|
2014-03-02 10:45:41 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_st_cheat_callback(void *userdata, const char *str)
|
2014-12-06 14:47:25 +00:00
|
|
|
{
|
|
|
|
menu_handle_t *menu = (menu_handle_t*)userdata;
|
2014-12-15 22:57:14 +00:00
|
|
|
cheat_manager_t *cheat = g_extern.cheat;
|
2014-12-06 14:47:25 +00:00
|
|
|
|
|
|
|
if (cheat && str && *str)
|
|
|
|
{
|
|
|
|
unsigned cheat_index = menu->keyboard.type - MENU_SETTINGS_CHEAT_BEGIN;
|
|
|
|
RARCH_LOG("cheat_index is: %d\n", cheat_index);
|
|
|
|
|
|
|
|
cheat->cheats[cheat_index].code = strdup(str);
|
|
|
|
cheat->cheats[cheat_index].state = true;
|
|
|
|
}
|
2015-01-11 05:42:53 +00:00
|
|
|
|
|
|
|
menu_input_key_end_line(menu);
|
2014-12-06 14:47:25 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_key_event(bool down, unsigned keycode,
|
2014-10-11 03:45:18 +00:00
|
|
|
uint32_t character, uint16_t mod)
|
2014-03-02 04:24:57 +00:00
|
|
|
{
|
2014-05-31 20:56:33 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 18:23:20 +00:00
|
|
|
return;
|
|
|
|
|
2014-03-02 04:24:57 +00:00
|
|
|
(void)down;
|
|
|
|
(void)keycode;
|
|
|
|
(void)mod;
|
|
|
|
|
|
|
|
if (character == '/')
|
|
|
|
{
|
2014-05-31 20:56:33 +00:00
|
|
|
driver.menu->keyboard.display = true;
|
|
|
|
driver.menu->keyboard.label = "Search: ";
|
2014-09-03 03:10:34 +00:00
|
|
|
driver.menu->keyboard.buffer =
|
2015-01-11 05:42:53 +00:00
|
|
|
input_keyboard_start_line(driver.menu, menu_input_search_callback);
|
2014-03-02 04:24:57 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-02 10:45:41 +00:00
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_poll_bind_state(struct menu_bind_state *state)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2014-08-20 14:26:34 +00:00
|
|
|
unsigned i, b, a, h;
|
|
|
|
const rarch_joypad_driver_t *joypad = NULL;
|
|
|
|
|
2014-06-08 17:48:38 +00:00
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(state->state, 0, sizeof(state->state));
|
2014-08-20 14:26:34 +00:00
|
|
|
state->skip = driver.input->input_state(driver.input_data, NULL, 0,
|
|
|
|
RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN);
|
2014-06-08 17:48:38 +00:00
|
|
|
|
|
|
|
if (driver.input && driver.input_data && driver.input->get_joypad_driver)
|
|
|
|
joypad = driver.input->get_joypad_driver(driver.input_data);
|
|
|
|
|
|
|
|
if (!joypad)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot poll raw joypad state.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-27 13:08:21 +00:00
|
|
|
if (joypad->poll)
|
2014-08-02 22:44:07 +00:00
|
|
|
joypad->poll();
|
|
|
|
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2014-06-09 23:42:26 +00:00
|
|
|
for (b = 0; b < MENU_MAX_BUTTONS; b++)
|
2014-06-08 17:48:38 +00:00
|
|
|
state->state[i].buttons[b] = input_joypad_button_raw(joypad, i, b);
|
2015-01-11 05:34:32 +00:00
|
|
|
|
2014-06-09 23:42:26 +00:00
|
|
|
for (a = 0; a < MENU_MAX_AXES; a++)
|
2014-06-08 17:48:38 +00:00
|
|
|
state->state[i].axes[a] = input_joypad_axis_raw(joypad, i, a);
|
2015-01-11 05:34:32 +00:00
|
|
|
|
2014-06-09 23:42:26 +00:00
|
|
|
for (h = 0; h < MENU_MAX_HATS; h++)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2015-01-11 05:34:32 +00:00
|
|
|
if (input_joypad_hat_raw(joypad, i, HAT_UP_MASK, h))
|
|
|
|
state->state[i].hats[h] |= HAT_UP_MASK;
|
|
|
|
if (input_joypad_hat_raw(joypad, i, HAT_DOWN_MASK, h))
|
|
|
|
state->state[i].hats[h] |= HAT_DOWN_MASK;
|
|
|
|
if (input_joypad_hat_raw(joypad, i, HAT_LEFT_MASK, h))
|
|
|
|
state->state[i].hats[h] |= HAT_LEFT_MASK;
|
|
|
|
if (input_joypad_hat_raw(joypad, i, HAT_RIGHT_MASK, h))
|
|
|
|
state->state[i].hats[h] |= HAT_RIGHT_MASK;
|
2014-06-08 17:48:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
void menu_input_poll_bind_get_rested_axes(struct menu_bind_state *state)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
|
|
|
unsigned i, a;
|
|
|
|
const rarch_joypad_driver_t *joypad = NULL;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (driver.input && driver.input_data && driver.input->get_joypad_driver)
|
|
|
|
joypad = driver.input->get_joypad_driver(driver.input_data);
|
|
|
|
|
|
|
|
if (!joypad)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot poll raw joypad state.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2014-06-09 23:42:26 +00:00
|
|
|
for (a = 0; a < MENU_MAX_AXES; a++)
|
2014-09-03 03:10:34 +00:00
|
|
|
state->axis_state[i].rested_axes[a] =
|
|
|
|
input_joypad_axis_raw(joypad, i, a);
|
2014-06-08 17:48:38 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
static bool menu_input_poll_find_trigger_pad(struct menu_bind_state *state,
|
2014-09-03 03:10:34 +00:00
|
|
|
struct menu_bind_state *new_state, unsigned p)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
|
|
|
unsigned a, b, h;
|
2014-09-03 03:10:34 +00:00
|
|
|
const struct menu_bind_state_port *n = (const struct menu_bind_state_port*)
|
|
|
|
&new_state->state[p];
|
|
|
|
const struct menu_bind_state_port *o = (const struct menu_bind_state_port*)
|
|
|
|
&state->state[p];
|
2014-06-08 17:48:38 +00:00
|
|
|
|
2014-06-09 23:42:26 +00:00
|
|
|
for (b = 0; b < MENU_MAX_BUTTONS; b++)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2015-01-11 05:34:32 +00:00
|
|
|
bool iterate = n->buttons[b] && !o->buttons[b];
|
|
|
|
|
|
|
|
if (!iterate)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
state->target->joykey = b;
|
|
|
|
state->target->joyaxis = AXIS_NONE;
|
|
|
|
return true;
|
2014-06-08 17:48:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 14:26:34 +00:00
|
|
|
/* Axes are a bit tricky ... */
|
2014-06-09 23:42:26 +00:00
|
|
|
for (a = 0; a < MENU_MAX_AXES; a++)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2014-09-03 03:10:34 +00:00
|
|
|
int locked_distance = abs(n->axes[a] -
|
|
|
|
new_state->axis_state[p].locked_axes[a]);
|
|
|
|
int rested_distance = abs(n->axes[a] -
|
|
|
|
new_state->axis_state[p].rested_axes[a]);
|
2014-06-08 17:48:38 +00:00
|
|
|
|
|
|
|
if (abs(n->axes[a]) >= 20000 &&
|
|
|
|
locked_distance >= 20000 &&
|
2014-08-20 14:26:34 +00:00
|
|
|
rested_distance >= 20000)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2014-08-20 14:26:34 +00:00
|
|
|
/* Take care of case where axis rests on +/- 0x7fff
|
2014-09-02 14:03:17 +00:00
|
|
|
* (e.g. 360 controller on Linux) */
|
2014-06-08 17:48:38 +00:00
|
|
|
state->target->joyaxis = n->axes[a] > 0 ? AXIS_POS(a) : AXIS_NEG(a);
|
|
|
|
state->target->joykey = NO_BTN;
|
|
|
|
|
2014-08-20 14:26:34 +00:00
|
|
|
/* Lock the current axis */
|
2014-06-08 17:48:38 +00:00
|
|
|
new_state->axis_state[p].locked_axes[a] = n->axes[a] > 0 ? 0x7fff : -0x7fff;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-20 14:26:34 +00:00
|
|
|
if (locked_distance >= 20000) /* Unlock the axis. */
|
2014-06-08 17:48:38 +00:00
|
|
|
new_state->axis_state[p].locked_axes[a] = 0;
|
|
|
|
}
|
|
|
|
|
2014-06-09 23:42:26 +00:00
|
|
|
for (h = 0; h < MENU_MAX_HATS; h++)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
|
|
|
uint16_t trigged = n->hats[h] & (~o->hats[h]);
|
|
|
|
uint16_t sane_trigger = 0;
|
2014-08-20 14:26:34 +00:00
|
|
|
|
2014-06-08 17:48:38 +00:00
|
|
|
if (trigged & HAT_UP_MASK)
|
|
|
|
sane_trigger = HAT_UP_MASK;
|
|
|
|
else if (trigged & HAT_DOWN_MASK)
|
|
|
|
sane_trigger = HAT_DOWN_MASK;
|
|
|
|
else if (trigged & HAT_LEFT_MASK)
|
|
|
|
sane_trigger = HAT_LEFT_MASK;
|
|
|
|
else if (trigged & HAT_RIGHT_MASK)
|
|
|
|
sane_trigger = HAT_RIGHT_MASK;
|
|
|
|
|
|
|
|
if (sane_trigger)
|
|
|
|
{
|
|
|
|
state->target->joykey = HAT_MAP(h, sane_trigger);
|
|
|
|
state->target->joyaxis = AXIS_NONE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
bool menu_input_poll_find_trigger(struct menu_bind_state *state,
|
2014-08-20 14:26:34 +00:00
|
|
|
struct menu_bind_state *new_state)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
if (!state || !new_state)
|
|
|
|
return false;
|
|
|
|
|
2015-01-05 00:45:57 +00:00
|
|
|
for (i = 0; i < g_settings.input.max_users; i++)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2015-01-11 05:42:53 +00:00
|
|
|
if (!menu_input_poll_find_trigger_pad(state, new_state, i))
|
2015-01-11 05:34:32 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Update the joypad mapping automatically.
|
|
|
|
* More friendly that way. */
|
|
|
|
g_settings.input.joypad_map[state->user] = i;
|
|
|
|
return true;
|
2014-06-08 17:48:38 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-11 05:42:53 +00:00
|
|
|
bool menu_input_custom_bind_keyboard_cb(void *data, unsigned code)
|
2014-06-08 17:48:38 +00:00
|
|
|
{
|
2014-06-10 00:06:10 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)data;
|
2014-06-08 17:48:38 +00:00
|
|
|
|
2014-06-10 00:06:10 +00:00
|
|
|
if (!menu)
|
2014-06-08 17:48:38 +00:00
|
|
|
return false;
|
|
|
|
|
2014-06-10 00:06:10 +00:00
|
|
|
menu->binds.target->key = (enum retro_key)code;
|
|
|
|
menu->binds.begin++;
|
|
|
|
menu->binds.target++;
|
2014-08-20 14:26:34 +00:00
|
|
|
menu->binds.timeout_end = rarch_get_time_usec() +
|
|
|
|
MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
|
|
|
|
|
2014-06-10 00:06:10 +00:00
|
|
|
return menu->binds.begin <= menu->binds.last;
|
2014-06-08 17:48:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 04:43:42 +00:00
|
|
|
int menu_input_bind_iterate(void *data)
|
|
|
|
{
|
2015-01-07 19:42:36 +00:00
|
|
|
char msg[PATH_MAX_LENGTH];
|
2014-09-24 04:43:42 +00:00
|
|
|
menu_handle_t *menu = (menu_handle_t*)data;
|
|
|
|
struct menu_bind_state binds = menu->binds;
|
2014-09-24 06:29:47 +00:00
|
|
|
|
2014-09-24 04:43:42 +00:00
|
|
|
if (driver.video_data && driver.menu_ctx &&
|
|
|
|
driver.menu_ctx->render)
|
|
|
|
driver.menu_ctx->render();
|
|
|
|
|
|
|
|
snprintf(msg, sizeof(msg), "[%s]\npress joypad\n(RETURN to skip)",
|
|
|
|
input_config_bind_map[
|
|
|
|
driver.menu->binds.begin - MENU_SETTINGS_BIND_BEGIN].desc);
|
|
|
|
|
|
|
|
if (driver.video_data && driver.menu_ctx
|
|
|
|
&& driver.menu_ctx->render_messagebox)
|
|
|
|
driver.menu_ctx->render_messagebox(msg);
|
|
|
|
|
2014-09-29 12:55:35 +00:00
|
|
|
driver.block_input = true;
|
2015-01-11 05:42:53 +00:00
|
|
|
menu_input_poll_bind_state(&binds);
|
2014-09-24 04:43:42 +00:00
|
|
|
|
|
|
|
if ((binds.skip && !menu->binds.skip) ||
|
2015-01-11 05:42:53 +00:00
|
|
|
menu_input_poll_find_trigger(&menu->binds, &binds))
|
2014-09-24 04:43:42 +00:00
|
|
|
{
|
2014-09-29 12:55:35 +00:00
|
|
|
driver.block_input = false;
|
|
|
|
|
|
|
|
/* Avoid new binds triggering things right away. */
|
|
|
|
driver.flushing_input = true;
|
|
|
|
|
2014-09-24 04:43:42 +00:00
|
|
|
binds.begin++;
|
2015-01-23 08:14:07 +00:00
|
|
|
|
|
|
|
if (binds.begin > binds.last)
|
2014-09-24 04:43:42 +00:00
|
|
|
return 1;
|
2015-01-23 08:14:07 +00:00
|
|
|
|
|
|
|
binds.target++;
|
2014-09-24 04:43:42 +00:00
|
|
|
}
|
|
|
|
menu->binds = binds;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int menu_input_bind_iterate_keyboard(void *data)
|
|
|
|
{
|
2015-01-07 19:42:36 +00:00
|
|
|
char msg[PATH_MAX_LENGTH];
|
2014-09-24 04:43:42 +00:00
|
|
|
int64_t current;
|
|
|
|
int timeout = 0;
|
|
|
|
bool timed_out = false;
|
|
|
|
menu_handle_t *menu = (menu_handle_t*)data;
|
|
|
|
|
|
|
|
if (driver.video_data && driver.menu_ctx &&
|
|
|
|
driver.menu_ctx->render)
|
|
|
|
driver.menu_ctx->render();
|
|
|
|
|
|
|
|
current = rarch_get_time_usec();
|
|
|
|
timeout = (driver.menu->binds.timeout_end - current) / 1000000;
|
|
|
|
snprintf(msg, sizeof(msg), "[%s]\npress keyboard\n(timeout %d seconds)",
|
|
|
|
input_config_bind_map[
|
|
|
|
driver.menu->binds.begin - MENU_SETTINGS_BIND_BEGIN].desc,
|
|
|
|
timeout);
|
|
|
|
|
|
|
|
if (driver.video_data && driver.menu_ctx
|
|
|
|
&& driver.menu_ctx->render_messagebox)
|
|
|
|
driver.menu_ctx->render_messagebox(msg);
|
|
|
|
|
|
|
|
if (timeout <= 0)
|
|
|
|
{
|
|
|
|
menu->binds.begin++;
|
|
|
|
|
|
|
|
/* Could be unsafe, but whatever. */
|
|
|
|
menu->binds.target->key = RETROK_UNKNOWN;
|
|
|
|
|
|
|
|
menu->binds.target++;
|
|
|
|
menu->binds.timeout_end = rarch_get_time_usec() +
|
|
|
|
MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
|
|
|
|
timed_out = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* binds.begin is updated in keyboard_press callback. */
|
|
|
|
if (menu->binds.begin > menu->binds.last)
|
|
|
|
{
|
|
|
|
/* Avoid new binds triggering things right away. */
|
2014-09-29 12:55:35 +00:00
|
|
|
driver.flushing_input = true;
|
2014-09-24 04:43:42 +00:00
|
|
|
|
|
|
|
/* We won't be getting any key events, so just cancel early. */
|
|
|
|
if (timed_out)
|
|
|
|
input_keyboard_wait_keys_cancel();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-10 05:33:05 +00:00
|
|
|
|
2015-01-27 00:29:33 +00:00
|
|
|
unsigned menu_input_frame(retro_input_t input, retro_input_t trigger_input)
|
2015-01-10 05:33:05 +00:00
|
|
|
{
|
2015-01-27 00:29:33 +00:00
|
|
|
static bool initial_held = true;
|
|
|
|
static bool first_held = false;
|
|
|
|
static const retro_input_t input_repeat =
|
|
|
|
(1ULL << RETRO_DEVICE_ID_JOYPAD_UP)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_L)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_R);
|
|
|
|
|
|
|
|
driver.retro_ctx.poll_cb();
|
|
|
|
|
|
|
|
/* don't run anything first frame, only capture held inputs
|
|
|
|
* for old_input_state. */
|
|
|
|
|
|
|
|
if (input & input_repeat)
|
|
|
|
{
|
|
|
|
if (!first_held)
|
|
|
|
{
|
|
|
|
first_held = true;
|
|
|
|
driver.menu->delay_timer = initial_held ? 12 : 6;
|
|
|
|
driver.menu->delay_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driver.menu->delay_count >= driver.menu->delay_timer)
|
|
|
|
{
|
|
|
|
first_held = false;
|
|
|
|
trigger_input |= input & input_repeat;
|
|
|
|
driver.menu->scroll_accel = min(driver.menu->scroll_accel + 1, 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
initial_held = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first_held = false;
|
|
|
|
initial_held = true;
|
|
|
|
driver.menu->scroll_accel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
driver.menu->mouse.enable = g_settings.menu.mouse_enable;
|
|
|
|
|
|
|
|
driver.menu->delay_count++;
|
|
|
|
|
|
|
|
if (driver.block_input)
|
|
|
|
trigger_input = 0;
|
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_UP))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_UP;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_DOWN;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_LEFT;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_RIGHT;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_L))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_SCROLL_UP;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_R))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_SCROLL_DOWN;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_B))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_CANCEL;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_A))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_OK;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_Y))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_Y;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_START))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_START;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_SELECT;
|
2015-01-27 00:29:33 +00:00
|
|
|
if (trigger_input & (1ULL << RARCH_MENU_TOGGLE))
|
2015-01-25 03:52:26 +00:00
|
|
|
return MENU_ACTION_TOGGLE;
|
2015-01-10 05:33:05 +00:00
|
|
|
return MENU_ACTION_NOOP;
|
|
|
|
}
|