2013-04-17 21:31:49 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
2014-04-13 10:12:12 +00:00
|
|
|
*
|
2013-04-17 21:31:49 +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 "menu_common.h"
|
|
|
|
|
2014-04-14 00:32:54 +00:00
|
|
|
void menu_update_system_info(void *data, bool *load_no_rom)
|
2014-03-02 13:07:07 +00:00
|
|
|
{
|
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
|
|
|
|
2014-03-05 21:39:00 +00:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2014-03-02 13:07:07 +00:00
|
|
|
libretro_free_system_info(&rgui->info);
|
2014-05-09 16:51:20 +00:00
|
|
|
if (*g_settings.libretro)
|
2014-03-02 13:07:07 +00:00
|
|
|
{
|
|
|
|
libretro_get_system_info(g_settings.libretro, &rgui->info, load_no_rom);
|
2014-03-05 21:39:00 +00:00
|
|
|
#endif
|
2014-03-02 13:07:07 +00:00
|
|
|
// Keep track of info for the currently selected core.
|
|
|
|
if (rgui->core_info)
|
|
|
|
{
|
2014-05-31 18:37:37 +00:00
|
|
|
if (core_info_list_get_info(rgui->core_info, rgui->core_info_current, g_settings.libretro))
|
2014-03-02 13:07:07 +00:00
|
|
|
{
|
2014-05-31 18:37:37 +00:00
|
|
|
const core_info_t *info = (const core_info_t*)rgui->core_info_current;
|
2014-03-02 13:07:07 +00:00
|
|
|
|
|
|
|
RARCH_LOG("[Core Info]:\n");
|
|
|
|
if (info->display_name)
|
|
|
|
RARCH_LOG(" Display Name: %s\n", info->display_name);
|
|
|
|
if (info->supported_extensions)
|
|
|
|
RARCH_LOG(" Supported Extensions: %s\n", info->supported_extensions);
|
|
|
|
if (info->authors)
|
|
|
|
RARCH_LOG(" Authors: %s\n", info->authors);
|
|
|
|
if (info->permissions)
|
|
|
|
RARCH_LOG(" Permissions: %s\n", info->permissions);
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 21:39:00 +00:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2014-03-02 13:07:07 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-03-05 21:39:00 +00:00
|
|
|
}
|
2014-03-02 13:07:07 +00:00
|
|
|
|
2014-05-22 01:12:56 +00:00
|
|
|
// When selection is presented back, returns 0. If it can make a decision right now, returns -1.
|
2014-05-22 04:19:15 +00:00
|
|
|
int menu_defer_core(void *info_, const char *dir, const char *path, char *deferred_path, size_t sizeof_deferred_path)
|
2014-05-22 01:12:56 +00:00
|
|
|
{
|
2014-05-22 04:19:15 +00:00
|
|
|
core_info_list_t *core_info;
|
|
|
|
const core_info_t *info;
|
2014-05-22 04:20:10 +00:00
|
|
|
size_t supported;
|
|
|
|
|
2014-05-22 04:19:15 +00:00
|
|
|
core_info = (core_info_list_t*)info_;
|
|
|
|
info = NULL;
|
2014-05-22 04:20:10 +00:00
|
|
|
supported = 0;
|
2014-05-22 01:12:56 +00:00
|
|
|
|
2014-05-22 04:19:15 +00:00
|
|
|
fill_pathname_join(deferred_path, dir, path, sizeof_deferred_path);
|
2014-05-22 01:12:56 +00:00
|
|
|
|
2014-05-22 04:19:15 +00:00
|
|
|
if (core_info)
|
|
|
|
core_info_list_get_supported_cores(core_info, deferred_path, &info, &supported);
|
2014-05-22 01:12:56 +00:00
|
|
|
|
|
|
|
if (supported == 1) // Can make a decision right now.
|
|
|
|
{
|
2014-05-22 04:19:15 +00:00
|
|
|
strlcpy(g_extern.fullpath, deferred_path, sizeof(g_extern.fullpath));
|
2014-05-22 01:12:56 +00:00
|
|
|
strlcpy(g_settings.libretro, info->path, sizeof(g_settings.libretro));
|
|
|
|
|
|
|
|
#ifdef HAVE_DYNAMIC
|
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME);
|
|
|
|
#else
|
|
|
|
rarch_environment_cb(RETRO_ENVIRONMENT_SET_LIBRETRO_PATH, (void*)g_settings.libretro);
|
|
|
|
rarch_environment_cb(RETRO_ENVIRONMENT_EXEC, (void*)g_extern.fullpath);
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void menu_rom_history_push(const char *path,
|
2013-05-17 16:22:03 +00:00
|
|
|
const char *core_path,
|
|
|
|
const char *core_name)
|
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
if (driver.menu && driver.menu->history)
|
|
|
|
rom_history_push(driver.menu->history, path, core_path, core_name);
|
2013-05-17 16:22:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void menu_rom_history_push_current(void)
|
2013-05-17 16:33:16 +00:00
|
|
|
{
|
|
|
|
// g_extern.fullpath can be relative here.
|
|
|
|
// Ensure we're pushing absolute path.
|
|
|
|
char tmp[PATH_MAX];
|
2014-05-30 17:33:10 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 17:33:10 +00:00
|
|
|
return;
|
2013-05-30 20:53:40 +00:00
|
|
|
|
2014-04-04 12:58:42 +00:00
|
|
|
strlcpy(tmp, g_extern.fullpath, sizeof(tmp));
|
2013-05-30 20:53:40 +00:00
|
|
|
|
2013-05-17 16:33:16 +00:00
|
|
|
if (*tmp)
|
|
|
|
path_resolve_realpath(tmp, sizeof(tmp));
|
|
|
|
|
2013-11-03 04:49:46 +00:00
|
|
|
if (g_extern.system.no_game || *tmp)
|
2014-05-30 17:33:10 +00:00
|
|
|
menu_rom_history_push(*tmp ? tmp : NULL,
|
2013-11-03 04:49:46 +00:00
|
|
|
g_settings.libretro,
|
|
|
|
g_extern.system.info.library_name);
|
2013-05-17 16:33:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void load_menu_game_prepare(void)
|
2013-04-28 14:38:13 +00:00
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 17:33:10 +00:00
|
|
|
return;
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (*g_extern.fullpath || driver.menu->load_no_rom)
|
2013-04-28 14:38:13 +00:00
|
|
|
{
|
2013-10-10 23:28:26 +00:00
|
|
|
if (*g_extern.fullpath)
|
2013-04-28 15:30:08 +00:00
|
|
|
{
|
|
|
|
char tmp[PATH_MAX];
|
|
|
|
char str[PATH_MAX];
|
2013-04-28 14:38:13 +00:00
|
|
|
|
2013-04-28 15:30:08 +00:00
|
|
|
fill_pathname_base(tmp, g_extern.fullpath, sizeof(tmp));
|
|
|
|
snprintf(str, sizeof(str), "INFO - Loading %s ...", tmp);
|
|
|
|
msg_queue_push(g_extern.msg_queue, str, 1, 1);
|
|
|
|
}
|
2013-04-28 14:38:13 +00:00
|
|
|
|
2013-11-03 14:17:45 +00:00
|
|
|
#ifdef RARCH_CONSOLE
|
|
|
|
if (g_extern.system.no_game || *g_extern.fullpath)
|
|
|
|
#endif
|
2014-05-30 17:33:10 +00:00
|
|
|
menu_rom_history_push(*g_extern.fullpath ? g_extern.fullpath : NULL,
|
2013-11-03 09:46:10 +00:00
|
|
|
g_settings.libretro,
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->info.library_name ? driver.menu->info.library_name : "");
|
2013-04-28 14:38:13 +00:00
|
|
|
}
|
|
|
|
|
2013-04-29 20:01:41 +00:00
|
|
|
// redraw RGUI frame
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->old_input_state = driver.menu->trigger_state = 0;
|
|
|
|
driver.menu->do_held = false;
|
|
|
|
driver.menu->msg_force = true;
|
2013-09-19 12:49:07 +00:00
|
|
|
|
2014-04-14 00:32:54 +00:00
|
|
|
if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->iterate)
|
2014-05-30 18:23:20 +00:00
|
|
|
driver.menu_ctx->backend->iterate(RGUI_ACTION_NOOP);
|
2013-04-29 20:01:41 +00:00
|
|
|
|
2013-04-28 14:38:13 +00:00
|
|
|
// Draw frame for loading message
|
2014-03-25 09:19:02 +00:00
|
|
|
if (driver.video_data && driver.video_poke && driver.video_poke->set_texture_enable)
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.video_poke->set_texture_enable(driver.video_data, driver.menu->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
|
2013-04-28 14:38:13 +00:00
|
|
|
|
2013-04-28 14:58:58 +00:00
|
|
|
if (driver.video)
|
|
|
|
rarch_render_cached_frame();
|
2013-04-28 14:38:13 +00:00
|
|
|
|
2014-03-25 09:19:02 +00:00
|
|
|
if (driver.video_data && driver.video_poke && driver.video_poke->set_texture_enable)
|
|
|
|
driver.video_poke->set_texture_enable(driver.video_data, false,
|
2013-04-28 14:38:13 +00:00
|
|
|
MENU_TEXTURE_FULLSCREEN);
|
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void load_menu_game_history(unsigned game_index)
|
2013-04-29 01:05:46 +00:00
|
|
|
{
|
|
|
|
const char *path = NULL;
|
2013-08-25 09:07:06 +00:00
|
|
|
const char *core_path = NULL;
|
2013-04-29 01:05:46 +00:00
|
|
|
const char *core_name = NULL;
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-09 03:47:32 +00:00
|
|
|
return;
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
rom_history_get_index(driver.menu->history,
|
2013-08-25 09:07:06 +00:00
|
|
|
game_index, &path, &core_path, &core_name);
|
2013-04-29 01:05:46 +00:00
|
|
|
|
2014-01-03 20:32:42 +00:00
|
|
|
// SET_LIBRETRO_PATH is unsafe here.
|
|
|
|
// Risks booting different and wrong core if core doesn't exist anymore.
|
|
|
|
strlcpy(g_settings.libretro, core_path, sizeof(g_settings.libretro));
|
2013-05-02 12:42:58 +00:00
|
|
|
|
|
|
|
if (path)
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->load_no_rom = false;
|
2013-05-02 12:42:58 +00:00
|
|
|
else
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->load_no_rom = true;
|
2013-04-29 01:05:46 +00:00
|
|
|
|
2013-08-25 09:07:06 +00:00
|
|
|
rarch_environment_cb(RETRO_ENVIRONMENT_EXEC, (void*)path);
|
2013-08-24 23:37:15 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_DYNAMIC)
|
2014-05-31 19:45:16 +00:00
|
|
|
menu_update_system_info(driver.menu, NULL);
|
2013-04-29 01:05:46 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-09 03:47:32 +00:00
|
|
|
static void menu_init_history(void *data)
|
2013-09-15 13:36:45 +00:00
|
|
|
{
|
2014-05-09 03:47:32 +00:00
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
if (!rgui)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rgui->history)
|
2013-09-15 13:36:45 +00:00
|
|
|
{
|
|
|
|
rom_history_free(rgui->history);
|
|
|
|
rgui->history = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*g_extern.config_path)
|
|
|
|
{
|
|
|
|
char history_path[PATH_MAX];
|
|
|
|
if (*g_settings.game_history_path)
|
|
|
|
strlcpy(history_path, g_settings.game_history_path, sizeof(history_path));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fill_pathname_resolve_relative(history_path, g_extern.config_path,
|
|
|
|
".retroarch-game-history.txt", sizeof(history_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
RARCH_LOG("[RGUI]: Opening history: %s.\n", history_path);
|
|
|
|
rgui->history = rom_history_init(history_path, g_settings.game_history_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-09 03:47:32 +00:00
|
|
|
static void menu_update_libretro_info(void *data)
|
2013-09-15 13:36:45 +00:00
|
|
|
{
|
2014-05-09 03:47:32 +00:00
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
|
|
|
|
|
|
|
if (!rgui)
|
|
|
|
return;
|
|
|
|
|
2013-10-31 01:53:01 +00:00
|
|
|
#ifndef HAVE_DYNAMIC
|
|
|
|
retro_get_system_info(&rgui->info);
|
|
|
|
#endif
|
|
|
|
|
2013-10-05 15:07:56 +00:00
|
|
|
core_info_list_free(rgui->core_info);
|
|
|
|
rgui->core_info = NULL;
|
2014-05-09 16:51:20 +00:00
|
|
|
if (*g_settings.libretro_directory)
|
|
|
|
rgui->core_info = core_info_list_new(g_settings.libretro_directory);
|
2014-03-02 13:07:07 +00:00
|
|
|
|
|
|
|
menu_update_system_info(rgui, NULL);
|
2013-09-15 13:36:45 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void load_menu_game_prepare_dummy(void)
|
2014-01-23 19:00:25 +00:00
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-09 03:47:32 +00:00
|
|
|
return;
|
|
|
|
|
2014-01-23 19:00:25 +00:00
|
|
|
// Starts dummy core.
|
|
|
|
*g_extern.fullpath = '\0';
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->load_no_rom = false;
|
2014-01-23 19:00:25 +00:00
|
|
|
|
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME);
|
|
|
|
g_extern.lifecycle_state &= ~(1ULL << MODE_GAME);
|
|
|
|
g_extern.system.shutdown = false;
|
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
bool load_menu_game(void)
|
2013-04-28 14:38:13 +00:00
|
|
|
{
|
2014-05-30 17:33:10 +00:00
|
|
|
int ret;
|
2014-05-09 03:47:32 +00:00
|
|
|
struct rarch_main_wrap args = {0};
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 15:49:04 +00:00
|
|
|
return false;
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
args.no_rom = driver.menu->load_no_rom;
|
2014-05-30 15:49:04 +00:00
|
|
|
|
2013-04-28 14:38:13 +00:00
|
|
|
if (g_extern.main_is_init)
|
|
|
|
rarch_main_deinit();
|
|
|
|
|
|
|
|
args.verbose = g_extern.verbose;
|
|
|
|
args.config_path = *g_extern.config_path ? g_extern.config_path : NULL;
|
|
|
|
args.sram_path = *g_extern.savefile_dir ? g_extern.savefile_dir : NULL;
|
|
|
|
args.state_path = *g_extern.savestate_dir ? g_extern.savestate_dir : NULL;
|
2013-04-28 14:58:58 +00:00
|
|
|
args.rom_path = *g_extern.fullpath ? g_extern.fullpath : NULL;
|
2013-09-15 13:36:45 +00:00
|
|
|
args.libretro_path = *g_settings.libretro ? g_settings.libretro : NULL;
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
ret = rarch_main_init_wrap(&args);
|
|
|
|
|
|
|
|
if (ret != 0)
|
2013-04-28 14:38:13 +00:00
|
|
|
{
|
2014-05-09 03:47:32 +00:00
|
|
|
char name[PATH_MAX], msg[PATH_MAX];
|
|
|
|
|
2013-05-01 01:45:02 +00:00
|
|
|
fill_pathname_base(name, g_extern.fullpath, sizeof(name));
|
|
|
|
snprintf(msg, sizeof(msg), "Failed to load %s.\n", name);
|
|
|
|
msg_queue_push(g_extern.msg_queue, msg, 1, 90);
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->msg_force = true;
|
2013-04-28 14:38:13 +00:00
|
|
|
RARCH_ERR("rarch_main_init_wrap() failed.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-09 03:47:32 +00:00
|
|
|
|
|
|
|
RARCH_LOG("rarch_main_init_wrap() succeeded.\n");
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
// Update menu state which depends on config.
|
|
|
|
menu_update_libretro_info(driver.menu);
|
|
|
|
menu_init_history(driver.menu);
|
2014-05-30 15:49:04 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->shader_manager_init)
|
|
|
|
driver.menu_ctx->backend->shader_manager_init(driver.menu);
|
2014-05-09 03:47:32 +00:00
|
|
|
|
|
|
|
return true;
|
2013-04-28 14:38:13 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 15:49:04 +00:00
|
|
|
void *menu_init(const void *data)
|
2013-04-18 12:57:28 +00:00
|
|
|
{
|
2014-05-26 21:18:49 +00:00
|
|
|
rgui_handle_t *rgui;
|
2014-05-30 15:49:04 +00:00
|
|
|
menu_ctx_driver_t *menu_ctx = (menu_ctx_driver_t*)data;
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-30 15:49:04 +00:00
|
|
|
if (!menu_ctx)
|
2014-05-09 03:47:32 +00:00
|
|
|
return NULL;
|
|
|
|
|
2014-05-30 15:49:04 +00:00
|
|
|
rgui = (rgui_handle_t*)menu_ctx->init();
|
2014-05-26 21:18:49 +00:00
|
|
|
|
|
|
|
if (!rgui)
|
2014-05-27 17:21:44 +00:00
|
|
|
return NULL;
|
2013-04-18 16:33:03 +00:00
|
|
|
|
2014-05-30 15:49:04 +00:00
|
|
|
strlcpy(g_settings.menu.driver, menu_ctx->ident, sizeof(g_settings.menu.driver));
|
2014-05-26 21:18:49 +00:00
|
|
|
|
2013-11-08 03:48:31 +00:00
|
|
|
rgui->menu_stack = (file_list_t*)calloc(1, sizeof(file_list_t));
|
|
|
|
rgui->selection_buf = (file_list_t*)calloc(1, sizeof(file_list_t));
|
2014-05-31 18:37:37 +00:00
|
|
|
rgui->core_info_current = (core_info_t*)calloc(1, sizeof(core_info_t));
|
2014-05-31 19:08:32 +00:00
|
|
|
#ifdef HAVE_SHADER_MANAGER
|
|
|
|
rgui->shader = (struct gfx_shader*)calloc(1, sizeof(struct gfx_shader));
|
|
|
|
#endif
|
2013-11-08 03:48:31 +00:00
|
|
|
file_list_push(rgui->menu_stack, "", RGUI_SETTINGS, 0);
|
2014-02-28 22:14:42 +00:00
|
|
|
menu_clear_navigation(rgui);
|
2013-11-04 12:18:07 +00:00
|
|
|
rgui->push_start_screen = g_settings.rgui_show_start_screen;
|
|
|
|
g_settings.rgui_show_start_screen = false;
|
2014-04-14 00:32:54 +00:00
|
|
|
|
2014-05-30 15:49:04 +00:00
|
|
|
if (menu_ctx && menu_ctx->backend && menu_ctx->backend->entries_init)
|
|
|
|
menu_ctx->backend->entries_init(rgui, RGUI_SETTINGS);
|
2013-11-04 12:18:07 +00:00
|
|
|
|
2013-04-19 15:53:01 +00:00
|
|
|
rgui->trigger_state = 0;
|
|
|
|
rgui->old_input_state = 0;
|
|
|
|
rgui->do_held = false;
|
|
|
|
rgui->frame_buf_show = true;
|
2013-05-04 14:13:58 +00:00
|
|
|
rgui->current_pad = 0;
|
2013-04-19 15:53:01 +00:00
|
|
|
|
2014-05-09 03:47:32 +00:00
|
|
|
menu_update_libretro_info(rgui);
|
2013-04-22 20:14:25 +00:00
|
|
|
|
2014-05-30 15:49:04 +00:00
|
|
|
if (menu_ctx && menu_ctx->backend && menu_ctx->backend->shader_manager_init)
|
|
|
|
menu_ctx->backend->shader_manager_init(rgui);
|
2013-04-28 01:48:35 +00:00
|
|
|
|
2014-05-09 03:47:32 +00:00
|
|
|
menu_init_history(rgui);
|
2013-07-06 18:39:19 +00:00
|
|
|
rgui->last_time = rarch_get_time_usec();
|
2014-05-09 03:47:32 +00:00
|
|
|
|
|
|
|
return rgui;
|
2013-04-18 12:57:28 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 03:47:32 +00:00
|
|
|
void menu_free(void *data)
|
2013-04-18 12:57:28 +00:00
|
|
|
{
|
2014-05-09 03:47:32 +00:00
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
|
|
|
|
|
|
|
if (!rgui)
|
|
|
|
return;
|
2014-05-31 19:08:32 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SHADER_MANAGER
|
|
|
|
if (rgui->shader)
|
|
|
|
free(rgui->shader);
|
|
|
|
rgui->shader = NULL;
|
|
|
|
#endif
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-04-01 02:03:55 +00:00
|
|
|
if (driver.menu_ctx && driver.menu_ctx->free)
|
|
|
|
driver.menu_ctx->free(rgui);
|
2013-04-18 15:29:04 +00:00
|
|
|
|
2014-03-06 01:14:38 +00:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2013-11-04 12:18:07 +00:00
|
|
|
libretro_free_system_info(&rgui->info);
|
2014-03-06 01:14:38 +00:00
|
|
|
#endif
|
2013-11-04 12:18:07 +00:00
|
|
|
|
2013-11-08 03:48:31 +00:00
|
|
|
file_list_free(rgui->menu_stack);
|
|
|
|
file_list_free(rgui->selection_buf);
|
2013-11-04 12:18:07 +00:00
|
|
|
|
2013-04-28 01:48:35 +00:00
|
|
|
rom_history_free(rgui->history);
|
2013-10-05 15:07:56 +00:00
|
|
|
core_info_list_free(rgui->core_info);
|
2013-04-28 01:48:35 +00:00
|
|
|
|
2014-05-31 18:37:37 +00:00
|
|
|
if (rgui->core_info_current)
|
|
|
|
free(rgui->core_info_current);
|
|
|
|
|
2014-05-30 18:53:10 +00:00
|
|
|
free(data);
|
2013-04-18 12:57:28 +00:00
|
|
|
}
|
2013-04-19 15:53:01 +00:00
|
|
|
|
2013-05-05 19:42:14 +00:00
|
|
|
void menu_ticker_line(char *buf, size_t len, unsigned index, const char *str, bool selected)
|
2013-05-05 09:26:02 +00:00
|
|
|
{
|
|
|
|
size_t str_len = strlen(str);
|
|
|
|
if (str_len <= len)
|
|
|
|
{
|
|
|
|
strlcpy(buf, str, len + 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-05 19:42:14 +00:00
|
|
|
if (!selected)
|
2013-05-05 20:19:27 +00:00
|
|
|
{
|
|
|
|
strlcpy(buf, str, len + 1 - 3);
|
|
|
|
strlcat(buf, "...", len + 1);
|
|
|
|
}
|
2013-05-05 09:26:02 +00:00
|
|
|
else
|
2013-05-05 19:42:14 +00:00
|
|
|
{
|
|
|
|
// Wrap long strings in options with some kind of ticker line.
|
|
|
|
unsigned ticker_period = 2 * (str_len - len) + 4;
|
|
|
|
unsigned phase = index % ticker_period;
|
|
|
|
|
|
|
|
unsigned phase_left_stop = 2;
|
|
|
|
unsigned phase_left_moving = phase_left_stop + (str_len - len);
|
|
|
|
unsigned phase_right_stop = phase_left_moving + 2;
|
|
|
|
|
|
|
|
unsigned left_offset = phase - phase_left_stop;
|
|
|
|
unsigned right_offset = (str_len - len) - (phase - phase_right_stop);
|
|
|
|
|
|
|
|
// Ticker period: [Wait at left (2 ticks), Progress to right (type_len - w), Wait at right (2 ticks), Progress to left].
|
|
|
|
if (phase < phase_left_stop)
|
|
|
|
strlcpy(buf, str, len + 1);
|
|
|
|
else if (phase < phase_left_moving)
|
|
|
|
strlcpy(buf, str + left_offset, len + 1);
|
|
|
|
else if (phase < phase_right_stop)
|
|
|
|
strlcpy(buf, str + str_len - len, len + 1);
|
|
|
|
else
|
|
|
|
strlcpy(buf, str + right_offset, len + 1);
|
|
|
|
}
|
2013-05-05 09:26:02 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
uint64_t menu_input(void)
|
2013-05-27 09:11:23 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned i;
|
2014-05-09 03:47:32 +00:00
|
|
|
uint64_t input_state;
|
2013-12-12 21:10:11 +00:00
|
|
|
static const struct retro_keybind *binds[] = { g_settings.input.binds[0] };
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-09 03:47:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
input_state = 0;
|
|
|
|
|
|
|
|
|
2014-05-14 02:40:06 +00:00
|
|
|
input_push_analog_dpad((struct retro_keybind*)binds[0], (g_settings.input.analog_dpad_mode[0] == ANALOG_DPAD_NONE) ? ANALOG_DPAD_LSTICK : g_settings.input.analog_dpad_mode[0]);
|
2014-01-08 16:47:07 +00:00
|
|
|
for (i = 0; i < MAX_PLAYERS; i++)
|
|
|
|
input_push_analog_dpad(g_settings.input.autoconf_binds[i], g_settings.input.analog_dpad_mode[i]);
|
2014-01-08 16:31:14 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < RETRO_DEVICE_ID_JOYPAD_R2; i++)
|
2013-05-27 09:11:23 +00:00
|
|
|
{
|
|
|
|
input_state |= input_input_state_func(binds,
|
2013-09-27 12:31:16 +00:00
|
|
|
0, RETRO_DEVICE_JOYPAD, 0, i) ? (1ULL << i) : 0;
|
2013-05-27 09:11:23 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
2013-09-27 12:31:16 +00:00
|
|
|
input_state |= (driver.overlay_state.buttons & (UINT64_C(1) << i)) ? (1ULL << i) : 0;
|
2013-05-27 09:11:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-27 12:31:16 +00:00
|
|
|
input_state |= input_key_pressed_func(RARCH_MENU_TOGGLE) ? (1ULL << RARCH_MENU_TOGGLE) : 0;
|
2013-05-27 09:11:23 +00:00
|
|
|
|
2014-01-08 16:31:14 +00:00
|
|
|
input_pop_analog_dpad((struct retro_keybind*)binds[0]);
|
2014-01-08 16:47:07 +00:00
|
|
|
for (i = 0; i < MAX_PLAYERS; i++)
|
|
|
|
input_pop_analog_dpad(g_settings.input.autoconf_binds[i]);
|
2014-01-08 16:31:14 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->trigger_state = input_state & ~driver.menu->old_input_state;
|
2013-05-27 09:11:23 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->do_held = (input_state & (
|
2013-09-27 12:31:16 +00:00
|
|
|
(1ULL << RETRO_DEVICE_ID_JOYPAD_UP)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_L)
|
|
|
|
| (1ULL << RETRO_DEVICE_ID_JOYPAD_R)
|
|
|
|
)) && !(input_state & (1ULL << RARCH_MENU_TOGGLE));
|
2013-05-27 09:11:23 +00:00
|
|
|
|
|
|
|
return input_state;
|
|
|
|
}
|
|
|
|
|
2014-04-13 10:12:12 +00:00
|
|
|
bool menu_custom_bind_keyboard_cb(void *data, unsigned code)
|
|
|
|
{
|
|
|
|
rgui_handle_t *rgui = (rgui_handle_t*)data;
|
2014-05-30 17:33:10 +00:00
|
|
|
|
|
|
|
if (!rgui)
|
|
|
|
return false;
|
|
|
|
|
2014-04-14 07:07:15 +00:00
|
|
|
rgui->binds.target->key = (enum retro_key)code;
|
2014-04-13 10:12:12 +00:00
|
|
|
rgui->binds.begin++;
|
|
|
|
rgui->binds.target++;
|
|
|
|
rgui->binds.timeout_end = rarch_get_time_usec() + RGUI_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
|
|
|
|
return rgui->binds.begin <= rgui->binds.last;
|
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void menu_flush_stack_type(unsigned final_type)
|
2013-11-04 15:23:37 +00:00
|
|
|
{
|
|
|
|
unsigned type;
|
2014-05-30 17:33:10 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 17:33:10 +00:00
|
|
|
return;
|
|
|
|
|
2013-11-04 15:23:37 +00:00
|
|
|
type = 0;
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->need_refresh = true;
|
|
|
|
file_list_get_last(driver.menu->menu_stack, NULL, &type);
|
2013-11-04 15:23:37 +00:00
|
|
|
while (type != final_type)
|
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
file_list_pop(driver.menu->menu_stack, &driver.menu->selection_ptr);
|
|
|
|
file_list_get_last(driver.menu->menu_stack, NULL, &type);
|
2013-11-04 15:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
void load_menu_game_new_core(void)
|
2013-11-24 21:02:57 +00:00
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-09 03:47:32 +00:00
|
|
|
return;
|
|
|
|
|
2013-11-24 21:02:57 +00:00
|
|
|
#ifdef HAVE_DYNAMIC
|
2014-05-31 19:45:16 +00:00
|
|
|
menu_update_system_info(driver.menu, &driver.menu->load_no_rom);
|
2013-11-24 21:02:57 +00:00
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME);
|
|
|
|
#else
|
|
|
|
rarch_environment_cb(RETRO_ENVIRONMENT_SET_LIBRETRO_PATH, (void*)g_settings.libretro);
|
|
|
|
rarch_environment_cb(RETRO_ENVIRONMENT_EXEC, (void*)g_extern.fullpath);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-05-30 18:53:10 +00:00
|
|
|
bool menu_iterate(void)
|
2013-04-19 15:53:01 +00:00
|
|
|
{
|
2013-11-04 15:23:37 +00:00
|
|
|
unsigned action;
|
2013-04-19 15:53:01 +00:00
|
|
|
static bool initial_held = true;
|
|
|
|
static bool first_held = false;
|
2014-05-09 03:47:32 +00:00
|
|
|
uint64_t input_state;
|
2014-05-14 01:47:11 +00:00
|
|
|
int32_t input_entry_ret, ret;
|
2014-04-13 10:12:12 +00:00
|
|
|
|
2014-05-09 03:47:32 +00:00
|
|
|
input_state = 0;
|
2014-02-28 00:44:03 +00:00
|
|
|
input_entry_ret = 0;
|
|
|
|
ret = 0;
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-09 03:47:32 +00:00
|
|
|
return false;
|
2013-04-19 15:53:01 +00:00
|
|
|
|
2013-11-07 20:44:44 +00:00
|
|
|
if (g_extern.lifecycle_state & (1ULL << MODE_MENU_PREINIT))
|
2013-04-19 15:53:01 +00:00
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->need_refresh = true;
|
2013-11-07 20:44:44 +00:00
|
|
|
g_extern.lifecycle_state &= ~(1ULL << MODE_MENU_PREINIT);
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->old_input_state |= 1ULL << RARCH_MENU_TOGGLE;
|
2013-04-19 15:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rarch_input_poll();
|
2014-03-17 10:34:25 +00:00
|
|
|
rarch_check_block_hotkey();
|
2013-04-19 15:53:01 +00:00
|
|
|
#ifdef HAVE_OVERLAY
|
|
|
|
rarch_check_overlay();
|
|
|
|
#endif
|
2014-02-08 15:27:09 +00:00
|
|
|
rarch_check_fullscreen();
|
2013-04-19 15:53:01 +00:00
|
|
|
|
|
|
|
if (input_key_pressed_func(RARCH_QUIT_KEY) || !video_alive_func())
|
|
|
|
{
|
2013-11-07 20:44:44 +00:00
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_GAME);
|
2014-03-17 10:34:25 +00:00
|
|
|
return false;
|
2013-04-19 15:53:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 17:33:10 +00:00
|
|
|
input_state = menu_input();
|
2013-04-19 15:53:01 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (driver.menu->do_held)
|
2013-04-19 15:53:01 +00:00
|
|
|
{
|
2013-04-20 22:01:49 +00:00
|
|
|
if (!first_held)
|
2013-04-19 15:53:01 +00:00
|
|
|
{
|
|
|
|
first_held = true;
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->delay_timer = initial_held ? 12 : 6;
|
|
|
|
driver.menu->delay_count = 0;
|
2013-04-19 15:53:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (driver.menu->delay_count >= driver.menu->delay_timer)
|
2013-04-19 15:53:01 +00:00
|
|
|
{
|
|
|
|
first_held = false;
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->trigger_state = input_state;
|
|
|
|
driver.menu->scroll_accel = min(driver.menu->scroll_accel + 1, 64);
|
2013-04-19 15:53:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initial_held = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first_held = false;
|
|
|
|
initial_held = true;
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->scroll_accel = 0;
|
2013-04-19 15:53:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->delay_count++;
|
|
|
|
driver.menu->old_input_state = input_state;
|
2013-09-19 12:49:07 +00:00
|
|
|
|
2013-12-09 15:18:58 +00:00
|
|
|
if (driver.block_input)
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->trigger_state = 0;
|
2013-12-09 15:18:58 +00:00
|
|
|
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_NOOP;
|
|
|
|
|
|
|
|
// don't run anything first frame, only capture held inputs for old_input_state
|
2014-05-31 19:45:16 +00:00
|
|
|
if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_UP))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_UP;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_DOWN;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_LEFT;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_RIGHT;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_L))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_SCROLL_UP;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_R))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_SCROLL_DOWN;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_B))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_CANCEL;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_A))
|
2013-09-26 20:34:06 +00:00
|
|
|
action = RGUI_ACTION_OK;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_START))
|
2013-09-27 15:00:00 +00:00
|
|
|
action = RGUI_ACTION_START;
|
2014-05-31 19:45:16 +00:00
|
|
|
else if (driver.menu->trigger_state & (1ULL << RETRO_DEVICE_ID_JOYPAD_SELECT))
|
2014-05-31 03:14:04 +00:00
|
|
|
action = RGUI_ACTION_SELECT;
|
2013-09-26 20:34:06 +00:00
|
|
|
|
2014-04-14 00:32:54 +00:00
|
|
|
if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->iterate)
|
2014-05-30 18:23:20 +00:00
|
|
|
input_entry_ret = driver.menu_ctx->backend->iterate(action);
|
2014-03-09 15:47:36 +00:00
|
|
|
|
2014-03-25 09:19:02 +00:00
|
|
|
if (driver.video_data && driver.video_poke && driver.video_poke->set_texture_enable)
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.video_poke->set_texture_enable(driver.video_data, driver.menu->frame_buf_show, MENU_TEXTURE_FULLSCREEN);
|
2013-04-19 15:53:01 +00:00
|
|
|
|
|
|
|
rarch_render_cached_frame();
|
|
|
|
|
2013-07-06 18:39:19 +00:00
|
|
|
// Throttle in case VSync is broken (avoid 1000+ FPS RGUI).
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->time = rarch_get_time_usec();
|
|
|
|
driver.menu->delta = (driver.menu->time - driver.menu->last_time) / 1000;
|
|
|
|
driver.menu->target_msec = 750 / g_settings.video.refresh_rate; // Try to sleep less, so we can hopefully rely on FPS logger.
|
|
|
|
driver.menu->sleep_msec = driver.menu->target_msec - driver.menu->delta;
|
2014-05-09 15:29:41 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (driver.menu->sleep_msec > 0)
|
|
|
|
rarch_sleep((unsigned int)driver.menu->sleep_msec);
|
|
|
|
driver.menu->last_time = rarch_get_time_usec();
|
2013-07-06 18:39:19 +00:00
|
|
|
|
2014-03-25 09:19:02 +00:00
|
|
|
if (driver.video_data && driver.video_poke && driver.video_poke->set_texture_enable)
|
|
|
|
driver.video_poke->set_texture_enable(driver.video_data, false,
|
2013-04-20 08:56:04 +00:00
|
|
|
MENU_TEXTURE_FULLSCREEN);
|
2013-04-19 15:53:01 +00:00
|
|
|
|
2014-04-01 02:03:55 +00:00
|
|
|
if (driver.menu_ctx && driver.menu_ctx->input_postprocess)
|
2014-05-31 19:45:16 +00:00
|
|
|
ret = driver.menu_ctx->input_postprocess(driver.menu->old_input_state);
|
2013-11-04 15:37:51 +00:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
unsigned type = 0;
|
2014-05-31 19:45:16 +00:00
|
|
|
file_list_get_last(driver.menu->menu_stack, NULL, &type);
|
2013-11-04 15:37:51 +00:00
|
|
|
while (type != RGUI_SETTINGS)
|
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
file_list_pop(driver.menu->menu_stack, &driver.menu->selection_ptr);
|
|
|
|
file_list_get_last(driver.menu->menu_stack, NULL, &type);
|
2013-11-04 15:37:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret || input_entry_ret)
|
2014-03-17 10:34:25 +00:00
|
|
|
return false;
|
2013-04-19 15:53:01 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-15 13:36:45 +00:00
|
|
|
|
|
|
|
// Quite intrusive and error prone.
|
|
|
|
// Likely to have lots of small bugs.
|
|
|
|
// Cleanly exit the main loop to ensure that all the tiny details get set properly.
|
|
|
|
// This should mitigate most of the smaller bugs.
|
2014-05-30 17:33:10 +00:00
|
|
|
bool menu_replace_config(const char *path)
|
2013-09-15 13:36:45 +00:00
|
|
|
{
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 17:33:10 +00:00
|
|
|
return false;
|
2014-05-09 03:47:32 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (strcmp(path, g_extern.config_path) == 0)
|
2013-09-15 13:36:45 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (g_extern.config_save_on_exit && *g_extern.config_path)
|
|
|
|
config_save_file(g_extern.config_path);
|
|
|
|
|
|
|
|
strlcpy(g_extern.config_path, path, sizeof(g_extern.config_path));
|
|
|
|
g_extern.block_config_read = false;
|
|
|
|
|
|
|
|
// Load dummy core.
|
|
|
|
*g_extern.fullpath = '\0';
|
|
|
|
*g_settings.libretro = '\0'; // Load core in new config.
|
2013-11-07 20:44:44 +00:00
|
|
|
g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME);
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->load_no_rom = false;
|
2013-09-15 13:36:45 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-22 10:48:33 +00:00
|
|
|
// Save a new config to a file. Filename is based on heuristics to avoid typing.
|
|
|
|
bool menu_save_new_config(void)
|
|
|
|
{
|
|
|
|
char config_dir[PATH_MAX];
|
|
|
|
*config_dir = '\0';
|
|
|
|
|
|
|
|
if (*g_settings.rgui_config_directory)
|
|
|
|
strlcpy(config_dir, g_settings.rgui_config_directory, sizeof(config_dir));
|
|
|
|
else if (*g_extern.config_path) // Fallback
|
|
|
|
fill_pathname_basedir(config_dir, g_extern.config_path, sizeof(config_dir));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *msg = "Config directory not set. Cannot save new config.";
|
|
|
|
msg_queue_clear(g_extern.msg_queue);
|
|
|
|
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
|
|
|
RARCH_ERR("%s\n", msg);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool found_path = false;
|
|
|
|
char config_name[PATH_MAX];
|
|
|
|
char config_path[PATH_MAX];
|
2014-05-09 16:51:20 +00:00
|
|
|
if (*g_settings.libretro && path_file_exists(g_settings.libretro)) // Infer file name based on libretro core.
|
2013-09-22 10:48:33 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned i;
|
2013-09-22 10:48:33 +00:00
|
|
|
// In case of collision, find an alternative name.
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < 16; i++)
|
2013-09-22 10:48:33 +00:00
|
|
|
{
|
|
|
|
fill_pathname_base(config_name, g_settings.libretro, sizeof(config_name));
|
|
|
|
path_remove_extension(config_name);
|
|
|
|
fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path));
|
|
|
|
|
|
|
|
char tmp[64];
|
|
|
|
*tmp = '\0';
|
|
|
|
if (i)
|
|
|
|
snprintf(tmp, sizeof(tmp), "-%u.cfg", i);
|
|
|
|
else
|
|
|
|
strlcpy(tmp, ".cfg", sizeof(tmp));
|
|
|
|
|
|
|
|
strlcat(config_path, tmp, sizeof(config_path));
|
|
|
|
|
|
|
|
if (!path_file_exists(config_path))
|
|
|
|
{
|
|
|
|
found_path = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to system time ...
|
|
|
|
if (!found_path)
|
|
|
|
{
|
|
|
|
RARCH_WARN("Cannot infer new config path. Use current time.\n");
|
|
|
|
fill_dated_filename(config_name, "cfg", sizeof(config_name));
|
|
|
|
fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
char msg[512];
|
|
|
|
bool ret;
|
|
|
|
if (config_save_file(config_path))
|
|
|
|
{
|
|
|
|
strlcpy(g_extern.config_path, config_path, sizeof(g_extern.config_path));
|
|
|
|
snprintf(msg, sizeof(msg), "Saved new config to \"%s\".", config_path);
|
|
|
|
RARCH_LOG("%s\n", msg);
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".", config_path);
|
|
|
|
RARCH_ERR("%s\n", msg);
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg_queue_clear(g_extern.msg_queue);
|
|
|
|
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-31 19:31:31 +00:00
|
|
|
void menu_poll_bind_state(void *data)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2014-05-31 19:31:31 +00:00
|
|
|
struct rgui_bind_state *state = (struct rgui_bind_state*)data;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
2013-11-04 10:32:43 +00:00
|
|
|
unsigned i, b, a, h;
|
2013-09-29 15:58:46 +00:00
|
|
|
memset(state->state, 0, sizeof(state->state));
|
|
|
|
state->skip = input_input_state_func(NULL, 0, RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN);
|
|
|
|
|
|
|
|
const rarch_joypad_driver_t *joypad = NULL;
|
|
|
|
if (driver.input && driver.input_data && driver.input->get_joypad_driver)
|
|
|
|
joypad = driver.input->get_joypad_driver(driver.input_data);
|
|
|
|
|
|
|
|
if (!joypad)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot poll raw joypad state.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_joypad_poll(joypad);
|
2013-11-04 10:32:43 +00:00
|
|
|
for (i = 0; i < MAX_PLAYERS; i++)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
for (b = 0; b < RGUI_MAX_BUTTONS; b++)
|
2013-11-04 10:32:43 +00:00
|
|
|
state->state[i].buttons[b] = input_joypad_button_raw(joypad, i, b);
|
2013-10-22 13:08:17 +00:00
|
|
|
for (a = 0; a < RGUI_MAX_AXES; a++)
|
2013-11-04 10:32:43 +00:00
|
|
|
state->state[i].axes[a] = input_joypad_axis_raw(joypad, i, a);
|
2013-10-22 13:08:17 +00:00
|
|
|
for (h = 0; h < RGUI_MAX_HATS; h++)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-11-04 10:32:43 +00:00
|
|
|
state->state[i].hats[h] |= input_joypad_hat_raw(joypad, i, HAT_UP_MASK, h) ? HAT_UP_MASK : 0;
|
|
|
|
state->state[i].hats[h] |= input_joypad_hat_raw(joypad, i, HAT_DOWN_MASK, h) ? HAT_DOWN_MASK : 0;
|
|
|
|
state->state[i].hats[h] |= input_joypad_hat_raw(joypad, i, HAT_LEFT_MASK, h) ? HAT_LEFT_MASK : 0;
|
|
|
|
state->state[i].hats[h] |= input_joypad_hat_raw(joypad, i, HAT_RIGHT_MASK, h) ? HAT_RIGHT_MASK : 0;
|
2013-09-29 15:58:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 19:31:31 +00:00
|
|
|
void menu_poll_bind_get_rested_axes(void *data)
|
2013-09-29 17:09:33 +00:00
|
|
|
{
|
2013-11-04 10:32:43 +00:00
|
|
|
unsigned i, a;
|
2013-09-29 17:09:33 +00:00
|
|
|
const rarch_joypad_driver_t *joypad = NULL;
|
2014-05-31 19:31:31 +00:00
|
|
|
struct rgui_bind_state *state = (struct rgui_bind_state*)data;
|
|
|
|
|
|
|
|
if (!state)
|
|
|
|
return;
|
|
|
|
|
2013-09-29 17:09:33 +00:00
|
|
|
if (driver.input && driver.input_data && driver.input->get_joypad_driver)
|
|
|
|
joypad = driver.input->get_joypad_driver(driver.input_data);
|
|
|
|
|
|
|
|
if (!joypad)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Cannot poll raw joypad state.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-04 10:32:43 +00:00
|
|
|
for (i = 0; i < MAX_PLAYERS; i++)
|
2013-10-22 13:08:17 +00:00
|
|
|
for (a = 0; a < RGUI_MAX_AXES; a++)
|
2013-11-04 10:32:43 +00:00
|
|
|
state->axis_state[i].rested_axes[a] = input_joypad_axis_raw(joypad, i, a);
|
2013-09-29 17:09:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool menu_poll_find_trigger_pad(struct rgui_bind_state *state, struct rgui_bind_state *new_state, unsigned p)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
unsigned a, b, h;
|
2014-05-31 19:45:16 +00:00
|
|
|
const struct rgui_bind_state_port *n = (const struct rgui_bind_state_port*)&new_state->state[p];
|
|
|
|
const struct rgui_bind_state_port *o = (const struct rgui_bind_state_port*)&state->state[p];
|
2013-09-29 17:09:33 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (b = 0; b < RGUI_MAX_BUTTONS; b++)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
|
|
|
if (n->buttons[b] && !o->buttons[b])
|
|
|
|
{
|
|
|
|
state->target->joykey = b;
|
|
|
|
state->target->joyaxis = AXIS_NONE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-29 17:09:33 +00:00
|
|
|
// Axes are a bit tricky ...
|
2013-10-22 13:08:17 +00:00
|
|
|
for (a = 0; a < RGUI_MAX_AXES; a++)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-09-29 17:09:33 +00:00
|
|
|
int locked_distance = abs(n->axes[a] - new_state->axis_state[p].locked_axes[a]);
|
|
|
|
int rested_distance = abs(n->axes[a] - new_state->axis_state[p].rested_axes[a]);
|
|
|
|
|
|
|
|
if (abs(n->axes[a]) >= 20000 &&
|
|
|
|
locked_distance >= 20000 &&
|
|
|
|
rested_distance >= 20000) // Take care of case where axis rests on +/- 0x7fff (e.g. 360 controller on Linux)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
|
|
|
state->target->joyaxis = n->axes[a] > 0 ? AXIS_POS(a) : AXIS_NEG(a);
|
|
|
|
state->target->joykey = NO_BTN;
|
2013-09-29 17:09:33 +00:00
|
|
|
|
|
|
|
// Lock the current axis.
|
2014-04-13 10:12:12 +00:00
|
|
|
new_state->axis_state[p].locked_axes[a] = n->axes[a] > 0 ? 0x7fff : -0x7fff;
|
2013-09-29 15:58:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-29 17:09:33 +00:00
|
|
|
|
|
|
|
if (locked_distance >= 20000) // Unlock the axis.
|
|
|
|
new_state->axis_state[p].locked_axes[a] = 0;
|
2013-09-29 15:58:46 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (h = 0; h < RGUI_MAX_HATS; h++)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
|
|
|
uint16_t trigged = n->hats[h] & (~o->hats[h]);
|
|
|
|
uint16_t sane_trigger = 0;
|
|
|
|
if (trigged & HAT_UP_MASK)
|
|
|
|
sane_trigger = HAT_UP_MASK;
|
|
|
|
else if (trigged & HAT_DOWN_MASK)
|
|
|
|
sane_trigger = HAT_DOWN_MASK;
|
|
|
|
else if (trigged & HAT_LEFT_MASK)
|
|
|
|
sane_trigger = HAT_LEFT_MASK;
|
|
|
|
else if (trigged & HAT_RIGHT_MASK)
|
|
|
|
sane_trigger = HAT_RIGHT_MASK;
|
|
|
|
|
|
|
|
if (sane_trigger)
|
|
|
|
{
|
|
|
|
state->target->joykey = HAT_MAP(h, sane_trigger);
|
|
|
|
state->target->joyaxis = AXIS_NONE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-31 19:31:31 +00:00
|
|
|
bool menu_poll_find_trigger(void *data1, void *data2)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-11-04 10:32:43 +00:00
|
|
|
unsigned i;
|
2014-05-31 19:31:31 +00:00
|
|
|
struct rgui_bind_state *state, *new_state;
|
|
|
|
state = (struct rgui_bind_state*)data1;
|
|
|
|
new_state = (struct rgui_bind_state*)data2;
|
|
|
|
|
|
|
|
if (!state || !new_state)
|
|
|
|
return false;
|
|
|
|
|
2013-11-04 10:32:43 +00:00
|
|
|
for (i = 0; i < MAX_PLAYERS; i++)
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-11-04 10:32:43 +00:00
|
|
|
if (menu_poll_find_trigger_pad(state, new_state, i))
|
2013-09-29 15:58:46 +00:00
|
|
|
{
|
2013-11-04 10:32:43 +00:00
|
|
|
g_settings.input.joypad_map[state->player] = i; // Update the joypad mapping automatically. More friendly that way.
|
2013-09-29 15:58:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-22 10:48:33 +00:00
|
|
|
|
2013-11-08 03:48:31 +00:00
|
|
|
static inline int menu_list_get_first_char(file_list_t *buf, unsigned offset)
|
2013-11-04 10:57:24 +00:00
|
|
|
{
|
|
|
|
const char *path = NULL;
|
2013-11-08 03:48:31 +00:00
|
|
|
file_list_get_alt_at_offset(buf, offset, &path);
|
2013-11-04 10:57:24 +00:00
|
|
|
int ret = tolower(*path);
|
2014-04-13 10:12:12 +00:00
|
|
|
|
2013-11-04 10:57:24 +00:00
|
|
|
// "Normalize" non-alphabetical entries so they are lumped together for purposes of jumping.
|
|
|
|
if (ret < 'a')
|
|
|
|
ret = 'a' - 1;
|
|
|
|
else if (ret > 'z')
|
|
|
|
ret = 'z' + 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-08 03:48:31 +00:00
|
|
|
static inline bool menu_list_elem_is_dir(file_list_t *buf, unsigned offset)
|
2013-11-04 10:57:24 +00:00
|
|
|
{
|
|
|
|
const char *path = NULL;
|
|
|
|
unsigned type = 0;
|
2013-11-08 03:48:31 +00:00
|
|
|
file_list_get_at_offset(buf, offset, &path, &type);
|
2013-11-04 10:57:24 +00:00
|
|
|
return type != RGUI_FILE_PLAIN;
|
|
|
|
}
|
|
|
|
|
2014-05-30 20:06:54 +00:00
|
|
|
void menu_build_scroll_indices(file_list_t *buf)
|
2013-11-04 10:57:24 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
int current;
|
|
|
|
bool current_is_dir;
|
2014-05-30 20:06:54 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
if (!driver.menu)
|
2014-05-30 20:06:54 +00:00
|
|
|
return;
|
2013-11-04 10:57:24 +00:00
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->scroll_indices_size = 0;
|
2013-11-04 10:57:24 +00:00
|
|
|
if (!buf->size)
|
|
|
|
return;
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->scroll_indices[driver.menu->scroll_indices_size++] = 0;
|
2013-11-04 10:57:24 +00:00
|
|
|
|
2013-11-08 02:37:06 +00:00
|
|
|
current = menu_list_get_first_char(buf, 0);
|
|
|
|
current_is_dir = menu_list_elem_is_dir(buf, 0);
|
2013-11-04 10:57:24 +00:00
|
|
|
|
|
|
|
for (i = 1; i < buf->size; i++)
|
|
|
|
{
|
|
|
|
int first;
|
|
|
|
bool is_dir;
|
|
|
|
|
2013-11-08 02:37:06 +00:00
|
|
|
first = menu_list_get_first_char(buf, i);
|
|
|
|
is_dir = menu_list_elem_is_dir(buf, i);
|
2013-11-04 10:57:24 +00:00
|
|
|
|
|
|
|
if ((current_is_dir && !is_dir) || (first > current))
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->scroll_indices[driver.menu->scroll_indices_size++] = i;
|
2013-11-04 10:57:24 +00:00
|
|
|
|
|
|
|
current = first;
|
|
|
|
current_is_dir = is_dir;
|
|
|
|
}
|
|
|
|
|
2014-05-31 19:45:16 +00:00
|
|
|
driver.menu->scroll_indices[driver.menu->scroll_indices_size++] = buf->size - 1;
|
2013-11-04 10:57:24 +00:00
|
|
|
}
|