RetroArch/menu/drivers/rgui.c

696 lines
18 KiB
C
Raw Normal View History

2012-05-06 02:04:33 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2015-01-07 16:46:50 +00:00
* Copyright (C) 2011-2015 - Daniel De Matteis
* Copyright (C) 2012-2015 - Michael Lelli
*
2012-05-06 02:04:33 +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 <stdlib.h>
#include <stddef.h>
2014-10-16 05:27:42 +00:00
#include <stdint.h>
2012-05-06 02:04:33 +00:00
#include <string.h>
#include <limits.h>
2015-01-10 03:53:37 +00:00
#include "../menu.h"
2014-10-21 05:58:58 +00:00
#include <compat/posix_string.h>
2014-10-21 22:23:06 +00:00
#include <file/file_path.h>
2013-03-09 14:33:44 +00:00
2015-01-12 22:34:10 +00:00
#include "../../gfx/drivers_font_renderer/bitmap.h"
#include "shared.h"
#define RGUI_TERM_START_X (menu->frame_buf.width / 21)
#define RGUI_TERM_START_Y (menu->frame_buf.height / 9)
#define RGUI_TERM_WIDTH (((menu->frame_buf.width - RGUI_TERM_START_X - RGUI_TERM_START_X) / (FONT_WIDTH_STRIDE)))
#define RGUI_TERM_HEIGHT (((menu->frame_buf.height - RGUI_TERM_START_Y - RGUI_TERM_START_X) / (FONT_HEIGHT_STRIDE)) - 1)
2015-03-14 22:44:27 +00:00
#if defined(GEKKO)|| defined(PSP)
2015-03-20 21:22:06 +00:00
#define HOVER_COLOR(settings) ((3 << 0) | (10 << 4) | (3 << 8) | (7 << 12))
#define NORMAL_COLOR(settings) 0x7FFF
#define TITLE_COLOR(settings) HOVER_COLOR(settings)
2015-03-14 22:44:27 +00:00
#else
2015-03-20 21:22:06 +00:00
#define HOVER_COLOR(settings) (argb32_to_rgba4444(settings->menu.entry_hover_color))
#define NORMAL_COLOR(settings) (argb32_to_rgba4444(settings->menu.entry_normal_color))
#define TITLE_COLOR(settings) (argb32_to_rgba4444(settings->menu.title_color))
2015-03-14 22:44:27 +00:00
#endif
2015-03-14 22:21:55 +00:00
2015-03-14 23:08:07 +00:00
static inline uint16_t argb32_to_rgba4444(uint32_t col)
2015-03-14 22:21:55 +00:00
{
unsigned a = ((col >> 24) & 0xff) >> 4;
unsigned r = ((col >> 16) & 0xff) >> 4;
unsigned g = ((col >> 8) & 0xff) >> 4;
unsigned b = (col & 0xff) >> 4;
2015-03-14 23:08:07 +00:00
return (r << 12) | (g << 8) | (b << 4) | a;
2015-03-14 22:21:55 +00:00
}
static int rgui_entry_iterate(unsigned action)
2015-01-26 09:54:13 +00:00
{
const char *label = NULL;
menu_file_list_cbs_t *cbs = NULL;
menu_handle_t *menu = menu_driver_resolve();
2015-03-18 05:47:22 +00:00
runloop_t *runloop = rarch_main_get_ptr();
if (!menu)
return -1;
if (!menu->menu_list)
return -1;
2015-03-08 19:39:21 +00:00
if (action != MENU_ACTION_NOOP || menu->need_refresh ||
2015-03-18 05:47:22 +00:00
runloop->frames.video.current.menu.label.is_updated ||
runloop->frames.video.current.menu.animation.is_active)
{
2015-03-18 05:47:22 +00:00
runloop->frames.video.current.menu.framebuf.dirty = true;
}
2015-03-08 17:12:13 +00:00
cbs = (menu_file_list_cbs_t*)menu_list_get_actiondata_at_offset(
2015-02-13 23:47:42 +00:00
menu->menu_list->selection_buf, menu->navigation.selection_ptr);
2015-01-26 09:54:13 +00:00
2015-02-11 18:28:06 +00:00
menu_list_get_last_stack(menu->menu_list, NULL, &label, NULL);
2015-01-26 09:54:13 +00:00
if (cbs && cbs->action_iterate)
return cbs->action_iterate(label, action);
2015-01-26 09:54:13 +00:00
return -1;
2015-01-26 09:54:13 +00:00
}
static void rgui_copy_glyph(uint8_t *glyph, const uint8_t *buf)
{
2015-02-02 18:02:34 +00:00
int x, y;
if (!glyph)
return;
for (y = 0; y < FONT_HEIGHT; y++)
{
for (x = 0; x < FONT_WIDTH; x++)
{
uint32_t col =
((uint32_t)buf[3 * (-y * 256 + x) + 0] << 0) |
((uint32_t)buf[3 * (-y * 256 + x) + 1] << 8) |
((uint32_t)buf[3 * (-y * 256 + x) + 2] << 16);
2015-02-11 04:16:19 +00:00
uint8_t rem = 1 << ((x + y * FONT_WIDTH) & 7);
unsigned offset = (x + y * FONT_WIDTH) >> 3;
if (col != 0xff)
glyph[offset] |= rem;
}
}
}
static uint16_t gray_filler(unsigned x, unsigned y)
{
unsigned col;
x >>= 1;
y >>= 1;
col = ((x + y) & 1) + 1;
2014-02-18 21:01:04 +00:00
#if defined(GEKKO) || defined(PSP)
return (6 << 12) | (col << 8) | (col << 4) | (col << 0);
#else
return (col << 13) | (col << 9) | (col << 5) | (12 << 0);
#endif
}
static uint16_t green_filler(unsigned x, unsigned y)
{
unsigned col;
x >>= 1;
y >>= 1;
col = ((x + y) & 1) + 1;
2014-02-18 21:01:04 +00:00
#if defined(GEKKO) || defined(PSP)
return (6 << 12) | (col << 8) | (col << 5) | (col << 0);
#else
return (col << 13) | (col << 10) | (col << 5) | (12 << 0);
#endif
}
static void fill_rect(menu_framebuf_t *frame_buf,
unsigned x, unsigned y,
unsigned width, unsigned height,
uint16_t (*col)(unsigned x, unsigned y))
{
2015-02-02 18:02:34 +00:00
unsigned i, j;
if (!frame_buf->data || !col)
return;
for (j = y; j < y + height; j++)
for (i = x; i < x + width; i++)
frame_buf->data[j * (frame_buf->pitch >> 1) + i] = col(i, j);
}
2015-02-11 04:23:02 +00:00
static void color_rect(menu_handle_t *menu,
2014-10-25 21:21:28 +00:00
unsigned x, unsigned y,
unsigned width, unsigned height,
uint16_t color)
{
2015-02-02 18:02:34 +00:00
unsigned i, j;
2015-02-11 17:36:37 +00:00
if (!menu->frame_buf.data)
return;
2014-10-25 21:21:28 +00:00
for (j = y; j < y + height; j++)
for (i = x; i < x + width; i++)
if (i < menu->frame_buf.width && j < menu->frame_buf.height)
2015-02-11 17:36:37 +00:00
menu->frame_buf.data[j * (menu->frame_buf.pitch >> 1) + i] = color;
2014-10-25 21:21:28 +00:00
}
2015-03-14 22:44:27 +00:00
static void blit_line(menu_handle_t *menu, int x, int y, const char *message, uint16_t color)
{
2015-02-02 18:02:34 +00:00
unsigned i, j;
while (*message)
{
for (j = 0; j < FONT_HEIGHT; j++)
{
for (i = 0; i < FONT_WIDTH; i++)
{
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
2015-01-19 05:44:46 +00:00
int offset = (i + j * FONT_WIDTH) >> 3;
2015-02-11 04:23:02 +00:00
bool col = (menu->font[FONT_OFFSET
2014-08-31 23:59:30 +00:00
((unsigned char)*message) + offset] & rem);
2015-01-19 05:44:46 +00:00
if (!col)
continue;
2015-02-11 17:36:37 +00:00
menu->frame_buf.data[(y + j) *
2015-03-14 22:21:55 +00:00
(menu->frame_buf.pitch >> 1) + (x + i)] = color;
}
}
x += FONT_WIDTH_STRIDE;
message++;
}
}
static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf)
{
unsigned i;
uint8_t *font = (uint8_t *) calloc(1, FONT_OFFSET(256));
if (!font)
{
RARCH_ERR("Font memory allocation failed.\n");
return false;
}
menu->alloc_font = true;
for (i = 0; i < 256; i++)
{
unsigned y = i / 16;
unsigned x = i % 16;
rgui_copy_glyph(&font[FONT_OFFSET(i)],
font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x));
}
menu->font = font;
return true;
}
static bool rguidisp_init_font(menu_handle_t *menu)
{
const uint8_t *font_bmp_buf = NULL;
const uint8_t *font_bin_buf = bitmap_bin;
if (!menu)
return false;
if (font_bmp_buf)
return init_font(menu, font_bmp_buf);
2015-02-01 07:18:33 +00:00
if (!font_bin_buf)
2014-08-27 02:02:32 +00:00
return false;
2015-02-01 07:18:33 +00:00
menu->font = font_bin_buf;
2014-08-27 02:02:32 +00:00
return true;
}
static void rgui_render_background(void)
{
menu_handle_t *menu = menu_driver_resolve();
if (!menu)
return;
size_t pitch_in_pixels = menu->frame_buf.pitch >> 1;
size_t size = menu->frame_buf.pitch * 4;
uint16_t *src = menu->frame_buf.data + pitch_in_pixels * menu->frame_buf.height;
uint16_t *dst = menu->frame_buf.data;
while (dst < src)
{
memcpy(dst, src, size);
dst += pitch_in_pixels * 4;
}
fill_rect(&menu->frame_buf, 5, 5, menu->frame_buf.width - 10, 5, green_filler);
fill_rect(&menu->frame_buf, 5, menu->frame_buf.height - 10, menu->frame_buf.width - 10, 5,
green_filler);
fill_rect(&menu->frame_buf, 5, 5, 5, menu->frame_buf.height - 10, green_filler);
fill_rect(&menu->frame_buf, menu->frame_buf.width - 10, 5, 5, menu->frame_buf.height - 10,
green_filler);
}
static void rgui_render_messagebox(const char *message)
{
size_t i;
int x, y;
unsigned width, glyphs_width, height;
2015-03-16 15:57:27 +00:00
uint16_t color;
struct string_list *list = NULL;
2015-03-20 21:22:06 +00:00
menu_handle_t *menu = menu_driver_resolve();
settings_t *settings = config_get_ptr();
if (!menu)
return;
if (!message || !*message)
return;
list = string_split(message, "\n");
if (!list)
return;
if (list->elems == 0)
2015-02-02 18:02:34 +00:00
goto end;
2015-02-11 04:16:19 +00:00
width = 0;
glyphs_width = 0;
2015-02-11 04:16:19 +00:00
for (i = 0; i < list->size; i++)
{
unsigned line_width;
char *msg = list->elems[i].data;
unsigned msglen = strlen(msg);
2014-02-28 00:34:10 +00:00
if (msglen > RGUI_TERM_WIDTH)
{
2014-02-28 00:34:10 +00:00
msg[RGUI_TERM_WIDTH - 2] = '.';
msg[RGUI_TERM_WIDTH - 1] = '.';
msg[RGUI_TERM_WIDTH - 0] = '.';
msg[RGUI_TERM_WIDTH + 1] = '\0';
msglen = RGUI_TERM_WIDTH;
}
line_width = msglen * FONT_WIDTH_STRIDE - 1 + 6 + 10;
width = max(width, line_width);
glyphs_width = max(glyphs_width, msglen);
}
height = FONT_HEIGHT_STRIDE * list->size + 6 + 10;
x = (menu->frame_buf.width - width) / 2;
y = (menu->frame_buf.height - height) / 2;
fill_rect(&menu->frame_buf, x + 5, y + 5, width - 10, height - 10, gray_filler);
fill_rect(&menu->frame_buf, x, y, width - 5, 5, green_filler);
fill_rect(&menu->frame_buf, x + width - 5, y, 5, height - 5, green_filler);
fill_rect(&menu->frame_buf, x + 5, y + height - 5, width - 5, 5, green_filler);
fill_rect(&menu->frame_buf, x, y + 5, 5, height - 5, green_filler);
2015-03-20 21:22:06 +00:00
color = NORMAL_COLOR(settings);
2015-03-14 22:44:27 +00:00
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
int offset_x = FONT_WIDTH_STRIDE * (glyphs_width - strlen(msg)) / 2;
int offset_y = FONT_HEIGHT_STRIDE * i;
2015-03-14 22:44:27 +00:00
blit_line(menu, x + 8 + offset_x, y + 8 + offset_y, msg, color);
}
2015-02-02 18:02:34 +00:00
end:
string_list_free(list);
}
static void rgui_blit_cursor(menu_handle_t *menu)
2014-10-25 21:21:28 +00:00
{
2015-02-11 04:16:19 +00:00
int16_t x = menu->mouse.x;
int16_t y = menu->mouse.y;
2014-10-25 21:21:28 +00:00
2015-02-11 20:15:39 +00:00
color_rect(menu, x, y - 5, 1, 11, 0xFFFF);
color_rect(menu, x - 5, y, 11, 1, 0xFFFF);
2014-10-25 21:21:28 +00:00
}
static void rgui_render(void)
{
size_t i, end;
char title[256], title_buf[256], title_msg[64];
2015-01-17 03:50:46 +00:00
char timedate[PATH_MAX_LENGTH];
unsigned x, y, menu_type = 0;
2015-03-16 15:57:27 +00:00
uint16_t hover_color, normal_color;
2015-03-20 21:22:06 +00:00
const char *dir = NULL;
const char *label = NULL;
const char *core_name = NULL;
const char *core_version = NULL;
2015-03-20 21:22:06 +00:00
menu_handle_t *menu = menu_driver_resolve();
runloop_t *runloop = rarch_main_get_ptr();
driver_t *driver = driver_get_ptr();
2015-03-21 04:42:49 +00:00
global_t *global = global_get_ptr();
2015-03-20 21:22:06 +00:00
settings_t *settings = config_get_ptr();
2015-03-18 19:31:01 +00:00
(void)driver;
if (!menu)
return;
2015-03-18 05:47:22 +00:00
if (menu->need_refresh && runloop->is_menu
&& !menu->msg_force)
return;
2015-03-18 05:47:22 +00:00
if (runloop->is_idle)
return;
2015-03-11 15:35:12 +00:00
if (!menu_display_update_pending())
2015-03-08 17:12:13 +00:00
return;
2015-03-08 19:39:21 +00:00
/* ensures the framebuffer will be rendered on the screen */
2015-03-18 05:47:22 +00:00
runloop->frames.video.current.menu.framebuf.dirty = true;
runloop->frames.video.current.menu.animation.is_active = false;
runloop->frames.video.current.menu.label.is_updated = false;
2015-02-11 18:28:06 +00:00
menu->mouse.ptr = menu->mouse.y / 11 - 2 + menu->begin;
2014-10-26 23:55:14 +00:00
2015-03-10 14:22:46 +00:00
if (menu->mouse.scrolldown && menu->begin
2015-02-11 18:28:06 +00:00
< menu_list_get_size(menu->menu_list) - RGUI_TERM_HEIGHT)
menu->begin++;
2014-10-26 21:31:53 +00:00
2015-03-10 14:22:46 +00:00
if (menu->mouse.scrollup && menu->begin > 0)
2015-02-11 18:28:06 +00:00
menu->begin--;
/* Do not scroll if all items are visible. */
2015-02-11 18:28:06 +00:00
if (menu_list_get_size(menu->menu_list) <= RGUI_TERM_HEIGHT)
menu->begin = 0;
2015-02-11 18:28:06 +00:00
end = (menu->begin + RGUI_TERM_HEIGHT <=
menu_list_get_size(menu->menu_list)) ?
menu->begin + RGUI_TERM_HEIGHT :
menu_list_get_size(menu->menu_list);
rgui_render_background();
2015-02-11 18:28:06 +00:00
menu_list_get_last_stack(menu->menu_list,
&dir, &label, &menu_type);
#if 0
RARCH_LOG("Dir is: %s\n", label);
#endif
get_title(label, dir, menu_type, title, sizeof(title));
menu_animation_ticker_line(title_buf, RGUI_TERM_WIDTH - 3,
2015-03-18 05:47:22 +00:00
runloop->frames.video.count / RGUI_TERM_START_X, title, true);
2015-03-14 22:44:27 +00:00
2015-03-20 21:22:06 +00:00
hover_color = HOVER_COLOR(settings);
normal_color = NORMAL_COLOR(settings);
2015-03-14 22:44:27 +00:00
2015-03-20 21:22:06 +00:00
blit_line(menu, RGUI_TERM_START_X + RGUI_TERM_START_X, RGUI_TERM_START_X, title_buf, TITLE_COLOR(settings));
2015-03-21 04:42:49 +00:00
core_name = global->menu.info.library_name;
if (!core_name)
2015-03-21 04:42:49 +00:00
core_name = global->system.info.library_name;
if (!core_name)
core_name = "No Core";
2015-03-20 21:22:06 +00:00
if (settings->menu.core_enable)
{
2015-03-21 04:42:49 +00:00
core_version = global->menu.info.library_version;
if (!core_version)
2015-03-21 04:42:49 +00:00
core_version = global->system.info.library_version;
if (!core_version)
core_version = "";
2015-01-17 03:50:46 +00:00
snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION,
core_name, core_version);
blit_line(menu,
RGUI_TERM_START_X + RGUI_TERM_START_X,
(RGUI_TERM_HEIGHT * FONT_HEIGHT_STRIDE) +
2015-03-14 22:44:27 +00:00
RGUI_TERM_START_Y + 2, title_msg, hover_color);
}
2015-03-20 21:22:06 +00:00
if (settings->menu.timedate_enable)
{
disp_timedate_set_label(timedate, sizeof(timedate), 3);
2015-02-11 18:28:06 +00:00
blit_line(menu,
2015-01-17 03:50:46 +00:00
(RGUI_TERM_WIDTH * FONT_HEIGHT_STRIDE) + (60),
(RGUI_TERM_HEIGHT * FONT_HEIGHT_STRIDE) +
2015-03-14 22:44:27 +00:00
RGUI_TERM_START_Y + 2, timedate, hover_color);
}
2015-01-17 03:50:46 +00:00
2014-02-28 00:34:10 +00:00
x = RGUI_TERM_START_X;
y = RGUI_TERM_START_Y;
2015-02-11 18:28:06 +00:00
for (i = menu->begin; i < end; i++, y += FONT_HEIGHT_STRIDE)
{
char message[PATH_MAX_LENGTH], type_str[PATH_MAX_LENGTH],
entry_title_buf[PATH_MAX_LENGTH], type_str_buf[PATH_MAX_LENGTH],
path_buf[PATH_MAX_LENGTH];
const char *path = NULL, *entry_label = NULL;
unsigned type = 0, w = 0;
bool selected = false;
menu_file_list_cbs_t *cbs = NULL;
2015-02-11 18:28:06 +00:00
menu_list_get_at_offset(menu->menu_list->selection_buf, i, &path,
&entry_label, &type);
cbs = (menu_file_list_cbs_t*)
2015-02-11 18:28:06 +00:00
menu_list_get_actiondata_at_offset(menu->menu_list->selection_buf,
i);
if (cbs && cbs->action_get_representation)
2015-02-11 18:28:06 +00:00
cbs->action_get_representation(menu->menu_list->selection_buf,
&w, type, i, label,
type_str, sizeof(type_str),
entry_label, path,
path_buf, sizeof(path_buf));
2015-02-13 23:47:42 +00:00
selected = (i == menu->navigation.selection_ptr);
2015-02-13 23:47:42 +00:00
if (i > (menu->navigation.selection_ptr + 100))
2015-02-01 22:55:13 +00:00
continue;
menu_animation_ticker_line(entry_title_buf, RGUI_TERM_WIDTH - (w + 1 + 2),
2015-03-18 05:47:22 +00:00
runloop->frames.video.count / RGUI_TERM_START_X, path_buf, selected);
menu_animation_ticker_line(type_str_buf, w, runloop->frames.video.count / RGUI_TERM_START_X,
2014-08-31 23:59:30 +00:00
type_str, selected);
snprintf(message, sizeof(message), "%c %-*.*s %-*s",
selected ? '>' : ' ',
2014-09-09 02:04:12 +00:00
RGUI_TERM_WIDTH - (w + 1 + 2),
RGUI_TERM_WIDTH - (w + 1 + 2),
entry_title_buf,
w,
type_str_buf);
2015-03-14 22:44:27 +00:00
blit_line(menu, x, y, message, selected ? hover_color : normal_color);
}
#ifdef GEKKO
const char *message_queue;
2015-02-11 18:28:06 +00:00
if (menu->msg_force)
{
message_queue = rarch_main_msg_queue_pull();
2015-02-11 18:28:06 +00:00
menu->msg_force = false;
}
else
message_queue = driver->current_msg;
rgui_render_messagebox( message_queue);
#endif
2015-02-11 18:28:06 +00:00
if (menu->keyboard.display)
{
char msg[PATH_MAX_LENGTH];
2015-02-11 18:28:06 +00:00
const char *str = *menu->keyboard.buffer;
if (!str)
str = "";
2015-02-11 18:28:06 +00:00
snprintf(msg, sizeof(msg), "%s\n%s", menu->keyboard.label, str);
rgui_render_messagebox(msg);
}
2014-10-25 21:21:28 +00:00
2015-03-20 21:22:06 +00:00
if (settings->menu.mouse.enable)
2015-02-11 18:28:06 +00:00
rgui_blit_cursor(menu);
}
static void *rgui_init(void)
2012-05-06 02:04:33 +00:00
{
bool ret = false;
menu_handle_t *menu = (menu_handle_t*)calloc(1, sizeof(*menu));
2012-05-06 02:04:33 +00:00
if (!menu)
return NULL;
/* 4 extra lines to cache the checked background */
menu->frame_buf.data = (uint16_t*)calloc(400 * (240 + 4), sizeof(uint16_t));
2015-02-11 17:36:37 +00:00
if (!menu->frame_buf.data)
2015-02-02 17:56:58 +00:00
goto error;
menu->frame_buf.width = 320;
menu->frame_buf.height = 240;
menu->begin = 0;
menu->frame_buf.pitch = menu->frame_buf.width * sizeof(uint16_t);
2012-05-06 02:04:33 +00:00
ret = rguidisp_init_font(menu);
if (!ret)
{
RARCH_ERR("No font bitmap or binary, abort");
2015-02-02 17:56:58 +00:00
goto error;
}
2012-05-06 02:04:33 +00:00
fill_rect(&menu->frame_buf, 0, menu->frame_buf.height, menu->frame_buf.width, 4, gray_filler);
return menu;
2015-02-02 17:56:58 +00:00
error:
if (menu)
{
2015-02-11 17:36:37 +00:00
if (menu->frame_buf.data)
free(menu->frame_buf.data);
if (menu->userdata)
free(menu->userdata);
2015-02-02 17:56:58 +00:00
free(menu);
}
2015-02-02 17:56:58 +00:00
return NULL;
2012-05-06 02:04:33 +00:00
}
static void rgui_free(void *data)
2012-05-06 02:04:33 +00:00
{
menu_handle_t *menu = (menu_handle_t*)data;
if (!menu)
return;
if (menu->userdata)
free(menu->userdata);
2015-02-11 20:15:39 +00:00
menu->userdata = NULL;
if (menu->alloc_font)
free((uint8_t*)menu->font);
2012-05-06 02:04:33 +00:00
}
static void rgui_set_texture(void)
{
menu_handle_t *menu = menu_driver_resolve();
2015-03-18 05:47:22 +00:00
runloop_t *runloop = rarch_main_get_ptr();
driver_t *driver = driver_get_ptr();
2015-03-18 05:47:22 +00:00
2015-02-11 04:16:19 +00:00
if (!menu)
2015-02-01 07:18:33 +00:00
return;
if (!driver->video_data)
2015-02-01 07:18:33 +00:00
return;
if (!driver->video_poke)
2015-02-01 07:18:33 +00:00
return;
if (!driver->video_poke->set_texture_frame)
2015-02-01 07:18:33 +00:00
return;
2015-03-18 05:47:22 +00:00
if (!runloop->frames.video.current.menu.framebuf.dirty)
return;
2015-03-18 05:47:22 +00:00
runloop->frames.video.current.menu.framebuf.dirty = false;
2015-02-01 07:18:33 +00:00
driver->video_poke->set_texture_frame(driver->video_data,
menu->frame_buf.data, false, menu->frame_buf.width, menu->frame_buf.height, 1.0f);
}
static void rgui_navigation_clear(bool pending_push)
2014-10-26 21:31:53 +00:00
{
menu_handle_t *menu = menu_driver_resolve();
2015-02-11 19:40:48 +00:00
if (menu)
menu->begin = 0;
2014-10-26 21:31:53 +00:00
}
static void rgui_navigation_set(bool scroll)
2014-10-26 21:31:53 +00:00
{
menu_handle_t *menu = menu_driver_resolve();
if (!menu)
return;
2014-10-26 21:31:53 +00:00
if (!scroll)
return;
2015-02-13 23:47:42 +00:00
if (menu->navigation.selection_ptr < RGUI_TERM_HEIGHT/2)
2015-02-11 04:16:19 +00:00
menu->begin = 0;
2015-02-13 23:47:42 +00:00
else if (menu->navigation.selection_ptr >= RGUI_TERM_HEIGHT/2
&& menu->navigation.selection_ptr <
2015-02-11 04:16:19 +00:00
menu_list_get_size(menu->menu_list) - RGUI_TERM_HEIGHT/2)
2015-02-13 23:47:42 +00:00
menu->begin = menu->navigation.selection_ptr - RGUI_TERM_HEIGHT/2;
else if (menu->navigation.selection_ptr >=
2015-02-11 04:16:19 +00:00
menu_list_get_size(menu->menu_list) - RGUI_TERM_HEIGHT/2)
menu->begin = menu_list_get_size(menu->menu_list)
- RGUI_TERM_HEIGHT;
2014-10-26 21:31:53 +00:00
}
static void rgui_navigation_set_last(void)
{
menu_handle_t *menu = menu_driver_resolve();
if (menu)
rgui_navigation_set(true);
}
static void rgui_navigation_descend_alphabet(size_t *unused)
{
menu_handle_t *menu = menu_driver_resolve();
if (menu)
rgui_navigation_set(true);
}
static void rgui_navigation_ascend_alphabet(size_t *unused)
{
menu_handle_t *menu = menu_driver_resolve();
if (menu)
rgui_navigation_set(true);
}
static void rgui_populate_entries(const char *path,
const char *label, unsigned k)
{
menu_handle_t *menu = menu_driver_resolve();
if (menu)
rgui_navigation_set(true);
}
2014-09-11 05:06:20 +00:00
menu_ctx_driver_t menu_ctx_rgui = {
rgui_set_texture,
rgui_render_messagebox,
rgui_render,
NULL,
2013-09-19 12:49:07 +00:00
rgui_init,
rgui_free,
NULL,
NULL,
rgui_populate_entries,
NULL,
2014-10-26 21:31:53 +00:00
rgui_navigation_clear,
2014-04-13 21:41:47 +00:00
NULL,
NULL,
2014-10-26 21:31:53 +00:00
rgui_navigation_set,
rgui_navigation_set_last,
rgui_navigation_descend_alphabet,
rgui_navigation_ascend_alphabet,
2014-04-13 22:09:52 +00:00
NULL,
NULL,
NULL,
NULL,
NULL,
2015-01-26 09:54:13 +00:00
rgui_entry_iterate,
NULL,
2013-09-19 12:49:07 +00:00
"rgui",
};