(Settings/menu) Add WITH_CMD to settings_data.c

This commit is contained in:
twinaphex 2014-09-14 23:44:14 +02:00
parent 05024d529a
commit 899e69f921
4 changed files with 100 additions and 100 deletions

View File

@ -226,6 +226,9 @@ static int menu_common_setting_set_current_path_selection(
menu_entries_push(driver.menu->menu_stack,
start_path, label, type,
driver.menu->selection_ptr);
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
break;
case MENU_ACTION_START:
*setting->value.string = '\0';
@ -235,8 +238,12 @@ static int menu_common_setting_set_current_path_selection(
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
@ -249,8 +256,12 @@ static int menu_common_setting_set_current_string_path(
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
@ -278,8 +289,12 @@ int menu_common_setting_set_current_string(
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
@ -306,8 +321,12 @@ static int handle_setting(rarch_setting_t *setting,
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
}
return 0;
}

View File

@ -36,13 +36,21 @@ int menu_action_setting_boolean(
else if (action == MENU_ACTION_RIGHT)
g_settings.state_slot++;
else if (action == MENU_ACTION_OK)
{
*setting->value.boolean = !(*setting->value.boolean);
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
}
}
else
{
switch (action)
{
case MENU_ACTION_OK:
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
/* fall-through */
case MENU_ACTION_LEFT:
case MENU_ACTION_RIGHT:
*setting->value.boolean = !(*setting->value.boolean);
@ -56,8 +64,12 @@ int menu_action_setting_boolean(
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
@ -90,8 +102,11 @@ int menu_action_setting_unsigned_integer(
}
break;
case MENU_ACTION_RIGHT:
case MENU_ACTION_OK:
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
/* fall-through */
case MENU_ACTION_RIGHT:
*setting->value.unsigned_integer =
*setting->value.unsigned_integer + setting->step;
@ -112,8 +127,12 @@ int menu_action_setting_unsigned_integer(
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
@ -137,6 +156,9 @@ int menu_action_setting_fraction(
/* Incase refresh rate update forced non-block video. */
rarch_main_command(RARCH_CMD_VIDEO_SET_BLOCKING_STATE);
}
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
}
}
else if (!strcmp(setting->name, "fastforward_ratio"))
@ -178,8 +200,11 @@ int menu_action_setting_fraction(
}
break;
case MENU_ACTION_RIGHT:
case MENU_ACTION_OK:
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
/* fall-through */
case MENU_ACTION_RIGHT:
*setting->value.fraction =
*setting->value.fraction + setting->step;
@ -199,8 +224,12 @@ int menu_action_setting_fraction(
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT)
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}

View File

@ -39,7 +39,7 @@
#endif
static void get_input_config_prefix(char *buf, size_t sizeof_buf,
const rarch_setting_t *setting)
rarch_setting_t *setting)
{
if (!buf)
{
@ -58,7 +58,7 @@ static void get_input_config_prefix(char *buf, size_t sizeof_buf,
}
static void get_input_config_key(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting, const char* type)
rarch_setting_t* setting, const char* type)
{
char prefix[32];
@ -83,7 +83,7 @@ static void get_input_config_key(char *buf, size_t sizeof_buf,
/* FIXME - make portable */
static void get_key_name(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting)
rarch_setting_t* setting)
{
uint32_t hidkey, i;
@ -116,7 +116,7 @@ static void get_key_name(char *buf, size_t sizeof_buf,
#endif
static void get_button_name(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting)
rarch_setting_t* setting)
{
if (!buf)
{
@ -138,7 +138,7 @@ static void get_button_name(char *buf, size_t sizeof_buf,
}
static void get_axis_name(char *buf, size_t sizeof_buf,
const rarch_setting_t* setting)
rarch_setting_t* setting)
{
uint32_t joyaxis;
@ -162,7 +162,7 @@ static void get_axis_name(char *buf, size_t sizeof_buf,
snprintf(buf, sizeof_buf, "+%u", AXIS_POS_GET(joyaxis));
}
void setting_data_reset_setting(const rarch_setting_t* setting)
void setting_data_reset_setting(rarch_setting_t* setting)
{
if (!setting)
{
@ -219,14 +219,14 @@ void setting_data_reset_setting(const rarch_setting_t* setting)
setting->change_handler(setting);
}
void setting_data_reset(const rarch_setting_t* settings)
void setting_data_reset(rarch_setting_t* settings)
{
for (; settings->type != ST_NONE; settings++)
setting_data_reset_setting(settings);
}
static bool setting_data_load_config(
const rarch_setting_t* settings, config_file_t* config)
rarch_setting_t* settings, config_file_t* config)
{
if (!settings || !config)
return false;
@ -318,7 +318,7 @@ static bool setting_data_load_config(
return true;
}
bool setting_data_load_config_path(const rarch_setting_t* settings,
bool setting_data_load_config_path(rarch_setting_t* settings,
const char* path)
{
config_file_t *config = (config_file_t*)config_file_new(path);
@ -332,7 +332,7 @@ bool setting_data_load_config_path(const rarch_setting_t* settings,
return config;
}
bool setting_data_save_config(const rarch_setting_t* settings,
bool setting_data_save_config(rarch_setting_t* settings,
config_file_t* config)
{
if (!settings || !config)
@ -459,7 +459,7 @@ rarch_setting_t* setting_data_find_setting(rarch_setting_t* setting,
return setting;
}
void setting_data_set_with_string_representation(const rarch_setting_t* setting,
void setting_data_set_with_string_representation(rarch_setting_t* setting,
const char* value)
{
if (!setting || !value)
@ -2005,9 +2005,9 @@ void setting_data_get_label(char *type_str,
}
}
static void general_read_handler(const void *data)
static void general_read_handler(void *data)
{
const rarch_setting_t *setting = (const rarch_setting_t*)data;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return;
@ -2040,63 +2040,23 @@ static void general_read_handler(const void *data)
*setting->value.integer = g_settings.input.joypad_map[4];
}
static void general_write_handler(const void *data)
static void general_write_handler(void *data)
{
unsigned rarch_cmd = RARCH_CMD_NONE;
const rarch_setting_t *setting = (const rarch_setting_t*)data;
rarch_setting_t *setting = (rarch_setting_t*)data;
if (!setting)
return;
if (!strcmp(setting->name, "quit_retroarch"))
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_QUIT_RETROARCH;
*setting->value.boolean = false;
}
if (setting->cmd_trigger.triggered)
rarch_cmd = setting->cmd_trigger.idx;
}
else if (!strcmp(setting->name, "save_new_config"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_MENU_SAVE_CONFIG;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "restart_retroarch"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_RESTART_RETROARCH;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "resume_content"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_RESUME;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "restart_content"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_RESET;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "take_screenshot"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_TAKE_SCREENSHOT;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "help"))
if (!strcmp(setting->name, "help"))
{
if (*setting->value.boolean)
{
@ -2182,22 +2142,6 @@ static void general_write_handler(const void *data)
g_settings.audio.rate_control_delta = *setting->value.fraction;
}
}
else if (!strcmp(setting->name, "savestate"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_SAVE_STATE;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "loadstate"))
{
if (*setting->value.boolean)
{
rarch_cmd = RARCH_CMD_LOAD_STATE;
*setting->value.boolean = false;
}
}
else if (!strcmp(setting->name, "autosave_interval"))
rarch_cmd = RARCH_CMD_AUTOSAVE;
#ifdef HAVE_OVERLAY
@ -2264,7 +2208,7 @@ static void general_write_handler(const void *data)
g_extern.has_set_verbosity = *setting->value.boolean;
}
if (rarch_cmd)
if (rarch_cmd || setting->cmd_trigger.triggered)
rarch_main_command(rarch_cmd);
}
@ -2317,6 +2261,8 @@ static void general_write_handler(const void *data)
#define WITH_VALUES(VALUES) (list[index -1]).values = VALUES;
#define WITH_CMD(VALUES) (list[index -1]).cmd_trigger.idx = VALUES;
#ifdef GEKKO
#define MAX_GAMMA_SETTING 2
#else
@ -2375,19 +2321,19 @@ rarch_setting_t *setting_data_get_mainmenu(bool regenerate)
}
if (g_extern.main_is_init && !g_extern.libretro_dummy)
{
CONFIG_BOOL(lists[9], "savestate", "Save State", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_EXIT)
CONFIG_BOOL(lists[10], "loadstate", "Load State", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_EXIT)
CONFIG_BOOL(lists[11], "take_screenshot", "Take Screenshot", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION)
CONFIG_BOOL(lists[12], "resume_content", "Resume Content", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_FLAGS(SD_FLAG_EXIT)
CONFIG_BOOL(lists[13], "restart_content", "Restart Content", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_FLAGS(SD_FLAG_EXIT)
CONFIG_BOOL(lists[9], "savestate", "Save State", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_EXIT) WITH_CMD(RARCH_CMD_SAVE_STATE)
CONFIG_BOOL(lists[10], "loadstate", "Load State", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_EXIT) WITH_CMD(RARCH_CMD_LOAD_STATE)
CONFIG_BOOL(lists[11], "take_screenshot", "Take Screenshot", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_CMD(RARCH_CMD_TAKE_SCREENSHOT)
CONFIG_BOOL(lists[12], "resume_content", "Resume Content", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_FLAGS(SD_FLAG_EXIT) WITH_CMD(RARCH_CMD_RESUME)
CONFIG_BOOL(lists[13], "restart_content", "Restart Content", false, "", "", GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_FLAGS(SD_FLAG_EXIT) WITH_CMD(RARCH_CMD_RESET)
}
#ifndef HAVE_DYNAMIC
CONFIG_BOOL(lists[14], "restart_retroarch", "Restart RetroArch", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION)
CONFIG_BOOL(lists[14], "restart_retroarch", "Restart RetroArch", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_CMD(RARCH_CMD_RESTART_RETROARCH)
#endif
CONFIG_BOOL(lists[15], "configurations", "Configurations", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler)
CONFIG_BOOL(lists[16], "save_new_config", "Save New Config", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION)
CONFIG_BOOL(lists[16], "save_new_config", "Save New Config", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_CMD(RARCH_CMD_MENU_SAVE_CONFIG)
CONFIG_BOOL(lists[17], "help", "Help", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION)
CONFIG_BOOL(lists[18], "quit_retroarch", "Quit RetroArch", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION)
CONFIG_BOOL(lists[18], "quit_retroarch", "Quit RetroArch", false, "", "",GROUP_NAME, SUBGROUP_NAME, general_write_handler, general_read_handler) WITH_FLAGS(SD_FLAG_PUSH_ACTION) WITH_CMD(RARCH_CMD_QUIT_RETROARCH)
END_SUB_GROUP()
END_GROUP()

View File

@ -23,7 +23,7 @@
extern "C" {
#endif
typedef void (*change_handler_t)(const void *data);
typedef void (*change_handler_t)(void *data);
#define BINDFOR(s) (*(&(s))->value.keybind)
@ -105,6 +105,12 @@ typedef struct rarch_setting_t
const char *empty_path;
} dir;
struct
{
unsigned idx;
bool triggered;
} cmd_trigger;
struct
{
const char *off_label;
@ -117,19 +123,19 @@ typedef struct rarch_setting_t
bool enforce_maxrange;
} rarch_setting_t;
void setting_data_reset_setting(const rarch_setting_t* setting);
void setting_data_reset(const rarch_setting_t* settings);
void setting_data_reset_setting(rarch_setting_t* setting);
void setting_data_reset(rarch_setting_t* settings);
bool setting_data_load_config_path(const rarch_setting_t* settings,
bool setting_data_load_config_path(rarch_setting_t* settings,
const char* path);
bool setting_data_save_config(const rarch_setting_t* settings,
bool setting_data_save_config(rarch_setting_t* settings,
config_file_t* config);
rarch_setting_t* setting_data_find_setting(rarch_setting_t* settings,
const char* name);
void setting_data_set_with_string_representation(
const rarch_setting_t* setting, const char* value);
rarch_setting_t* setting, const char* value);
void setting_data_get_string_representation(rarch_setting_t* setting,
char* buf, size_t sizeof_buf);