From ec53a400a7e2f4870dbaa9746af43ec6548cfa8c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 12 Feb 2020 17:06:53 +0100 Subject: [PATCH] Reduce dependency on settings in menu_widgets.c --- menu/widgets/menu_widgets.c | 52 +++++++++++++++++++++---------------- menu/widgets/menu_widgets.h | 15 ++++++++--- retroarch.c | 25 +++++++++++++----- 3 files changed, 59 insertions(+), 33 deletions(-) diff --git a/menu/widgets/menu_widgets.c b/menu/widgets/menu_widgets.c index 2a4769d15f..deb504fa8f 100644 --- a/menu/widgets/menu_widgets.c +++ b/menu/widgets/menu_widgets.c @@ -336,7 +336,8 @@ void menu_widgets_msg_queue_push( char *title, enum message_queue_icon icon, enum message_queue_category category, - unsigned prio, bool flush) + unsigned prio, bool flush, + float video_font_size) { menu_widget_msg_t* msg_widget = NULL; @@ -423,9 +424,9 @@ void menu_widgets_msg_queue_push( unsigned width = menu_driver_is_alive() ? msg_queue_default_rect_width_menu_alive : msg_queue_default_rect_width; unsigned text_width = font_driver_get_message_width(font_regular, title, title_length, msg_queue_text_scale_factor); - settings_t *settings = config_get_ptr(); - msg_widget->text_height = msg_queue_text_scale_factor * settings->floats.video_font_size; + msg_widget->text_height = msg_queue_text_scale_factor + * video_font_size; /* Text is too wide, split it into two lines */ if (text_width > width) @@ -863,7 +864,9 @@ static void menu_widgets_hourglass_tick(void *userdata) menu_animation_push(&entry); } -void menu_widgets_iterate(unsigned width, unsigned height) +void menu_widgets_iterate( + float video_font_size, + unsigned width, unsigned height) { size_t i; @@ -944,8 +947,6 @@ void menu_widgets_iterate(unsigned width, unsigned height) if (screenshot_filename[0] != '\0') { menu_timer_ctx_entry_t timer; - settings_t *settings = config_get_ptr(); - float video_font_size = settings->floats.video_font_size; video_driver_texture_unload(&screenshot_texture); @@ -981,6 +982,7 @@ void menu_widgets_iterate(unsigned width, unsigned height) static int menu_widgets_draw_indicator(video_frame_info_t *video_info, menu_texture_item icon, int y, int top_right_x_advance, + float video_font_size, enum msg_hash_enums msg) { unsigned width; @@ -1013,8 +1015,6 @@ static int menu_widgets_draw_indicator(video_frame_info_t *video_info, { unsigned height = simple_widget_height; const char *txt = msg_hash_to_str(msg); - settings_t *settings = config_get_ptr(); - float video_font_size = settings->floats.video_font_size; width = font_driver_get_message_width(font_regular, txt, (unsigned)strlen(txt), 1) + simple_widget_padding*2; @@ -1038,7 +1038,8 @@ static int menu_widgets_draw_indicator(video_frame_info_t *video_info, return width; } -static void menu_widgets_draw_task_msg(menu_widget_msg_t *msg, video_frame_info_t *video_info) +static void menu_widgets_draw_task_msg( + menu_widget_msg_t *msg, video_frame_info_t *video_info) { unsigned text_color; unsigned bar_width; @@ -1791,21 +1792,25 @@ void menu_widgets_frame(void *data) if (video_info->widgets_is_paused) top_right_x_advance -= menu_widgets_draw_indicator(video_info, menu_widgets_icons_textures[MENU_WIDGETS_ICON_PAUSED], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance, + video_font_size, MSG_PAUSED); if (video_info->widgets_is_fast_forwarding) top_right_x_advance -= menu_widgets_draw_indicator(video_info, menu_widgets_icons_textures[MENU_WIDGETS_ICON_FAST_FORWARD], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance, + video_font_size, MSG_PAUSED); if (video_info->widgets_is_rewinding) top_right_x_advance -= menu_widgets_draw_indicator(video_info, menu_widgets_icons_textures[MENU_WIDGETS_ICON_REWIND], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance, + video_font_size, MSG_REWINDING); if (video_info->runloop_is_slowmotion) top_right_x_advance -= menu_widgets_draw_indicator(video_info, menu_widgets_icons_textures[MENU_WIDGETS_ICON_SLOW_MOTION], (video_info->fps_show ? simple_widget_height : 0), top_right_x_advance, + video_font_size, MSG_SLOW_MOTION); /* Screenshot */ @@ -1863,8 +1868,13 @@ error: return false; } -void menu_widgets_context_reset(bool is_threaded, - unsigned width, unsigned height) +void menu_widgets_context_reset( + bool is_threaded, + unsigned width, unsigned height, + float video_font_size, + const char *dir_assets, + char *path_font + ) { int i; char xmb_path[PATH_MAX_LENGTH]; @@ -1873,20 +1883,18 @@ void menu_widgets_context_reset(bool is_threaded, char theme_path[PATH_MAX_LENGTH]; char ozone_path[PATH_MAX_LENGTH]; char font_path[PATH_MAX_LENGTH]; - settings_t *settings = config_get_ptr(); - float video_font_size = settings->floats.video_font_size; /* Textures paths */ fill_pathname_join( menu_widgets_path, - settings->paths.directory_assets, + dir_assets, "menu_widgets", sizeof(menu_widgets_path) ); fill_pathname_join( xmb_path, - settings->paths.directory_assets, + dir_assets, "xmb", sizeof(xmb_path) ); @@ -1923,13 +1931,13 @@ void menu_widgets_context_reset(bool is_threaded, /* Fonts paths */ fill_pathname_join( ozone_path, - settings->paths.directory_assets, + dir_assets, "ozone", sizeof(ozone_path) ); /* Fonts */ - if (settings->paths.path_font[0] == '\0') + if (path_font[0] == '\0') { fill_pathname_join(font_path, ozone_path, "regular.ttf", sizeof(font_path)); font_regular = menu_display_font_file(font_path, video_font_size, is_threaded); @@ -1939,8 +1947,8 @@ void menu_widgets_context_reset(bool is_threaded, } else { - font_regular = menu_display_font_file(settings->paths.path_font, video_font_size, is_threaded); - font_bold = menu_display_font_file(settings->paths.path_font, video_font_size, is_threaded); + font_regular = menu_display_font_file(path_font, video_font_size, is_threaded); + font_bold = menu_display_font_file(path_font, video_font_size, is_threaded); } /* Metrics */ @@ -2013,7 +2021,7 @@ void menu_widgets_context_destroy(void) menu_display_font_free(font_bold); font_regular = NULL; - font_bold = NULL; + font_bold = NULL; } static void menu_widgets_achievement_free(void *userdata) @@ -2122,12 +2130,10 @@ static void menu_widgets_volume_timer_end(void *userdata) menu_animation_push(&entry); } -void menu_widgets_volume_update_and_show(void) +void menu_widgets_volume_update_and_show(float new_volume) { menu_timer_ctx_entry_t entry; - settings_t *settings = config_get_ptr(); bool mute = *(audio_get_bool_ptr(AUDIO_ACTION_MUTE_ENABLE)); - float new_volume = settings->floats.audio_volume; menu_animation_kill_by_tag(&volume_tag); diff --git a/menu/widgets/menu_widgets.h b/menu/widgets/menu_widgets.h index 287bd21cdc..ef2d128381 100644 --- a/menu/widgets/menu_widgets.h +++ b/menu/widgets/menu_widgets.h @@ -46,11 +46,14 @@ void menu_widgets_msg_queue_push( char *title, enum message_queue_icon icon, enum message_queue_category category, - unsigned prio, bool flush); + unsigned prio, bool flush, + float video_font_size); -void menu_widgets_volume_update_and_show(void); +void menu_widgets_volume_update_and_show(float new_volume); -void menu_widgets_iterate(unsigned width, unsigned height); +void menu_widgets_iterate( + float video_font_size, + unsigned width, unsigned height); void menu_widgets_screenshot_taken(const char *shotname, const char *filename); @@ -70,7 +73,11 @@ void menu_widgets_start_load_content_animation( void menu_widgets_cleanup_load_content_animation(void); void menu_widgets_context_reset(bool is_threaded, - unsigned width, unsigned height); + unsigned width, unsigned height, + float video_font_size, + const char *dir_assets, + char *font_path + ); void menu_widgets_context_destroy(void); diff --git a/retroarch.c b/retroarch.c index b4969e5631..3a89d6e2e6 100644 --- a/retroarch.c +++ b/retroarch.c @@ -5407,7 +5407,7 @@ static void command_event_set_volume(float gain) #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) if (menu_widgets_inited) - menu_widgets_volume_update_and_show(); + menu_widgets_volume_update_and_show(settings->floats.audio_volume); else #endif runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -6889,7 +6889,8 @@ TODO: Add a setting for these tweaks */ #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) if (menu_widgets_inited) - menu_widgets_volume_update_and_show(); + menu_widgets_volume_update_and_show( + configuration_settings->floats.audio_volume); else #endif runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -23425,7 +23426,11 @@ static void drivers_init(int flags) if (menu_widgets_inited) menu_widgets_context_reset(video_is_threaded, - video_driver_width, video_driver_height); + video_driver_width, video_driver_height, + settings->floats.video_font_size, + settings->paths.directory_assets, + settings->paths.path_font + ); } else { @@ -25768,7 +25773,12 @@ static void runloop_task_msg_queue_push( runloop_msg_queue_lock(); ui_companion_driver_msg_queue_push(msg, prio, task ? duration : duration * 60 / 1000, flush); - menu_widgets_msg_queue_push(task, msg, duration, NULL, (enum message_queue_icon)MESSAGE_QUEUE_CATEGORY_INFO, (enum message_queue_category)MESSAGE_QUEUE_ICON_DEFAULT, prio, flush); + menu_widgets_msg_queue_push(task, msg, duration, NULL, + (enum message_queue_icon)MESSAGE_QUEUE_CATEGORY_INFO, + (enum message_queue_category)MESSAGE_QUEUE_ICON_DEFAULT, + prio, flush, + configuration_settings->floats.video_font_size + ); runloop_msg_queue_unlock(); } else @@ -26640,7 +26650,8 @@ void runloop_msg_queue_push(const char *msg, { menu_widgets_msg_queue_push(NULL, msg, roundf((float)duration / 60.0f * 1000.0f), - title, icon, category, prio, flush); + title, icon, category, prio, flush, + configuration_settings->floats.video_font_size); duration = duration * 60 / 1000; } else @@ -27141,7 +27152,9 @@ static enum runloop_state runloop_check_state(void) if (menu_widgets_inited) { runloop_msg_queue_lock(); - menu_widgets_iterate(video_driver_width, video_driver_height); + menu_widgets_iterate( + settings->floats.video_font_size, + video_driver_width, video_driver_height); runloop_msg_queue_unlock(); } #endif