(XMB) Cleanups

This commit is contained in:
twinaphex 2015-02-01 15:25:37 +01:00
parent 6bfbe1dc6d
commit d84b6ee5ea
2 changed files with 77 additions and 59 deletions

View File

@ -89,15 +89,17 @@ static void rmenu_render_background(void)
static void rmenu_render_messagebox(const char *message) static void rmenu_render_messagebox(const char *message)
{ {
struct font_params font_parms; struct font_params font_parms;
size_t i, j; size_t i, j;
struct string_list *list = NULL;
if (!message || !*message) if (!message || !*message)
return; return;
struct string_list *list = string_split(message, "\n"); list = string_split(message, "\n");
if (!list) if (!list)
return; return;
if (list->elems == 0) if (list->elems == 0)
{ {
string_list_free(list); string_list_free(list);
@ -105,10 +107,12 @@ static void rmenu_render_messagebox(const char *message)
} }
j = 0; j = 0;
for (i = 0; i < list->size; i++, j++) for (i = 0; i < list->size; i++, j++)
{ {
char *msg = list->elems[i].data; char *msg = list->elems[i].data;
unsigned msglen = strlen(msg); unsigned msglen = strlen(msg);
if (msglen > RMENU_TERM_WIDTH) if (msglen > RMENU_TERM_WIDTH)
{ {
msg[RMENU_TERM_WIDTH - 2] = '.'; msg[RMENU_TERM_WIDTH - 2] = '.';
@ -164,7 +168,7 @@ static void rmenu_render(void)
begin = (menu->selection_ptr >= (ENTRIES_HEIGHT / 2)) ? begin = (menu->selection_ptr >= (ENTRIES_HEIGHT / 2)) ?
(menu->selection_ptr - (ENTRIES_HEIGHT / 2)) : 0; (menu->selection_ptr - (ENTRIES_HEIGHT / 2)) : 0;
end = ((menu->selection_ptr + ENTRIES_HEIGHT) <= end = ((menu->selection_ptr + ENTRIES_HEIGHT) <=
menu_list_get_size(driver.menu->menu_list)) ? menu_list_get_size(driver.menu->menu_list)) ?
menu->selection_ptr + ENTRIES_HEIGHT : menu->selection_ptr + ENTRIES_HEIGHT :
menu_list_get_size(driver.menu->menu_list); menu_list_get_size(driver.menu->menu_list);

View File

@ -165,10 +165,10 @@ static char *xmb_str_replace (const char *string,
/* if either substr or replacement is NULL, /* if either substr or replacement is NULL,
* duplicate string a let caller handle it. */ * duplicate string a let caller handle it. */
if (!substr || !replacement) if (!substr || !replacement)
return strdup (string); return strdup(string);
newstr = strdup (string); newstr = strdup(string);
head = newstr; head = newstr;
while ( (tok = strstr ( head, substr ))) while ( (tok = strstr ( head, substr )))
{ {
@ -178,10 +178,12 @@ static char *xmb_str_replace (const char *string,
if (!newstr) if (!newstr)
{ {
/*failed to alloc mem, free old string and return NULL */ /* Failed to allocate memory,
* free old string and return NULL. */
free (oldstr); free (oldstr);
return NULL; return NULL;
} }
memcpy(newstr, oldstr, tok - oldstr ); memcpy(newstr, oldstr, tok - oldstr );
memcpy(newstr + (tok - oldstr), replacement, strlen ( replacement ) ); memcpy(newstr + (tok - oldstr), replacement, strlen ( replacement ) );
memcpy(newstr + (tok - oldstr) + strlen( replacement ), tok + memcpy(newstr + (tok - oldstr) + strlen( replacement ), tok +
@ -189,7 +191,8 @@ static char *xmb_str_replace (const char *string,
strlen ( substr ) - ( tok - oldstr ) ); strlen ( substr ) - ( tok - oldstr ) );
memset(newstr + strlen ( oldstr ) - strlen ( substr ) + memset(newstr + strlen ( oldstr ) - strlen ( substr ) +
strlen ( replacement ) , 0, 1 ); strlen ( replacement ) , 0, 1 );
/* move back head right after the last replacement */
/* Move back head right after the last replacement. */
head = newstr + (tok - oldstr) + strlen( replacement ); head = newstr + (tok - oldstr) + strlen( replacement );
free (oldstr); free (oldstr);
} }
@ -219,8 +222,11 @@ static void xmb_draw_icon(GLuint texture, float x, float y,
if (!gl) if (!gl)
return; return;
if (x < -xmb->icon_size/2 || x > gl->win_width if (
|| y < xmb->icon_size/2 || y > gl->win_height + xmb->icon_size) x < -xmb->icon_size/2 ||
x > gl->win_width ||
y < xmb->icon_size/2 ||
y > gl->win_height + xmb->icon_size)
return; return;
GLfloat color[] = { GLfloat color[] = {
@ -270,7 +276,9 @@ static void xmb_draw_text(const char *str, float x,
if (alpha > xmb->alpha) if (alpha > xmb->alpha)
alpha = xmb->alpha; alpha = xmb->alpha;
a8 = 255 * alpha; a8 = 255 * alpha;
if (a8 == 0) if (a8 == 0)
return; return;
@ -616,9 +624,9 @@ static GLuint xmb_png_texture_load(const char* file_name)
static xmb_node_t* xmb_node_for_core(int i) static xmb_node_t* xmb_node_for_core(int i)
{ {
core_info_t *info = NULL; core_info_t *info = NULL;
core_info_list_t *info_list = NULL; core_info_list_t *info_list = NULL;
xmb_node_t *node = NULL; xmb_node_t *node = NULL;
xmb_handle_t *xmb = (xmb_handle_t*)driver.menu->userdata; xmb_handle_t *xmb = (xmb_handle_t*)driver.menu->userdata;
@ -676,7 +684,8 @@ static void xmb_list_switch_old(file_list_t *list, int dir, size_t current)
for (i = 0; i < file_list_get_size(list); i++) for (i = 0; i < file_list_get_size(list); i++)
{ {
xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(list, i); xmb_node_t *node = (xmb_node_t*)
file_list_get_userdata_at_offset(list, i);
if (!xmb) if (!xmb)
continue; continue;
@ -698,7 +707,8 @@ static void xmb_list_switch_new(file_list_t *list, int dir, size_t current)
for (i = 0; i < file_list_get_size(list); i++) for (i = 0; i < file_list_get_size(list); i++)
{ {
float ia = 0.5; float ia = 0.5;
xmb_node_t *node = (xmb_node_t*)file_list_get_userdata_at_offset(list, i); xmb_node_t *node = (xmb_node_t*)
file_list_get_userdata_at_offset(list, i);
if (!xmb) if (!xmb)
continue; continue;
@ -709,6 +719,7 @@ static void xmb_list_switch_new(file_list_t *list, int dir, size_t current)
if (i == current) if (i == current)
ia = 1.0; ia = 1.0;
add_tween(XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL); add_tween(XMB_DELAY, ia, &node->alpha, &inOutQuad, NULL);
add_tween(XMB_DELAY, ia, &node->label_alpha, &inOutQuad, NULL); add_tween(XMB_DELAY, ia, &node->label_alpha, &inOutQuad, NULL);
add_tween(XMB_DELAY, 0, &node->x, &inOutQuad, NULL); add_tween(XMB_DELAY, 0, &node->x, &inOutQuad, NULL);
@ -741,10 +752,8 @@ static void xmb_set_title(void)
info = (core_info_t*)&info_list->list[driver.menu->cat_selection_ptr - 1]; info = (core_info_t*)&info_list->list[driver.menu->cat_selection_ptr - 1];
if (!info) if (info)
return; strlcpy(xmb->title, info->display_name, sizeof(xmb->title));
strlcpy(xmb->title, info->display_name, sizeof(xmb->title));
} }
} }
@ -815,14 +824,17 @@ static void xmb_list_switch()
xmb_list_open_old(xmb->selection_buf_old, dir, xmb->selection_ptr_old); xmb_list_open_old(xmb->selection_buf_old, dir, xmb->selection_ptr_old);
xmb_list_open_new(driver.menu->menu_list->selection_buf, dir, driver.menu->selection_ptr); xmb_list_open_new(driver.menu->menu_list->selection_buf, dir, driver.menu->selection_ptr);
if (xmb->depth == 1 || xmb->depth == 2) switch (xmb->depth)
add_tween(XMB_DELAY, xmb->icon_size*-(xmb->depth*2-2), &xmb->x, &inOutQuad, NULL); {
case 1:
if (xmb->depth == 1) add_tween(XMB_DELAY, xmb->icon_size*-(xmb->depth*2-2), &xmb->x, &inOutQuad, NULL);
add_tween(XMB_DELAY, 0, &xmb->arrow_alpha, &inOutQuad, NULL); add_tween(XMB_DELAY, 0, &xmb->arrow_alpha, &inOutQuad, NULL);
break;
if (xmb->depth == 2) case 2:
add_tween(XMB_DELAY, 1, &xmb->arrow_alpha, &inOutQuad, NULL); add_tween(XMB_DELAY, xmb->icon_size*-(xmb->depth*2-2), &xmb->x, &inOutQuad, NULL);
add_tween(XMB_DELAY, 1, &xmb->arrow_alpha, &inOutQuad, NULL);
break;
}
xmb->old_depth = xmb->depth; xmb->old_depth = xmb->depth;
} }
@ -878,6 +890,7 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack,
unsigned type = 0, w = 0; unsigned type = 0, w = 0;
xmb_node_t *node = NULL; xmb_node_t *node = NULL;
menu_file_list_cbs_t *cbs = NULL; menu_file_list_cbs_t *cbs = NULL;
GLuint icon = 0;
menu_list_get_at_offset(list, i, &path, &entry_label, &type); menu_list_get_at_offset(list, i, &path, &entry_label, &type);
node = (xmb_node_t*)file_list_get_userdata_at_offset(list, i); node = (xmb_node_t*)file_list_get_userdata_at_offset(list, i);
@ -896,7 +909,6 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack,
if (type == MENU_FILE_CONTENTLIST_ENTRY) if (type == MENU_FILE_CONTENTLIST_ENTRY)
strlcpy(path_buf, path_basename(path_buf), sizeof(path_buf)); strlcpy(path_buf, path_basename(path_buf), sizeof(path_buf));
GLuint icon = 0;
switch(type) switch(type)
{ {
case MENU_FILE_DIRECTORY: case MENU_FILE_DIRECTORY:
@ -909,7 +921,9 @@ static void xmb_draw_items(file_list_t *list, file_list_t *stack,
icon = xmb->textures[XMB_TEXTURE_FILE].id; icon = xmb->textures[XMB_TEXTURE_FILE].id;
break; break;
case MENU_FILE_CONTENTLIST_ENTRY: case MENU_FILE_CONTENTLIST_ENTRY:
icon = core_node ? core_node->content_icon : xmb->textures[XMB_TEXTURE_FILE].id; icon = xmb->textures[XMB_TEXTURE_FILE].id;
if (core_node)
icon = core_node->content_icon;
break; break;
case MENU_FILE_CARCHIVE: case MENU_FILE_CARCHIVE:
icon = xmb->textures[XMB_TEXTURE_ZIP].id; icon = xmb->textures[XMB_TEXTURE_ZIP].id;
@ -1172,26 +1186,26 @@ static void *xmb_init(void)
xmb->menu_stack_old = (file_list_t*)calloc(1, sizeof(file_list_t)); xmb->menu_stack_old = (file_list_t*)calloc(1, sizeof(file_list_t));
xmb->selection_buf_old = (file_list_t*)calloc(1, sizeof(file_list_t)); xmb->selection_buf_old = (file_list_t*)calloc(1, sizeof(file_list_t));
xmb->active_category = 0; xmb->active_category = 0;
xmb->active_category_old = 0; xmb->active_category_old = 0;
xmb->x = 0; xmb->x = 0;
xmb->categories_x = 0; xmb->categories_x = 0;
xmb->alpha = 1.0f; xmb->alpha = 1.0f;
xmb->arrow_alpha = 0; xmb->arrow_alpha = 0;
xmb->depth = 1; xmb->depth = 1;
xmb->old_depth = 1; xmb->old_depth = 1;
xmb->alpha = 0; xmb->alpha = 0;
xmb->prevent_populate = false; xmb->prevent_populate = false;
xmb->c_active_zoom = 1.0; xmb->c_active_zoom = 1.0;
xmb->c_passive_zoom = 0.5; xmb->c_passive_zoom = 0.5;
xmb->i_active_zoom = 1.0; xmb->i_active_zoom = 1.0;
xmb->i_passive_zoom = 0.5; xmb->i_passive_zoom = 0.5;
xmb->c_active_alpha = 1.0; xmb->c_active_alpha = 1.0;
xmb->c_passive_alpha = 0.5; xmb->c_passive_alpha = 0.5;
xmb->i_active_alpha = 1.0; xmb->i_active_alpha = 1.0;
xmb->i_passive_alpha = 0.5; xmb->i_passive_alpha = 0.5;
xmb->above_subitem_offset = 1.5; xmb->above_subitem_offset = 1.5;
xmb->above_item_offset = -1.0; xmb->above_item_offset = -1.0;
@ -1213,18 +1227,18 @@ static void *xmb_init(void)
strlcpy(xmb->icon_dir, "256", sizeof(xmb->icon_dir)); strlcpy(xmb->icon_dir, "256", sizeof(xmb->icon_dir));
xmb->icon_size = 128.0 * scale_factor; xmb->icon_size = 128.0 * scale_factor;
xmb->font_size = 32.0 * scale_factor; xmb->font_size = 32.0 * scale_factor;
xmb->hspacing = 200.0 * scale_factor; xmb->hspacing = 200.0 * scale_factor;
xmb->vspacing = 64.0 * scale_factor; xmb->vspacing = 64.0 * scale_factor;
xmb->margin_left = 336.0 * scale_factor; xmb->margin_left = 336.0 * scale_factor;
xmb->margin_top = (256+32) * scale_factor; xmb->margin_top = (256+32) * scale_factor;
xmb->title_margin_left = 60 * scale_factor; xmb->title_margin_left = 60 * scale_factor;
xmb->title_margin_top = 60 * scale_factor + xmb->font_size/3; xmb->title_margin_top = 60 * scale_factor + xmb->font_size/3;
xmb->title_margin_bottom = 60 * scale_factor - xmb->font_size/3; xmb->title_margin_bottom = 60 * scale_factor - xmb->font_size/3;
xmb->label_margin_left = 85.0 * scale_factor; xmb->label_margin_left = 85.0 * scale_factor;
xmb->label_margin_top = xmb->font_size/3.0; xmb->label_margin_top = xmb->font_size/3.0;
xmb->setting_margin_left = 600.0 * scale_factor; xmb->setting_margin_left = 600.0 * scale_factor;
xmb_init_core_info(menu); xmb_init_core_info(menu);