2015-01-12 19:00:43 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* 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 <string.h>
|
2015-06-05 16:22:15 +00:00
|
|
|
|
2015-01-12 19:02:39 +00:00
|
|
|
#include "menu.h"
|
2015-10-18 05:15:54 +00:00
|
|
|
#include "menu_display.h"
|
2015-09-13 22:13:36 +00:00
|
|
|
#include "../general.h"
|
2015-10-26 07:39:35 +00:00
|
|
|
#include "../string_list_special.h"
|
2015-01-12 19:00:43 +00:00
|
|
|
|
2015-05-19 18:11:57 +00:00
|
|
|
static bool menu_alive = false;
|
|
|
|
|
2015-01-12 19:00:43 +00:00
|
|
|
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
|
|
|
|
#if defined(HAVE_RMENU)
|
|
|
|
&menu_ctx_rmenu,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_RMENU_XUI)
|
|
|
|
&menu_ctx_rmenu_xui,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_GLUI)
|
|
|
|
&menu_ctx_glui,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_XMB)
|
|
|
|
&menu_ctx_xmb,
|
|
|
|
#endif
|
|
|
|
#if defined(HAVE_RGUI)
|
|
|
|
&menu_ctx_rgui,
|
2015-10-02 00:15:23 +00:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_ZARCH)
|
|
|
|
&menu_ctx_zarch,
|
2015-01-12 19:00:43 +00:00
|
|
|
#endif
|
2015-03-09 13:39:39 +00:00
|
|
|
&menu_ctx_null,
|
2015-01-12 19:00:43 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* menu_driver_find_handle:
|
2015-01-15 20:10:36 +00:00
|
|
|
* @idx : index of driver to get handle to.
|
2015-01-12 19:00:43 +00:00
|
|
|
*
|
|
|
|
* Returns: handle to menu driver at index. Can be NULL
|
|
|
|
* if nothing found.
|
|
|
|
**/
|
2015-01-15 20:10:36 +00:00
|
|
|
const void *menu_driver_find_handle(int idx)
|
2015-01-12 19:00:43 +00:00
|
|
|
{
|
2015-01-15 20:10:36 +00:00
|
|
|
const void *drv = menu_ctx_drivers[idx];
|
2015-01-12 19:00:43 +00:00
|
|
|
if (!drv)
|
|
|
|
return NULL;
|
|
|
|
return drv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* menu_driver_find_ident:
|
2015-01-15 20:10:36 +00:00
|
|
|
* @idx : index of driver to get handle to.
|
2015-01-12 19:00:43 +00:00
|
|
|
*
|
|
|
|
* Returns: Human-readable identifier of menu driver at index. Can be NULL
|
|
|
|
* if nothing found.
|
|
|
|
**/
|
2015-01-15 20:10:36 +00:00
|
|
|
const char *menu_driver_find_ident(int idx)
|
2015-01-12 19:00:43 +00:00
|
|
|
{
|
2015-01-15 20:10:36 +00:00
|
|
|
const menu_ctx_driver_t *drv = menu_ctx_drivers[idx];
|
2015-01-12 19:00:43 +00:00
|
|
|
if (!drv)
|
|
|
|
return NULL;
|
|
|
|
return drv->ident;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* config_get_menu_driver_options:
|
|
|
|
*
|
|
|
|
* Get an enumerated list of all menu driver names,
|
|
|
|
* separated by '|'.
|
|
|
|
*
|
|
|
|
* Returns: string listing of all menu driver names,
|
|
|
|
* separated by '|'.
|
|
|
|
**/
|
2015-10-26 07:39:35 +00:00
|
|
|
const char *config_get_menu_driver_options(void)
|
2015-01-12 19:00:43 +00:00
|
|
|
{
|
2015-10-26 18:16:20 +00:00
|
|
|
return string_list_special_new(STRING_LIST_MENU_DRIVERS, NULL);
|
2015-01-12 19:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void find_menu_driver(void)
|
|
|
|
{
|
2015-03-20 19:43:22 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-03-18 18:40:00 +00:00
|
|
|
|
2015-08-17 03:13:45 +00:00
|
|
|
int i = find_driver_index("menu_driver", settings->menu.driver);
|
2015-01-12 19:00:43 +00:00
|
|
|
if (i >= 0)
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->menu_ctx = (const menu_ctx_driver_t*)menu_driver_find_handle(i);
|
2015-01-12 19:00:43 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned d;
|
|
|
|
RARCH_WARN("Couldn't find any menu driver named \"%s\"\n",
|
2015-03-20 19:43:22 +00:00
|
|
|
settings->menu.driver);
|
2015-01-12 19:00:43 +00:00
|
|
|
RARCH_LOG_OUTPUT("Available menu drivers are:\n");
|
|
|
|
for (d = 0; menu_driver_find_handle(d); d++)
|
|
|
|
RARCH_LOG_OUTPUT("\t%s\n", menu_driver_find_ident(d));
|
|
|
|
RARCH_WARN("Going to default to first menu driver...\n");
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
driver->menu_ctx = (const menu_ctx_driver_t*)menu_driver_find_handle(0);
|
2015-01-12 19:00:43 +00:00
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!driver->menu_ctx)
|
2015-10-26 02:18:13 +00:00
|
|
|
retro_fail(1, "find_menu_driver()");
|
2015-01-12 19:00:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-17 03:09:36 +00:00
|
|
|
static void init_menu_fallback(void)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_RGUI
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
driver_t *driver = driver_get_ptr();
|
2015-08-17 03:13:45 +00:00
|
|
|
int i = find_driver_index("menu_driver", "rgui");
|
2015-08-17 03:09:36 +00:00
|
|
|
|
|
|
|
if (i >= 0)
|
|
|
|
{
|
|
|
|
driver->menu_ctx = (const menu_ctx_driver_t*)menu_driver_find_handle(i);
|
|
|
|
if (settings)
|
|
|
|
strlcpy(settings->menu.driver, "rgui", sizeof(settings->menu.driver));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-10-03 01:15:47 +00:00
|
|
|
menu_handle_t *menu_driver_get_ptr(void)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
if (!driver || !driver->menu)
|
|
|
|
return NULL;
|
|
|
|
return driver->menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
const menu_ctx_driver_t *menu_ctx_driver_get_ptr(void)
|
|
|
|
{
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
if (!driver || !driver->menu_ctx)
|
|
|
|
return NULL;
|
|
|
|
return driver->menu_ctx;
|
|
|
|
}
|
|
|
|
|
2015-01-12 19:00:43 +00:00
|
|
|
void init_menu(void)
|
|
|
|
{
|
2015-08-17 03:05:29 +00:00
|
|
|
const char *video_driver;
|
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (driver->menu)
|
2015-01-12 19:00:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
find_menu_driver();
|
2015-07-04 20:59:40 +00:00
|
|
|
|
2015-08-17 18:51:12 +00:00
|
|
|
video_driver = menu_video_get_ident();
|
2015-07-04 20:59:40 +00:00
|
|
|
|
2015-08-17 03:05:29 +00:00
|
|
|
switch (driver->menu_ctx->type)
|
|
|
|
{
|
|
|
|
case MENU_VIDEO_DRIVER_GENERIC:
|
2015-08-17 03:09:36 +00:00
|
|
|
break;
|
2015-08-17 03:05:29 +00:00
|
|
|
case MENU_VIDEO_DRIVER_DIRECT3D:
|
2015-08-17 03:09:36 +00:00
|
|
|
if (video_driver && (strcmp(video_driver, "d3d") != 0))
|
|
|
|
init_menu_fallback();
|
2015-08-17 03:05:29 +00:00
|
|
|
break;
|
|
|
|
case MENU_VIDEO_DRIVER_OPENGL:
|
2015-08-17 03:07:25 +00:00
|
|
|
if (video_driver && (strcmp(video_driver, "gl") != 0))
|
2015-08-17 03:09:36 +00:00
|
|
|
init_menu_fallback();
|
2015-08-17 03:05:29 +00:00
|
|
|
break;
|
2015-07-04 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!(driver->menu = (menu_handle_t*)menu_init(driver->menu_ctx)))
|
2015-10-26 02:18:13 +00:00
|
|
|
retro_fail(1, "init_menu()");
|
2015-01-12 19:00:43 +00:00
|
|
|
|
2015-10-03 02:32:38 +00:00
|
|
|
if (driver->menu_ctx->lists_init)
|
|
|
|
if (!driver->menu_ctx->lists_init(driver->menu))
|
2015-10-26 02:18:13 +00:00
|
|
|
retro_fail(1, "init_menu()");
|
2015-02-13 18:00:34 +00:00
|
|
|
}
|
2015-03-22 04:21:14 +00:00
|
|
|
|
|
|
|
|
2015-06-12 12:15:48 +00:00
|
|
|
void menu_driver_list_free(file_list_t *list, size_t idx, size_t list_size)
|
2015-05-19 21:28:32 +00:00
|
|
|
{
|
2015-06-02 10:31:49 +00:00
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
2015-06-12 12:15:48 +00:00
|
|
|
if (driver->list_free)
|
|
|
|
driver->list_free(list, idx, list_size);
|
2015-05-19 21:28:32 +00:00
|
|
|
|
2015-06-12 12:17:27 +00:00
|
|
|
file_list_free_userdata (list, idx);
|
2015-06-12 02:09:35 +00:00
|
|
|
file_list_free_actiondata(list, idx);
|
2015-05-19 21:28:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-11 03:28:40 +00:00
|
|
|
void menu_driver_context_destroy(void)
|
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
2015-07-25 13:48:22 +00:00
|
|
|
if (driver && driver->context_destroy)
|
2015-04-11 03:28:40 +00:00
|
|
|
driver->context_destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_driver_list_set_selection(file_list_t *list)
|
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
2015-07-25 13:48:22 +00:00
|
|
|
if (driver && driver->list_set_selection)
|
2015-04-11 03:28:40 +00:00
|
|
|
driver->list_set_selection(list);
|
|
|
|
}
|
|
|
|
|
2015-06-15 17:00:52 +00:00
|
|
|
size_t menu_driver_list_get_selection(void)
|
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
menu_handle_t *menu = menu_driver_get_ptr();
|
|
|
|
|
2015-07-25 13:48:22 +00:00
|
|
|
if (driver && driver->list_get_selection)
|
2015-06-15 17:00:52 +00:00
|
|
|
return driver->list_get_selection(menu);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-22 02:12:32 +00:00
|
|
|
bool menu_driver_list_push(menu_displaylist_info_t *info, unsigned type)
|
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
|
|
|
if (driver->list_push)
|
|
|
|
if (driver->list_push(info, type) == 0)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-07 09:20:36 +00:00
|
|
|
void menu_driver_list_cache(menu_list_type_t type, unsigned action)
|
2015-04-11 03:28:40 +00:00
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
|
|
|
if (driver->list_cache)
|
2015-06-07 09:20:36 +00:00
|
|
|
driver->list_cache(type, action);
|
2015-04-11 03:28:40 +00:00
|
|
|
}
|
|
|
|
|
2015-06-07 13:43:03 +00:00
|
|
|
size_t menu_driver_list_get_size(menu_list_type_t type)
|
|
|
|
{
|
|
|
|
menu_handle_t *menu = menu_driver_get_ptr();
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
2015-06-07 13:49:58 +00:00
|
|
|
if (driver && driver->list_get_size)
|
2015-06-07 13:43:03 +00:00
|
|
|
return driver->list_get_size(menu, type);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-08 15:02:14 +00:00
|
|
|
void *menu_driver_list_get_entry(menu_list_type_t type, unsigned i)
|
|
|
|
{
|
|
|
|
menu_handle_t *menu = menu_driver_get_ptr();
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
|
|
|
if (driver && driver->list_get_entry)
|
|
|
|
return driver->list_get_entry(menu, type, i);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-22 04:21:14 +00:00
|
|
|
void menu_driver_set_texture(void)
|
|
|
|
{
|
2015-04-11 03:15:38 +00:00
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
2015-03-22 04:21:14 +00:00
|
|
|
|
2015-04-11 03:15:38 +00:00
|
|
|
if (driver->set_texture)
|
|
|
|
driver->set_texture();
|
2015-03-22 04:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void menu_driver_context_reset(void)
|
|
|
|
{
|
2015-04-11 03:15:38 +00:00
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
2015-03-22 04:21:14 +00:00
|
|
|
|
2015-04-11 03:15:38 +00:00
|
|
|
if (driver->context_reset)
|
|
|
|
driver->context_reset();
|
2015-03-22 04:21:14 +00:00
|
|
|
}
|
2015-03-22 04:27:19 +00:00
|
|
|
|
|
|
|
void menu_driver_frame(void)
|
|
|
|
{
|
2015-04-11 03:15:38 +00:00
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
2015-03-22 04:27:19 +00:00
|
|
|
|
2015-04-11 03:15:38 +00:00
|
|
|
if (driver->frame)
|
|
|
|
driver->frame();
|
2015-03-22 04:27:19 +00:00
|
|
|
}
|
2015-03-22 04:32:43 +00:00
|
|
|
|
2015-06-08 14:06:51 +00:00
|
|
|
int menu_driver_bind_init(menu_file_list_cbs_t *cbs,
|
|
|
|
const char *path, const char *label, unsigned type, size_t idx,
|
|
|
|
const char *elem0, const char *elem1,
|
|
|
|
uint32_t label_hash, uint32_t menu_label_hash)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
|
|
|
if (driver && driver->bind_init)
|
|
|
|
ret = driver->bind_init(cbs, path, label, type, idx, elem0, elem1,
|
|
|
|
label_hash, menu_label_hash);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-22 04:32:43 +00:00
|
|
|
void menu_driver_free(menu_handle_t *menu)
|
|
|
|
{
|
2015-04-11 03:15:38 +00:00
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
2015-03-22 04:32:43 +00:00
|
|
|
|
2015-04-11 03:15:38 +00:00
|
|
|
if (driver->free)
|
|
|
|
driver->free(menu);
|
2015-03-22 04:32:43 +00:00
|
|
|
}
|
2015-03-22 04:35:46 +00:00
|
|
|
|
2015-08-21 23:42:26 +00:00
|
|
|
bool menu_driver_alive(void)
|
|
|
|
{
|
|
|
|
return menu_alive;
|
|
|
|
}
|
|
|
|
|
2015-10-11 10:58:21 +00:00
|
|
|
int menu_driver_iterate(enum menu_action action)
|
2015-10-03 03:08:29 +00:00
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
|
|
|
if (driver->iterate)
|
2015-10-11 10:58:21 +00:00
|
|
|
return driver->iterate(action);
|
2015-10-03 03:08:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-03-22 05:02:02 +00:00
|
|
|
void menu_driver_toggle(bool latch)
|
|
|
|
{
|
2015-09-26 23:43:13 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
const menu_ctx_driver_t *menu_driver = menu_ctx_driver_get_ptr();
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
|
|
|
rarch_system_info_t *system = rarch_system_info_get_ptr();
|
2015-03-22 05:02:02 +00:00
|
|
|
|
2015-09-26 23:43:13 +00:00
|
|
|
if (menu_driver->toggle)
|
|
|
|
menu_driver->toggle(latch);
|
2015-08-21 23:42:26 +00:00
|
|
|
|
2015-08-21 23:43:13 +00:00
|
|
|
menu_alive = latch;
|
2015-09-26 23:38:21 +00:00
|
|
|
|
2015-09-26 23:43:13 +00:00
|
|
|
if (menu_alive == true)
|
|
|
|
{
|
2015-10-22 01:54:34 +00:00
|
|
|
menu_entries_set_refresh(false);
|
2015-09-26 23:43:13 +00:00
|
|
|
|
|
|
|
/* Menu should always run with vsync on. */
|
|
|
|
event_command(EVENT_CMD_VIDEO_SET_BLOCKING_STATE);
|
|
|
|
/* Stop all rumbling before entering the menu. */
|
|
|
|
event_command(EVENT_CMD_RUMBLE_STOP);
|
|
|
|
|
|
|
|
if (settings->menu.pause_libretro)
|
|
|
|
event_command(EVENT_CMD_AUDIO_STOP);
|
|
|
|
|
|
|
|
/* Override keyboard callback to redirect to menu instead.
|
|
|
|
* We'll use this later for something ...
|
|
|
|
* FIXME: This should probably be moved to menu_common somehow. */
|
|
|
|
if (global)
|
|
|
|
{
|
|
|
|
global->frontend_key_event = system->key_event;
|
|
|
|
system->key_event = menu_input_key_event;
|
|
|
|
system->frame_time_last = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
driver_set_nonblock_state(driver->nonblock_state);
|
|
|
|
|
|
|
|
if (settings && settings->menu.pause_libretro)
|
|
|
|
event_command(EVENT_CMD_AUDIO_START);
|
|
|
|
|
|
|
|
/* Prevent stray input from going to libretro core */
|
|
|
|
driver->flushing_input = true;
|
|
|
|
|
|
|
|
/* Restore libretro keyboard callback. */
|
|
|
|
if (global)
|
|
|
|
system->key_event = global->frontend_key_event;
|
|
|
|
}
|
2015-03-22 05:02:02 +00:00
|
|
|
}
|
2015-03-22 05:43:35 +00:00
|
|
|
|
2015-06-04 08:39:48 +00:00
|
|
|
bool menu_driver_load_image(void *data, menu_image_type_t type)
|
2015-03-22 05:48:03 +00:00
|
|
|
{
|
2015-04-11 03:15:38 +00:00
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
2015-03-22 05:48:03 +00:00
|
|
|
|
2015-06-04 08:39:48 +00:00
|
|
|
if (driver->load_image)
|
|
|
|
return driver->load_image(data, type);
|
2015-03-22 05:48:03 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-22 06:07:07 +00:00
|
|
|
|
2015-07-07 23:01:41 +00:00
|
|
|
|
|
|
|
bool menu_environment_cb(menu_environ_cb_t type, void *data)
|
|
|
|
{
|
|
|
|
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
|
|
|
|
|
|
|
|
if (driver->environ_cb)
|
|
|
|
{
|
|
|
|
int ret = driver->environ_cb(type, data);
|
|
|
|
if (ret == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|