(Menu) Create setting_data_get_label and move code from menu_common_backend.c

to settings_data.c
This commit is contained in:
twinaphex 2014-09-07 06:00:41 +02:00
parent ff01041e7c
commit 88b77df234
3 changed files with 381 additions and 369 deletions

View File

@ -1908,379 +1908,12 @@ static int menu_common_iterate(unsigned action)
return ret;
}
#ifdef GEKKO
static unsigned menu_gx_resolutions[GX_RESOLUTIONS_LAST][2] = {
{ 512, 192 },
{ 598, 200 },
{ 640, 200 },
{ 384, 224 },
{ 448, 224 },
{ 480, 224 },
{ 512, 224 },
{ 576, 224 },
{ 608, 224 },
{ 640, 224 },
{ 340, 232 },
{ 512, 232 },
{ 512, 236 },
{ 336, 240 },
{ 352, 240 },
{ 384, 240 },
{ 512, 240 },
{ 530, 240 },
{ 640, 240 },
{ 512, 384 },
{ 598, 400 },
{ 640, 400 },
{ 384, 448 },
{ 448, 448 },
{ 480, 448 },
{ 512, 448 },
{ 576, 448 },
{ 608, 448 },
{ 640, 448 },
{ 340, 464 },
{ 512, 464 },
{ 512, 472 },
{ 352, 480 },
{ 384, 480 },
{ 512, 480 },
{ 530, 480 },
{ 608, 480 },
{ 640, 480 },
};
static unsigned menu_current_gx_resolution = GX_RESOLUTIONS_640_480;
#endif
static void menu_common_setting_set_label_perf(char *type_str,
size_t type_str_size, unsigned *w, unsigned type,
const struct retro_perf_counter **counters, unsigned offset)
{
if (counters[offset] && counters[offset]->call_cnt)
{
snprintf(type_str, type_str_size,
#ifdef _WIN32
"%I64u ticks, %I64u runs.",
#else
"%llu ticks, %llu runs.",
#endif
((unsigned long long)counters[offset]->total /
(unsigned long long)counters[offset]->call_cnt),
(unsigned long long)counters[offset]->call_cnt);
}
else
{
*type_str = '\0';
*w = 0;
}
}
static void menu_common_setting_set_label_st_bool(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (!strcmp(setting->name, "savestate") ||
!strcmp(setting->name, "loadstate"))
{
if (g_settings.state_slot < 0)
strlcpy(type_str, "-1 (auto)", type_str_size);
else
snprintf(type_str, type_str_size, "%d", g_settings.state_slot);
}
else
strlcpy(type_str, *setting->value.boolean ? setting->boolean.on_label :
setting->boolean.off_label, type_str_size);
}
static void menu_common_setting_set_label_st_float(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (setting && !strcmp(setting->name, "video_refresh_rate_auto"))
{
double refresh_rate = 0.0;
double deviation = 0.0;
unsigned sample_points = 0;
if (driver_monitor_fps_statistics(&refresh_rate, &deviation, &sample_points))
snprintf(type_str, type_str_size, "%.3f Hz (%.1f%% dev, %u samples)",
refresh_rate, 100.0 * deviation, sample_points);
else
strlcpy(type_str, "N/A", type_str_size);
}
else
snprintf(type_str, type_str_size, setting->rounding_fraction,
*setting->value.fraction);
}
static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (setting && !strcmp(setting->name, "video_monitor_index"))
{
if (*setting->value.unsigned_integer)
snprintf(type_str, type_str_size, "%d",
*setting->value.unsigned_integer);
else
strlcpy(type_str, "0 (Auto)", type_str_size);
}
else if (setting && !strcmp(setting->name, "video_rotation"))
strlcpy(type_str, rotation_lut[*setting->value.unsigned_integer],
type_str_size);
else if (setting && !strcmp(setting->name, "aspect_ratio_index"))
strlcpy(type_str,
aspectratio_lut[*setting->value.unsigned_integer].name,
type_str_size);
else if (setting && !strcmp(setting->name, "autosave_interval"))
{
if (*setting->value.unsigned_integer)
snprintf(type_str, type_str_size, "%u seconds",
*setting->value.unsigned_integer);
else
strlcpy(type_str, "OFF", type_str_size);
}
else if (setting && !strcmp(setting->name, "user_language"))
{
static const char *modes[] = {
"English",
"Japanese",
"French",
"Spanish",
"German",
"Italian",
"Dutch",
"Portuguese",
"Russian",
"Korean",
"Chinese (Traditional)",
"Chinese (Simplified)"
};
strlcpy(type_str, modes[g_settings.user_language], type_str_size);
}
else if (setting && !strcmp(setting->name, "libretro_log_level"))
{
static const char *modes[] = {
"0 (Debug)",
"1 (Info)",
"2 (Warning)",
"3 (Error)"
};
strlcpy(type_str, modes[*setting->value.unsigned_integer],
type_str_size);
}
else
snprintf(type_str, type_str_size, "%d",
*setting->value.unsigned_integer);
}
static void handle_setting_label(char *type_str,
size_t type_str_size, rarch_setting_t *setting)
{
if (setting->type == ST_BOOL)
menu_common_setting_set_label_st_bool(setting, type_str, type_str_size);
else if (setting->type == ST_UINT)
menu_common_setting_set_label_st_uint(setting, type_str, type_str_size);
else if (setting->type == ST_FLOAT)
menu_common_setting_set_label_st_float(setting, type_str, type_str_size);
else if (setting->type == ST_DIR)
strlcpy(type_str,
*setting->value.string ?
setting->value.string : setting->dir.empty_path,
type_str_size);
else if (setting->type == ST_PATH)
strlcpy(type_str, path_basename(setting->value.string), type_str_size);
else if (setting->type == ST_STRING)
strlcpy(type_str, setting->value.string, type_str_size);
else if (setting->type == ST_GROUP)
strlcpy(type_str, "...", type_str_size);
}
static void menu_common_setting_set_label(char *type_str,
size_t type_str_size, unsigned *w, unsigned type,
const char *menu_label, const char *label, unsigned index)
{
rarch_setting_t *setting_data = (rarch_setting_t*)setting_data_get_list();
rarch_setting_t *setting = (rarch_setting_t*)setting_data_find_setting(setting_data,
driver.menu->selection_buf->list[index].label);
if ((!strcmp(menu_label, "Shader Options") ||
!strcmp(menu_label, "video_shader_parameters") ||
!strcmp(menu_label, "video_shader_preset_parameters"))
&&
driver.menu_ctx && driver.menu_ctx->backend &&
driver.menu_ctx->backend->shader_manager_get_str
)
{
driver.menu_ctx->backend->shader_manager_get_str(
driver.menu->shader, type_str, type_str_size,
menu_label, label, type);
}
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN
&& type <= MENU_SETTINGS_PERF_COUNTERS_END)
menu_common_setting_set_label_perf(type_str, type_str_size, w, type,
perf_counters_rarch,
type - MENU_SETTINGS_PERF_COUNTERS_BEGIN);
else if (type >= MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN
&& type <= MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_END)
menu_common_setting_set_label_perf(type_str, type_str_size, w, type,
perf_counters_libretro,
type - MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN);
else if (type >= MENU_SETTINGS_BIND_BEGIN &&
type <= MENU_SETTINGS_BIND_ALL_LAST)
{
const struct retro_keybind *auto_bind =
(const struct retro_keybind*)input_get_auto_bind(
driver.menu->current_pad,
type - MENU_SETTINGS_BIND_BEGIN);
input_get_bind_string(type_str,
&g_settings.input.binds[driver.menu->current_pad]
[type - MENU_SETTINGS_BIND_BEGIN], auto_bind, type_str_size);
}
else if (setting)
handle_setting_label(type_str, type_str_size, setting);
else
{
setting_data = (rarch_setting_t*)setting_data_get_mainmenu(true);
setting = (rarch_setting_t*)setting_data_find_setting(setting_data,
driver.menu->selection_buf->list[index].label);
if (setting)
{
if (!strcmp(setting->name, "configurations"))
{
if (*g_extern.config_path)
fill_pathname_base(type_str, g_extern.config_path,
type_str_size);
else
strlcpy(type_str, "<default>", type_str_size);
}
else if (!strcmp(setting->name, "disk_index"))
{
const struct retro_disk_control_callback *control =
(const struct retro_disk_control_callback*)
&g_extern.system.disk_control;
unsigned images = control->get_num_images();
unsigned current = control->get_image_index();
if (current >= images)
strlcpy(type_str, "No Disk", type_str_size);
else
snprintf(type_str, type_str_size, "%u", current + 1);
}
else
handle_setting_label(type_str, type_str_size, setting);
}
else
{
switch (type)
{
#if defined(GEKKO)
case MENU_SETTINGS_VIDEO_RESOLUTION:
strlcpy(type_str, gx_get_video_mode(), type_str_size);
break;
#elif defined(__CELLOS_LV2__)
case MENU_SETTINGS_VIDEO_RESOLUTION:
{
unsigned width = gfx_ctx_get_resolution_width(
g_extern.console.screen.resolutions.list
[g_extern.console.screen.resolutions.current.idx]);
unsigned height = gfx_ctx_get_resolution_height(
g_extern.console.screen.resolutions.list
[g_extern.console.screen.resolutions.current.idx]);
snprintf(type_str, type_str_size, "%ux%u", width, height);
}
break;
#endif
case MENU_SETTINGS_CUSTOM_VIEWPORT:
case MENU_SETTINGS_CUSTOM_BIND_ALL:
case MENU_SETTINGS_CUSTOM_BIND_DEFAULT_ALL:
strlcpy(type_str, "...", type_str_size);
break;
case MENU_SETTINGS_BIND_PLAYER:
snprintf(type_str, type_str_size, "#%u",
driver.menu->current_pad + 1);
break;
case MENU_SETTINGS_BIND_DEVICE:
{
int map = g_settings.input.joypad_map
[driver.menu->current_pad];
if (map >= 0 && map < MAX_PLAYERS)
{
const char *device_name =
g_settings.input.device_names[map];
if (*device_name)
strlcpy(type_str, device_name, type_str_size);
else
snprintf(type_str, type_str_size,
"N/A (port #%d)", map);
}
else
strlcpy(type_str, "Disabled", type_str_size);
}
break;
case MENU_SETTINGS_BIND_ANALOG_MODE:
{
static const char *modes[] = {
"None",
"Left Analog",
"Right Analog",
"Dual Analog",
};
strlcpy(type_str, modes[g_settings.input.analog_dpad_mode
[driver.menu->current_pad] % ANALOG_DPAD_LAST],
type_str_size);
}
break;
case MENU_SETTINGS_BIND_DEVICE_TYPE:
{
const struct retro_controller_description *desc = NULL;
if (driver.menu->current_pad < g_extern.system.num_ports)
desc = libretro_find_controller_description(
&g_extern.system.ports[driver.menu->current_pad],
g_settings.input.libretro_device
[driver.menu->current_pad]);
const char *name = desc ? desc->desc : NULL;
if (!name)
{
/* Find generic name. */
switch (g_settings.input.libretro_device
[driver.menu->current_pad])
{
case RETRO_DEVICE_NONE:
name = "None";
break;
case RETRO_DEVICE_JOYPAD:
name = "RetroPad";
break;
case RETRO_DEVICE_ANALOG:
name = "RetroPad w/ Analog";
break;
default:
name = "Unknown";
break;
}
}
strlcpy(type_str, name, type_str_size);
}
break;
case MENU_SETTINGS_CUSTOM_BIND_MODE:
strlcpy(type_str, driver.menu->bind_mode_keyboard ?
"RetroKeyboard" : "RetroPad", type_str_size);
break;
default:
*type_str = '\0';
*w = 0;
break;
}
}
}
setting_data_get_label(type_str, type_str_size, w,
type, menu_label, label, index);
}
const menu_ctx_driver_backend_t menu_ctx_backend_common = {

View File

@ -1358,6 +1358,381 @@ int setting_data_get_description(const char *label, char *msg,
return 0;
}
#ifdef GEKKO
static unsigned menu_gx_resolutions[GX_RESOLUTIONS_LAST][2] = {
{ 512, 192 },
{ 598, 200 },
{ 640, 200 },
{ 384, 224 },
{ 448, 224 },
{ 480, 224 },
{ 512, 224 },
{ 576, 224 },
{ 608, 224 },
{ 640, 224 },
{ 340, 232 },
{ 512, 232 },
{ 512, 236 },
{ 336, 240 },
{ 352, 240 },
{ 384, 240 },
{ 512, 240 },
{ 530, 240 },
{ 640, 240 },
{ 512, 384 },
{ 598, 400 },
{ 640, 400 },
{ 384, 448 },
{ 448, 448 },
{ 480, 448 },
{ 512, 448 },
{ 576, 448 },
{ 608, 448 },
{ 640, 448 },
{ 340, 464 },
{ 512, 464 },
{ 512, 472 },
{ 352, 480 },
{ 384, 480 },
{ 512, 480 },
{ 530, 480 },
{ 608, 480 },
{ 640, 480 },
};
static unsigned menu_current_gx_resolution = GX_RESOLUTIONS_640_480;
#endif
static void menu_common_setting_set_label_perf(char *type_str,
size_t type_str_size, unsigned *w, unsigned type,
const struct retro_perf_counter **counters, unsigned offset)
{
if (counters[offset] && counters[offset]->call_cnt)
{
snprintf(type_str, type_str_size,
#ifdef _WIN32
"%I64u ticks, %I64u runs.",
#else
"%llu ticks, %llu runs.",
#endif
((unsigned long long)counters[offset]->total /
(unsigned long long)counters[offset]->call_cnt),
(unsigned long long)counters[offset]->call_cnt);
}
else
{
*type_str = '\0';
*w = 0;
}
}
static void menu_common_setting_set_label_st_bool(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (!strcmp(setting->name, "savestate") ||
!strcmp(setting->name, "loadstate"))
{
if (g_settings.state_slot < 0)
strlcpy(type_str, "-1 (auto)", type_str_size);
else
snprintf(type_str, type_str_size, "%d", g_settings.state_slot);
}
else
strlcpy(type_str, *setting->value.boolean ? setting->boolean.on_label :
setting->boolean.off_label, type_str_size);
}
static void menu_common_setting_set_label_st_float(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (setting && !strcmp(setting->name, "video_refresh_rate_auto"))
{
double refresh_rate = 0.0;
double deviation = 0.0;
unsigned sample_points = 0;
if (driver_monitor_fps_statistics(&refresh_rate, &deviation, &sample_points))
snprintf(type_str, type_str_size, "%.3f Hz (%.1f%% dev, %u samples)",
refresh_rate, 100.0 * deviation, sample_points);
else
strlcpy(type_str, "N/A", type_str_size);
}
else
snprintf(type_str, type_str_size, setting->rounding_fraction,
*setting->value.fraction);
}
static void menu_common_setting_set_label_st_uint(rarch_setting_t *setting,
char *type_str, size_t type_str_size)
{
if (setting && !strcmp(setting->name, "video_monitor_index"))
{
if (*setting->value.unsigned_integer)
snprintf(type_str, type_str_size, "%d",
*setting->value.unsigned_integer);
else
strlcpy(type_str, "0 (Auto)", type_str_size);
}
else if (setting && !strcmp(setting->name, "video_rotation"))
strlcpy(type_str, rotation_lut[*setting->value.unsigned_integer],
type_str_size);
else if (setting && !strcmp(setting->name, "aspect_ratio_index"))
strlcpy(type_str,
aspectratio_lut[*setting->value.unsigned_integer].name,
type_str_size);
else if (setting && !strcmp(setting->name, "autosave_interval"))
{
if (*setting->value.unsigned_integer)
snprintf(type_str, type_str_size, "%u seconds",
*setting->value.unsigned_integer);
else
strlcpy(type_str, "OFF", type_str_size);
}
else if (setting && !strcmp(setting->name, "user_language"))
{
static const char *modes[] = {
"English",
"Japanese",
"French",
"Spanish",
"German",
"Italian",
"Dutch",
"Portuguese",
"Russian",
"Korean",
"Chinese (Traditional)",
"Chinese (Simplified)"
};
strlcpy(type_str, modes[g_settings.user_language], type_str_size);
}
else if (setting && !strcmp(setting->name, "libretro_log_level"))
{
static const char *modes[] = {
"0 (Debug)",
"1 (Info)",
"2 (Warning)",
"3 (Error)"
};
strlcpy(type_str, modes[*setting->value.unsigned_integer],
type_str_size);
}
else
snprintf(type_str, type_str_size, "%d",
*setting->value.unsigned_integer);
}
static void handle_setting_label(char *type_str,
size_t type_str_size, rarch_setting_t *setting)
{
if (setting->type == ST_BOOL)
menu_common_setting_set_label_st_bool(setting, type_str, type_str_size);
else if (setting->type == ST_UINT)
menu_common_setting_set_label_st_uint(setting, type_str, type_str_size);
else if (setting->type == ST_FLOAT)
menu_common_setting_set_label_st_float(setting, type_str, type_str_size);
else if (setting->type == ST_DIR)
strlcpy(type_str,
*setting->value.string ?
setting->value.string : setting->dir.empty_path,
type_str_size);
else if (setting->type == ST_PATH)
strlcpy(type_str, path_basename(setting->value.string), type_str_size);
else if (setting->type == ST_STRING)
strlcpy(type_str, setting->value.string, type_str_size);
else if (setting->type == ST_GROUP)
strlcpy(type_str, "...", type_str_size);
}
void setting_data_get_label(char *type_str,
size_t type_str_size, unsigned *w, unsigned type,
const char *menu_label, const char *label, unsigned index)
{
rarch_setting_t *setting_data = (rarch_setting_t*)setting_data_get_list();
rarch_setting_t *setting = (rarch_setting_t*)setting_data_find_setting(setting_data,
driver.menu->selection_buf->list[index].label);
if ((!strcmp(menu_label, "Shader Options") ||
!strcmp(menu_label, "video_shader_parameters") ||
!strcmp(menu_label, "video_shader_preset_parameters"))
&&
driver.menu_ctx && driver.menu_ctx->backend &&
driver.menu_ctx->backend->shader_manager_get_str
)
{
driver.menu_ctx->backend->shader_manager_get_str(
driver.menu->shader, type_str, type_str_size,
menu_label, label, type);
}
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN
&& type <= MENU_SETTINGS_PERF_COUNTERS_END)
menu_common_setting_set_label_perf(type_str, type_str_size, w, type,
perf_counters_rarch,
type - MENU_SETTINGS_PERF_COUNTERS_BEGIN);
else if (type >= MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN
&& type <= MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_END)
menu_common_setting_set_label_perf(type_str, type_str_size, w, type,
perf_counters_libretro,
type - MENU_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN);
else if (type >= MENU_SETTINGS_BIND_BEGIN &&
type <= MENU_SETTINGS_BIND_ALL_LAST)
{
const struct retro_keybind *auto_bind =
(const struct retro_keybind*)input_get_auto_bind(
driver.menu->current_pad,
type - MENU_SETTINGS_BIND_BEGIN);
input_get_bind_string(type_str,
&g_settings.input.binds[driver.menu->current_pad]
[type - MENU_SETTINGS_BIND_BEGIN], auto_bind, type_str_size);
}
else if (setting)
handle_setting_label(type_str, type_str_size, setting);
else
{
setting_data = (rarch_setting_t*)setting_data_get_mainmenu(true);
setting = (rarch_setting_t*)setting_data_find_setting(setting_data,
driver.menu->selection_buf->list[index].label);
if (setting)
{
if (!strcmp(setting->name, "configurations"))
{
if (*g_extern.config_path)
fill_pathname_base(type_str, g_extern.config_path,
type_str_size);
else
strlcpy(type_str, "<default>", type_str_size);
}
else if (!strcmp(setting->name, "disk_index"))
{
const struct retro_disk_control_callback *control =
(const struct retro_disk_control_callback*)
&g_extern.system.disk_control;
unsigned images = control->get_num_images();
unsigned current = control->get_image_index();
if (current >= images)
strlcpy(type_str, "No Disk", type_str_size);
else
snprintf(type_str, type_str_size, "%u", current + 1);
}
else
handle_setting_label(type_str, type_str_size, setting);
}
else
{
switch (type)
{
#if defined(GEKKO)
case MENU_SETTINGS_VIDEO_RESOLUTION:
strlcpy(type_str, gx_get_video_mode(), type_str_size);
break;
#elif defined(__CELLOS_LV2__)
case MENU_SETTINGS_VIDEO_RESOLUTION:
{
unsigned width = gfx_ctx_get_resolution_width(
g_extern.console.screen.resolutions.list
[g_extern.console.screen.resolutions.current.idx]);
unsigned height = gfx_ctx_get_resolution_height(
g_extern.console.screen.resolutions.list
[g_extern.console.screen.resolutions.current.idx]);
snprintf(type_str, type_str_size, "%ux%u", width, height);
}
break;
#endif
case MENU_SETTINGS_CUSTOM_VIEWPORT:
case MENU_SETTINGS_CUSTOM_BIND_ALL:
case MENU_SETTINGS_CUSTOM_BIND_DEFAULT_ALL:
strlcpy(type_str, "...", type_str_size);
break;
case MENU_SETTINGS_BIND_PLAYER:
snprintf(type_str, type_str_size, "#%u",
driver.menu->current_pad + 1);
break;
case MENU_SETTINGS_BIND_DEVICE:
{
int map = g_settings.input.joypad_map
[driver.menu->current_pad];
if (map >= 0 && map < MAX_PLAYERS)
{
const char *device_name =
g_settings.input.device_names[map];
if (*device_name)
strlcpy(type_str, device_name, type_str_size);
else
snprintf(type_str, type_str_size,
"N/A (port #%d)", map);
}
else
strlcpy(type_str, "Disabled", type_str_size);
}
break;
case MENU_SETTINGS_BIND_ANALOG_MODE:
{
static const char *modes[] = {
"None",
"Left Analog",
"Right Analog",
"Dual Analog",
};
strlcpy(type_str, modes[g_settings.input.analog_dpad_mode
[driver.menu->current_pad] % ANALOG_DPAD_LAST],
type_str_size);
}
break;
case MENU_SETTINGS_BIND_DEVICE_TYPE:
{
const struct retro_controller_description *desc = NULL;
if (driver.menu->current_pad < g_extern.system.num_ports)
desc = libretro_find_controller_description(
&g_extern.system.ports[driver.menu->current_pad],
g_settings.input.libretro_device
[driver.menu->current_pad]);
const char *name = desc ? desc->desc : NULL;
if (!name)
{
/* Find generic name. */
switch (g_settings.input.libretro_device
[driver.menu->current_pad])
{
case RETRO_DEVICE_NONE:
name = "None";
break;
case RETRO_DEVICE_JOYPAD:
name = "RetroPad";
break;
case RETRO_DEVICE_ANALOG:
name = "RetroPad w/ Analog";
break;
default:
name = "Unknown";
break;
}
}
strlcpy(type_str, name, type_str_size);
}
break;
case MENU_SETTINGS_CUSTOM_BIND_MODE:
strlcpy(type_str, driver.menu->bind_mode_keyboard ?
"RetroKeyboard" : "RetroPad", type_str_size);
break;
default:
*type_str = '\0';
*w = 0;
break;
}
}
}
}
static void general_read_handler(const void *data)
{
const rarch_setting_t *setting = (const rarch_setting_t*)data;

View File

@ -169,6 +169,10 @@ rarch_setting_t setting_data_bind_setting(const char* name,
int setting_data_get_description(const char *label, char *msg,
size_t msg_sizeof);
void setting_data_get_label(char *type_str,
size_t type_str_size, unsigned *w, unsigned type,
const char *menu_label, const char *label, unsigned index);
#ifdef HAVE_MENU
rarch_setting_t* setting_data_get_mainmenu(bool regenerate);
#endif