From b6337d2734ac599b885ad978b68d67a8882eef46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 21 Apr 2015 08:36:09 +0700 Subject: [PATCH 1/5] (GLUI) Use DPI, reduce header size to line height, center font verticaly for every font size --- menu/drivers/glui.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 88ce233022..0e6c95611b 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -81,10 +81,19 @@ 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(); + settings_t *settings = config_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 + settings->video.font_size/3) / gl->win_height; params.scale = 1.0; params.color = color; params.full_screen = true; @@ -328,12 +337,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; } @@ -450,7 +459,7 @@ 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); @@ -460,18 +469,18 @@ static void glui_frame(void) 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); core_name = global->menu.info.library_name; @@ -555,10 +564,14 @@ 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->textures.bg.id = 0; if (font_driver->bind_block && font_driver->flush) From 1f31033394d5deb3f995c7c3ec2dee20bc46da78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 21 Apr 2015 08:47:46 +0700 Subject: [PATCH 2/5] (GLUI) Use render_quad instead of render_background to darken the screen --- menu/drivers/glui.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 0e6c95611b..421cb230f8 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -102,9 +102,8 @@ static void glui_blit_line(gl_t *gl, float x, float y, const char *message, uint video_driver_set_osd_msg(message, ¶ms, NULL); } -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, @@ -145,7 +144,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; @@ -451,7 +449,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); @@ -518,14 +516,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'; } From 8ef70debcb765b85264e39cb1ab762ba390ba79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 21 Apr 2015 09:47:02 +0700 Subject: [PATCH 3/5] (GLUI) Scrollbar --- menu/drivers/glui.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 421cb230f8..4661a4feca 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -218,6 +218,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; @@ -481,6 +510,8 @@ static void glui_frame(void) 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; From 5e96ea77273daf8620a60b1a3d053bd30eaf6af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 21 Apr 2015 11:43:52 +0700 Subject: [PATCH 4/5] (GLUI) Fix a bug when going backward on a long list --- menu/drivers/glui.c | 86 ++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 4661a4feca..38d978b073 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -679,6 +679,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(); @@ -689,53 +725,29 @@ static void glui_navigation_clear(bool pending_push) menu->scroll_y = 0; } -static void glui_navigation_set(bool 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; - - glui = (glui_handle_t*)menu->userdata; - - if (!glui) - return; - if (!scroll) - return; - - int half = (gl->win_height / glui->line_height) / 2; - - 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); + 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); + 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) - glui_navigation_set(true); + if (!menu) + return; + + menu->scroll_y = glui_get_scroll(); } menu_ctx_driver_t menu_ctx_glui = { @@ -747,7 +759,7 @@ menu_ctx_driver_t menu_ctx_glui = { glui_free, NULL, glui_context_destroy, - NULL, + glui_populate_entries, NULL, glui_navigation_clear, NULL, From ede94ef66c9334684df2220665c446028f80d4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 21 Apr 2015 14:20:18 +0700 Subject: [PATCH 5/5] (GLUI) Use a font size adapted to the dpi --- menu/drivers/glui.c | 79 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 7 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 38d978b073..3ed859f269 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -25,6 +25,7 @@ #include "../../runloop_data.h" #include +#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 @@ -83,7 +91,6 @@ static void glui_blit_line(gl_t *gl, float x, float y, const char *message, uint { glui_handle_t *glui = NULL; menu_handle_t *menu = menu_driver_get_ptr(); - settings_t *settings = config_get_ptr(); if (!menu) return; @@ -93,13 +100,13 @@ static void glui_blit_line(gl_t *gl, float x, float y, const char *message, uint struct font_params params = {0}; params.x = x / gl->win_width; - params.y = 1.0f - (y + glui->line_height/2 + settings->video.font_size/3) / 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, @@ -297,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); @@ -305,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: @@ -491,7 +498,7 @@ static void glui_frame(void) 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; @@ -601,6 +608,7 @@ static void *glui_init(void) 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) @@ -750,6 +758,63 @@ static void glui_populate_entries(const char *path, 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(); + settings_t *settings = config_get_ptr(); + + if (!menu) + return; + + glui = (glui_handle_t*)menu->userdata; + + if (!glui) + return; + + gl_t *gl = (gl_t*)video_driver_get_ptr(NULL); + if (!gl) + return; + + font_drv = (const font_renderer_driver_t *)gl->font_driver; + + 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 = { NULL, glui_get_message, @@ -757,7 +822,7 @@ menu_ctx_driver_t menu_ctx_glui = { glui_frame, glui_init, glui_free, - NULL, + glui_context_reset, glui_context_destroy, glui_populate_entries, NULL,