Start moving callback functions to their dedicated files

This commit is contained in:
twinaphex 2018-04-09 03:48:08 +02:00
parent be5057eafc
commit 4db665130c
4 changed files with 389 additions and 337 deletions

View File

@ -35,6 +35,9 @@
#include "../../core_info.h"
#include "../../managers/cheat_manager.h"
#include "../../file_path_special.h"
#include "../../driver.h"
#include "../../audio/audio_driver.h"
#include "../../gfx/video_driver.h"
#include "../../retroarch.h"
#include "../../network/netplay/netplay.h"
@ -48,6 +51,254 @@
extern struct key_desc key_descriptors[RARCH_MAX_KEYS];
int setting_action_left_analog_dpad_mode(void *data, bool wraparound)
{
unsigned port = 0;
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
if (!setting)
return -1;
port = setting->index_offset;
configuration_set_uint(settings, settings->uints.input_analog_dpad_mode[port],
(settings->uints.input_analog_dpad_mode
[port] + ANALOG_DPAD_LAST - 1) % ANALOG_DPAD_LAST);
return 0;
}
int setting_action_left_libretro_device_type(
void *data, bool wraparound)
{
retro_ctx_controller_info_t pad;
unsigned current_device, current_idx, i, devices[128],
types = 0, port = 0;
const struct retro_controller_info *desc = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data;
rarch_system_info_t *system = NULL;
if (!setting)
return -1;
port = setting->index_offset;
devices[types++] = RETRO_DEVICE_NONE;
devices[types++] = RETRO_DEVICE_JOYPAD;
system = runloop_get_system_info();
if (system)
{
/* Only push RETRO_DEVICE_ANALOG as default if we use an
* older core which doesn't use SET_CONTROLLER_INFO. */
if (!system->ports.size)
devices[types++] = RETRO_DEVICE_ANALOG;
if (port < system->ports.size)
desc = &system->ports.data[port];
}
if (desc)
{
for (i = 0; i < desc->num_types; i++)
{
unsigned id = desc->types[i].id;
if (types < ARRAY_SIZE(devices) &&
id != RETRO_DEVICE_NONE &&
id != RETRO_DEVICE_JOYPAD)
devices[types++] = id;
}
}
current_device = input_config_get_device(port);
current_idx = 0;
for (i = 0; i < types; i++)
{
if (current_device != devices[i])
continue;
current_idx = i;
break;
}
current_device = devices
[(current_idx + types - 1) % types];
input_config_set_device(port, current_device);
pad.port = port;
pad.device = current_device;
core_set_controller_port_device(&pad);
return 0;
}
int setting_action_left_bind_device(void *data, bool wraparound)
{
unsigned *p = NULL;
unsigned index_offset = 0;
unsigned max_devices = input_config_get_device_count();
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
if (!setting || max_devices == 0)
return -1;
index_offset = setting->index_offset;
p = &settings->uints.input_joypad_map[index_offset];
if ((*p) >= max_devices)
*p = max_devices - 1;
else if ((*p) > 0)
(*p)--;
return 0;
}
int setting_action_left_mouse_index(void *data, bool wraparound)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
if (!setting)
return -1;
if (settings->uints.input_mouse_index[setting->index_offset])
{
--settings->uints.input_mouse_index[setting->index_offset];
settings->modified = true;
}
return 0;
}
int setting_uint_action_left_custom_viewport_width(
void *data, bool wraparound)
{
video_viewport_t vp;
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
video_viewport_t *custom = video_viewport_get_custom();
settings_t *settings = config_get_ptr();
struct retro_game_geometry *geom = (struct retro_game_geometry*)
&av_info->geometry;
if (!settings || !av_info)
return -1;
video_driver_get_viewport_info(&vp);
if (custom->width <= 1)
custom->width = 1;
else if (settings->bools.video_scale_integer)
{
if (custom->width > geom->base_width)
custom->width -= geom->base_width;
}
else
custom->width -= 1;
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
return 0;
}
int setting_uint_action_left_custom_viewport_height(
void *data, bool wraparound)
{
video_viewport_t vp;
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
video_viewport_t *custom = video_viewport_get_custom();
settings_t *settings = config_get_ptr();
struct retro_game_geometry *geom = (struct retro_game_geometry*)
&av_info->geometry;
if (!settings || !av_info)
return -1;
video_driver_get_viewport_info(&vp);
if (custom->height <= 1)
custom->height = 1;
else if (settings->bools.video_scale_integer)
{
if (custom->height > geom->base_height)
custom->height -= geom->base_height;
}
else
custom->height -= 1;
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
return 0;
}
int setting_string_action_left_audio_device(
void *data, bool wraparound)
{
#if !defined(RARCH_CONSOLE)
int audio_device_index;
struct string_list *ptr = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!audio_driver_get_devices_list((void**)&ptr))
return -1;
if (!ptr)
return -1;
/* Get index in the string list */
audio_device_index = string_list_find_elem(
ptr, setting->value.target.string) - 1;
audio_device_index--;
/* Reset index if needed */
if (audio_device_index < 0)
audio_device_index = (int)(ptr->size - 1);
strlcpy(setting->value.target.string, ptr->elems[audio_device_index].data, setting->size);
#endif
return 0;
}
int setting_string_action_left_driver(void *data,
bool wraparound)
{
driver_ctx_info_t drv;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return -1;
drv.label = setting->name;
drv.s = setting->value.target.string;
drv.len = setting->size;
if (!driver_ctl(RARCH_DRIVER_CTL_FIND_PREV, &drv))
{
settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_navigation_wraparound_enable)
{
drv.label = setting->name;
drv.s = setting->value.target.string;
drv.len = setting->size;
driver_ctl(RARCH_DRIVER_CTL_FIND_LAST, &drv);
}
}
if (setting->change_handler)
setting->change_handler(setting);
return 0;
}
static int generic_shader_action_parameter_left(
struct video_shader_parameter *param,
unsigned type, const char *label, bool wraparound)

View File

@ -26,13 +26,21 @@
#include "../../config.h"
#endif
#include "../../config.def.h"
#include "../../config.def.keybinds.h"
#include "../../wifi/wifi_driver.h"
#include "../../driver.h"
#include "../menu_driver.h"
#include "../menu_cbs.h"
#include "../menu_setting.h"
#include "../menu_shader.h"
#include "../widgets/menu_dialog.h"
#include "../widgets/menu_entry.h"
#include "../widgets/menu_filebrowser.h"
#include "../widgets/menu_input_dialog.h"
#include "../widgets/menu_input_bind_dialog.h"
#include "../menu_input.h"
#include "../menu_networking.h"
#include "../menu_content.h"
#include "../menu_shader.h"
@ -121,6 +129,99 @@ static char *lakka_get_project(void)
info.enum_idx = a; \
dl_type = b;
int setting_action_ok_video_refresh_rate_auto(void *data, bool wraparound)
{
double video_refresh_rate = 0.0;
double deviation = 0.0;
unsigned sample_points = 0;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return -1;
if (video_monitor_fps_statistics(&video_refresh_rate,
&deviation, &sample_points))
{
float video_refresh_rate_float = (float)video_refresh_rate;
driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &video_refresh_rate_float);
/* Incase refresh rate update forced non-block video. */
command_event(CMD_EVENT_VIDEO_SET_BLOCKING_STATE, NULL);
}
if (setting_generic_action_ok_default(setting, wraparound) != 0)
return -1;
return 0;
}
int setting_action_ok_bind_all(void *data, bool wraparound)
{
(void)wraparound;
if (!menu_input_key_bind_set_mode(MENU_INPUT_BINDS_CTL_BIND_ALL, data))
return -1;
return 0;
}
int setting_action_ok_bind_all_save_autoconfig(void *data,
bool wraparound)
{
unsigned index_offset;
rarch_setting_t *setting = (rarch_setting_t*)data;
const char *name = NULL;
(void)wraparound;
if (!setting)
return -1;
index_offset = setting->index_offset;
name = input_config_get_device_name(index_offset);
if(!string_is_empty(name) && config_save_autoconf_profile(name, index_offset))
runloop_msg_queue_push(
msg_hash_to_str(MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY), 1, 100, true);
else
runloop_msg_queue_push(
msg_hash_to_str(MSG_AUTOCONFIG_FILE_ERROR_SAVING), 1, 100, true);
return 0;
}
int setting_action_ok_bind_defaults(void *data, bool wraparound)
{
unsigned i;
menu_input_ctx_bind_limits_t lim;
struct retro_keybind *target = NULL;
const struct retro_keybind *def_binds = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data;
(void)wraparound;
if (!setting)
return -1;
target = &input_config_binds[setting->index_offset][0];
def_binds = (setting->index_offset) ?
retro_keybinds_rest : retro_keybinds_1;
lim.min = MENU_SETTINGS_BIND_BEGIN;
lim.max = MENU_SETTINGS_BIND_LAST;
menu_input_key_bind_set_min_max(&lim);
for (i = MENU_SETTINGS_BIND_BEGIN;
i <= MENU_SETTINGS_BIND_LAST; i++, target++)
{
target->key = def_binds[i - MENU_SETTINGS_BIND_BEGIN].key;
target->joykey = NO_BTN;
target->joyaxis = AXIS_NONE;
target->mbutton = NO_BTN;
}
return 0;
}
static enum msg_hash_enums action_ok_dl_to_enum(unsigned lbl)
{
switch (lbl)

View File

@ -161,6 +161,36 @@ int action_right_input_desc_kbd(unsigned type, const char *label,
int action_right_cheat(unsigned type, const char *label,
bool wraparound);
int setting_action_ok_video_refresh_rate_auto(void *data, bool wraparound);
int setting_action_ok_bind_all(void *data, bool wraparound);
int setting_action_ok_bind_all_save_autoconfig(void *data,
bool wraparound);
int setting_action_ok_bind_defaults(void *data, bool wraparound);
int setting_action_left_analog_dpad_mode(void *data, bool wraparound);
int setting_action_left_libretro_device_type(
void *data, bool wraparound);
int setting_action_left_bind_device(void *data, bool wraparound);
int setting_action_left_mouse_index(void *data, bool wraparound);
int setting_uint_action_left_custom_viewport_width(
void *data, bool wraparound);
int setting_uint_action_left_custom_viewport_height(
void *data, bool wraparound);
int setting_string_action_left_driver(void *data,
bool wraparound);
int setting_string_action_left_audio_device(
void *data, bool wraparound);
/* End of function callbacks */
int menu_cbs_init_bind_left(menu_file_list_cbs_t *cbs,

View File

@ -55,6 +55,7 @@
#include "widgets/menu_input_bind_dialog.h"
#include "menu_setting.h"
#include "menu_cbs.h"
#include "menu_driver.h"
#include "menu_animation.h"
#include "menu_input.h"
@ -234,37 +235,8 @@ static void setting_get_string_representation_int_audio_wasapi_sh_buffer_length(
}
#endif
static int setting_uint_action_left_custom_viewport_width(void *data, bool wraparound)
{
video_viewport_t vp;
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
video_viewport_t *custom = video_viewport_get_custom();
settings_t *settings = config_get_ptr();
struct retro_game_geometry *geom = (struct retro_game_geometry*)
&av_info->geometry;
if (!settings || !av_info)
return -1;
video_driver_get_viewport_info(&vp);
if (custom->width <= 1)
custom->width = 1;
else if (settings->bools.video_scale_integer)
{
if (custom->width > geom->base_width)
custom->width -= geom->base_width;
}
else
custom->width -= 1;
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
return 0;
}
static int setting_uint_action_right_custom_viewport_width(void *data, bool wraparound)
static int setting_uint_action_right_custom_viewport_width(
void *data, bool wraparound)
{
video_viewport_t vp;
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
@ -289,37 +261,8 @@ static int setting_uint_action_right_custom_viewport_width(void *data, bool wrap
return 0;
}
static int setting_uint_action_left_custom_viewport_height(void *data, bool wraparound)
{
video_viewport_t vp;
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
video_viewport_t *custom = video_viewport_get_custom();
settings_t *settings = config_get_ptr();
struct retro_game_geometry *geom = (struct retro_game_geometry*)
&av_info->geometry;
if (!settings || !av_info)
return -1;
video_driver_get_viewport_info(&vp);
if (custom->height <= 1)
custom->height = 1;
else if (settings->bools.video_scale_integer)
{
if (custom->height > geom->base_height)
custom->height -= geom->base_height;
}
else
custom->height -= 1;
aspectratio_lut[ASPECT_RATIO_CUSTOM].value =
(float)custom->width / custom->height;
return 0;
}
static int setting_uint_action_right_custom_viewport_height(void *data, bool wraparound)
static int setting_uint_action_right_custom_viewport_height(
void *data, bool wraparound)
{
video_viewport_t vp;
struct retro_system_av_info *av_info = video_viewport_get_system_av_info();
@ -345,32 +288,8 @@ static int setting_uint_action_right_custom_viewport_height(void *data, bool wra
}
#if !defined(RARCH_CONSOLE)
static int setting_string_action_left_audio_device(void *data, bool wraparound)
{
int audio_device_index;
struct string_list *ptr = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!audio_driver_get_devices_list((void**)&ptr))
return -1;
if (!ptr)
return -1;
/* Get index in the string list */
audio_device_index = string_list_find_elem(ptr,setting->value.target.string) - 1;
audio_device_index--;
/* Reset index if needed */
if (audio_device_index < 0)
audio_device_index = (int)(ptr->size - 1);
strlcpy(setting->value.target.string, ptr->elems[audio_device_index].data, setting->size);
return 0;
}
static int setting_string_action_right_audio_device(void *data, bool wraparound)
static int setting_string_action_right_audio_device(
void *data, bool wraparound)
{
int audio_device_index;
struct string_list *ptr = NULL;
@ -396,38 +315,6 @@ static int setting_string_action_right_audio_device(void *data, bool wraparound)
}
#endif
static int setting_string_action_left_driver(void *data,
bool wraparound)
{
driver_ctx_info_t drv;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return -1;
drv.label = setting->name;
drv.s = setting->value.target.string;
drv.len = setting->size;
if (!driver_ctl(RARCH_DRIVER_CTL_FIND_PREV, &drv))
{
settings_t *settings = config_get_ptr();
if (settings && settings->bools.menu_navigation_wraparound_enable)
{
drv.label = setting->name;
drv.s = setting->value.target.string;
drv.len = setting->size;
driver_ctl(RARCH_DRIVER_CTL_FIND_LAST, &drv);
}
}
if (setting->change_handler)
setting->change_handler(setting);
return 0;
}
static int setting_string_action_right_driver(void *data,
bool wraparound)
{
@ -1145,24 +1032,6 @@ static int setting_action_start_video_refresh_rate_auto(
******* ACTION TOGGLE CALLBACK FUNCTIONS *******
**/
static int setting_action_left_analog_dpad_mode(void *data, bool wraparound)
{
unsigned port = 0;
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
if (!setting)
return -1;
port = setting->index_offset;
configuration_set_uint(settings, settings->uints.input_analog_dpad_mode[port],
(settings->uints.input_analog_dpad_mode
[port] + ANALOG_DPAD_LAST - 1) % ANALOG_DPAD_LAST);
return 0;
}
static int setting_action_right_analog_dpad_mode(void *data, bool wraparound)
{
unsigned port = 0;
@ -1182,73 +1051,6 @@ static int setting_action_right_analog_dpad_mode(void *data, bool wraparound)
return 0;
}
static int setting_action_left_libretro_device_type(
void *data, bool wraparound)
{
retro_ctx_controller_info_t pad;
unsigned current_device, current_idx, i, devices[128],
types = 0, port = 0;
const struct retro_controller_info *desc = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data;
rarch_system_info_t *system = NULL;
if (!setting)
return -1;
port = setting->index_offset;
devices[types++] = RETRO_DEVICE_NONE;
devices[types++] = RETRO_DEVICE_JOYPAD;
system = runloop_get_system_info();
if (system)
{
/* Only push RETRO_DEVICE_ANALOG as default if we use an
* older core which doesn't use SET_CONTROLLER_INFO. */
if (!system->ports.size)
devices[types++] = RETRO_DEVICE_ANALOG;
if (port < system->ports.size)
desc = &system->ports.data[port];
}
if (desc)
{
for (i = 0; i < desc->num_types; i++)
{
unsigned id = desc->types[i].id;
if (types < ARRAY_SIZE(devices) &&
id != RETRO_DEVICE_NONE &&
id != RETRO_DEVICE_JOYPAD)
devices[types++] = id;
}
}
current_device = input_config_get_device(port);
current_idx = 0;
for (i = 0; i < types; i++)
{
if (current_device != devices[i])
continue;
current_idx = i;
break;
}
current_device = devices
[(current_idx + types - 1) % types];
input_config_set_device(port, current_device);
pad.port = port;
pad.device = current_device;
core_set_controller_port_device(&pad);
return 0;
}
static int setting_action_right_libretro_device_type(
void *data, bool wraparound)
{
@ -1314,29 +1116,6 @@ static int setting_action_right_libretro_device_type(
return 0;
}
static int setting_action_left_bind_device(void *data, bool wraparound)
{
unsigned *p = NULL;
unsigned index_offset = 0;
unsigned max_devices = input_config_get_device_count();
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
if (!setting || max_devices == 0)
return -1;
index_offset = setting->index_offset;
p = &settings->uints.input_joypad_map[index_offset];
if ((*p) >= max_devices)
*p = max_devices - 1;
else if ((*p) > 0)
(*p)--;
return 0;
}
static int setting_action_right_bind_device(void *data, bool wraparound)
{
unsigned index_offset;
@ -1358,23 +1137,6 @@ static int setting_action_right_bind_device(void *data, bool wraparound)
return 0;
}
static int setting_action_left_mouse_index(void *data, bool wraparound)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
settings_t *settings = config_get_ptr();
if (!setting)
return -1;
if (settings->uints.input_mouse_index[setting->index_offset])
{
--settings->uints.input_mouse_index[setting->index_offset];
settings->modified = true;
}
return 0;
}
static int setting_action_right_mouse_index(void *data, bool wraparound)
{
rarch_setting_t *setting = (rarch_setting_t*)data;
@ -1393,73 +1155,6 @@ static int setting_action_right_mouse_index(void *data, bool wraparound)
******* ACTION OK CALLBACK FUNCTIONS *******
**/
static int setting_action_ok_bind_all(void *data, bool wraparound)
{
(void)wraparound;
if (!menu_input_key_bind_set_mode(MENU_INPUT_BINDS_CTL_BIND_ALL, data))
return -1;
return 0;
}
static int setting_action_ok_bind_all_save_autoconfig(void *data, bool wraparound)
{
unsigned index_offset;
rarch_setting_t *setting = (rarch_setting_t*)data;
const char *name = NULL;
(void)wraparound;
if (!setting)
return -1;
index_offset = setting->index_offset;
name = input_config_get_device_name(index_offset);
if(!string_is_empty(name) && config_save_autoconf_profile(name, index_offset))
runloop_msg_queue_push(
msg_hash_to_str(MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY), 1, 100, true);
else
runloop_msg_queue_push(
msg_hash_to_str(MSG_AUTOCONFIG_FILE_ERROR_SAVING), 1, 100, true);
return 0;
}
static int setting_action_ok_bind_defaults(void *data, bool wraparound)
{
unsigned i;
menu_input_ctx_bind_limits_t lim;
struct retro_keybind *target = NULL;
const struct retro_keybind *def_binds = NULL;
rarch_setting_t *setting = (rarch_setting_t*)data;
(void)wraparound;
if (!setting)
return -1;
target = &input_config_binds[setting->index_offset][0];
def_binds = (setting->index_offset) ?
retro_keybinds_rest : retro_keybinds_1;
lim.min = MENU_SETTINGS_BIND_BEGIN;
lim.max = MENU_SETTINGS_BIND_LAST;
menu_input_key_bind_set_min_max(&lim);
for (i = MENU_SETTINGS_BIND_BEGIN;
i <= MENU_SETTINGS_BIND_LAST; i++, target++)
{
target->key = def_binds[i - MENU_SETTINGS_BIND_BEGIN].key;
target->joykey = NO_BTN;
target->joyaxis = AXIS_NONE;
target->mbutton = NO_BTN;
}
return 0;
}
static void
setting_get_string_representation_st_float_video_refresh_rate_auto(
void *data, char *s, size_t len)
@ -1482,31 +1177,6 @@ setting_get_string_representation_st_float_video_refresh_rate_auto(
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE), len);
}
static int setting_action_ok_video_refresh_rate_auto(void *data, bool wraparound)
{
double video_refresh_rate = 0.0;
double deviation = 0.0;
unsigned sample_points = 0;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return -1;
if (video_monitor_fps_statistics(&video_refresh_rate,
&deviation, &sample_points))
{
float video_refresh_rate_float = (float)video_refresh_rate;
driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &video_refresh_rate_float);
/* Incase refresh rate update forced non-block video. */
command_event(CMD_EVENT_VIDEO_SET_BLOCKING_STATE, NULL);
}
if (setting_generic_action_ok_default(setting, wraparound) != 0)
return -1;
return 0;
}
static void get_string_representation_bind_device(void * data, char *s,
size_t len)
{