RetroArch/menu/drivers/menu_generic.c

334 lines
11 KiB
C
Raw Normal View History

2015-10-03 01:15:47 +00:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2017-01-22 12:40:32 +00:00
* Copyright (C) 2011-2017 - Daniel De Matteis
2015-10-03 01:15:47 +00:00
* Copyright (C) 2012-2015 - Michael Lelli
2017-01-22 12:40:32 +00:00
* Copyright (C) 2016-2017 - Brad Parker
2015-10-03 01:15:47 +00:00
*
* 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 <compat/strl.h>
#include <string/stdstring.h>
2015-10-03 01:15:47 +00:00
#include "menu_generic.h"
2015-12-06 16:55:27 +00:00
#include "../menu_driver.h"
#include "../widgets/menu_dialog.h"
2016-09-15 18:35:39 +00:00
#include "../widgets/menu_input_bind_dialog.h"
2015-10-03 01:15:47 +00:00
2015-11-23 11:03:38 +00:00
#include "../../verbosity.h"
#include "../../content.h"
#include "../../retroarch.h"
2015-10-03 02:21:38 +00:00
struct menu_generic_iterate_type
2015-10-03 02:21:38 +00:00
{
enum msg_hash_enums id;
enum action_iterate_type type;
};
static struct menu_generic_iterate_type iterate_lbl_list[] = {
{
MENU_ENUM_LABEL_HELP,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_HELP_CONTROLS,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_HELP_WHAT_IS_A_CORE,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_HELP_LOADING_CONTENT,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_HELP_CHANGE_VIRTUAL_GAMEPAD,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_HELP_CHEEVOS_DESCRIPTION,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_HELP_AUDIO_VIDEO_TROUBLESHOOTING,
ITERATE_TYPE_HELP
},
2015-10-03 02:21:38 +00:00
{
MENU_ENUM_LABEL_HELP_SCANNING_CONTENT,
ITERATE_TYPE_HELP
},
{
MENU_ENUM_LABEL_INFO_SCREEN,
ITERATE_TYPE_INFO
},
{
MENU_ENUM_LABEL_CUSTOM_BIND,
ITERATE_TYPE_BIND
},
{
MENU_ENUM_LABEL_CUSTOM_BIND_ALL,
ITERATE_TYPE_BIND
},
{
MENU_ENUM_LABEL_CUSTOM_BIND_DEFAULTS,
ITERATE_TYPE_BIND
2015-10-03 02:21:38 +00:00
}
};
2015-10-03 02:21:38 +00:00
/**
* menu_iterate:
* @input : input sample for this frame
* @old_input : input sample of the previous frame
* @trigger_input : difference' input sample - difference
* between 'input' and 'old_input'
*
* Runs RetroArch menu for one frame.
*
* Returns: 0 on success, -1 if we need to quit out of the loop.
2015-10-03 02:21:38 +00:00
**/
2015-12-10 18:38:46 +00:00
int generic_menu_iterate(void *data, void *userdata, enum menu_action action)
2015-10-03 02:21:38 +00:00
{
enum action_iterate_type iterate_type = ITERATE_TYPE_DEFAULT;
unsigned file_type = 0;
int ret = 0;
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
const char *label = NULL;
menu_handle_t *menu = (menu_handle_t*)data;
size_t selection = menu_navigation_get_selection();
menu_entries_get_last_stack(NULL, &label, &file_type, &enum_idx, NULL);
2015-10-03 02:21:38 +00:00
2015-10-17 17:21:18 +00:00
if (!menu)
2015-10-03 02:21:38 +00:00
return 0;
2017-09-28 06:55:40 +00:00
menu->menu_state_msg[0] = '\0';
2017-02-24 03:53:54 +00:00
if (!string_is_empty(label))
{
unsigned k;
for (k = 0; k < ARRAY_SIZE(iterate_lbl_list); k++)
{
if (string_is_equal(label, msg_hash_to_str(iterate_lbl_list[k].id)))
{
iterate_type = iterate_lbl_list[k].type;
break;
}
}
}
2015-10-03 02:21:38 +00:00
menu_driver_set_binding_state(iterate_type == ITERATE_TYPE_BIND);
2015-12-11 20:41:59 +00:00
if ( action != MENU_ACTION_NOOP
|| menu_entries_ctl(MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL)
|| menu_display_get_update_pending())
2015-10-03 02:21:38 +00:00
{
BIT64_SET(menu->state, MENU_STATE_RENDER_FRAMEBUFFER);
2015-10-03 02:21:38 +00:00
}
switch (iterate_type)
{
case ITERATE_TYPE_HELP:
2016-09-15 14:07:20 +00:00
ret = menu_dialog_iterate(
2017-09-28 06:55:40 +00:00
menu->menu_state_msg, sizeof(menu->menu_state_msg), label);
2015-10-03 02:21:38 +00:00
BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX);
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
if (ret == 1 || action == MENU_ACTION_OK)
{
BIT64_SET(menu->state, MENU_STATE_POP_STACK);
2016-09-15 14:07:20 +00:00
menu_dialog_set_active(false);
}
if (action == MENU_ACTION_CANCEL)
{
BIT64_SET(menu->state, MENU_STATE_POP_STACK);
2016-09-15 14:07:20 +00:00
menu_dialog_set_active(false);
}
2015-10-03 02:21:38 +00:00
break;
case ITERATE_TYPE_BIND:
{
2016-02-25 16:55:45 +00:00
menu_input_ctx_bind_t bind;
2017-09-28 06:55:40 +00:00
bind.s = menu->menu_state_msg;
bind.len = sizeof(menu->menu_state_msg);
2016-02-25 16:55:45 +00:00
2016-09-15 18:45:00 +00:00
if (menu_input_key_bind_iterate(&bind))
2016-02-25 16:55:45 +00:00
{
menu_entries_pop_stack(&selection, 0, 0);
menu_navigation_set_selection(selection);
2016-02-25 16:55:45 +00:00
}
else
BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX);
2015-10-03 02:21:38 +00:00
}
break;
case ITERATE_TYPE_INFO:
{
2016-07-27 14:37:28 +00:00
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
menu_file_list_cbs_t *cbs = selection_buf ?
2017-10-02 05:07:18 +00:00
(menu_file_list_cbs_t*)
file_list_get_actiondata_at_offset(selection_buf, selection)
: NULL;
2015-10-03 02:21:38 +00:00
if (cbs->enum_idx != MSG_UNKNOWN)
{
ret = menu_hash_get_help_enum(cbs->enum_idx,
2017-09-28 06:55:40 +00:00
menu->menu_state_msg, sizeof(menu->menu_state_msg));
}
else
{
unsigned type = 0;
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
menu_entries_get_at_offset(selection_buf, selection,
NULL, NULL, &type, NULL, NULL);
switch (type)
{
2016-07-27 14:37:28 +00:00
case FILE_TYPE_FONT:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_FONT;
break;
case FILE_TYPE_RDB:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_RDB;
break;
case FILE_TYPE_OVERLAY:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_OVERLAY;
break;
case FILE_TYPE_CHEAT:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_CHEAT;
break;
case FILE_TYPE_SHADER_PRESET:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_SHADER_PRESET;
break;
case FILE_TYPE_SHADER:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_SHADER;
break;
2016-07-27 14:49:13 +00:00
case FILE_TYPE_REMAP:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_REMAP;
break;
2016-07-27 18:47:54 +00:00
case FILE_TYPE_RECORD_CONFIG:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_RECORD_CONFIG;
break;
case FILE_TYPE_CURSOR:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_CURSOR;
break;
2016-07-27 19:01:39 +00:00
case FILE_TYPE_CONFIG:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_CONFIG;
break;
2016-07-27 19:28:33 +00:00
case FILE_TYPE_CARCHIVE:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_COMPRESSED_ARCHIVE;
break;
case FILE_TYPE_DIRECTORY:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_DIRECTORY;
break;
case FILE_TYPE_VIDEOFILTER: /* TODO/FIXME */
case FILE_TYPE_AUDIOFILTER: /* TODO/FIXME */
case FILE_TYPE_SHADER_SLANG: /* TODO/FIXME */
case FILE_TYPE_SHADER_GLSL: /* TODO/FIXME */
case FILE_TYPE_SHADER_HLSL: /* TODO/FIXME */
case FILE_TYPE_SHADER_CG: /* TODO/FIXME */
case FILE_TYPE_SHADER_PRESET_GLSLP: /* TODO/FIXME */
case FILE_TYPE_SHADER_PRESET_HLSLP: /* TODO/FIXME */
case FILE_TYPE_SHADER_PRESET_CGP: /* TODO/FIXME */
case FILE_TYPE_SHADER_PRESET_SLANGP: /* TODO/FIXME */
case FILE_TYPE_PLAIN:
enum_idx = MENU_ENUM_LABEL_FILE_BROWSER_PLAIN_FILE;
break;
default:
break;
}
if (enum_idx != MSG_UNKNOWN)
ret = menu_hash_get_help_enum(enum_idx,
2017-09-28 06:55:40 +00:00
menu->menu_state_msg, sizeof(menu->menu_state_msg));
}
2015-10-03 02:21:38 +00:00
}
BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX);
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
if (action == MENU_ACTION_OK || action == MENU_ACTION_CANCEL)
2016-09-29 02:25:55 +00:00
{
2015-10-03 02:21:38 +00:00
BIT64_SET(menu->state, MENU_STATE_POP_STACK);
2016-09-29 02:25:55 +00:00
}
menu_dialog_set_active(false);
2015-10-03 02:21:38 +00:00
break;
case ITERATE_TYPE_DEFAULT:
2017-09-28 04:02:14 +00:00
{
menu_entry_t entry;
/* FIXME: Crappy hack, needed for mouse controls
* to not be completely broken in case we press back.
*
* We need to fix this entire mess, mouse controls
* should not rely on a hack like this in order to work. */
selection = MAX(MIN(selection, (menu_entries_get_size() - 1)), 0);
menu_entry_init(&entry);
menu_entry_get(&entry, 0, selection, NULL, false);
ret = menu_entry_action(&entry,
(unsigned)selection, (enum menu_action)action);
menu_entry_free(&entry);
if (ret)
goto end;
BIT64_SET(menu->state, MENU_STATE_POST_ITERATE);
/* Have to defer it so we let settings refresh. */
menu_dialog_push();
}
2015-10-03 02:21:38 +00:00
break;
}
BIT64_SET(menu->state, MENU_STATE_BLIT);
2015-10-03 02:21:38 +00:00
if (BIT64_GET(menu->state, MENU_STATE_POP_STACK))
{
size_t new_selection_ptr = selection;
menu_entries_pop_stack(&new_selection_ptr, 0, 0);
menu_navigation_set_selection(selection);
2015-10-03 02:21:38 +00:00
}
2015-10-03 02:21:38 +00:00
if (BIT64_GET(menu->state, MENU_STATE_POST_ITERATE))
menu_input_post_iterate(&ret, action);
end:
if (ret)
return -1;
return 0;
}
2015-10-03 01:15:47 +00:00
bool generic_menu_init_list(void *data)
{
2017-09-10 20:38:03 +00:00
menu_displaylist_info_t info;
2016-12-04 03:43:53 +00:00
file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0);
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
2015-10-03 01:15:47 +00:00
2017-09-10 20:38:03 +00:00
menu_displaylist_info_init(&info);
2017-09-28 00:45:03 +00:00
info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU));
2016-06-17 21:47:23 +00:00
info.enum_idx = MENU_ENUM_LABEL_MAIN_MENU;
2015-10-03 01:15:47 +00:00
2017-09-28 01:06:54 +00:00
menu_entries_append_enum(menu_stack,
info.path,
2016-06-16 11:13:43 +00:00
info.label,
MENU_ENUM_LABEL_MAIN_MENU,
info.type, info.flags, 0);
2015-10-22 01:02:03 +00:00
info.list = selection_buf;
2016-02-24 22:05:54 +00:00
if (menu_displaylist_ctl(DISPLAYLIST_MAIN_MENU, &info))
2017-05-26 18:12:52 +00:00
menu_displaylist_process(&info);
2015-10-03 01:15:47 +00:00
2017-09-10 20:57:26 +00:00
menu_displaylist_info_free(&info);
2015-10-03 01:15:47 +00:00
return true;
}