RetroArch/frontend/menu/menu_action.c

216 lines
5.7 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2014 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "menu_common.h"
#include "menu_input_line_cb.h"
#include "menu_action.h"
#include "menu_entries.h"
#include "menu_shader.h"
2014-10-16 17:19:48 +02:00
int setting_handler(
2014-10-15 05:51:00 +02:00
rarch_setting_t *setting, unsigned action)
{
2014-10-16 02:53:35 +02:00
switch (action)
{
case MENU_ACTION_LEFT:
case MENU_ACTION_RIGHT:
if (setting->action_toggle)
setting->action_toggle(setting, action);
break;
case MENU_ACTION_OK:
if (setting->action_ok)
setting->action_ok(setting, action);
break;
case MENU_ACTION_START:
if (setting->action_start)
setting->action_start(setting);
break;
}
2014-10-15 05:51:00 +02:00
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
int menu_action_setting_set_current_string(
rarch_setting_t *setting, const char *str)
{
strlcpy(setting->value.string, str, setting->size);
2014-10-15 05:51:00 +02:00
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
int menu_action_set_current_string_based_on_label(
const char *label, const char *str)
{
if (!strcmp(label, "video_shader_preset_save_as"))
menu_shader_manager_save_preset(str, false);
return 0;
}
int menu_action_setting_set_current_string_path(
rarch_setting_t *setting, const char *dir, const char *path)
{
fill_pathname_join(setting->value.string, dir, path, setting->size);
2014-10-15 05:51:00 +02:00
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
static int menu_entries_set_current_path_selection(
rarch_setting_t *setting, const char *start_path,
const char *label, unsigned type,
unsigned action)
{
switch (action)
{
case MENU_ACTION_OK:
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';
break;
}
2014-10-15 05:51:00 +02:00
if (setting->change_handler)
setting->change_handler(setting);
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
}
return 0;
}
2014-10-15 05:57:15 +02:00
int menu_action_handle_setting(rarch_setting_t *setting,
2014-10-15 01:23:13 +02:00
unsigned type, unsigned action)
{
2014-10-15 01:23:13 +02:00
if (!setting)
return -1;
2014-10-16 17:19:48 +02:00
switch (setting->type)
{
2014-10-16 17:19:48 +02:00
case ST_BOOL:
case ST_UINT:
case ST_FLOAT:
return setting_handler(setting, action);
case ST_PATH:
return menu_entries_set_current_path_selection(setting,
setting->default_value.string, setting->name, type, action);
case ST_DIR:
switch (action)
{
case MENU_ACTION_START:
if (setting->action_start)
2014-10-16 17:57:42 +02:00
setting->action_start(setting);
break;
}
2014-10-16 17:19:48 +02:00
if (setting->change_handler)
setting->change_handler(setting);
2014-10-16 17:19:48 +02:00
if (setting->flags & SD_FLAG_EXIT
&& setting->cmd_trigger.triggered)
{
setting->cmd_trigger.triggered = false;
return -1;
2014-10-16 17:19:48 +02:00
}
break;
case ST_STRING:
switch (action)
{
case MENU_ACTION_LEFT:
case MENU_ACTION_RIGHT:
if (setting->action_toggle)
2014-10-16 17:57:42 +02:00
setting->action_toggle(setting, action);
2014-10-16 17:19:48 +02:00
break;
case MENU_ACTION_START:
if (setting->action_start)
2014-10-16 17:57:42 +02:00
setting->action_start(setting);
2014-10-16 17:19:48 +02:00
break;
case MENU_ACTION_OK:
if (setting->action_ok)
2014-10-16 17:57:42 +02:00
setting->action_ok(setting, action);
2014-10-16 17:19:48 +02:00
break;
}
break;
default:
break;
}
return 0;
}
2014-10-14 22:10:18 +02:00
int menu_action_setting_set(unsigned type, const char *label,
unsigned action)
{
const file_list_t *list = (const file_list_t*)driver.menu->selection_buf;
/* Check if setting belongs to settings menu. */
rarch_setting_t *setting = (rarch_setting_t*)setting_data_find_setting(
driver.menu->list_settings, list->list[driver.menu->selection_ptr].label);
if (setting)
2014-10-15 01:23:13 +02:00
return menu_action_handle_setting(setting, type, action);
/* Check if setting belongs to main menu. */
setting = (rarch_setting_t*)setting_data_find_setting(
driver.menu->list_mainmenu, list->list[driver.menu->selection_ptr].label);
if (setting)
2014-10-15 01:23:13 +02:00
return menu_action_handle_setting(setting, type, action);
return 0;
}