RetroArch/menu/menu_action.c

139 lines
3.7 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - 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_action.h"
#include "menu_entries.h"
2014-10-28 21:32:00 +00:00
static int setting_extra_handler(rarch_setting_t *setting)
{
2014-10-28 21:32:00 +00:00
if (!setting)
return -1;
if (setting->cmd_trigger.idx != RARCH_CMD_NONE)
setting->cmd_trigger.triggered = true;
2014-10-15 03:51:00 +00: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-28 21:32:00 +00:00
static void process_setting_handler(
rarch_setting_t *setting,
unsigned action)
{
2014-10-28 21:32:00 +00:00
if (!setting)
return;
2014-10-15 03:51:00 +00:00
2014-10-28 21:32:00 +00:00
switch (action)
2014-10-15 03:51:00 +00:00
{
2014-10-28 21:32:00 +00:00
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;
2015-01-09 03:43:24 +00:00
case MENU_ACTION_CANCEL:
if (setting->action_cancel)
setting->action_cancel(setting, action);
break;
2014-10-28 21:32:00 +00:00
case MENU_ACTION_START:
if (setting->action_start)
setting->action_start(setting);
break;
2014-10-15 03:51:00 +00:00
}
2014-10-28 21:32:00 +00:00
}
2014-10-15 03:51:00 +00:00
2014-10-28 21:32:00 +00:00
int setting_handler(
rarch_setting_t *setting, unsigned action)
{
process_setting_handler(setting, action);
return setting_extra_handler(setting);
}
2014-10-15 03:57:15 +00:00
int menu_action_handle_setting(rarch_setting_t *setting,
2014-10-14 23:23:13 +00:00
unsigned type, unsigned action)
{
2014-10-14 23:23:13 +00:00
if (!setting)
return -1;
2014-10-16 15:19:48 +00:00
switch (setting->type)
{
2014-10-28 19:12:21 +00:00
case ST_PATH:
if (action == MENU_ACTION_OK)
2014-10-28 21:32:00 +00:00
menu_list_push_stack_refresh(
driver.menu->menu_list,
setting->default_value.string,
setting->name,
type,
driver.menu->selection_ptr);
/* fall-through. */
2014-10-16 15:19:48 +00:00
case ST_BOOL:
case ST_INT:
2014-10-16 15:19:48 +00:00
case ST_UINT:
case ST_FLOAT:
case ST_STRING:
case ST_DIR:
case ST_BIND:
case ST_ACTION:
2014-10-28 21:32:00 +00:00
process_setting_handler(setting, action);
break;
2014-10-16 15:19:48 +00:00
default:
break;
}
2014-10-28 21:32:00 +00:00
return setting_extra_handler(setting);
}
2014-10-28 18:08:18 +00:00
static rarch_setting_t *find_setting(void)
{
const file_list_t *list = (const file_list_t*)driver.menu->menu_list->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);
2014-10-28 20:53:26 +00:00
/* Check if setting belongs to main menu. */
2014-10-28 18:08:18 +00:00
if (!setting)
setting = (rarch_setting_t*)setting_data_find_setting(
driver.menu->list_mainmenu, list->list[driver.menu->selection_ptr].label);
return setting;
}
2014-10-28 18:08:18 +00:00
int menu_action_setting_set(unsigned type, const char *label,
unsigned action)
{
rarch_setting_t *setting = find_setting();
if (setting)
2014-10-14 23:23:13 +00:00
return menu_action_handle_setting(setting, type, action);
return 0;
}