From 4722bb45c8641e804559b1f0d94ebf83b22021f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Thu, 3 Nov 2016 15:56:21 +0100 Subject: [PATCH] Move the font_param stuff to menu_display.c --- menu/drivers/materialui.c | 52 ++++++++++++++++----------------------- menu/drivers/xmb.c | 37 +++++++++------------------- menu/menu_display.c | 33 ++++++++++++++++++++++--- menu/menu_display.h | 7 ++++-- 4 files changed, 68 insertions(+), 61 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index 22b0e76081..d336b79abd 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -259,24 +259,6 @@ static void mui_draw_tab(mui_handle_t *mui, &tab_color[0]); } -static void mui_draw_text(font_data_t *font, float x, float y, unsigned width, unsigned height, - const char *msg, uint32_t color, enum text_alignment text_align) -{ - struct font_params params; - - params.x = x / width; - params.y = 1.0f - (y + font->size / 3) / height; - params.scale = 1.0f; - params.drop_mod = 0.0f; - params.drop_x = 0.0f; - params.drop_y = 0.0f; - params.color = color; - params.full_screen = true; - params.text_align = text_align; - - menu_display_draw_text(font, msg, width, height, ¶ms); -} - static void mui_render_keyboard(mui_handle_t *mui, const char *grid[], unsigned id) { unsigned i, width, height; @@ -324,10 +306,11 @@ static void mui_render_keyboard(mui_handle_t *mui, const char *grid[], unsigned &white[0], texture); - mui_draw_text(mui->font, + menu_display_draw_text(mui->font, grid[i], width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width + ptr_width/2.0, - height/2.0 + ptr_height + line_y, - width, height, grid[i], 0xffffffff, TEXT_ALIGN_CENTER); + height/2.0 + ptr_height + line_y + mui->font->size / 3, + width, height, 0xffffffff, TEXT_ALIGN_CENTER, 1.0f, + false, 0); } } @@ -497,9 +480,11 @@ static void mui_render_messagebox(mui_handle_t *mui, { const char *msg = list->elems[i].data; if (msg) - mui_draw_text(mui->font, x - longest_width/2.0, y + i * line_height, - width, height, - msg, font_color, TEXT_ALIGN_LEFT); + menu_display_draw_text(mui->font, msg, + x - longest_width/2.0, + y + i * line_height + mui->font->size / 3, + width, height, font_color, TEXT_ALIGN_LEFT, 1.0f, false, 0); + } if (menu_input_dialog_get_display_kb()) @@ -627,8 +612,10 @@ static void mui_render_label_value(mui_handle_t *mui, menu_animation_ctl(MENU_ANIMATION_CTL_TICKER, &ticker); - mui_draw_text(mui->font, mui->margin, y + mui->line_height / 2, - width, height, label_str, color, TEXT_ALIGN_LEFT); + menu_display_draw_text(mui->font, label_str, + mui->margin, + y + mui->line_height / 2 + mui->font->size / 3, + width, height, color, TEXT_ALIGN_LEFT, 1.0f, false, 0); if (string_is_equal(value, "disabled") || string_is_equal(value, "off")) { @@ -686,9 +673,10 @@ static void mui_render_label_value(mui_handle_t *mui, } if (do_draw_text) - mui_draw_text(mui->font, width - mui->margin, - y + mui->line_height / 2, - width, height, value_str, color, TEXT_ALIGN_RIGHT); + menu_display_draw_text(mui->font, value_str, + width - mui->margin, + y + mui->line_height / 2 + mui->font->size / 3, + width, height, color, TEXT_ALIGN_RIGHT, 1.0f, false, 0); if (texture_switch) mui_draw_icon( @@ -1276,8 +1264,10 @@ static void mui_frame(void *data) strlcpy(title_buf, title_buf_msg_tmp, sizeof(title_buf)); } - mui_draw_text(mui->font, title_margin, header_height / 2, width, height, - title_buf, font_header_color, TEXT_ALIGN_LEFT); + menu_display_draw_text(mui->font, title_buf, + title_margin, + header_height / 2 + mui->font->size / 3, + width, height, font_header_color, TEXT_ALIGN_LEFT, 1.0f, false, 0); mui_draw_scrollbar(mui, width, height, &grey_bg[0]); diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 9f84e9c911..fa2aeed04c 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -648,38 +648,24 @@ static void xmb_draw_text(xmb_handle_t *xmb, { settings_t *settings = config_get_ptr(); struct font_params params; - uint8_t a8 = 0; + uint8_t a8; + uint32_t color; if (alpha > xmb->alpha) alpha = xmb->alpha; a8 = 255 * alpha; + /* Avoid drawing 100% transparent text */ if (a8 == 0) return; - if (x < -xmb->icon.size || x > width + xmb->icon.size - || y < -xmb->icon.size || y > height + xmb->icon.size) - return; + color = FONT_COLOR_RGBA(255, 255, 255, a8); - params.x = x / width; - params.y = 1.0f - y / height; - params.scale = scale_factor; - params.drop_mod = 0.0f; - params.drop_x = 0.0f; - params.drop_y = 0.0f; - params.color = FONT_COLOR_RGBA(255, 255, 255, a8); - params.full_screen = true; - params.text_align = text_align; - - if (settings->menu.xmb.shadows_enable) - { - params.drop_x = xmb->shadow_offset; - params.drop_y = -xmb->shadow_offset; - params.drop_alpha = 0.35f; - } - - menu_display_draw_text(font, str, width, height, ¶ms); + menu_display_draw_text(font, str, x, y, + width, height, color, text_align, scale_factor, + settings->menu.xmb.shadows_enable, + xmb->shadow_offset); } static void xmb_messagebox(void *data, const char *message) @@ -741,10 +727,11 @@ static void xmb_render_keyboard(xmb_handle_t *xmb, const char *grid[], unsigned menu_display_blend_end(); - xmb_draw_text(xmb, grid[i], + menu_display_draw_text(xmb->font, grid[i], width/2.0 - (11*ptr_width)/2.0 + (i % 11) * ptr_width + ptr_width/2.0, - height/2.0 + ptr_height + xmb->font->size/4.0 + line_y, - 1, 1, TEXT_ALIGN_CENTER, width, height, xmb->font); + height/2.0 + ptr_height + line_y + xmb->font->size / 3, + width, height, 0xffffffff, TEXT_ALIGN_CENTER, 1.0f, + false, 0); } } diff --git a/menu/menu_display.c b/menu/menu_display.c index 27392f656e..6c8e8e2747 100644 --- a/menu/menu_display.c +++ b/menu/menu_display.c @@ -852,10 +852,37 @@ void menu_display_snow(int width, int height) } } -void menu_display_draw_text(const font_data_t *font, const char *msg, - int width, int height, struct font_params *params) +void menu_display_draw_text( + const font_data_t *font, const char *text, + float x, float y, int width, int height, + uint32_t color, enum text_alignment text_align, + float scale, bool shadows_enable, float shadow_offset) { - video_driver_set_osd_msg(msg, params, (void*)font); + struct font_params params; + + /* Don't draw outside of the screen */ + if (x < -64 || x > width + 64 + || y < -64 || y > height + 64) + return; + + params.x = x / width; + params.y = 1.0f - y / height; + params.scale = scale; + params.drop_mod = 0.0f; + params.drop_x = 0.0f; + params.drop_y = 0.0f; + params.color = color; + params.full_screen = true; + params.text_align = text_align; + + if (shadows_enable) + { + params.drop_x = shadow_offset; + params.drop_y = -shadow_offset; + params.drop_alpha = 0.35f; + } + + video_driver_set_osd_msg(text, ¶ms, (void*)font); } void menu_display_set_alpha(float *color, float alpha_value) diff --git a/menu/menu_display.h b/menu/menu_display.h index 122348fe7c..33a1bcc18d 100644 --- a/menu/menu_display.h +++ b/menu/menu_display.h @@ -260,8 +260,11 @@ void menu_display_draw_cursor( float *color, float cursor_size, uintptr_t texture, float x, float y, unsigned width, unsigned height); -void menu_display_draw_text(const font_data_t *font, const char *msg, int width, int height, - struct font_params *params); +void menu_display_draw_text( + const font_data_t *font, const char *text, + float x, float y, int width, int height, + uint32_t color, enum text_alignment text_align, + float scale_factor, bool shadows_enable, float shadow_offset); bool menu_display_shader_pipeline_active(void);