mirror of
https://github.com/libretro/RetroArch
synced 2025-02-10 12:40:03 +00:00
Cleanups, 80-char limit
This commit is contained in:
parent
3060d0757c
commit
e68f62040d
@ -19,7 +19,7 @@
|
||||
|
||||
#include "../general.h"
|
||||
|
||||
// Input responder
|
||||
/* Input responder */
|
||||
#define MAX_TOUCHES 16
|
||||
#define MAX_KEYS 256
|
||||
|
||||
@ -45,39 +45,55 @@ typedef struct
|
||||
} apple_input_data_t;
|
||||
|
||||
struct apple_pad_connection;
|
||||
|
||||
struct apple_pad_interface
|
||||
{
|
||||
void* (*connect)(struct apple_pad_connection* connection, uint32_t slot);
|
||||
void (*disconnect)(void* device);
|
||||
void (*packet_handler)(void* device, uint8_t *packet, uint16_t size);
|
||||
void (*set_rumble)(void* device, enum retro_rumble_effect effect, uint16_t strength);
|
||||
void (*set_rumble)(void* device, enum retro_rumble_effect effect,
|
||||
uint16_t strength);
|
||||
};
|
||||
|
||||
|
||||
// Joypad data
|
||||
int32_t apple_joypad_connect(const char* name, struct apple_pad_connection* connection);
|
||||
int32_t apple_joypad_connect(const char* name,
|
||||
struct apple_pad_connection* connection);
|
||||
|
||||
int32_t apple_joypad_connect_gcapi(void);
|
||||
|
||||
void apple_joypad_disconnect(uint32_t slot);
|
||||
|
||||
void apple_joypad_packet(uint32_t slot, uint8_t* data, uint32_t length);
|
||||
|
||||
// Determine if connected joypad is a hidpad backed device; if false apple_joypad_packet cannot be used
|
||||
/* Determine if connected joypad is a hidpad backed device.
|
||||
* If false, apple_joypad_packet cannot be used */
|
||||
bool apple_joypad_has_interface(uint32_t slot);
|
||||
|
||||
// This is implemented in the platform specific portions of the input code
|
||||
void apple_joypad_send_hid_control(struct apple_pad_connection* connection, uint8_t* data, size_t size);
|
||||
/* This is implemented in the platform-specific
|
||||
* portions of the input code */
|
||||
void apple_joypad_send_hid_control(struct apple_pad_connection* connection,
|
||||
uint8_t* data, size_t size);
|
||||
|
||||
// Input data for the main thread and the game thread
|
||||
/* Input data for the main thread and the game thread */
|
||||
extern apple_input_data_t g_current_input_data;
|
||||
|
||||
// Main thread only
|
||||
/* Main thread only */
|
||||
void apple_input_enable_icade(bool on);
|
||||
|
||||
void apple_input_enable_small_keyboard(bool on);
|
||||
|
||||
uint32_t apple_input_get_icade_buttons(void);
|
||||
|
||||
void apple_input_reset_icade_buttons(void);
|
||||
void apple_input_keyboard_event(bool down, unsigned code, uint32_t character, uint32_t mod);
|
||||
|
||||
void apple_input_keyboard_event(bool down, unsigned code,
|
||||
uint32_t character, uint32_t mod);
|
||||
|
||||
extern int32_t apple_input_find_any_key(void);
|
||||
|
||||
extern int32_t apple_input_find_any_button(uint32_t port);
|
||||
|
||||
extern int32_t apple_input_find_any_axis(uint32_t port);
|
||||
|
||||
#endif
|
||||
|
@ -92,9 +92,8 @@ DECL_AXIS(r_x_minus, -2) \
|
||||
DECL_AXIS(r_y_plus, -3) \
|
||||
DECL_AXIS(r_y_minus, +3)
|
||||
|
||||
// TODO: missing Libsicksaxis binds
|
||||
/* TODO: missing Libsicksaxis binds */
|
||||
|
||||
// Some hardcoded autoconfig information. Will be used for pads with no autoconfig cfg files.
|
||||
const char* const input_builtin_autoconfs[] =
|
||||
{
|
||||
DECL_AUTOCONF_DEVICE("GameCube Controller", "gx", GXINPUT_GAMECUBE_DEFAULT_BINDS),
|
||||
|
@ -42,7 +42,6 @@ DECL_AXIS(r_x_minus, -2) \
|
||||
DECL_AXIS(r_y_plus, -3) \
|
||||
DECL_AXIS(r_y_minus, +3)
|
||||
|
||||
// Some hardcoded autoconfig information. Will be used for pads with no autoconfig cfg files.
|
||||
const char* const input_builtin_autoconfs[] =
|
||||
{
|
||||
DECL_AUTOCONF_DEVICE("SixAxis Controller", "ps3", PS3INPUT_DEFAULT_BINDS),
|
||||
|
@ -40,7 +40,6 @@ DECL_AXIS(r_x_minus, -2) \
|
||||
DECL_AXIS(r_y_plus, -3) \
|
||||
DECL_AXIS(r_y_minus, +3)
|
||||
|
||||
// Some hardcoded autoconfig information. Will be used for pads with no autoconfig cfg files.
|
||||
const char* const input_builtin_autoconfs[] =
|
||||
{
|
||||
DECL_AUTOCONF_DEVICE("PSP Controller", "psp", PSPINPUT_DEFAULT_BINDS),
|
||||
|
@ -42,7 +42,6 @@ DECL_AXIS(r_x_minus, -2) \
|
||||
DECL_AXIS(r_y_plus, -3) \
|
||||
DECL_AXIS(r_y_minus, +3)
|
||||
|
||||
// Some hardcoded autoconfig information. Will be used for pads with no autoconfig cfg files.
|
||||
const char* const input_builtin_autoconfs[] =
|
||||
{
|
||||
DECL_AUTOCONF_DEVICE("XInput Controller (Player 1)", "winxinput", XINPUT_DEFAULT_BINDS),
|
||||
|
@ -41,7 +41,6 @@ DECL_AXIS(r_x_minus, -2) \
|
||||
DECL_AXIS(r_y_plus, -3) \
|
||||
DECL_AXIS(r_y_minus, +3)
|
||||
|
||||
// Some hardcoded autoconfig information. Will be used for pads with no autoconfig cfg files.
|
||||
const char* const input_builtin_autoconfs[] =
|
||||
{
|
||||
DECL_AUTOCONF_DEVICE("XInput Controller", "xdk", XINPUT_DEFAULT_BINDS),
|
||||
|
@ -95,9 +95,11 @@ const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident)
|
||||
|
||||
for (i = 0; joypad_drivers[i]; i++)
|
||||
{
|
||||
if (strcmp(ident, joypad_drivers[i]->ident) == 0 && joypad_drivers[i]->init())
|
||||
if (strcmp(ident, joypad_drivers[i]->ident) == 0
|
||||
&& joypad_drivers[i]->init())
|
||||
{
|
||||
RARCH_LOG("Found joypad driver: \"%s\".\n", joypad_drivers[i]->ident);
|
||||
RARCH_LOG("Found joypad driver: \"%s\".\n",
|
||||
joypad_drivers[i]->ident);
|
||||
return joypad_drivers[i];
|
||||
}
|
||||
}
|
||||
@ -112,7 +114,8 @@ const rarch_joypad_driver_t *input_joypad_init_first(void)
|
||||
{
|
||||
if (joypad_drivers[i]->init())
|
||||
{
|
||||
RARCH_LOG("Found joypad driver: \"%s\".\n", joypad_drivers[i]->ident);
|
||||
RARCH_LOG("Found joypad driver: \"%s\".\n",
|
||||
joypad_drivers[i]->ident);
|
||||
return joypad_drivers[i];
|
||||
}
|
||||
}
|
||||
@ -120,7 +123,8 @@ const rarch_joypad_driver_t *input_joypad_init_first(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *input_joypad_name(const rarch_joypad_driver_t *driver, unsigned joypad)
|
||||
const char *input_joypad_name(const rarch_joypad_driver_t *driver,
|
||||
unsigned joypad)
|
||||
{
|
||||
if (!driver)
|
||||
return NULL;
|
||||
@ -151,8 +155,9 @@ bool input_joypad_pressed(const rarch_joypad_driver_t *driver,
|
||||
if (joy_index < 0 || joy_index >= MAX_PLAYERS)
|
||||
return false;
|
||||
|
||||
// Auto-binds are per joypad, not per player.
|
||||
const struct retro_keybind *auto_binds = g_settings.input.autoconf_binds[joy_index];
|
||||
/* Auto-binds are per joypad, not per player. */
|
||||
const struct retro_keybind *auto_binds =
|
||||
g_settings.input.autoconf_binds[joy_index];
|
||||
|
||||
if (!binds[key].valid)
|
||||
return false;
|
||||
@ -174,7 +179,8 @@ bool input_joypad_pressed(const rarch_joypad_driver_t *driver,
|
||||
}
|
||||
|
||||
int16_t input_joypad_analog(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, unsigned index, unsigned id, const struct retro_keybind *binds)
|
||||
unsigned port, unsigned index, unsigned id,
|
||||
const struct retro_keybind *binds)
|
||||
{
|
||||
if (!driver)
|
||||
return 0;
|
||||
@ -183,8 +189,9 @@ int16_t input_joypad_analog(const rarch_joypad_driver_t *driver,
|
||||
if (joy_index < 0 || joy_index >= MAX_PLAYERS)
|
||||
return 0;
|
||||
|
||||
// Auto-binds are per joypad, not per player.
|
||||
const struct retro_keybind *auto_binds = g_settings.input.autoconf_binds[joy_index];
|
||||
/* Auto-binds are per joypad, not per player. */
|
||||
const struct retro_keybind *auto_binds =
|
||||
g_settings.input.autoconf_binds[joy_index];
|
||||
|
||||
unsigned id_minus = 0;
|
||||
unsigned id_plus = 0;
|
||||
@ -217,8 +224,10 @@ int16_t input_joypad_analog(const rarch_joypad_driver_t *driver,
|
||||
if (key_plus == NO_BTN)
|
||||
key_plus = auto_binds[id_plus].joykey;
|
||||
|
||||
int16_t digital_left = driver->button(joy_index, (uint16_t)key_minus) ? -0x7fff : 0;
|
||||
int16_t digital_right = driver->button(joy_index, (uint16_t)key_plus) ? 0x7fff : 0;
|
||||
int16_t digital_left = driver->button(joy_index,
|
||||
(uint16_t)key_minus) ? -0x7fff : 0;
|
||||
int16_t digital_right = driver->button(joy_index,
|
||||
(uint16_t)key_plus) ? 0x7fff : 0;
|
||||
return digital_right + digital_left;
|
||||
}
|
||||
|
||||
@ -228,7 +237,8 @@ int16_t input_joypad_axis_raw(const rarch_joypad_driver_t *driver,
|
||||
if (!driver)
|
||||
return 0;
|
||||
|
||||
return driver->axis(joypad, AXIS_POS(axis)) + driver->axis(joypad, AXIS_NEG(axis));
|
||||
return driver->axis(joypad, AXIS_POS(axis)) +
|
||||
driver->axis(joypad, AXIS_NEG(axis));
|
||||
}
|
||||
|
||||
bool input_joypad_button_raw(const rarch_joypad_driver_t *driver,
|
||||
@ -251,7 +261,8 @@ bool input_joypad_hat_raw(const rarch_joypad_driver_t *driver,
|
||||
|
||||
#ifndef IS_RETROLAUNCH
|
||||
bool input_translate_coord_viewport(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_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y)
|
||||
{
|
||||
struct rarch_viewport vp = {0};
|
||||
bool have_viewport_info = driver.video && driver.video->viewport_info;
|
||||
@ -1151,7 +1162,8 @@ enum retro_key input_translate_str_to_rk(const char *str)
|
||||
return find_rk_bind(str);
|
||||
}
|
||||
|
||||
void input_config_parse_key(config_file_t *conf, const char *prefix, const char *btn,
|
||||
void input_config_parse_key(config_file_t *conf,
|
||||
const char *prefix, const char *btn,
|
||||
struct retro_keybind *bind)
|
||||
{
|
||||
char tmp[64];
|
||||
@ -1168,7 +1180,8 @@ const char *input_config_get_prefix(unsigned player, bool meta)
|
||||
return meta ? "input" : bind_player_prefix[player];
|
||||
else if (player != 0 && !meta)
|
||||
return bind_player_prefix[player];
|
||||
return NULL; // Don't bother with meta bind for anyone else than first player.
|
||||
/* Don't bother with meta bind for anyone else than first player. */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned input_translate_str_to_bind_id(const char *str)
|
||||
@ -1250,23 +1263,28 @@ void input_config_parse_joy_axis(config_file_t *conf, const char *prefix,
|
||||
bind->joyaxis = AXIS_NEG(axis);
|
||||
}
|
||||
|
||||
// Ensure that d-pad emulation doesn't screw this over.
|
||||
/* Ensure that d-pad emulation doesn't screw this over. */
|
||||
bind->orig_joyaxis = bind->joyaxis;
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(IS_JOYCONFIG) && !defined(IS_RETROLAUNCH)
|
||||
static void input_autoconfigure_joypad_conf(config_file_t *conf, struct retro_keybind *binds)
|
||||
static void input_autoconfigure_joypad_conf(config_file_t *conf,
|
||||
struct retro_keybind *binds)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < RARCH_BIND_LIST_END; i++)
|
||||
{
|
||||
input_config_parse_joy_button(conf, "input", input_config_bind_map[i].base, &binds[i]);
|
||||
input_config_parse_joy_axis(conf, "input", input_config_bind_map[i].base, &binds[i]);
|
||||
input_config_parse_joy_button(conf, "input",
|
||||
input_config_bind_map[i].base, &binds[i]);
|
||||
input_config_parse_joy_axis(conf, "input",
|
||||
input_config_bind_map[i].base, &binds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static bool input_try_autoconfigure_joypad_from_conf(config_file_t *conf, unsigned index, const char *name, const char *driver, bool block_osd_spam)
|
||||
static bool input_try_autoconfigure_joypad_from_conf(config_file_t *conf,
|
||||
unsigned index, const char *name, const char *driver,
|
||||
bool block_osd_spam)
|
||||
{
|
||||
if (!conf)
|
||||
return false;
|
||||
@ -1309,15 +1327,17 @@ found:
|
||||
return true;
|
||||
}
|
||||
|
||||
void input_config_autoconfigure_joypad(unsigned index, const char *name, const char *driver)
|
||||
void input_config_autoconfigure_joypad(unsigned index,
|
||||
const char *name, const char *driver)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!g_settings.input.autodetect_enable)
|
||||
return;
|
||||
|
||||
// This will be the case if input driver is reinit. No reason to spam autoconfigure messages
|
||||
// every time (fine in log).
|
||||
/* This will be the case if input driver is reinit.
|
||||
* No reason to spam autoconfigure messages
|
||||
* every time (fine in log). */
|
||||
bool block_osd_spam = g_settings.input.autoconfigured[index] && name;
|
||||
|
||||
for (i = 0; i < RARCH_BIND_LIST_END; i++)
|
||||
@ -1330,11 +1350,11 @@ void input_config_autoconfigure_joypad(unsigned index, const char *name, const c
|
||||
if (!name)
|
||||
return;
|
||||
|
||||
// false = load from both cfg files and internal
|
||||
/* false = load from both cfg files and internal */
|
||||
bool internal_only = !*g_settings.input.autoconfig_dir;
|
||||
|
||||
#ifdef HAVE_BUILTIN_AUTOCONFIG
|
||||
// First internal
|
||||
/* First internal */
|
||||
for (i = 0; input_builtin_autoconfs[i]; i++)
|
||||
{
|
||||
config_file_t *conf = config_file_new_from_string(input_builtin_autoconfs[i]);
|
||||
@ -1345,10 +1365,11 @@ void input_config_autoconfigure_joypad(unsigned index, const char *name, const c
|
||||
}
|
||||
#endif
|
||||
|
||||
// Now try files
|
||||
/* Now try files */
|
||||
if (!internal_only)
|
||||
{
|
||||
struct string_list *list = dir_list_new(g_settings.input.autoconfig_dir, "cfg", false);
|
||||
struct string_list *list = dir_list_new(
|
||||
g_settings.input.autoconfig_dir, "cfg", false);
|
||||
if (!list)
|
||||
return;
|
||||
|
||||
@ -1357,7 +1378,8 @@ void input_config_autoconfigure_joypad(unsigned index, const char *name, const c
|
||||
config_file_t *conf = config_file_new(list->elems[i].data);
|
||||
if (!conf)
|
||||
continue;
|
||||
bool success = input_try_autoconfigure_joypad_from_conf(conf, index, name, driver, block_osd_spam);
|
||||
bool success = input_try_autoconfigure_joypad_from_conf(conf,
|
||||
index, name, driver, block_osd_spam);
|
||||
config_file_free(conf);
|
||||
if (success)
|
||||
break;
|
||||
@ -1375,7 +1397,8 @@ const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id)
|
||||
return &g_settings.input.autoconf_binds[joy_index][id];
|
||||
}
|
||||
|
||||
static void input_get_bind_string_joykey(char *buf, const char *prefix, const struct retro_keybind *bind, size_t size)
|
||||
static void input_get_bind_string_joykey(char *buf, const char *prefix,
|
||||
const struct retro_keybind *bind, size_t size)
|
||||
{
|
||||
if (GET_HAT_DIR(bind->joykey))
|
||||
{
|
||||
@ -1388,13 +1411,15 @@ static void input_get_bind_string_joykey(char *buf, const char *prefix, const st
|
||||
case HAT_RIGHT_MASK: dir = "right"; break;
|
||||
default: dir = "?"; break;
|
||||
}
|
||||
snprintf(buf, size, "%sHat #%u %s ", prefix, (unsigned)GET_HAT(bind->joykey), dir);
|
||||
snprintf(buf, size, "%sHat #%u %s ", prefix,
|
||||
(unsigned)GET_HAT(bind->joykey), dir);
|
||||
}
|
||||
else
|
||||
snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey);
|
||||
}
|
||||
|
||||
static void input_get_bind_string_joyaxis(char *buf, const char *prefix, const struct retro_keybind *bind, size_t size)
|
||||
static void input_get_bind_string_joyaxis(char *buf, const char *prefix,
|
||||
const struct retro_keybind *bind, size_t size)
|
||||
{
|
||||
unsigned axis = 0;
|
||||
char dir = '\0';
|
||||
@ -1436,7 +1461,8 @@ void input_get_bind_string(char *buf, const struct retro_keybind *bind,
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void input_config_autoconfigure_joypad(unsigned index, const char *name, const char *driver)
|
||||
void input_config_autoconfigure_joypad(unsigned index, const char *name,
|
||||
const char *driver)
|
||||
{
|
||||
(void)index;
|
||||
(void)name;
|
||||
@ -1456,7 +1482,7 @@ void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode)
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_DOWN].orig_joyaxis = binds[RETRO_DEVICE_ID_JOYPAD_DOWN].joyaxis;
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_UP].orig_joyaxis = binds[RETRO_DEVICE_ID_JOYPAD_UP].joyaxis;
|
||||
|
||||
// Inherit joyaxis from analogs.
|
||||
/* Inherit joyaxis from analogs. */
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_RIGHT].joyaxis = binds[RARCH_ANALOG_LEFT_X_PLUS + 0].joyaxis;
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_LEFT].joyaxis = binds[RARCH_ANALOG_LEFT_X_PLUS + 1].joyaxis;
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_DOWN].joyaxis = binds[RARCH_ANALOG_LEFT_X_PLUS + 2].joyaxis;
|
||||
@ -1468,7 +1494,7 @@ void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode)
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_DOWN].orig_joyaxis = binds[RETRO_DEVICE_ID_JOYPAD_DOWN].joyaxis;
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_UP].orig_joyaxis = binds[RETRO_DEVICE_ID_JOYPAD_UP].joyaxis;
|
||||
|
||||
// Inherit joyaxis from analogs.
|
||||
/* Inherit joyaxis from analogs. */
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_RIGHT].joyaxis = binds[RARCH_ANALOG_RIGHT_X_PLUS + 0].joyaxis;
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_LEFT].joyaxis = binds[RARCH_ANALOG_RIGHT_X_PLUS + 1].joyaxis;
|
||||
binds[RETRO_DEVICE_ID_JOYPAD_DOWN].joyaxis = binds[RARCH_ANALOG_RIGHT_X_PLUS + 2].joyaxis;
|
||||
@ -1482,7 +1508,7 @@ void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode)
|
||||
}
|
||||
}
|
||||
|
||||
// Restore binds temporarily overridden by input_push_analog_dpad.
|
||||
/* Restore binds temporarily overridden by input_push_analog_dpad. */
|
||||
void input_pop_analog_dpad(struct retro_keybind *binds)
|
||||
{
|
||||
unsigned i;
|
||||
|
@ -52,7 +52,8 @@ static inline void input_conv_analog_id_to_bind_id(unsigned index, unsigned id,
|
||||
}
|
||||
|
||||
bool input_translate_coord_viewport(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_x, int16_t *res_y, int16_t *res_screen_x,
|
||||
int16_t *res_screen_y);
|
||||
|
||||
#ifdef ANDROID
|
||||
enum back_button_enums
|
||||
@ -71,38 +72,44 @@ struct rarch_joypad_driver
|
||||
bool (*button)(unsigned, uint16_t);
|
||||
int16_t (*axis)(unsigned, uint32_t);
|
||||
void (*poll)(void);
|
||||
bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t); // Optional
|
||||
bool (*set_rumble)(unsigned, enum retro_rumble_effect, uint16_t);
|
||||
const char *(*name)(unsigned);
|
||||
|
||||
const char *ident;
|
||||
};
|
||||
|
||||
// If ident points to NULL or a zero-length string, equivalent to calling input_joypad_init_first().
|
||||
/* If ident points to NULL or a zero-length string,
|
||||
* equivalent to calling input_joypad_init_first(). */
|
||||
const rarch_joypad_driver_t *input_joypad_init_driver(const char *ident);
|
||||
|
||||
const rarch_joypad_driver_t *input_joypad_init_first(void);
|
||||
|
||||
bool input_joypad_pressed(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, const struct retro_keybind *binds, unsigned key);
|
||||
|
||||
int16_t input_joypad_analog(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, unsigned index, unsigned id, const struct retro_keybind *binds);
|
||||
unsigned port, unsigned index, unsigned id,
|
||||
const struct retro_keybind *binds);
|
||||
|
||||
bool input_joypad_set_rumble(const rarch_joypad_driver_t *driver,
|
||||
unsigned port, enum retro_rumble_effect effect, uint16_t strength);
|
||||
|
||||
int16_t input_joypad_axis_raw(const rarch_joypad_driver_t *driver,
|
||||
unsigned joypad, unsigned axis);
|
||||
|
||||
bool input_joypad_button_raw(const rarch_joypad_driver_t *driver,
|
||||
unsigned joypad, unsigned button);
|
||||
|
||||
bool input_joypad_hat_raw(const rarch_joypad_driver_t *driver,
|
||||
unsigned joypad, unsigned hat_dir, unsigned hat);
|
||||
|
||||
const char *input_joypad_name(const rarch_joypad_driver_t *driver, unsigned joypad);
|
||||
const char *input_joypad_name(const rarch_joypad_driver_t *driver,
|
||||
unsigned joypad);
|
||||
|
||||
extern const rarch_joypad_driver_t dinput_joypad;
|
||||
extern const rarch_joypad_driver_t linuxraw_joypad;
|
||||
extern const rarch_joypad_driver_t udev_joypad;
|
||||
extern const rarch_joypad_driver_t winxinput_joypad; // Named as such to avoid confusion with xb1/360 port code
|
||||
extern const rarch_joypad_driver_t winxinput_joypad;
|
||||
extern const rarch_joypad_driver_t sdl_joypad;
|
||||
extern const rarch_joypad_driver_t ps3_joypad;
|
||||
extern const rarch_joypad_driver_t psp_joypad;
|
||||
@ -129,15 +136,16 @@ void input_init_keyboard_lut(const struct rarch_key_map *map);
|
||||
enum retro_key input_translate_keysym_to_rk(unsigned sym);
|
||||
unsigned input_translate_rk_to_keysym(enum retro_key key);
|
||||
|
||||
// Input config.
|
||||
/* Input config. */
|
||||
struct input_bind_map
|
||||
{
|
||||
bool valid;
|
||||
|
||||
// Meta binds get input as prefix, not input_playerN".
|
||||
// 0 = libretro related.
|
||||
// 1 = Common hotkey.
|
||||
// 2 = Uncommon/obscure hotkey.
|
||||
/* Meta binds get input as prefix, not input_playerN".
|
||||
* 0 = libretro related.
|
||||
* 1 = Common hotkey.
|
||||
* 2 = Uncommon/obscure hotkey.
|
||||
*/
|
||||
unsigned meta;
|
||||
|
||||
const char *base;
|
||||
@ -148,8 +156,10 @@ struct input_bind_map
|
||||
extern const struct input_bind_map input_config_bind_map[];
|
||||
|
||||
const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id);
|
||||
// auto_bind can be NULL.
|
||||
void input_get_bind_string(char *buf, const struct retro_keybind *bind, const struct retro_keybind *auto_bind, size_t size);
|
||||
|
||||
/* auto_bind can be NULL. */
|
||||
void input_get_bind_string(char *buf, const struct retro_keybind *bind,
|
||||
const struct retro_keybind *auto_bind, size_t size);
|
||||
|
||||
struct input_key_map
|
||||
{
|
||||
@ -163,19 +173,25 @@ enum retro_key input_translate_str_to_rk(const char *str);
|
||||
extern const char* const input_builtin_autoconfs[];
|
||||
|
||||
const char *input_config_get_prefix(unsigned player, bool meta);
|
||||
unsigned input_translate_str_to_bind_id(const char *str); // Returns RARCH_BIND_LIST_END on not found.
|
||||
|
||||
/* Returns RARCH_BIND_LIST_END on not found. */
|
||||
unsigned input_translate_str_to_bind_id(const char *str);
|
||||
|
||||
void input_config_parse_key(config_file_t *conf, const char *prefix, const char *btn,
|
||||
void input_config_parse_key(config_file_t *conf,
|
||||
const char *prefix, const char *btn,
|
||||
struct retro_keybind *bind);
|
||||
|
||||
void input_config_parse_joy_button(config_file_t *conf, const char *prefix,
|
||||
const char *btn, struct retro_keybind *bind);
|
||||
|
||||
void input_config_parse_joy_axis(config_file_t *conf, const char *prefix,
|
||||
const char *axis, struct retro_keybind *bind);
|
||||
|
||||
void input_config_autoconfigure_joypad(unsigned index, const char *name, const char *driver);
|
||||
void input_config_autoconfigure_joypad(unsigned index,
|
||||
const char *name, const char *driver);
|
||||
|
||||
void input_push_analog_dpad(struct retro_keybind *binds, unsigned mode);
|
||||
|
||||
void input_pop_analog_dpad(struct retro_keybind *binds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -43,7 +43,8 @@ void input_keyboard_line_free(input_keyboard_line_t *state)
|
||||
input_keyboard_line_t *input_keyboard_line_new(void *userdata,
|
||||
input_keyboard_line_complete_t cb)
|
||||
{
|
||||
input_keyboard_line_t *state = (input_keyboard_line_t*)calloc(1, sizeof(*state));
|
||||
input_keyboard_line_t *state = (input_keyboard_line_t*)
|
||||
calloc(1, sizeof(*state));
|
||||
if (!state)
|
||||
return NULL;
|
||||
|
||||
@ -52,9 +53,11 @@ input_keyboard_line_t *input_keyboard_line_new(void *userdata,
|
||||
return state;
|
||||
}
|
||||
|
||||
bool input_keyboard_line_event(input_keyboard_line_t *state, uint32_t character)
|
||||
bool input_keyboard_line_event(
|
||||
input_keyboard_line_t *state, uint32_t character)
|
||||
{
|
||||
// Treat extended chars as ? as we cannot support printable characters for unicode stuff.
|
||||
/* Treat extended chars as ? as we cannot support
|
||||
* printable characters for unicode stuff. */
|
||||
char c = character >= 128 ? '?' : character;
|
||||
if (c == '\r' || c == '\n')
|
||||
{
|
||||
@ -72,14 +75,16 @@ bool input_keyboard_line_event(input_keyboard_line_t *state, uint32_t character)
|
||||
state->size--;
|
||||
}
|
||||
}
|
||||
// Handle left/right here when suitable
|
||||
|
||||
/* Handle left/right here when suitable */
|
||||
else if (isprint(c))
|
||||
{
|
||||
char *newbuf = (char*)realloc(state->buffer, state->size + 2);
|
||||
if (!newbuf)
|
||||
return false;
|
||||
|
||||
memmove(newbuf + state->ptr + 1, newbuf + state->ptr, state->size - state->ptr + 1);
|
||||
memmove(newbuf + state->ptr + 1,
|
||||
newbuf + state->ptr, state->size - state->ptr + 1);
|
||||
newbuf[state->ptr] = c;
|
||||
state->ptr++;
|
||||
state->size++;
|
||||
@ -91,7 +96,8 @@ bool input_keyboard_line_event(input_keyboard_line_t *state, uint32_t character)
|
||||
return false;
|
||||
}
|
||||
|
||||
const char **input_keyboard_line_get_buffer(const input_keyboard_line_t *state)
|
||||
const char **input_keyboard_line_get_buffer(
|
||||
const input_keyboard_line_t *state)
|
||||
{
|
||||
return (const char**)&state->buffer;
|
||||
}
|
||||
@ -101,13 +107,15 @@ static input_keyboard_line_t *g_keyboard_line;
|
||||
static input_keyboard_press_t g_keyboard_press_cb;
|
||||
static void *g_keyboard_press_data;
|
||||
|
||||
const char **input_keyboard_start_line(void *userdata, input_keyboard_line_complete_t cb)
|
||||
const char **input_keyboard_start_line(void *userdata,
|
||||
input_keyboard_line_complete_t cb)
|
||||
{
|
||||
if (g_keyboard_line)
|
||||
input_keyboard_line_free(g_keyboard_line);
|
||||
|
||||
g_keyboard_line = input_keyboard_line_new(userdata, cb);
|
||||
// While reading keyboard line input, we have to block all hotkeys.
|
||||
|
||||
/* While reading keyboard line input, we have to block all hotkeys. */
|
||||
driver.block_input = true;
|
||||
|
||||
return input_keyboard_line_get_buffer(g_keyboard_line);
|
||||
@ -117,7 +125,8 @@ void input_keyboard_wait_keys(void *userdata, input_keyboard_press_t cb)
|
||||
{
|
||||
g_keyboard_press_cb = cb;
|
||||
g_keyboard_press_data = userdata;
|
||||
// While waiting for input, we have to block all hotkeys.
|
||||
|
||||
/* While waiting for input, we have to block all hotkeys. */
|
||||
driver.block_input = true;
|
||||
}
|
||||
|
||||
@ -128,7 +137,8 @@ void input_keyboard_wait_keys_cancel(void)
|
||||
driver.block_input = false;
|
||||
}
|
||||
|
||||
void input_keyboard_event(bool down, unsigned code, uint32_t character, uint16_t mod)
|
||||
void input_keyboard_event(bool down, unsigned code,
|
||||
uint32_t character, uint16_t mod)
|
||||
{
|
||||
static bool deferred_wait_keys;
|
||||
|
||||
@ -142,18 +152,19 @@ void input_keyboard_event(bool down, unsigned code, uint32_t character, uint16_t
|
||||
}
|
||||
else if (g_keyboard_press_cb)
|
||||
{
|
||||
if (down && code != RETROK_UNKNOWN && !g_keyboard_press_cb(g_keyboard_press_data, code))
|
||||
if (down && code != RETROK_UNKNOWN
|
||||
&& !g_keyboard_press_cb(g_keyboard_press_data, code))
|
||||
deferred_wait_keys = true;
|
||||
}
|
||||
else if (g_keyboard_line)
|
||||
{
|
||||
if (down && input_keyboard_line_event(g_keyboard_line, character))
|
||||
{
|
||||
// Line is complete, can free it now.
|
||||
/* Line is complete, can free it now. */
|
||||
input_keyboard_line_free(g_keyboard_line);
|
||||
g_keyboard_line = NULL;
|
||||
|
||||
// Unblock all hotkeys.
|
||||
/* Unblock all hotkeys. */
|
||||
driver.block_input = false;
|
||||
}
|
||||
}
|
||||
|
@ -24,33 +24,42 @@ extern "C" {
|
||||
#include "../libretro.h"
|
||||
#include <stdint.h>
|
||||
|
||||
// Keyboard line reader. Handles textual input in a direct fashion.
|
||||
/* Keyboard line reader. Handles textual input in a direct fashion. */
|
||||
typedef struct input_keyboard_line input_keyboard_line_t;
|
||||
|
||||
// Calls back after return is pressed with the completed line.
|
||||
// line can be NULL.
|
||||
typedef void (*input_keyboard_line_complete_t)(void *userdata, const char *line);
|
||||
/* Calls back after return is pressed with the completed line.
|
||||
* line can be NULL. */
|
||||
typedef void (*input_keyboard_line_complete_t)(void *userdata,
|
||||
const char *line);
|
||||
|
||||
typedef bool (*input_keyboard_press_t)(void *userdata, unsigned code);
|
||||
|
||||
input_keyboard_line_t *input_keyboard_line_new(void *userdata,
|
||||
input_keyboard_line_complete_t cb);
|
||||
|
||||
// Called on every keyboard character event.
|
||||
bool input_keyboard_line_event(input_keyboard_line_t *state, uint32_t character);
|
||||
/* Called on every keyboard character event. */
|
||||
bool input_keyboard_line_event(input_keyboard_line_t *state,
|
||||
uint32_t character);
|
||||
|
||||
/* Returns pointer to string. The underlying buffer can be reallocated at
|
||||
* any time (or be NULL), but the pointer to it remains constant
|
||||
* throughout the objects lifetime. */
|
||||
const char **input_keyboard_line_get_buffer(
|
||||
const input_keyboard_line_t *state);
|
||||
|
||||
// Returns pointer to string. The underlying buffer can be reallocated at any time (or be NULL), but the pointer to it remains constant throughout the objects lifetime.
|
||||
const char **input_keyboard_line_get_buffer(const input_keyboard_line_t *state);
|
||||
void input_keyboard_line_free(input_keyboard_line_t *state);
|
||||
|
||||
// Keyboard event utils. Called by drivers when keyboard events are fired.
|
||||
// This interfaces with the global driver struct and libretro callbacks.
|
||||
void input_keyboard_event(bool down, unsigned code, uint32_t character, uint16_t mod);
|
||||
/* Keyboard event utils. Called by drivers when keyboard events are fired.
|
||||
* This interfaces with the global driver struct and libretro callbacks. */
|
||||
void input_keyboard_event(bool down, unsigned code, uint32_t character,
|
||||
uint16_t mod);
|
||||
|
||||
const char **input_keyboard_start_line(void *userdata, input_keyboard_line_complete_t cb);
|
||||
|
||||
// Wait for keys to be pressed (used for binding keys in the menu).
|
||||
// Callback returns false when all polling is done.
|
||||
/* Wait for keys to be pressed (used for binding keys in the menu).
|
||||
* Callback returns false when all polling is done. */
|
||||
void input_keyboard_wait_keys(void *userdata, input_keyboard_press_t cb);
|
||||
|
||||
void input_keyboard_wait_keys_cancel(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
130
input/overlay.c
130
input/overlay.c
@ -114,8 +114,10 @@ static void input_overlay_scale(struct overlay *overlay, float scale)
|
||||
overlay->scale = scale;
|
||||
overlay->mod_w = overlay->w * scale;
|
||||
overlay->mod_h = overlay->h * scale;
|
||||
overlay->mod_x = overlay->center_x + (overlay->x - overlay->center_x) * scale;
|
||||
overlay->mod_y = overlay->center_y + (overlay->y - overlay->center_y) * scale;
|
||||
overlay->mod_x = overlay->center_x +
|
||||
(overlay->x - overlay->center_x) * scale;
|
||||
overlay->mod_y = overlay->center_y +
|
||||
(overlay->y - overlay->center_y) * scale;
|
||||
|
||||
for (i = 0; i < overlay->size; i++)
|
||||
{
|
||||
@ -139,7 +141,8 @@ static void input_overlay_set_vertex_geom(input_overlay_t *ol)
|
||||
size_t i;
|
||||
if (ol->active->image.pixels)
|
||||
ol->iface->vertex_geom(ol->iface_data, 0,
|
||||
ol->active->mod_x, ol->active->mod_y, ol->active->mod_w, ol->active->mod_h);
|
||||
ol->active->mod_x, ol->active->mod_y,
|
||||
ol->active->mod_w, ol->active->mod_h);
|
||||
|
||||
for (i = 0; i < ol->active->size; i++)
|
||||
{
|
||||
@ -179,24 +182,28 @@ static void input_overlay_free_overlays(input_overlay_t *ol)
|
||||
free(ol->overlays);
|
||||
}
|
||||
|
||||
static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, struct overlay_desc *desc,
|
||||
static bool input_overlay_load_desc(input_overlay_t *ol,
|
||||
config_file_t *conf, struct overlay_desc *desc,
|
||||
unsigned ol_index, unsigned desc_index,
|
||||
unsigned width, unsigned height,
|
||||
bool normalized, float alpha_mod, float range_mod)
|
||||
{
|
||||
bool ret = true;
|
||||
char overlay_desc_key[64];
|
||||
snprintf(overlay_desc_key, sizeof(overlay_desc_key), "overlay%u_desc%u", ol_index, desc_index);
|
||||
snprintf(overlay_desc_key, sizeof(overlay_desc_key),
|
||||
"overlay%u_desc%u", ol_index, desc_index);
|
||||
|
||||
char overlay_desc_image_key[64];
|
||||
snprintf(overlay_desc_image_key, sizeof(overlay_desc_image_key),
|
||||
"overlay%u_desc%u_overlay", ol_index, desc_index);
|
||||
|
||||
char image_path[PATH_MAX];
|
||||
if (config_get_path(conf, overlay_desc_image_key, image_path, sizeof(image_path)))
|
||||
if (config_get_path(conf, overlay_desc_image_key,
|
||||
image_path, sizeof(image_path)))
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
fill_pathname_resolve_relative(path, ol->overlay_path, image_path, sizeof(path));
|
||||
fill_pathname_resolve_relative(path, ol->overlay_path,
|
||||
image_path, sizeof(path));
|
||||
|
||||
struct texture_image img = {0};
|
||||
if (texture_image_load(&img, path))
|
||||
@ -266,8 +273,10 @@ static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, st
|
||||
if (desc->key_mask & (UINT64_C(1) << RARCH_OVERLAY_NEXT))
|
||||
{
|
||||
char overlay_target_key[64];
|
||||
snprintf(overlay_target_key, sizeof(overlay_target_key), "overlay%u_desc%u_next_target", ol_index, desc_index);
|
||||
config_get_array(conf, overlay_target_key, desc->next_index_name, sizeof(desc->next_index_name));
|
||||
snprintf(overlay_target_key, sizeof(overlay_target_key),
|
||||
"overlay%u_desc%u_next_target", ol_index, desc_index);
|
||||
config_get_array(conf, overlay_target_key,
|
||||
desc->next_index_name, sizeof(desc->next_index_name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -288,7 +297,9 @@ static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, st
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (desc->type == OVERLAY_TYPE_ANALOG_LEFT || desc->type == OVERLAY_TYPE_ANALOG_RIGHT)
|
||||
if (
|
||||
desc->type == OVERLAY_TYPE_ANALOG_LEFT ||
|
||||
desc->type == OVERLAY_TYPE_ANALOG_RIGHT)
|
||||
{
|
||||
if (desc->hitbox != OVERLAY_HITBOX_RADIAL)
|
||||
{
|
||||
@ -298,8 +309,10 @@ static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, st
|
||||
}
|
||||
|
||||
char overlay_analog_saturate_key[64];
|
||||
snprintf(overlay_analog_saturate_key, sizeof(overlay_analog_saturate_key), "overlay%u_desc%u_saturate_pct", ol_index, desc_index);
|
||||
if (!config_get_float(conf, overlay_analog_saturate_key, &desc->analog_saturate_pct))
|
||||
snprintf(overlay_analog_saturate_key, sizeof(overlay_analog_saturate_key),
|
||||
"overlay%u_desc%u_saturate_pct", ol_index, desc_index);
|
||||
if (!config_get_float(conf, overlay_analog_saturate_key,
|
||||
&desc->analog_saturate_pct))
|
||||
desc->analog_saturate_pct = 1.0f;
|
||||
}
|
||||
|
||||
@ -312,15 +325,18 @@ static bool input_overlay_load_desc(input_overlay_t *ol, config_file_t *conf, st
|
||||
desc->mod_h = 2.0f * desc->range_y;
|
||||
|
||||
char conf_key[64];
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_alpha_mod", ol_index, desc_index);
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_alpha_mod", ol_index, desc_index);
|
||||
desc->alpha_mod = alpha_mod;
|
||||
config_get_float(conf, conf_key, &desc->alpha_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_range_mod", ol_index, desc_index);
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_range_mod", ol_index, desc_index);
|
||||
desc->range_mod = range_mod;
|
||||
config_get_float(conf, conf_key, &desc->range_mod);
|
||||
|
||||
snprintf(conf_key, sizeof(conf_key), "overlay%u_desc%u_movable", ol_index, desc_index);
|
||||
snprintf(conf_key, sizeof(conf_key),
|
||||
"overlay%u_desc%u_movable", ol_index, desc_index);
|
||||
desc->movable = false;
|
||||
desc->delta_x = 0.0f;
|
||||
desc->delta_y = 0.0f;
|
||||
@ -335,7 +351,8 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf, const char *config_path,
|
||||
static bool input_overlay_load_overlay(input_overlay_t *ol,
|
||||
config_file_t *conf, const char *config_path,
|
||||
struct overlay *overlay, unsigned index)
|
||||
{
|
||||
size_t i;
|
||||
@ -344,8 +361,10 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
|
||||
char overlay_path[PATH_MAX];
|
||||
char overlay_resolved_path[PATH_MAX];
|
||||
|
||||
snprintf(overlay_path_key, sizeof(overlay_path_key), "overlay%u_overlay", index);
|
||||
if (config_get_path(conf, overlay_path_key, overlay_path, sizeof(overlay_path)))
|
||||
snprintf(overlay_path_key, sizeof(overlay_path_key),
|
||||
"overlay%u_overlay", index);
|
||||
if (config_get_path(conf, overlay_path_key,
|
||||
overlay_path, sizeof(overlay_path)))
|
||||
{
|
||||
struct texture_image img = {0};
|
||||
|
||||
@ -356,27 +375,34 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
|
||||
overlay->image = img;
|
||||
else
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to load image: %s.\n", overlay_resolved_path);
|
||||
RARCH_ERR("[Overlay]: Failed to load image: %s.\n",
|
||||
overlay_resolved_path);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(overlay_name_key, sizeof(overlay_name_key), "overlay%u_name", index);
|
||||
config_get_array(conf, overlay_name_key, overlay->name, sizeof(overlay->name));
|
||||
snprintf(overlay_name_key, sizeof(overlay_name_key),
|
||||
"overlay%u_name", index);
|
||||
config_get_array(conf, overlay_name_key,
|
||||
overlay->name, sizeof(overlay->name));
|
||||
|
||||
// By default, we stretch the overlay out in full.
|
||||
/* By default, we stretch the overlay out in full. */
|
||||
overlay->x = overlay->y = 0.0f;
|
||||
overlay->w = overlay->h = 1.0f;
|
||||
|
||||
char overlay_rect_key[64];
|
||||
snprintf(overlay_rect_key, sizeof(overlay_rect_key), "overlay%u_rect", index);
|
||||
snprintf(overlay_rect_key, sizeof(overlay_rect_key),
|
||||
"overlay%u_rect", index);
|
||||
char overlay_rect[256];
|
||||
if (config_get_array(conf, overlay_rect_key, overlay_rect, sizeof(overlay_rect)))
|
||||
|
||||
if (config_get_array(conf, overlay_rect_key,
|
||||
overlay_rect, sizeof(overlay_rect)))
|
||||
{
|
||||
struct string_list *list = string_split(overlay_rect, ", ");
|
||||
if (list->size < 4)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n", overlay_rect);
|
||||
RARCH_ERR("[Overlay]: Failed to split rect \"%s\" into at least four tokens.\n",
|
||||
overlay_rect);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -399,11 +425,14 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
|
||||
unsigned descs = 0;
|
||||
if (!config_get_uint(conf, overlay_descs_key, &descs))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n", overlay_descs_key);
|
||||
RARCH_ERR("[Overlay]: Failed to read number of descs from config key: %s.\n",
|
||||
overlay_descs_key);
|
||||
return false;
|
||||
}
|
||||
|
||||
overlay->descs = (struct overlay_desc*)calloc(descs, sizeof(*overlay->descs));
|
||||
overlay->descs = (struct overlay_desc*)
|
||||
calloc(descs, sizeof(*overlay->descs));
|
||||
|
||||
if (!overlay->descs)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to allocate descs.\n");
|
||||
@ -432,13 +461,16 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
|
||||
overlay->image.width, overlay->image.height,
|
||||
normalized, alpha_mod, range_mod))
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n", (unsigned)i);
|
||||
RARCH_ERR("[Overlay]: Failed to load overlay descs for overlay #%u.\n",
|
||||
(unsigned)i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Precache load image array for simplicity.
|
||||
overlay->load_images = (struct texture_image*)calloc(1 + overlay->size, sizeof(struct texture_image));
|
||||
/* Precache load image array for simplicity. */
|
||||
overlay->load_images = (struct texture_image*)
|
||||
calloc(1 + overlay->size, sizeof(struct texture_image));
|
||||
|
||||
if (!overlay->load_images)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Failed to allocate load_images.\n");
|
||||
@ -457,8 +489,8 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
|
||||
}
|
||||
}
|
||||
|
||||
// Assume for now that scaling center is in the middle.
|
||||
// TODO: Make this configurable.
|
||||
/* Assume for now that scaling center is in the middle.
|
||||
* TODO: Make this configurable. */
|
||||
overlay->block_scale = false;
|
||||
overlay->center_x = overlay->x + 0.5f * overlay->w;
|
||||
overlay->center_y = overlay->y + 0.5f * overlay->h;
|
||||
@ -466,7 +498,8 @@ static bool input_overlay_load_overlay(input_overlay_t *ol, config_file_t *conf,
|
||||
return true;
|
||||
}
|
||||
|
||||
static ssize_t input_overlay_find_index(const struct overlay *ol, const char *name, size_t size)
|
||||
static ssize_t input_overlay_find_index(const struct overlay *ol,
|
||||
const char *name, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < size; i++)
|
||||
@ -478,7 +511,8 @@ static ssize_t input_overlay_find_index(const struct overlay *ol, const char *na
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool input_overlay_resolve_targets(struct overlay *ol, size_t index, size_t size)
|
||||
static bool input_overlay_resolve_targets(struct overlay *ol,
|
||||
size_t index, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
struct overlay *current = &ol[index];
|
||||
@ -491,7 +525,8 @@ static bool input_overlay_resolve_targets(struct overlay *ol, size_t index, size
|
||||
ssize_t index = input_overlay_find_index(ol, next, size);
|
||||
if (index < 0)
|
||||
{
|
||||
RARCH_ERR("[Overlay]: Couldn't find overlay called: \"%s\".\n", next);
|
||||
RARCH_ERR("[Overlay]: Couldn't find overlay called: \"%s\".\n",
|
||||
next);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -565,7 +600,8 @@ end:
|
||||
|
||||
static void input_overlay_load_active(input_overlay_t *ol)
|
||||
{
|
||||
ol->iface->load(ol->iface_data, ol->active->load_images, ol->active->load_images_size);
|
||||
ol->iface->load(ol->iface_data, ol->active->load_images,
|
||||
ol->active->load_images_size);
|
||||
|
||||
input_overlay_set_alpha_mod(ol, g_settings.input.overlay_opacity);
|
||||
input_overlay_set_vertex_geom(ol);
|
||||
@ -631,7 +667,7 @@ static bool inside_hitbox(const struct overlay_desc *desc, float x, float y)
|
||||
{
|
||||
case OVERLAY_HITBOX_RADIAL:
|
||||
{
|
||||
// Ellipsis.
|
||||
/* Ellipsis. */
|
||||
float x_dist = (x - desc->x) / desc->range_x_mod;
|
||||
float y_dist = (y - desc->y) / desc->range_y_mod;
|
||||
float sq_dist = x_dist * x_dist + y_dist * y_dist;
|
||||
@ -657,7 +693,8 @@ static inline float clamp(float val, float lower, float upper)
|
||||
return val;
|
||||
}
|
||||
|
||||
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y)
|
||||
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out,
|
||||
int16_t norm_x, int16_t norm_y)
|
||||
{
|
||||
size_t i;
|
||||
memset(out, 0, sizeof(*out));
|
||||
@ -668,7 +705,8 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t
|
||||
return;
|
||||
}
|
||||
|
||||
// norm_x and norm_y is in [-0x7fff, 0x7fff] range, like RETRO_DEVICE_POINTER.
|
||||
/* norm_x and norm_y is in [-0x7fff, 0x7fff] range,
|
||||
* like RETRO_DEVICE_POINTER. */
|
||||
float x = (float)(norm_x + 0x7fff) / 0xffff;
|
||||
float y = (float)(norm_y + 0x7fff) / 0xffff;
|
||||
|
||||
@ -716,8 +754,10 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t
|
||||
{
|
||||
float x_dist = x - desc->x;
|
||||
float y_dist = y - desc->y;
|
||||
desc->delta_x = clamp(x_dist, -desc->range_x, desc->range_x) * ol->active->mod_w;
|
||||
desc->delta_y = clamp(y_dist, -desc->range_y, desc->range_y) * ol->active->mod_h;
|
||||
desc->delta_x = clamp(x_dist, -desc->range_x, desc->range_x)
|
||||
* ol->active->mod_w;
|
||||
desc->delta_y = clamp(y_dist, -desc->range_y, desc->range_y)
|
||||
* ol->active->mod_h;
|
||||
}
|
||||
}
|
||||
|
||||
@ -727,7 +767,8 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t
|
||||
memset(out, 0, sizeof(*out));
|
||||
}
|
||||
|
||||
static void input_overlay_update_desc_geom(input_overlay_t *ol, struct overlay_desc *desc)
|
||||
static void input_overlay_update_desc_geom(input_overlay_t *ol,
|
||||
struct overlay_desc *desc)
|
||||
{
|
||||
if (desc->image.pixels && desc->movable)
|
||||
{
|
||||
@ -752,7 +793,7 @@ void input_overlay_post_poll(input_overlay_t *ol)
|
||||
|
||||
if (desc->updated)
|
||||
{
|
||||
// If pressed this frame, change the hitbox.
|
||||
/* If pressed this frame, change the hitbox. */
|
||||
desc->range_x_mod = desc->range_x * desc->range_mod;
|
||||
desc->range_y_mod = desc->range_y * desc->range_mod;
|
||||
|
||||
@ -826,6 +867,7 @@ void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < ol->active->load_images_size; i++)
|
||||
ol->iface->set_alpha(ol->iface_data, i, g_settings.input.overlay_opacity);
|
||||
ol->iface->set_alpha(ol->iface_data, i,
|
||||
g_settings.input.overlay_opacity);
|
||||
}
|
||||
|
||||
|
@ -24,17 +24,20 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Overlay driver acts as a medium between input drivers and video driver.
|
||||
// Coordinates are fetched from input driver, and an overlay with pressable actions are
|
||||
// displayed on-screen.
|
||||
//
|
||||
// This interface requires that the video driver has support for the overlay interface.
|
||||
/* Overlay driver acts as a medium between input drivers and video driver.
|
||||
* Coordinates are fetched from input driver, and an overlay with pressable actions are
|
||||
* displayed on-screen.
|
||||
*
|
||||
* This interface requires that the video driver has support for the overlay interface.
|
||||
*/
|
||||
typedef struct input_overlay input_overlay_t;
|
||||
|
||||
typedef struct input_overlay_state
|
||||
{
|
||||
uint64_t buttons; // This is a bitmask of (1 << key_bind_id).
|
||||
int16_t analog[4]; // Left X, Left Y, Right X, Right Y
|
||||
/* This is a bitmask of (1 << key_bind_id). */
|
||||
uint64_t buttons;
|
||||
/* Left X, Left Y, Right X, Right Y */
|
||||
int16_t analog[4];
|
||||
uint32_t keys[RETROK_LAST / 32 + 1];
|
||||
} input_overlay_state_t;
|
||||
|
||||
@ -49,20 +52,25 @@ void input_overlay_enable(input_overlay_t *ol, bool enable);
|
||||
|
||||
bool input_overlay_full_screen(input_overlay_t *ol);
|
||||
|
||||
// norm_x and norm_y are the result of input_translate_coord_viewport().
|
||||
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y);
|
||||
/* norm_x and norm_y are the result of
|
||||
* input_translate_coord_viewport(). */
|
||||
void input_overlay_poll(input_overlay_t *ol,
|
||||
input_overlay_state_t *out, int16_t norm_x, int16_t norm_y);
|
||||
|
||||
// called after all the input_overlay_poll calls to update the range modifiers for pressed/unpressed regions and alpha mods
|
||||
/* called after all the input_overlay_poll calls to
|
||||
* update the range modifiers for pressed/unpressed regions
|
||||
* and alpha mods */
|
||||
void input_overlay_post_poll(input_overlay_t *ol);
|
||||
|
||||
// Call when there is nothing to poll. Allows overlay to clear certain state.
|
||||
/* Call when there is nothing to poll. Allows overlay to
|
||||
* clear certain state. */
|
||||
void input_overlay_poll_clear(input_overlay_t *ol);
|
||||
|
||||
// Sets a modulating factor for alpha channel. Default is 1.0.
|
||||
// The alpha factor is applied for all overlays.
|
||||
/* Sets a modulating factor for alpha channel. Default is 1.0.
|
||||
* The alpha factor is applied for all overlays. */
|
||||
void input_overlay_set_alpha_mod(input_overlay_t *ol, float mod);
|
||||
|
||||
// Scales the overlay by a factor of scale.
|
||||
/* Scales the overlay by a factor of scale. */
|
||||
void input_overlay_set_scale_factor(input_overlay_t *ol, float scale);
|
||||
|
||||
void input_overlay_next(input_overlay_t *ol);
|
||||
|
Loading…
x
Reference in New Issue
Block a user