361 lines
9.1 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2014-01-01 01:50:59 +01:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 17:46:50 +01:00
* Copyright (C) 2011-2015 - Daniel De Matteis
* Copyright (C) 2012-2015 - Michael Lelli
*
* 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 <stdlib.h>
#include <stddef.h>
2014-10-16 07:27:42 +02:00
#include <stdint.h>
#include <string.h>
#include <limits.h>
2015-06-05 18:22:15 +02:00
#include <compat/posix_string.h>
2015-06-17 19:48:55 +02:00
#include <string/string_list.h>
2015-06-05 18:22:15 +02:00
2015-10-03 03:15:47 +02:00
#include "menu_generic.h"
2015-07-09 18:39:40 +02:00
#include "../menu.h"
#include "../menu_driver.h"
#include "../menu_entry.h"
2015-01-26 10:54:13 +01:00
#include "../menu_input.h"
2015-06-02 21:41:09 +02:00
#include "../menu_setting.h"
2015-10-18 07:15:54 +02:00
#include "../menu_display.h"
2014-10-28 19:54:23 +01:00
#include "../../general.h"
#include "../../config.def.h"
#include "../../performance.h"
2014-10-28 19:54:23 +01:00
#include "../../screenshot.h"
2015-01-12 23:38:21 +01:00
#include "../../gfx/drivers_font_renderer/bitmap.h"
#if defined(HAVE_CG) || defined(HAVE_GLSL) || defined(HAVE_HLSL)
#define HAVE_SHADER_MANAGER
#endif
#if defined(_XBOX1)
#define ENTRIES_HEIGHT 9
#define POSITION_EDGE_MAX (480)
#define POSITION_EDGE_MIN 6
#define POSITION_EDGE_CENTER (425)
#define POSITION_OFFSET 30
#define POSITION_RENDER_OFFSET 128
2014-02-28 01:34:10 +01:00
#define RMENU_TERM_WIDTH 45
2013-11-11 03:36:30 +01:00
#define FONT_SIZE_NORMAL 21
#elif defined(__CELLOS_LV2__)
#define ENTRIES_HEIGHT 20
#define POSITION_MIDDLE 0.50f
#define POSITION_EDGE_MAX 1.00f
#define POSITION_EDGE_MIN 0.00f
#define POSITION_EDGE_CENTER 0.70f
#define POSITION_RENDER_OFFSET 0.20f
2013-11-07 16:40:04 +01:00
#define POSITION_OFFSET 0.03f
#define FONT_SIZE_NORMAL 0.95f
2014-02-28 01:34:10 +01:00
#define RMENU_TERM_WIDTH 60
#endif
struct texture_image *menu_texture;
static bool render_normal = true;
static bool menu_texture_inited =false;
static void rmenu_render_messagebox(const char *message)
{
2014-06-09 13:13:18 +02:00
struct font_params font_parms;
size_t i, j;
2015-02-01 15:25:37 +01:00
struct string_list *list = NULL;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
if (!message || !*message)
return;
2015-02-01 15:25:37 +01:00
list = string_split(message, "\n");
if (!list)
return;
2015-02-01 15:25:37 +01:00
if (list->elems == 0)
2015-02-11 06:59:19 +01:00
goto end;
2013-11-26 21:29:18 +01:00
j = 0;
2015-02-01 15:25:37 +01:00
for (i = 0; i < list->size; i++, j++)
{
2015-02-01 15:25:37 +01:00
char *msg = list->elems[i].data;
unsigned msglen = strlen(msg);
2015-02-01 15:25:37 +01:00
2014-02-28 01:34:10 +01:00
if (msglen > RMENU_TERM_WIDTH)
{
2014-02-28 01:34:10 +01:00
msg[RMENU_TERM_WIDTH - 2] = '.';
msg[RMENU_TERM_WIDTH - 1] = '.';
msg[RMENU_TERM_WIDTH - 0] = '.';
msg[RMENU_TERM_WIDTH + 1] = '\0';
msglen = RMENU_TERM_WIDTH;
}
font_parms.x = POSITION_EDGE_MIN + POSITION_OFFSET;
font_parms.y = POSITION_EDGE_MIN + POSITION_RENDER_OFFSET + (POSITION_OFFSET * j);
font_parms.scale = FONT_SIZE_NORMAL;
font_parms.color = WHITE;
2015-03-22 18:48:24 +01:00
video_driver_set_osd_msg(msg, &font_parms, NULL);
}
render_normal = false;
2015-02-11 06:59:19 +01:00
end:
string_list_free(list);
}
static void rmenu_render(void)
{
bool msg_force;
uint64_t *frame_count;
2015-09-25 15:00:13 +02:00
size_t begin, end, i, j, selection;
2015-06-12 16:17:19 +02:00
struct font_params font_parms = {0};
char title[256] = {0};
char title_buf[256] = {0};
char title_msg[64] = {0};
menu_handle_t *menu = menu_driver_get_ptr();
size_t entries_end = menu_entries_get_end();
2015-09-25 15:00:13 +02:00
video_driver_ctl(RARCH_DISPLAY_CTL_GET_FRAME_COUNT, &frame_count);
2015-09-25 15:00:13 +02:00
if (!menu_navigation_ctl(MENU_NAVIGATION_CTL_GET_SELECTION, &selection))
return;
if (!menu)
return;
if (!render_normal)
{
render_normal = true;
return;
}
menu_display_ctl(MENU_DISPLAY_CTL_MSG_FORCE, &msg_force);
if (menu_entries_needs_refresh() && menu_driver_alive()
&& !msg_force)
return;
2015-11-17 23:34:31 +01:00
menu_display_ctl(MENU_DISPLAY_CTL_UNSET_FRAMEBUFFER_DIRTY_FLAG, NULL);
menu_animation_ctl(MENU_ANIMATION_CTL_CLEAR_ACTIVE, NULL);
2015-09-06 02:06:02 +02:00
begin = (selection >= (ENTRIES_HEIGHT / 2)) ?
(selection - (ENTRIES_HEIGHT / 2)) : 0;
end = ((selection + ENTRIES_HEIGHT) <= entries_end)
? selection + ENTRIES_HEIGHT : entries_end;
2015-05-15 00:03:06 +02:00
if (entries_end <= ENTRIES_HEIGHT)
begin = 0;
if (end - begin > ENTRIES_HEIGHT)
end = begin + ENTRIES_HEIGHT;
2015-05-15 00:07:07 +02:00
menu_entries_get_title(title, sizeof(title));
menu_animation_ticker_str(title_buf, RMENU_TERM_WIDTH,
2015-08-03 23:01:07 +02:00
*frame_count / 15, title, true);
font_parms.x = POSITION_EDGE_MIN + POSITION_OFFSET;
font_parms.y = POSITION_EDGE_MIN + POSITION_RENDER_OFFSET
- (POSITION_OFFSET*2);
font_parms.scale = FONT_SIZE_NORMAL;
font_parms.color = WHITE;
2015-03-22 18:48:24 +01:00
video_driver_set_osd_msg(title_buf, &font_parms, NULL);
font_parms.x = POSITION_EDGE_MIN + POSITION_OFFSET;
font_parms.y = POSITION_EDGE_MAX - (POSITION_OFFSET*2);
font_parms.scale = FONT_SIZE_NORMAL;
font_parms.color = WHITE;
2015-05-21 04:43:50 +02:00
menu_entries_get_core_title(title_msg, sizeof(title_msg));
2015-03-22 18:48:24 +01:00
video_driver_set_osd_msg(title_msg, &font_parms, NULL);
j = 0;
for (i = begin; i < end; i++, j++)
{
2015-06-12 16:17:19 +02:00
char entry_path[PATH_MAX_LENGTH] = {0};
char entry_value[PATH_MAX_LENGTH] = {0};
char message[PATH_MAX_LENGTH] = {0};
char entry_title_buf[PATH_MAX_LENGTH] = {0};
char type_str_buf[PATH_MAX_LENGTH] = {0};
unsigned entry_spacing = menu_entry_get_spacing(i);
bool entry_selected = menu_entry_is_currently_selected(i);
2015-06-01 14:59:15 +02:00
menu_entry_get_value(i, entry_value, sizeof(entry_value));
menu_entry_get_path(i, entry_path, sizeof(entry_path));
menu_animation_ticker_str(entry_title_buf, RMENU_TERM_WIDTH - (entry_spacing + 1 + 2),
2015-08-03 23:01:07 +02:00
*frame_count / 15, entry_path, entry_selected);
menu_animation_ticker_str(type_str_buf, entry_spacing,
2015-08-03 23:01:07 +02:00
*frame_count / 15, entry_value, entry_selected);
snprintf(message, sizeof(message), "%c %s",
2015-06-01 15:13:49 +02:00
entry_selected ? '>' : ' ', entry_title_buf);
font_parms.x = POSITION_EDGE_MIN + POSITION_OFFSET;
font_parms.y = POSITION_EDGE_MIN + POSITION_RENDER_OFFSET
+ (POSITION_OFFSET * j);
font_parms.scale = FONT_SIZE_NORMAL;
font_parms.color = WHITE;
2015-03-22 18:48:24 +01:00
video_driver_set_osd_msg(message, &font_parms, NULL);
font_parms.x = POSITION_EDGE_CENTER + POSITION_OFFSET;
2015-03-22 18:48:24 +01:00
video_driver_set_osd_msg(type_str_buf, &font_parms, NULL);
}
}
static void rmenu_set_texture(void)
{
2015-09-25 20:42:45 +02:00
unsigned fb_width, fb_height;
menu_handle_t *menu = menu_driver_get_ptr();
if (!menu)
return;
if (menu_texture_inited)
return;
2015-02-01 08:15:46 +01:00
if (!menu_texture)
return;
if (!menu_texture->pixels)
return;
2015-09-25 20:42:45 +02:00
menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &fb_width);
menu_display_ctl(MENU_DISPLAY_CTL_HEIGHT, &fb_height);
2015-03-23 07:44:20 +01:00
video_driver_set_texture_frame(menu_texture->pixels, true,
2015-09-25 20:42:45 +02:00
fb_width, fb_height, 1.0f);
2015-02-01 08:15:46 +01:00
menu_texture_inited = true;
}
2015-06-02 18:28:51 +02:00
static void rmenu_wallpaper_set_defaults(char *s, size_t len)
2015-01-17 18:15:22 +01:00
{
2015-03-20 22:22:06 +01:00
settings_t *settings = config_get_ptr();
2015-06-02 18:28:51 +02:00
fill_pathname_join(s, settings->assets_directory,
"rmenu", len);
2015-01-17 18:15:22 +01:00
#ifdef _XBOX1
2015-06-02 18:28:51 +02:00
fill_pathname_join(s, s, "sd", len);
2015-01-17 18:15:22 +01:00
#else
2015-06-02 18:28:51 +02:00
fill_pathname_join(s, s, "hd", len);
2015-01-17 18:15:22 +01:00
#endif
2015-06-02 18:28:51 +02:00
fill_pathname_join(s, s, "main_menu.png", len);
2015-01-17 18:15:22 +01:00
}
2015-02-13 20:30:06 +01:00
static void rmenu_context_reset(void)
{
char menu_bg[PATH_MAX_LENGTH] = {0};
menu_handle_t *menu = menu_driver_get_ptr();
settings_t *settings = config_get_ptr();
if (!menu)
return;
2015-03-20 22:22:06 +01:00
if (*settings->menu.wallpaper)
strlcpy(menu_bg, settings->menu.wallpaper, sizeof(menu_bg));
2015-01-17 18:15:22 +01:00
else
2015-01-20 01:13:16 +01:00
rmenu_wallpaper_set_defaults(menu_bg, sizeof(menu_bg));
if (path_file_exists(menu_bg))
texture_image_load(menu_texture, menu_bg);
2015-09-25 20:42:45 +02:00
menu_display_ctl(MENU_DISPLAY_CTL_SET_WIDTH, &menu_texture->width);
menu_display_ctl(MENU_DISPLAY_CTL_SET_HEIGHT, &menu_texture->height);
menu_texture_inited = false;
}
static void *rmenu_init(void)
{
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
if (!menu)
return NULL;
menu_texture = (struct texture_image*)calloc(1, sizeof(*menu_texture));
2014-10-10 19:22:57 +02:00
if (!menu_texture)
{
free(menu);
2014-10-10 19:22:57 +02:00
return NULL;
}
2014-10-10 19:22:57 +02:00
return menu;
}
2015-02-13 20:30:06 +01:00
static void rmenu_context_destroy(void)
{
2014-06-17 17:44:48 +02:00
texture_image_free(menu_texture);
}
static void rmenu_free(void *data)
{
}
static int rmenu_environ(menu_environ_cb_t type, void *data)
2015-07-08 00:37:44 +02:00
{
switch (type)
{
2015-07-09 08:28:08 +02:00
case 0:
break;
2015-07-08 00:37:44 +02:00
default:
return -1;
}
return 0;
}
2014-09-11 07:06:20 +02:00
menu_ctx_driver_t menu_ctx_rmenu = {
rmenu_set_texture,
rmenu_render_messagebox,
generic_menu_iterate,
rmenu_render,
NULL,
rmenu_init,
rmenu_free,
rmenu_context_reset,
rmenu_context_destroy,
NULL,
NULL,
2014-10-01 15:17:34 +02:00
NULL,
2014-04-13 23:41:47 +02:00
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
2015-10-03 04:32:38 +02:00
generic_menu_init_list,
2014-04-13 23:41:47 +02:00
NULL,
NULL,
2014-04-14 00:09:52 +02:00
NULL,
NULL,
NULL,
NULL,
2015-06-07 15:43:03 +02:00
NULL,
NULL,
2015-06-15 19:00:52 +02:00
NULL,
2015-06-23 11:45:46 +02:00
NULL,
NULL,
"rmenu",
2015-07-08 00:37:44 +02:00
rmenu_environ,
NULL,
};