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>
|
|
|
|
#include <string/string_list.h>
|
2015-01-12 19:02:39 +00:00
|
|
|
#include "menu_driver.h"
|
|
|
|
#include "menu.h"
|
2015-02-10 14:02:38 +00:00
|
|
|
#include "menu_entries.h"
|
2015-01-12 19:02:39 +00:00
|
|
|
#include "../driver.h"
|
|
|
|
#include "../general.h"
|
2015-01-12 19:00:43 +00:00
|
|
|
|
|
|
|
static const menu_ctx_driver_t *menu_ctx_drivers[] = {
|
|
|
|
#ifdef IOS
|
|
|
|
&menu_ctx_ios,
|
|
|
|
#endif
|
|
|
|
#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,
|
|
|
|
#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 '|'.
|
|
|
|
**/
|
|
|
|
const char* config_get_menu_driver_options(void)
|
|
|
|
{
|
|
|
|
union string_list_elem_attr attr;
|
|
|
|
unsigned i;
|
|
|
|
char *options = NULL;
|
|
|
|
int options_len = 0;
|
|
|
|
struct string_list *options_l = string_list_new();
|
|
|
|
|
|
|
|
attr.i = 0;
|
|
|
|
|
2015-01-30 06:51:48 +00:00
|
|
|
if (!options_l)
|
|
|
|
return NULL;
|
|
|
|
|
2015-01-12 19:00:43 +00:00
|
|
|
for (i = 0; menu_driver_find_handle(i); i++)
|
|
|
|
{
|
|
|
|
const char *opt = menu_driver_find_ident(i);
|
|
|
|
options_len += strlen(opt) + 1;
|
|
|
|
string_list_append(options_l, opt, attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
options = (char*)calloc(options_len, sizeof(char));
|
|
|
|
|
2015-01-30 06:51:48 +00:00
|
|
|
if (!options)
|
|
|
|
{
|
|
|
|
string_list_free(options_l);
|
|
|
|
options_l = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-01-12 19:00:43 +00:00
|
|
|
string_list_join_concat(options, options_len, options_l, "|");
|
|
|
|
|
|
|
|
string_list_free(options_l);
|
|
|
|
options_l = NULL;
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-20 19:43:22 +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-01-12 19:00:43 +00:00
|
|
|
rarch_fail(1, "find_menu_driver()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_menu(void)
|
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
if (driver->menu)
|
2015-01-12 19:00:43 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
find_menu_driver();
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!(driver->menu = (menu_handle_t*)menu_init(driver->menu_ctx)))
|
2015-01-12 19:00:43 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot initialize menu.\n");
|
|
|
|
rarch_fail(1, "init_menu()");
|
|
|
|
}
|
|
|
|
|
2015-03-18 18:40:00 +00:00
|
|
|
if (!(menu_entries_init(driver->menu)))
|
2015-01-12 19:00:43 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot initialize menu lists.\n");
|
|
|
|
rarch_fail(1, "init_menu()");
|
|
|
|
}
|
|
|
|
}
|
2015-02-13 18:00:34 +00:00
|
|
|
|
|
|
|
menu_handle_t *menu_driver_resolve(void)
|
|
|
|
{
|
2015-03-18 18:40:00 +00:00
|
|
|
driver_t *driver = driver_get_ptr();
|
|
|
|
if (!driver->menu)
|
2015-02-13 18:00:34 +00:00
|
|
|
return NULL;
|
2015-03-18 18:40:00 +00:00
|
|
|
return driver->menu;
|
2015-02-13 18:00:34 +00:00
|
|
|
}
|