From b10ce11ad3a14b138ddbdad50c3689c9172597b3 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 24 Apr 2015 23:06:04 +0200 Subject: [PATCH] Move font variables to menu_handle_t --- menu/drivers/glui.c | 29 ++++++++++----------------- menu/drivers/rgui.c | 12 ++++++------ menu/drivers/xmb.c | 48 +++++++++++++++++++++------------------------ menu/menu_driver.h | 11 +++++++++-- 4 files changed, 47 insertions(+), 53 deletions(-) diff --git a/menu/drivers/glui.c b/menu/drivers/glui.c index 0c1d8353d6..5868af5a7f 100644 --- a/menu/drivers/glui.c +++ b/menu/drivers/glui.c @@ -41,12 +41,6 @@ typedef struct glui_handle unsigned ticker_limit; char box_message[PATH_MAX_LENGTH]; - struct - { - void *buf; - int size; - } font; - struct { struct @@ -101,14 +95,14 @@ static void glui_blit_line(gl_t *gl, float x, float y, struct font_params params = {0}; params.x = x / gl->win_width; - params.y = 1.0f - (y + glui->line_height/2 + glui->font.size/3) + params.y = 1.0f - (y + glui->line_height/2 + menu->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, glui->font.buf); + video_driver_set_osd_msg(message, ¶ms, menu->font.buf); } static void glui_render_background(settings_t *settings, gl_t *gl, @@ -305,7 +299,7 @@ static void glui_render_messagebox(const char *message) goto end; x = gl->win_width / 2; - y = gl->win_height / 2 - list->size * glui->font.size / 2; + y = gl->win_height / 2 - list->size * menu->font.size / 2; normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color); @@ -313,7 +307,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 * glui->font.size, msg, normal_color, TEXT_ALIGN_CENTER); + glui_blit_line(gl, x, y + i * menu->font.size, msg, normal_color, TEXT_ALIGN_CENTER); } end: @@ -495,7 +489,7 @@ static void glui_frame(void) font_driver = (const struct font_renderer*)gl->font_driver; if (font_driver->bind_block) - font_driver->bind_block(glui->font.buf, &glui->list_block); + font_driver->bind_block(menu->font.buf, &glui->list_block); glui_render_menu_list(runloop, gl, glui, menu, label, normal_color, hover_color); @@ -556,8 +550,8 @@ static void glui_frame(void) if (font_driver->flush) { - font_driver->flush(glui->font.buf); - font_driver->bind_block(glui->font.buf, NULL); + font_driver->flush(menu->font.buf); + font_driver->bind_block(menu->font.buf, NULL); } if (menu->keyboard.display) @@ -617,7 +611,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; + menu->font.size = dpi / 8; glui->textures.bg.id = 0; rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, @@ -649,9 +643,6 @@ static void glui_free(void *data) if (font_driver && font_driver->bind_block) font_driver->bind_block(gl->font_handle, NULL); - if (menu->alloc_font) - free((uint8_t*)menu->font); - if (menu->userdata) free(menu->userdata); } @@ -788,10 +779,10 @@ static void glui_context_reset(void) menu_display_font_init_first( &gl->font_driver, - &glui->font.buf, + &menu->font.buf, gl, NULL, - glui->font.size); + menu->font.size); } menu_ctx_driver_t menu_ctx_glui = { diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index 6e942c6a94..11cba64e63 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -184,7 +184,7 @@ static void blit_line(menu_handle_t *menu, int x, int y, { uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7); int offset = (i + j * FONT_WIDTH) >> 3; - bool col = (menu->font[FONT_OFFSET + bool col = (menu->font.framebuf[FONT_OFFSET ((unsigned char)*message) + offset] & rem); if (!col) @@ -211,7 +211,7 @@ static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf) return false; } - menu->alloc_font = true; + menu->font.alloc_framebuf = true; for (i = 0; i < 256; i++) { unsigned y = i / 16; @@ -220,7 +220,7 @@ static bool init_font(menu_handle_t *menu, const uint8_t *font_bmp_buf) font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x)); } - menu->font = font; + menu->font.framebuf = font; return true; } @@ -238,7 +238,7 @@ static bool rguidisp_init_font(menu_handle_t *menu) if (!font_bin_buf) return false; - menu->font = font_bin_buf; + menu->font.framebuf = font_bin_buf; return true; } @@ -621,8 +621,8 @@ static void rgui_free(void *data) free(menu->userdata); menu->userdata = NULL; - if (menu->alloc_font) - free((uint8_t*)menu->font); + if (menu->font.alloc_framebuf) + free((uint8_t*)menu->font.framebuf); } static void rgui_set_texture(void) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 0b510c8efe..cbccbfc277 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -207,12 +207,6 @@ typedef struct xmb_handle } passive; } item; - struct - { - void *buf; - int size; - } font; - xmb_node_t settings_node; bool prevent_populate; @@ -385,7 +379,8 @@ static void xmb_draw_icon_predone(gl_t *gl, xmb_handle_t *xmb, glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); } -static void xmb_draw_text(gl_t *gl, xmb_handle_t *xmb, +static void xmb_draw_text(menu_handle_t *menu, + gl_t *gl, xmb_handle_t *xmb, const char *str, float x, float y, float scale_factor, float alpha, enum text_alignment text_align) @@ -413,7 +408,7 @@ static void xmb_draw_text(gl_t *gl, xmb_handle_t *xmb, params.full_screen = true; params.text_align = text_align; - video_driver_set_osd_msg(str, ¶ms, xmb->font.buf); + video_driver_set_osd_msg(str, ¶ms, menu->font.buf); } static void xmb_frame_background(settings_t *settings, @@ -531,16 +526,16 @@ static void xmb_frame_messagebox(const char *message) if (list->elems == 0) goto end; - x = gl->win_width / 2 - strlen(list->elems[0].data) * xmb->font.size / 4; - y = gl->win_height / 2 - list->size * xmb->font.size / 2; + x = gl->win_width / 2 - strlen(list->elems[0].data) * menu->font.size / 4; + y = gl->win_height / 2 - list->size * menu->font.size / 2; for (i = 0; i < list->size; i++) { const char *msg = list->elems[i].data; if (msg) - xmb_draw_text(gl, xmb, msg, x, - y + i * xmb->font.size, 1, 1, TEXT_ALIGN_LEFT); + xmb_draw_text(menu, gl, xmb, msg, x, + y + i * menu->font.size, 1, 1, TEXT_ALIGN_LEFT); } end: @@ -1091,6 +1086,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, GLuint icon = 0; xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(list, i); runloop_t *runloop = rarch_main_get_ptr(); + menu_handle_t *menu = menu_driver_get_ptr(); if (!node) continue; @@ -1148,7 +1144,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, runloop->frames.video.count / 20, path_buf, (i == current)); - xmb_draw_text(gl, xmb, name, + xmb_draw_text(menu, gl, xmb, name, node->x + xmb->margins.screen.left + xmb->icon.spacing.horizontal + xmb->margins.label.left, xmb->margins.screen.top + node->y + xmb->margins.label.top, @@ -1171,7 +1167,7 @@ static void xmb_draw_items(xmb_handle_t *xmb, gl_t *gl, && !xmb->textures.list[XMB_TEXTURE_SWITCH_ON].id) || (!strcmp(type_str, "OFF") && !xmb->textures.list[XMB_TEXTURE_SWITCH_OFF].id))) - xmb_draw_text(gl, xmb, value, + xmb_draw_text(menu, gl, xmb, value, node->x + xmb->margins.screen.left + xmb->icon.spacing.horizontal + xmb->margins.label.left + xmb->margins.setting.left, xmb->margins.screen.top + node->y + xmb->margins.label.top, @@ -1332,13 +1328,13 @@ static void xmb_frame(void) font_driver = (const struct font_renderer*)gl->font_driver; if (font_driver->bind_block) - font_driver->bind_block(xmb->font.buf, &xmb->raster_block); + font_driver->bind_block(menu->font.buf, &xmb->raster_block); xmb->raster_block.carr.coords.vertices = 0; xmb_frame_background(settings, gl, xmb, false); - xmb_draw_text(gl, xmb, + xmb_draw_text(menu, gl, xmb, xmb->title_name, xmb->margins.title.left, xmb->margins.title.top, 1, 1, TEXT_ALIGN_LEFT); @@ -1346,7 +1342,7 @@ static void xmb_frame(void) { disp_timedate_set_label(timedate, sizeof(timedate), 0); - xmb_draw_text(gl, xmb, + xmb_draw_text(menu, gl, xmb, timedate, gl->win_width - xmb->margins.title.left - xmb->icon.size / 4, xmb->margins.title.top, 1, 1, TEXT_ALIGN_RIGHT); @@ -1370,7 +1366,7 @@ static void xmb_frame(void) snprintf(title_msg, sizeof(title_msg), "%s - %s %s", PACKAGE_VERSION, core_name, core_version); - xmb_draw_text(gl, xmb, title_msg, xmb->margins.title.left, + xmb_draw_text(menu, gl, xmb, title_msg, xmb->margins.title.left, gl->win_height - xmb->margins.title.bottom, 1, 1, TEXT_ALIGN_LEFT); } @@ -1434,8 +1430,8 @@ static void xmb_frame(void) if (font_driver->flush) { - font_driver->flush(xmb->font.buf); - font_driver->bind_block(xmb->font.buf, NULL); + font_driver->flush(menu->font.buf); + font_driver->bind_block(menu->font.buf, NULL); } if (menu->keyboard.display) @@ -1552,16 +1548,16 @@ static void *xmb_init(void) xmb->icon.size = 128.0 * scale_factor; xmb->cursor.size = 48.0; - xmb->font.size = 32.0 * scale_factor; + menu->font.size = 32.0 * scale_factor; xmb->icon.spacing.horizontal = 200.0 * scale_factor; xmb->icon.spacing.vertical = 64.0 * scale_factor; xmb->margins.screen.left = 336.0 * scale_factor; xmb->margins.screen.top = (256+32) * scale_factor; xmb->margins.title.left = 60 * scale_factor; - xmb->margins.title.top = 60 * scale_factor + xmb->font.size/3; - xmb->margins.title.bottom = 60 * scale_factor - xmb->font.size/3; + xmb->margins.title.top = 60 * scale_factor + menu->font.size/3; + xmb->margins.title.bottom = 60 * scale_factor - menu->font.size/3; xmb->margins.label.left = 85.0 * scale_factor; - xmb->margins.label.top = xmb->font.size/3.0; + xmb->margins.label.top = menu->font.size/3.0; xmb->margins.setting.left = 600.0 * scale_factor; menu->categories.size = 1; @@ -1680,10 +1676,10 @@ static void xmb_context_reset(void) menu_display_font_init_first( &gl->font_driver, - &xmb->font.buf, + &menu->font.buf, gl, fontpath, - xmb->font.size); + menu->font.size); fill_pathname_join(xmb->textures.list[XMB_TEXTURE_SETTINGS].path, iconpath, "settings.png", sizeof(xmb->textures.list[XMB_TEXTURE_SETTINGS].path)); diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 0f40c5e585..6b79b90086 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -145,8 +145,15 @@ typedef struct menu_framebuf_t frame_buf; - const uint8_t *font; - bool alloc_font; + + struct + { + void *buf; + int size; + + const uint8_t *framebuf; + bool alloc_framebuf; + } font; bool load_no_content;