From 2533bbdc0b2003555bd0846f0bfb2a1d54ea32eb Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Wed, 15 Jan 2025 12:37:35 +0100 Subject: [PATCH] Small cleanups --- gfx/gfx_widgets.c | 95 ++++++++++------------ gfx/widgets/gfx_widget_achievement_popup.c | 22 ++--- 2 files changed, 53 insertions(+), 64 deletions(-) diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index 6024d958ece4..b36f3abc0930 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -16,7 +16,6 @@ */ #include -#include #ifdef HAVE_CONFIG_H #include "../config.h" @@ -43,39 +42,11 @@ #include "../tasks/task_content.h" #include "../tasks/tasks_internal.h" -#define BASE_FONT_SIZE 32.0f - +#define BASE_FONT_SIZE 32.0f #define MSG_QUEUE_FONT_SIZE 20.0f -/* Icons */ -static const char -*gfx_widgets_icons_names[MENU_WIDGETS_ICON_LAST] = { - "menu_pause.png", - "menu_frameskip.png", - "menu_rewind.png", - "resume.png", - - "menu_hourglass.png", - "menu_check.png", - "menu_add.png", - "menu_exit.png", - - "menu_info.png", - - "menu_achievements.png" -}; - static dispgfx_widget_t dispwidget_st = {0}; /* uint64_t alignment */ -static void INLINE gfx_widgets_font_free(gfx_widget_font_data_t *font_data) -{ - if (font_data->font) - font_driver_free(font_data->font); - - font_data->font = NULL; - font_data->usage_count = 0; -} - /* Widgets list */ const static gfx_widget_t* const widgets[] = { #ifdef HAVE_NETWORKING @@ -1514,19 +1485,6 @@ static void gfx_widgets_draw_regular_msg( } } -static void INLINE gfx_widgets_font_bind(gfx_widget_font_data_t *font_data) -{ - font_driver_bind_block(font_data->font, &font_data->raster_block); - font_data->raster_block.carr.coords.vertices = 0; - font_data->usage_count = 0; -} - -static void INLINE gfx_widgets_font_unbind(gfx_widget_font_data_t *font_data) -{ - font_driver_bind_block(font_data->font, NULL); -} - - void gfx_widgets_frame(void *data) { size_t i; @@ -1568,9 +1526,19 @@ void gfx_widgets_frame(void *data) video_st->data, video_width, video_height, true, false); /* Font setup */ - gfx_widgets_font_bind(&p_dispwidget->gfx_widget_fonts.regular); - gfx_widgets_font_bind(&p_dispwidget->gfx_widget_fonts.bold); - gfx_widgets_font_bind(&p_dispwidget->gfx_widget_fonts.msg_queue); + font_driver_bind_block(p_dispwidget->gfx_widget_fonts.regular.font, + &p_dispwidget->gfx_widget_fonts.regular.raster_block); + font_driver_bind_block(p_dispwidget->gfx_widget_fonts.bold.font, + &p_dispwidget->gfx_widget_fonts.bold.raster_block); + font_driver_bind_block(p_dispwidget->gfx_widget_fonts.msg_queue.font, + &p_dispwidget->gfx_widget_fonts.msg_queue.raster_block); + + p_dispwidget->gfx_widget_fonts.regular.raster_block.carr.coords.vertices = 0; + p_dispwidget->gfx_widget_fonts.regular.usage_count = 0; + p_dispwidget->gfx_widget_fonts.bold.raster_block.carr.coords.vertices = 0; + p_dispwidget->gfx_widget_fonts.bold.usage_count = 0; + p_dispwidget->gfx_widget_fonts.msg_queue.raster_block.carr.coords.vertices = 0; + p_dispwidget->gfx_widget_fonts.msg_queue.usage_count = 0; #ifdef HAVE_TRANSLATE /* AI Service overlay */ @@ -1669,7 +1637,7 @@ void gfx_widgets_frame(void *data) } #endif - /* Status Text (fps, framecount, memory, core status message) */ + /* Status Text (FPS, framecount, memory, core status message) */ if ( fps_show || framecount_show || memory_show @@ -1835,9 +1803,9 @@ void gfx_widgets_frame(void *data) &p_dispwidget->gfx_widget_fonts.msg_queue); /* Unbind fonts */ - gfx_widgets_font_unbind(&p_dispwidget->gfx_widget_fonts.regular); - gfx_widgets_font_unbind(&p_dispwidget->gfx_widget_fonts.bold); - gfx_widgets_font_unbind(&p_dispwidget->gfx_widget_fonts.msg_queue); + font_driver_bind_block(p_dispwidget->gfx_widget_fonts.regular.font, NULL); + font_driver_bind_block(p_dispwidget->gfx_widget_fonts.bold.font, NULL); + font_driver_bind_block(p_dispwidget->gfx_widget_fonts.msg_queue.font, NULL); if (video_st->current_video && video_st->current_video->set_viewport) video_st->current_video->set_viewport( @@ -1938,6 +1906,23 @@ static void gfx_widgets_context_reset( unsigned width, unsigned height, bool fullscreen, const char *dir_assets, char *font_path) { + /* Icons */ + static const char + *gfx_widgets_icons_names[MENU_WIDGETS_ICON_LAST] = { + "menu_pause.png", + "menu_frameskip.png", + "menu_rewind.png", + "resume.png", + + "menu_hourglass.png", + "menu_check.png", + "menu_add.png", + "menu_exit.png", + + "menu_info.png", + + "menu_achievements.png" + }; size_t i; /* Load textures */ @@ -2111,6 +2096,15 @@ bool gfx_widgets_init( return false; } +static void gfx_widgets_font_free(gfx_widget_font_data_t *font_data) +{ + if (font_data->font) + font_driver_free(font_data->font); + + font_data->font = NULL; + font_data->usage_count = 0; +} + static void gfx_widgets_context_destroy(dispgfx_widget_t *p_dispwidget) { size_t i; @@ -2135,7 +2129,6 @@ static void gfx_widgets_context_destroy(dispgfx_widget_t *p_dispwidget) gfx_widgets_font_free(&p_dispwidget->gfx_widget_fonts.msg_queue); } - void gfx_widgets_deinit(bool widgets_persisting) { dispgfx_widget_t *p_dispwidget = &dispwidget_st; diff --git a/gfx/widgets/gfx_widget_achievement_popup.c b/gfx/widgets/gfx_widget_achievement_popup.c index ba583a8ab0b2..0de8cbe29c41 100644 --- a/gfx/widgets/gfx_widget_achievement_popup.c +++ b/gfx/widgets/gfx_widget_achievement_popup.c @@ -155,18 +155,14 @@ static void gfx_widget_achievement_popup_frame(void* data, void* userdata) gfx_display_ctx_driver_t* dispctx = p_disp->dispctx; dispgfx_widget_t* p_dispwidget = (dispgfx_widget_t*)userdata; - unsigned text_unfold_offset = 0; - bool is_folding = false; - unsigned screen_padding_x = 0; - unsigned screen_padding_y = 0; - int screen_pos_x = 0; - int screen_pos_y = 0; - + unsigned screen_padding_x = 0; + unsigned screen_padding_y = 0; + int screen_pos_x = 0; + int screen_pos_y = 0; /* Slight additional offset for title/subtitle while unfolding */ - text_unfold_offset = ((1.0f - state->unfold) * state->width) * 0.5; - + unsigned text_unfold_offset = ((1.0f - state->unfold) * state->width) * 0.5; /* Whether gfx scissoring should occur, partially hiding popup */ - is_folding = fabs(state->unfold - 1.0f) > 0.01; + bool is_folding = fabs(state->unfold - 1.0f) > 0.01; /* Calculate padding in screen space */ if (state->padding_auto) @@ -200,11 +196,11 @@ static void gfx_widget_achievement_popup_frame(void* data, void* userdata) switch (state->anchor_v) { case ANCHOR_TOP: - screen_pos_y = -(state->height); + screen_pos_y = -(state->height); screen_pos_y += (screen_padding_y + state->height) * state->slide_v; break; case ANCHOR_BOTTOM: - screen_pos_y = video_height; + screen_pos_y = video_height; screen_pos_y -= (screen_padding_y + state->height) * state->slide_v; break; } @@ -217,7 +213,7 @@ static void gfx_widget_achievement_popup_frame(void* data, void* userdata) state->queue[state->queue_read_index].badge_name) { const retro_time_t next_try = state->queue[state->queue_read_index].badge_retry; - const retro_time_t now = cpu_features_get_time_usec(); + const retro_time_t now = cpu_features_get_time_usec(); if (next_try == 0 || now > next_try) { /* try again in 250ms */