(Menu) Cleanups for drivers

This commit is contained in:
libretroadmin 2022-05-20 20:31:06 +02:00
parent d9948c00e1
commit 69d251ff6d
3 changed files with 80 additions and 120 deletions

View File

@ -2303,10 +2303,8 @@ static void materialui_refresh_playlist_icon_list(materialui_handle_t *mui,
* necessary (if 'invalid' playlist files * necessary (if 'invalid' playlist files
* are included in the list), but this * are included in the list), but this
* reduces code complexity */ * reduces code complexity */
mui->textures.playlist.icons = (materialui_playlist_icon_t*) if (!(mui->textures.playlist.icons = (materialui_playlist_icon_t*)
malloc(file_list->size * sizeof(materialui_playlist_icon_t)); malloc(file_list->size * sizeof(materialui_playlist_icon_t))))
if (!mui->textures.playlist.icons)
goto end; goto end;
mui->textures.playlist.size = file_list->size; mui->textures.playlist.size = file_list->size;
@ -2369,24 +2367,8 @@ static void materialui_set_node_playlist_icon(
materialui_handle_t *mui, materialui_node_t* node, materialui_handle_t *mui, materialui_node_t* node,
const char *playlist_path) const char *playlist_path)
{ {
const char *playlist_file = NULL;
size_t i; size_t i;
const char *playlist_file = path_basename_nocompression(playlist_path);
/* Set defaults */
node->icon_texture_index = MUI_TEXTURE_PLAYLIST;
node->icon_type = MUI_ICON_TYPE_INTERNAL;
if (mui->textures.playlist.size < 1)
return;
/* Get playlist file name */
if (string_is_empty(playlist_path))
return;
playlist_file = path_basename_nocompression(playlist_path);
if (string_is_empty(playlist_path))
return;
/* Search icon list for specified file */ /* Search icon list for specified file */
for (i = 0; i < mui->textures.playlist.size; i++) for (i = 0; i < mui->textures.playlist.size; i++)
@ -2410,15 +2392,13 @@ static uintptr_t materialui_get_playlist_icon(
materialui_handle_t *mui, unsigned texture_index) materialui_handle_t *mui, unsigned texture_index)
{ {
uintptr_t playlist_icon; uintptr_t playlist_icon;
/* Always use MUI_TEXTURE_PLAYLIST as /* Always use MUI_TEXTURE_PLAYLIST as
* a fallback */ * a fallback */
if (texture_index >= mui->textures.playlist.size) if (texture_index >= mui->textures.playlist.size)
return mui->textures.list[MUI_TEXTURE_PLAYLIST]; return mui->textures.list[MUI_TEXTURE_PLAYLIST];
if ((playlist_icon = mui->textures.playlist.icons[texture_index].image))
playlist_icon = mui->textures.playlist.icons[texture_index].image; return playlist_icon;
return mui->textures.list[MUI_TEXTURE_PLAYLIST];
return playlist_icon ? playlist_icon : mui->textures.list[MUI_TEXTURE_PLAYLIST];
} }
/* ============================== /* ==============================
@ -2516,21 +2496,12 @@ static void materialui_draw_thumbnail(
float scale_factor, float scale_factor,
math_matrix_4x4 *mymat) math_matrix_4x4 *mymat)
{ {
float bg_x;
float bg_y;
float bg_width;
float bg_height;
/* Sanity check */
if (scale_factor <= 0)
return;
/* Get background draw position + dimensions, /* Get background draw position + dimensions,
* accounting for scale factor */ * accounting for scale factor */
bg_width = (float)mui->thumbnail_width_max * scale_factor; float bg_width = (float)mui->thumbnail_width_max * scale_factor;
bg_height = (float)mui->thumbnail_height_max * scale_factor; float bg_height = (float)mui->thumbnail_height_max * scale_factor;
bg_x = x - (bg_width - (float)mui->thumbnail_width_max) / 2.0f; float bg_x = x - (bg_width - (float)mui->thumbnail_width_max) / 2.0f;
bg_y = y - (bg_height - (float)mui->thumbnail_height_max) / 2.0f; float bg_y = y - (bg_height - (float)mui->thumbnail_height_max) / 2.0f;
/* If thumbnail is missing, draw fallback image... */ /* If thumbnail is missing, draw fallback image... */
switch (thumbnail->status) switch (thumbnail->status)
@ -10236,7 +10207,12 @@ static void materialui_list_insert(
node->icon_type = MUI_ICON_TYPE_INTERNAL; node->icon_type = MUI_ICON_TYPE_INTERNAL;
break; break;
case FILE_TYPE_PLAYLIST_COLLECTION: case FILE_TYPE_PLAYLIST_COLLECTION:
materialui_set_node_playlist_icon(mui, node, path); /* Set defaults */
node->icon_texture_index = MUI_TEXTURE_PLAYLIST;
node->icon_type = MUI_ICON_TYPE_INTERNAL;
if (mui->textures.playlist.size >= 1)
if (!string_is_empty(path))
materialui_set_node_playlist_icon(mui, node, path);
break; break;
case FILE_TYPE_RDB: case FILE_TYPE_RDB:
node->icon_texture_index = MUI_TEXTURE_DATABASE; node->icon_texture_index = MUI_TEXTURE_DATABASE;

View File

@ -2564,16 +2564,14 @@ static float ozone_sidebar_get_scroll_y(
return scroll_y; return scroll_y;
} }
/* Flushing is slow - only do it if font
* has actually been used */
static void ozone_font_flush( static void ozone_font_flush(
unsigned video_width, unsigned video_height, unsigned video_width, unsigned video_height,
ozone_font_data_t *font_data) ozone_font_data_t *font_data)
{ {
/* Flushing is slow - only do it if font if (font_data->raster_block.carr.coords.vertices == 0)
* has actually been used */
if (!font_data ||
(font_data->raster_block.carr.coords.vertices == 0))
return; return;
font_driver_flush(video_width, video_height, font_data->font); font_driver_flush(video_width, video_height, font_data->font);
font_data->raster_block.carr.coords.vertices = 0; font_data->raster_block.carr.coords.vertices = 0;
} }
@ -9485,8 +9483,7 @@ static void ozone_messagebox_fadeout_cb(void *userdata)
ozone_handle_t *ozone = (ozone_handle_t*) userdata; ozone_handle_t *ozone = (ozone_handle_t*) userdata;
free(ozone->pending_message); free(ozone->pending_message);
ozone->pending_message = NULL; ozone->pending_message = NULL;
ozone->should_draw_messagebox = false; ozone->should_draw_messagebox = false;
} }
@ -9503,8 +9500,9 @@ static void INLINE ozone_font_unbind(ozone_font_data_t *font_data)
static void ozone_frame(void *data, video_frame_info_t *video_info) static void ozone_frame(void *data, video_frame_info_t *video_info)
{ {
math_matrix_4x4 mymat;
gfx_animation_ctx_entry_t entry; gfx_animation_ctx_entry_t entry;
ozone_handle_t* ozone = (ozone_handle_t*) data; ozone_handle_t* ozone = (ozone_handle_t*)data;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
unsigned color_theme = settings->uints.menu_ozone_color_theme; unsigned color_theme = settings->uints.menu_ozone_color_theme;
bool use_preferred_system_color_theme = settings->bools.menu_use_preferred_system_color_theme; bool use_preferred_system_color_theme = settings->bools.menu_use_preferred_system_color_theme;
@ -9526,7 +9524,6 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
gfx_display_t *p_disp = (gfx_display_t*)video_info->disp_userdata; gfx_display_t *p_disp = (gfx_display_t*)video_info->disp_userdata;
gfx_animation_t *p_anim = anim_get_ptr(); gfx_animation_t *p_anim = anim_get_ptr();
gfx_display_ctx_driver_t *dispctx = p_disp->dispctx; gfx_display_ctx_driver_t *dispctx = p_disp->dispctx;
math_matrix_4x4 mymat;
#if 0 #if 0
static bool reset = false; static bool reset = false;
@ -9538,7 +9535,6 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
} }
#endif #endif
if (!ozone) if (!ozone)
return; return;
@ -9763,37 +9759,37 @@ static void ozone_frame(void *data, video_frame_info_t *video_info)
/* Fade in animation */ /* Fade in animation */
if (ozone->messagebox_state_old != ozone->messagebox_state && ozone->messagebox_state) if (ozone->messagebox_state_old != ozone->messagebox_state && ozone->messagebox_state)
{ {
ozone->messagebox_state_old = ozone->messagebox_state; ozone->messagebox_state_old = ozone->messagebox_state;
gfx_animation_kill_by_tag(&messagebox_tag); gfx_animation_kill_by_tag(&messagebox_tag);
ozone->animations.messagebox_alpha = 0.0f; ozone->animations.messagebox_alpha = 0.0f;
entry.cb = NULL; entry.cb = NULL;
entry.duration = ANIMATION_PUSH_ENTRY_DURATION; entry.duration = ANIMATION_PUSH_ENTRY_DURATION;
entry.easing_enum = EASING_OUT_QUAD; entry.easing_enum = EASING_OUT_QUAD;
entry.subject = &ozone->animations.messagebox_alpha; entry.subject = &ozone->animations.messagebox_alpha;
entry.tag = messagebox_tag; entry.tag = messagebox_tag;
entry.target_value = 1.0f; entry.target_value = 1.0f;
entry.userdata = NULL; entry.userdata = NULL;
gfx_animation_push(&entry); gfx_animation_push(&entry);
} }
/* Fade out animation */ /* Fade out animation */
else if (ozone->messagebox_state_old != ozone->messagebox_state && !ozone->messagebox_state) else if (ozone->messagebox_state_old != ozone->messagebox_state && !ozone->messagebox_state)
{ {
ozone->messagebox_state_old = ozone->messagebox_state; ozone->messagebox_state_old = ozone->messagebox_state;
ozone->messagebox_state = false; ozone->messagebox_state = false;
gfx_animation_kill_by_tag(&messagebox_tag); gfx_animation_kill_by_tag(&messagebox_tag);
ozone->animations.messagebox_alpha = 1.0f; ozone->animations.messagebox_alpha = 1.0f;
entry.cb = ozone_messagebox_fadeout_cb; entry.cb = ozone_messagebox_fadeout_cb;
entry.duration = ANIMATION_PUSH_ENTRY_DURATION; entry.duration = ANIMATION_PUSH_ENTRY_DURATION;
entry.easing_enum = EASING_OUT_QUAD; entry.easing_enum = EASING_OUT_QUAD;
entry.subject = &ozone->animations.messagebox_alpha; entry.subject = &ozone->animations.messagebox_alpha;
entry.tag = messagebox_tag; entry.tag = messagebox_tag;
entry.target_value = 0.0f; entry.target_value = 0.0f;
entry.userdata = ozone; entry.userdata = ozone;
gfx_animation_push(&entry); gfx_animation_push(&entry);
} }
@ -9888,7 +9884,7 @@ static void ozone_set_header(ozone_handle_t *ozone)
static void ozone_animation_end(void *userdata) static void ozone_animation_end(void *userdata)
{ {
ozone_handle_t *ozone = (ozone_handle_t*) userdata; ozone_handle_t *ozone = (ozone_handle_t*) userdata;
ozone->draw_old_list = false; ozone->draw_old_list = false;
ozone->animations.cursor_alpha = 1.0f; ozone->animations.cursor_alpha = 1.0f;
} }
@ -10007,11 +10003,9 @@ static void ozone_populate_entries(void *data,
bool goto_sidebar = false; bool goto_sidebar = false;
if (!list || (list->size < 1)) if (!list || (list->size < 1))
goto_sidebar = true; goto_sidebar = true;
else if ((list->list[0].type != FILE_TYPE_RPL_ENTRY))
if (!goto_sidebar && goto_sidebar = true;
(list->list[0].type != FILE_TYPE_RPL_ENTRY))
goto_sidebar = true;
if (goto_sidebar) if (goto_sidebar)
{ {
@ -10096,17 +10090,14 @@ static void ozone_toggle(void *userdata, bool menu_on)
return; return;
settings = config_get_ptr(); settings = config_get_ptr();
tmp = !menu_entries_ctl( if ((tmp = !menu_entries_ctl(MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL)))
MENU_ENTRIES_CTL_NEEDS_REFRESH, NULL);
if (tmp)
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
else else
menu_driver_ctl(RARCH_MENU_CTL_UNSET_PREVENT_POPULATE, NULL); menu_driver_ctl(RARCH_MENU_CTL_UNSET_PREVENT_POPULATE, NULL);
if (ozone->depth == 1) if (ozone->depth == 1)
{ {
ozone->draw_sidebar = true; ozone->draw_sidebar = true;
ozone->sidebar_offset = 0.0f; ozone->sidebar_offset = 0.0f;
} }
@ -10134,7 +10125,7 @@ static bool ozone_menu_init_list(void *data)
MENU_ENUM_LABEL_MAIN_MENU, MENU_ENUM_LABEL_MAIN_MENU,
info.type, info.flags, 0); info.type, info.flags, 0);
info.list = selection_buf; info.list = selection_buf;
if (!menu_displaylist_ctl(DISPLAYLIST_MAIN_MENU, &info, settings)) if (!menu_displaylist_ctl(DISPLAYLIST_MAIN_MENU, &info, settings))
goto error; goto error;
@ -10161,23 +10152,21 @@ static void ozone_list_insert(void *userdata,
unsigned type) unsigned type)
{ {
ozone_handle_t *ozone = (ozone_handle_t*) userdata; ozone_handle_t *ozone = (ozone_handle_t*) userdata;
ozone_node_t *node = NULL; ozone_node_t *node = NULL;
int i = (int)list_size; int i = (int)list_size;
if (!ozone || !list) if (!ozone || !list)
return; return;
ozone->need_compute = true; ozone->need_compute = true;
node = (ozone_node_t*)list->list[i].userdata; if (!(node = (ozone_node_t*)list->list[i].userdata))
if (!node)
node = ozone_alloc_node();
if (!node)
{ {
RARCH_ERR("ozone node could not be allocated.\n"); if (!(node = ozone_alloc_node()))
return; {
RARCH_ERR("ozone node could not be allocated.\n");
return;
}
} }
if (!string_is_empty(fullpath)) if (!string_is_empty(fullpath))
@ -10185,7 +10174,7 @@ static void ozone_list_insert(void *userdata,
if (node->fullpath) if (node->fullpath)
free(node->fullpath); free(node->fullpath);
node->fullpath = strdup(fullpath); node->fullpath = strdup(fullpath);
} }
list->list[i].userdata = node; list->list[i].userdata = node;
@ -10209,10 +10198,7 @@ static int ozone_environ_cb(enum menu_environ_cb type, void *data, void *userdat
case MENU_ENVIRON_RESET_HORIZONTAL_LIST: case MENU_ENVIRON_RESET_HORIZONTAL_LIST:
if (!ozone) if (!ozone)
return -1; return -1;
{ ozone_refresh_horizontal_list(ozone, config_get_ptr());
settings_t *settings = config_get_ptr();
ozone_refresh_horizontal_list(ozone, settings);
}
break; break;
case MENU_ENVIRON_ENABLE_SCREENSAVER: case MENU_ENVIRON_ENABLE_SCREENSAVER:
ozone->show_screensaver = true; ozone->show_screensaver = true;
@ -10237,7 +10223,7 @@ static void ozone_messagebox(void *data, const char *message)
if (ozone->pending_message) if (ozone->pending_message)
{ {
free(ozone->pending_message); free(ozone->pending_message);
ozone->pending_message = NULL; ozone->pending_message = NULL;
} }
ozone->pending_message = strdup(message); ozone->pending_message = strdup(message);

View File

@ -452,7 +452,7 @@ static float xmb_coord_white[] = {
1, 1, 1, 1 1, 1, 1, 1
}; };
static float item_color[] = { static float xmb_item_color[] = {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
@ -5310,7 +5310,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
/**************************/ /**************************/
/* Clock image */ /* Clock image */
gfx_display_set_alpha(item_color, MIN(xmb->alpha, 1.00f)); gfx_display_set_alpha(xmb_item_color, MIN(xmb->alpha, 1.00f));
if (battery_level_enable) if (battery_level_enable)
{ {
@ -5357,7 +5357,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
1, 1,
0, 0,
1, 1,
&item_color[0], &xmb_item_color[0],
xmb->shadow_offset, xmb->shadow_offset,
&mymat); &mymat);
if (dispctx && dispctx->blend_end) if (dispctx && dispctx->blend_end)
@ -5406,7 +5406,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
1, 1,
0, 0,
1, 1,
&item_color[0], &xmb_item_color[0],
xmb->shadow_offset, xmb->shadow_offset,
&mymat); &mymat);
if (dispctx && dispctx->blend_end) if (dispctx && dispctx->blend_end)
@ -5429,7 +5429,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
} }
/* Arrow image */ /* Arrow image */
gfx_display_set_alpha(item_color, gfx_display_set_alpha(xmb_item_color,
MIN(xmb->textures_arrow_alpha, xmb->alpha)); MIN(xmb->textures_arrow_alpha, xmb->alpha));
if (!xmb->assets_missing) if (!xmb->assets_missing)
@ -5456,7 +5456,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
xmb->textures_arrow_alpha, xmb->textures_arrow_alpha,
0, 0,
1, 1,
&item_color[0], &xmb_item_color[0],
xmb->shadow_offset, xmb->shadow_offset,
&mymat); &mymat);
if (dispctx && dispctx->blend_end) if (dispctx && dispctx->blend_end)
@ -5478,9 +5478,9 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
if (!node) if (!node)
continue; continue;
gfx_display_set_alpha(item_color, MIN(node->alpha, xmb->alpha)); gfx_display_set_alpha(xmb_item_color, MIN(node->alpha, xmb->alpha));
if (item_color[3] != 0) if (xmb_item_color[3] != 0)
{ {
gfx_display_ctx_rotate_draw_t rotate_draw; gfx_display_ctx_rotate_draw_t rotate_draw;
math_matrix_4x4 mymat_tmp; math_matrix_4x4 mymat_tmp;
@ -5501,7 +5501,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
if (x > x_threshold) if (x > x_threshold)
{ {
float fade_alpha = item_color[3]; float fade_alpha = xmb_item_color[3];
float fade_offset = (x - x_threshold) * 2.0f; float fade_offset = (x - x_threshold) * 2.0f;
fade_offset = (fade_offset > xmb->icon_size) ? xmb->icon_size : fade_offset; fade_offset = (fade_offset > xmb->icon_size) ? xmb->icon_size : fade_offset;
@ -5510,7 +5510,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
if (fade_alpha <= 0.0f) if (fade_alpha <= 0.0f)
continue; continue;
gfx_display_set_alpha(item_color, fade_alpha); gfx_display_set_alpha(xmb_item_color, fade_alpha);
} }
} }
@ -5539,7 +5539,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
1.0, 1.0,
0, /* rotation */ 0, /* rotation */
scale_factor, scale_factor,
&item_color[0], &xmb_item_color[0],
xmb->shadow_offset, xmb->shadow_offset,
&mymat_tmp); &mymat_tmp);
} }
@ -5562,7 +5562,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
(xmb_list_get_size(xmb, MENU_LIST_PLAIN) > 1) (xmb_list_get_size(xmb, MENU_LIST_PLAIN) > 1)
? xmb->categories_selection_ptr : ? xmb->categories_selection_ptr :
xmb->categories_selection_ptr_old, xmb->categories_selection_ptr_old,
&item_color[0], &xmb_item_color[0],
video_width, video_width,
video_height, video_height,
&mymat); &mymat);
@ -5581,7 +5581,7 @@ static void xmb_frame(void *data, video_frame_info_t *video_info)
selection_buf, selection_buf,
selection, selection,
xmb->categories_selection_ptr, xmb->categories_selection_ptr,
&item_color[0], &xmb_item_color[0],
video_width, video_width,
video_height, video_height,
&mymat); &mymat);
@ -6498,7 +6498,7 @@ static void xmb_context_reset_textures(
(settings->uints.menu_xmb_theme == XMB_ICON_THEME_MONOCHROME_INVERTED) || (settings->uints.menu_xmb_theme == XMB_ICON_THEME_MONOCHROME_INVERTED) ||
(settings->uints.menu_xmb_theme == XMB_ICON_THEME_AUTOMATIC_INVERTED) (settings->uints.menu_xmb_theme == XMB_ICON_THEME_AUTOMATIC_INVERTED)
) )
memcpy(item_color, xmb_coord_black, sizeof(item_color)); memcpy(xmb_item_color, xmb_coord_black, sizeof(xmb_item_color));
else else
{ {
if ( if (
@ -6510,14 +6510,14 @@ static void xmb_context_reset_textures(
{ {
if ((i==3) || (i==7) || (i==11) || (i==15)) if ((i==3) || (i==7) || (i==11) || (i==15))
{ {
item_color[i] = 1; xmb_item_color[i] = 1;
continue; continue;
} }
item_color[i] = 0.95; xmb_item_color[i] = 0.95;
} }
} }
else else
memcpy(item_color, xmb_coord_white, sizeof(item_color)); memcpy(xmb_item_color, xmb_coord_white, sizeof(xmb_item_color));
} }
return; return;
@ -6708,15 +6708,13 @@ static void xmb_list_insert(void *userdata,
if (!xmb || !list) if (!xmb || !list)
return; return;
node = (xmb_node_t*)list->list[i].userdata; if (!(node = (xmb_node_t*)list->list[i].userdata))
if (!node)
node = xmb_alloc_node();
if (!node)
{ {
RARCH_ERR("XMB node could not be allocated.\n"); if (!(node = xmb_alloc_node()))
return; {
RARCH_ERR("XMB node could not be allocated.\n");
return;
}
} }
current = (int)selection; current = (int)selection;