RetroArch/menu/menu_setting.c

265 lines
6.7 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:46:50 +01: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/>.
*/
2015-02-14 01:51:28 +01:00
#include "menu_setting.h"
2015-01-11 01:34:08 +01:00
#include "../retroarch.h"
2015-05-12 13:14:04 +02:00
#include "../settings.h"
int menu_setting_set_flags(rarch_setting_t *setting)
{
if (!setting)
return 0;
if (setting->flags & SD_FLAG_IS_DRIVER)
return MENU_SETTING_DRIVER;
switch (setting->type)
{
case ST_ACTION:
return MENU_SETTING_ACTION;
case ST_PATH:
return MENU_FILE_PATH;
case ST_GROUP:
return MENU_SETTING_GROUP;
case ST_SUB_GROUP:
return MENU_SETTING_SUBGROUP;
default:
break;
}
return 0;
}
2015-02-14 01:51:28 +01:00
int menu_setting_generic(rarch_setting_t *setting)
{
2014-10-28 22:32:00 +01:00
if (!setting)
return -1;
2015-04-13 10:29:15 +02:00
if (setting->cmd_trigger.idx != EVENT_CMD_NONE)
2014-10-28 22:32:00 +01:00
setting->cmd_trigger.triggered = true;
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;
}
2015-03-17 03:28:06 +01:00
static int setting_handler(rarch_setting_t *setting, unsigned action)
{
2015-03-17 03:28:06 +01:00
int ret = -1;
2014-10-28 22:32:00 +01:00
if (!setting)
2015-03-17 03:28:06 +01:00
return -1;
2014-10-15 05:51:00 +02:00
2014-10-28 22:32:00 +01:00
switch (action)
2014-10-15 05:51:00 +02:00
{
case MENU_ACTION_UP:
case MENU_ACTION_DOWN:
if (setting->action_up_or_down)
2015-03-17 03:28:06 +01:00
{
setting->action_up_or_down(setting, action);
2015-03-17 03:28:06 +01:00
ret = 0;
}
break;
2014-10-28 22:32:00 +01:00
case MENU_ACTION_LEFT:
case MENU_ACTION_RIGHT:
if (setting->action_toggle)
2015-03-17 03:28:06 +01:00
{
setting->action_toggle(setting, action, true);
2015-03-17 03:28:06 +01:00
ret = 0;
}
2014-10-28 22:32:00 +01:00
break;
case MENU_ACTION_OK:
if (setting->action_ok)
2015-03-17 03:28:06 +01:00
{
2014-10-28 22:32:00 +01:00
setting->action_ok(setting, action);
2015-03-17 03:28:06 +01:00
ret = 0;
}
2014-10-28 22:32:00 +01:00
break;
2015-01-09 04:43:24 +01:00
case MENU_ACTION_CANCEL:
if (setting->action_cancel)
2015-03-17 03:28:06 +01:00
{
2015-01-09 04:43:24 +01:00
setting->action_cancel(setting, action);
2015-03-17 03:28:06 +01:00
ret = 0;
}
2015-01-09 04:43:24 +01:00
break;
2014-10-28 22:32:00 +01:00
case MENU_ACTION_START:
if (setting->action_start)
2015-03-17 03:28:06 +01:00
{
2014-10-28 22:32:00 +01:00
setting->action_start(setting);
2015-03-17 03:28:06 +01:00
ret = 0;
}
2014-10-28 22:32:00 +01:00
break;
2014-10-15 05:51:00 +02:00
}
2015-03-17 03:28:06 +01:00
return ret;
2014-10-28 22:32:00 +01:00
}
2014-10-15 05:51:00 +02:00
2015-02-14 01:51:28 +01:00
int menu_setting_handler(rarch_setting_t *setting, unsigned action)
2014-10-28 22:32:00 +01:00
{
2015-03-17 03:28:06 +01:00
if (setting_handler(setting, action) == 0)
return menu_setting_generic(setting);
return -1;
}
2015-01-27 01:58:48 +01:00
static int menu_action_handle_setting(rarch_setting_t *setting,
2015-03-09 04:18:47 +01:00
unsigned type, unsigned action, bool wraparound)
{
menu_displaylist_info_t info = {0};
2015-04-14 12:56:37 +02:00
menu_handle_t *menu = menu_driver_get_ptr();
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-28 20:12:21 +01:00
case ST_PATH:
if (action == MENU_ACTION_OK)
{
info.list = menu->menu_list->menu_stack;
info.type = type;
info.directory_ptr = menu->navigation.selection_ptr;
strlcpy(info.path, setting->default_value.string, sizeof(info.path));
strlcpy(info.label, setting->name, sizeof(info.label));
menu_displaylist_push_list(&info, DISPLAYLIST_GENERIC);
}
2014-10-28 22:32:00 +01:00
/* fall-through. */
2014-10-16 17:19:48 +02:00
case ST_BOOL:
case ST_INT:
2014-10-16 17:19:48 +02:00
case ST_UINT:
2015-03-15 13:00:07 -03:00
case ST_HEX:
2014-10-16 17:19:48 +02:00
case ST_FLOAT:
case ST_STRING:
case ST_DIR:
case ST_BIND:
case ST_ACTION:
2015-03-17 03:28:06 +01:00
return menu_setting_handler(setting, action);
2014-10-16 17:19:48 +02:00
default:
break;
}
2015-03-17 03:28:06 +01:00
return -1;
}
2015-05-08 20:36:08 +02:00
rarch_setting_t *menu_setting_get_ptr(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return NULL;
return menu->list_settings;
}
2015-02-14 01:51:28 +01:00
rarch_setting_t *menu_setting_find(const char *label)
{
rarch_setting_t *settings = menu_setting_get_ptr();
2015-04-14 12:56:37 +02:00
if (!settings)
2015-03-22 04:56:13 +01:00
return NULL;
return setting_find_setting(settings, label);
2014-10-28 19:08:18 +01:00
}
int menu_setting_set(unsigned type, const char *label,
unsigned action, bool wraparound)
2014-10-28 19:08:18 +01:00
{
2015-03-22 04:56:13 +01:00
int ret = 0;
rarch_setting_t *setting = NULL;
2015-04-14 12:56:37 +02:00
menu_handle_t *menu = menu_driver_get_ptr();
2015-03-22 04:56:13 +01:00
2015-05-07 04:57:49 +02:00
if (!menu)
2015-03-22 04:56:13 +01:00
return 0;
setting = menu_setting_find(
2015-04-14 12:56:37 +02:00
menu->menu_list->selection_buf->list
[menu->navigation.selection_ptr].label);
2015-01-25 05:49:39 +01:00
2015-01-22 23:09:58 +01:00
if (!setting)
return 0;
2015-03-17 03:28:06 +01:00
ret = menu_action_handle_setting(setting,
2015-03-09 04:18:47 +01:00
type, action, wraparound);
2015-03-17 03:28:06 +01:00
if (ret == -1)
return 0;
return ret;
}
2015-05-15 00:22:26 +02:00
void menu_setting_apply_deferred(void)
{
menu_handle_t *menu = menu_driver_get_ptr();
rarch_setting_t *setting = menu ? menu->list_settings : NULL;
if (!menu || !setting)
return;
for (; setting->type != ST_NONE; setting++)
{
if (setting->type >= ST_GROUP)
continue;
if (!(setting->flags & SD_FLAG_IS_DEFERRED))
continue;
switch (setting->type)
{
case ST_BOOL:
if (*setting->value.boolean != setting->original_value.boolean)
{
setting->original_value.boolean = *setting->value.boolean;
setting->deferred_handler(setting);
}
break;
case ST_INT:
if (*setting->value.integer != setting->original_value.integer)
{
setting->original_value.integer = *setting->value.integer;
setting->deferred_handler(setting);
}
break;
case ST_UINT:
if (*setting->value.unsigned_integer != setting->original_value.unsigned_integer)
{
setting->original_value.unsigned_integer = *setting->value.unsigned_integer;
setting->deferred_handler(setting);
}
break;
case ST_FLOAT:
if (*setting->value.fraction != setting->original_value.fraction)
{
setting->original_value.fraction = *setting->value.fraction;
setting->deferred_handler(setting);
}
break;
case ST_PATH:
case ST_DIR:
case ST_STRING:
case ST_BIND:
/* Always run the deferred write handler */
setting->deferred_handler(setting);
break;
default:
break;
}
}
}