commit
6dfc966a6d
|
@ -25,6 +25,7 @@
|
|||
#include "../../runloop_data.h"
|
||||
|
||||
#include <file/file_path.h>
|
||||
#include "../../gfx/video_thread_wrapper.h"
|
||||
#include "../../gfx/drivers/gl_common.h"
|
||||
#include "../../gfx/font_driver.h"
|
||||
#include "../../gfx/video_texture.h"
|
||||
|
@ -38,6 +39,13 @@ typedef struct glui_handle
|
|||
unsigned margin;
|
||||
unsigned ticker_limit;
|
||||
char box_message[PATH_MAX_LENGTH];
|
||||
|
||||
struct
|
||||
{
|
||||
void *buf;
|
||||
int size;
|
||||
} font;
|
||||
|
||||
struct
|
||||
{
|
||||
struct
|
||||
|
@ -81,21 +89,28 @@ static int glui_entry_iterate(unsigned action)
|
|||
|
||||
static void glui_blit_line(gl_t *gl, float x, float y, const char *message, uint32_t color, enum text_alignment text_align)
|
||||
{
|
||||
glui_handle_t *glui = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
|
||||
if (!menu)
|
||||
return;
|
||||
|
||||
glui = (glui_handle_t*)menu->userdata;
|
||||
|
||||
struct font_params params = {0};
|
||||
|
||||
params.x = x / gl->win_width;
|
||||
params.y = 1.0f - y / gl->win_height;
|
||||
params.y = 1.0f - (y + glui->line_height/2 + glui->font.size/3) / gl->win_height;
|
||||
params.scale = 1.0;
|
||||
params.color = color;
|
||||
params.full_screen = true;
|
||||
params.text_align = text_align;
|
||||
|
||||
video_driver_set_osd_msg(message, ¶ms, NULL);
|
||||
video_driver_set_osd_msg(message, ¶ms, glui->font.buf);
|
||||
}
|
||||
|
||||
static void glui_render_background(settings_t *settings,
|
||||
gl_t *gl, glui_handle_t *glui,
|
||||
bool force_transparency)
|
||||
static void glui_render_background(settings_t *settings, gl_t *gl,
|
||||
glui_handle_t *glui)
|
||||
{
|
||||
static const GLfloat vertex[] = {
|
||||
0, 0,
|
||||
|
@ -136,7 +151,6 @@ static void glui_render_background(settings_t *settings,
|
|||
|
||||
if ((settings->menu.pause_libretro
|
||||
|| !global->main_is_init || global->libretro_dummy)
|
||||
&& !force_transparency
|
||||
&& glui->textures.bg.id)
|
||||
{
|
||||
coords.color = color;
|
||||
|
@ -211,6 +225,35 @@ static void glui_draw_cursor(gl_t *gl, float x, float y)
|
|||
glui_render_quad(gl, x-5, y-5, 10, 10, 1, 1, 1, 1);
|
||||
}
|
||||
|
||||
static void glui_draw_scrollbar(gl_t *gl)
|
||||
{
|
||||
int width = 4;
|
||||
glui_handle_t *glui = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
|
||||
if (!menu)
|
||||
return;
|
||||
|
||||
glui = (glui_handle_t*)menu->userdata;
|
||||
|
||||
float content_height = menu_list_get_size(menu->menu_list) * glui->line_height;
|
||||
float total_height = gl->win_height - menu->header_height * 2;
|
||||
|
||||
float height = total_height / (content_height / total_height);
|
||||
|
||||
float y = total_height * menu->scroll_y / content_height;
|
||||
|
||||
if (content_height < total_height)
|
||||
return;
|
||||
|
||||
glui_render_quad(gl,
|
||||
gl->win_width - width,
|
||||
menu->header_height + y,
|
||||
width,
|
||||
height,
|
||||
1, 1, 1, 1);
|
||||
}
|
||||
|
||||
static void glui_get_message(const char *message)
|
||||
{
|
||||
glui_handle_t *glui = NULL;
|
||||
|
@ -261,7 +304,7 @@ static void glui_render_messagebox(const char *message)
|
|||
goto end;
|
||||
|
||||
x = gl->win_width / 2;
|
||||
y = gl->win_height / 2 - list->size * settings->video.font_size / 2;
|
||||
y = gl->win_height / 2 - list->size * glui->font.size / 2;
|
||||
|
||||
normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color);
|
||||
|
||||
|
@ -269,7 +312,7 @@ static void glui_render_messagebox(const char *message)
|
|||
{
|
||||
const char *msg = list->elems[i].data;
|
||||
if (msg)
|
||||
glui_blit_line(gl, x, y + i * settings->video.font_size, msg, normal_color, TEXT_ALIGN_CENTER);
|
||||
glui_blit_line(gl, x, y + i * glui->font.size, msg, normal_color, TEXT_ALIGN_CENTER);
|
||||
}
|
||||
|
||||
end:
|
||||
|
@ -328,12 +371,12 @@ static void glui_render(void)
|
|||
if (menu->scroll_y < 0)
|
||||
menu->scroll_y = 0;
|
||||
|
||||
bottom = (menu_list_get_size(menu->menu_list)-1) * glui->line_height
|
||||
bottom = menu_list_get_size(menu->menu_list) * glui->line_height
|
||||
- gl->win_height + menu->header_height * 2;
|
||||
if (menu->scroll_y > bottom)
|
||||
menu->scroll_y = bottom;
|
||||
|
||||
if ((menu_list_get_size(menu->menu_list)-1) * glui->line_height
|
||||
if (menu_list_get_size(menu->menu_list) * glui->line_height
|
||||
< gl->win_height - menu->header_height*2)
|
||||
menu->scroll_y = 0;
|
||||
}
|
||||
|
@ -442,7 +485,7 @@ static void glui_frame(void)
|
|||
|
||||
gl_set_viewport(gl, gl->win_width, gl->win_height, true, false);
|
||||
|
||||
glui_render_background(settings, gl, glui, false);
|
||||
glui_render_background(settings, gl, glui);
|
||||
|
||||
menu_list_get_last_stack(menu->menu_list, &dir, &label, &menu_type);
|
||||
|
||||
|
@ -450,30 +493,32 @@ static void glui_frame(void)
|
|||
|
||||
glui_render_quad(gl, 0,
|
||||
menu->header_height - menu->scroll_y + glui->line_height *
|
||||
menu->navigation.selection_ptr - glui->line_height / 2 - 4,
|
||||
menu->navigation.selection_ptr,
|
||||
gl->win_width, glui->line_height, 1, 1, 1, 0.1);
|
||||
|
||||
glui_render_menu_list(runloop, gl, glui, menu, label, normal_color, hover_color);
|
||||
|
||||
runloop->frames.video.current.menu.animation.is_active = false;
|
||||
runloop->frames.video.current.menu.animation.is_active = true;
|
||||
runloop->frames.video.current.menu.label.is_updated = false;
|
||||
runloop->frames.video.current.menu.framebuf.dirty = false;
|
||||
|
||||
glui_render_quad(gl, 0, 0, gl->win_width,
|
||||
menu->header_height - glui->line_height/2 - 4, 0.2, 0.2, 0.2, 1);
|
||||
menu->header_height, 0.2, 0.2, 0.2, 1);
|
||||
|
||||
menu_animation_ticker_line(title_buf, glui->ticker_limit,
|
||||
runloop->frames.video.count / 100, title, true);
|
||||
glui_blit_line(gl, gl->win_width/2, glui->line_height, title_buf, title_color, TEXT_ALIGN_CENTER);
|
||||
glui_blit_line(gl, gl->win_width/2, 0, title_buf, title_color, TEXT_ALIGN_CENTER);
|
||||
|
||||
if (file_list_get_size(menu->menu_list->menu_stack) > 1)
|
||||
glui_blit_line(gl, glui->margin, glui->line_height, "BACK", title_color, TEXT_ALIGN_LEFT);
|
||||
glui_blit_line(gl, glui->margin, 0, "BACK", title_color, TEXT_ALIGN_LEFT);
|
||||
|
||||
glui_render_quad(gl, 0,
|
||||
gl->win_height - (menu->header_height - glui->line_height/2 + 4),
|
||||
gl->win_width, menu->header_height - glui->line_height/2 + 4,
|
||||
gl->win_height - menu->header_height,
|
||||
gl->win_width, menu->header_height,
|
||||
0.2, 0.2, 0.2, 1);
|
||||
|
||||
glui_draw_scrollbar(gl);
|
||||
|
||||
core_name = global->menu.info.library_name;
|
||||
if (!core_name)
|
||||
core_name = global->system.info.library_name;
|
||||
|
@ -509,14 +554,14 @@ static void glui_frame(void)
|
|||
const char *str = *menu->keyboard.buffer;
|
||||
if (!str)
|
||||
str = "";
|
||||
glui_render_background(settings, gl, glui, true);
|
||||
glui_render_quad(gl, 0, 0, gl->win_width, gl->win_height, 0, 0, 0, 0.75);
|
||||
snprintf(msg, sizeof(msg), "%s\n%s", menu->keyboard.label, str);
|
||||
glui_render_messagebox(msg);
|
||||
}
|
||||
|
||||
if (glui->box_message[0] != '\0')
|
||||
{
|
||||
glui_render_background(settings, gl, glui, true);
|
||||
glui_render_quad(gl, 0, 0, gl->win_width, gl->win_height, 0, 0, 0, 0.75);
|
||||
glui_render_messagebox(glui->box_message);
|
||||
glui->box_message[0] = '\0';
|
||||
}
|
||||
|
@ -555,10 +600,15 @@ static void *glui_init(void)
|
|||
|
||||
glui = (glui_handle_t*)menu->userdata;
|
||||
|
||||
glui->line_height = 44;
|
||||
glui->margin = 22;
|
||||
glui->ticker_limit = 44;
|
||||
menu->header_height = 88;
|
||||
float dpi = 96;
|
||||
if (!gfx_ctx_get_metrics(DISPLAY_METRIC_DPI, &dpi))
|
||||
dpi = 96;
|
||||
|
||||
glui->line_height = dpi/3;
|
||||
glui->margin = dpi/6;
|
||||
glui->ticker_limit = dpi/3;
|
||||
menu->header_height = dpi/3;
|
||||
glui->font.size = dpi/8;
|
||||
glui->textures.bg.id = 0;
|
||||
|
||||
if (font_driver->bind_block && font_driver->flush)
|
||||
|
@ -637,6 +687,42 @@ static bool glui_load_wallpaper(void *data)
|
|||
return true;
|
||||
}
|
||||
|
||||
static float glui_get_scroll()
|
||||
{
|
||||
glui_handle_t *glui = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
||||
float sy = 0;
|
||||
|
||||
if (!menu)
|
||||
return 0;
|
||||
|
||||
glui = (glui_handle_t*)menu->userdata;
|
||||
|
||||
if (!glui)
|
||||
return 0;
|
||||
|
||||
int half = (gl->win_height / glui->line_height) / 2;
|
||||
|
||||
if (menu->navigation.selection_ptr < half)
|
||||
return 0;
|
||||
else
|
||||
return ((menu->navigation.selection_ptr + 2 - half) * glui->line_height);
|
||||
}
|
||||
|
||||
static void glui_navigation_set(bool scroll)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (!menu)
|
||||
return;
|
||||
|
||||
if (!scroll)
|
||||
return;
|
||||
|
||||
menu_animation_push(menu->animation, 10, glui_get_scroll(),
|
||||
&menu->scroll_y, EASING_IN_OUT_QUAD, NULL);
|
||||
}
|
||||
|
||||
static void glui_navigation_clear(bool pending_push)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
|
@ -647,12 +733,69 @@ static void glui_navigation_clear(bool pending_push)
|
|||
menu->scroll_y = 0;
|
||||
}
|
||||
|
||||
static void glui_navigation_set(bool scroll)
|
||||
static void glui_navigation_set_last(void)
|
||||
{
|
||||
glui_navigation_set(true);
|
||||
}
|
||||
|
||||
static void glui_navigation_descend_alphabet(size_t *unused)
|
||||
{
|
||||
glui_navigation_set(true);
|
||||
}
|
||||
|
||||
static void glui_navigation_ascend_alphabet(size_t *unused)
|
||||
{
|
||||
glui_navigation_set(true);
|
||||
}
|
||||
|
||||
static void glui_populate_entries(const char *path,
|
||||
const char *label, unsigned i)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (!menu)
|
||||
return;
|
||||
|
||||
menu->scroll_y = glui_get_scroll();
|
||||
}
|
||||
|
||||
static bool glui_font_init_first(const void **font_driver,
|
||||
void **font_handle, void *video_data, const char *font_path,
|
||||
float font_size)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (settings->video.threaded
|
||||
&& !global->system.hw_render_callback.context_type)
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
thread_video_t *thr = (thread_video_t*)driver->video_data;
|
||||
|
||||
if (!thr)
|
||||
return false;
|
||||
|
||||
thr->cmd_data.font_init.method = gl_font_init_first;
|
||||
thr->cmd_data.font_init.font_driver = (const void**)font_driver;
|
||||
thr->cmd_data.font_init.font_handle = font_handle;
|
||||
thr->cmd_data.font_init.video_data = video_data;
|
||||
thr->cmd_data.font_init.font_path = font_path;
|
||||
thr->cmd_data.font_init.font_size = font_size;
|
||||
thr->send_cmd_func(thr, CMD_FONT_INIT);
|
||||
thr->wait_reply_func(thr, CMD_FONT_INIT);
|
||||
|
||||
return thr->cmd_data.font_init.return_value;
|
||||
}
|
||||
|
||||
return gl_font_init_first(font_driver, font_handle, video_data,
|
||||
font_path, font_size);
|
||||
}
|
||||
|
||||
static void glui_context_reset(void)
|
||||
{
|
||||
glui_handle_t *glui = NULL;
|
||||
const font_renderer_driver_t *font_drv = NULL;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
||||
float sy = 0;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!menu)
|
||||
return;
|
||||
|
@ -661,39 +804,15 @@ static void glui_navigation_set(bool scroll)
|
|||
|
||||
if (!glui)
|
||||
return;
|
||||
if (!scroll)
|
||||
|
||||
gl_t *gl = (gl_t*)video_driver_get_ptr(NULL);
|
||||
if (!gl)
|
||||
return;
|
||||
|
||||
int half = (gl->win_height / glui->line_height) / 2;
|
||||
font_drv = (const font_renderer_driver_t *)gl->font_driver;
|
||||
|
||||
if (menu->navigation.selection_ptr < half)
|
||||
sy = 0;
|
||||
else
|
||||
sy = ((menu->navigation.selection_ptr + 2 - half) * glui->line_height);
|
||||
|
||||
menu_animation_push(menu->animation, 10, sy,
|
||||
&menu->scroll_y, EASING_IN_OUT_QUAD, NULL);
|
||||
}
|
||||
|
||||
static void glui_navigation_set_last(void)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (menu)
|
||||
glui_navigation_set(true);
|
||||
}
|
||||
|
||||
static void glui_navigation_descend_alphabet(size_t *unused)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (menu)
|
||||
glui_navigation_set(true);
|
||||
}
|
||||
|
||||
static void glui_navigation_ascend_alphabet(size_t *unused)
|
||||
{
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (menu)
|
||||
glui_navigation_set(true);
|
||||
glui_font_init_first(&gl->font_driver,
|
||||
&glui->font.buf, gl, font_drv->get_default_font(), glui->font.size);
|
||||
}
|
||||
|
||||
menu_ctx_driver_t menu_ctx_glui = {
|
||||
|
@ -703,9 +822,9 @@ menu_ctx_driver_t menu_ctx_glui = {
|
|||
glui_frame,
|
||||
glui_init,
|
||||
glui_free,
|
||||
NULL,
|
||||
glui_context_reset,
|
||||
glui_context_destroy,
|
||||
NULL,
|
||||
glui_populate_entries,
|
||||
NULL,
|
||||
glui_navigation_clear,
|
||||
NULL,
|
||||
|
|
Loading…
Reference in New Issue