From 2e81d7f8dcddd38a0f47abf0988ae6b3d6c32766 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 7 Jun 2015 11:20:36 +0200 Subject: [PATCH] Refactor xmb_list_cache function callback --- menu/drivers/xmb.c | 68 ++++++++++++++++++----------------- menu/menu_displaylist.c | 2 +- menu/menu_driver.c | 4 +-- menu/menu_driver.h | 4 +-- menu/menu_entries_cbs_left.c | 2 +- menu/menu_entries_cbs_right.c | 2 +- menu/menu_list.c | 2 +- menu/menu_list.h | 6 ++++ 8 files changed, 50 insertions(+), 40 deletions(-) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index bb5e5ba392..bb65d1fc92 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1870,7 +1870,7 @@ static void xmb_list_delete(file_list_t *list, list->list[idx].userdata = NULL; } -static void xmb_list_cache(bool horizontal, unsigned action) +static void xmb_list_cache(menu_list_type_t type, unsigned action) { size_t stack_size; xmb_handle_t *xmb = NULL; @@ -1888,41 +1888,45 @@ static void xmb_list_cache(bool horizontal, unsigned action) file_list_copy(menu->menu_list->menu_stack, xmb->menu_stack_old); xmb->selection_ptr_old = menu->navigation.selection_ptr; - if(!horizontal) - return; - - xmb->categories.selection_ptr_old = menu->categories.selection_ptr; - - switch (action) + switch (type) { - case MENU_ACTION_LEFT: - menu->categories.selection_ptr--; + case MENU_LIST_PLAIN: break; - default: - menu->categories.selection_ptr++; + case MENU_LIST_HORIZONTAL: + xmb->categories.selection_ptr_old = menu->categories.selection_ptr; + + switch (action) + { + case MENU_ACTION_LEFT: + menu->categories.selection_ptr--; + break; + default: + menu->categories.selection_ptr++; + break; + } + + stack_size = menu->menu_list->menu_stack->size; + + if (menu->menu_list->menu_stack->list[stack_size - 1].label) + free(menu->menu_list->menu_stack->list[stack_size - 1].label); + menu->menu_list->menu_stack->list[stack_size - 1].label = NULL; + + if (menu->categories.selection_ptr == 0) + { + menu->menu_list->menu_stack->list[stack_size - 1].label = + strdup("Main Menu"); + menu->menu_list->menu_stack->list[stack_size - 1].type = + MENU_SETTINGS; + } + else + { + menu->menu_list->menu_stack->list[stack_size - 1].label = + strdup("Horizontal Menu"); + menu->menu_list->menu_stack->list[stack_size - 1].type = + MENU_SETTING_HORIZONTAL_MENU; + } break; } - - stack_size = menu->menu_list->menu_stack->size; - - if (menu->menu_list->menu_stack->list[stack_size - 1].label) - free(menu->menu_list->menu_stack->list[stack_size - 1].label); - menu->menu_list->menu_stack->list[stack_size - 1].label = NULL; - - if (menu->categories.selection_ptr == 0) - { - menu->menu_list->menu_stack->list[stack_size - 1].label = - strdup("Main Menu"); - menu->menu_list->menu_stack->list[stack_size - 1].type = - MENU_SETTINGS; - } - else - { - menu->menu_list->menu_stack->list[stack_size - 1].label = - strdup("Horizontal Menu"); - menu->menu_list->menu_stack->list[stack_size - 1].type = - MENU_SETTING_HORIZONTAL_MENU; - } } static void xmb_context_destroy(void) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index fe39bd0378..78c4cb55bc 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1717,7 +1717,7 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) menu_list_push(info->list, info->path, info->label, info->type, info->directory_ptr); break; case DISPLAYLIST_GENERIC: - menu_driver_list_cache(false, 0); + menu_driver_list_cache(MENU_LIST_PLAIN, 0); menu_list_push(info->list, info->path, info->label, info->type, info->directory_ptr); menu_navigation_clear(&menu->navigation, true); diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 0127446860..f1024a9558 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -251,12 +251,12 @@ void menu_driver_list_insert(file_list_t *list, const char *path, menu_entries_cbs_init(list, path, label, type, idx); } -void menu_driver_list_cache(bool state, unsigned action) +void menu_driver_list_cache(menu_list_type_t type, unsigned action) { const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr(); if (driver->list_cache) - driver->list_cache(state, action); + driver->list_cache(type, action); } void menu_driver_navigation_increment(void) diff --git a/menu/menu_driver.h b/menu/menu_driver.h index b970523047..4e8434ea5d 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -254,7 +254,7 @@ typedef struct menu_ctx_driver void (*list_insert)(file_list_t *list, const char *, const char *, size_t); void (*list_delete)(file_list_t *list, size_t, size_t); void (*list_clear)(file_list_t *list); - void (*list_cache)(bool, unsigned); + void (*list_cache)(menu_list_type_t, unsigned); void (*list_set_selection)(file_list_t *list); bool (*load_image)(void *data, menu_image_type_t type); const char *ident; @@ -336,7 +336,7 @@ void menu_driver_navigation_descend_alphabet(size_t *); void menu_driver_navigation_ascend_alphabet(size_t *); -void menu_driver_list_cache(bool state, unsigned action); +void menu_driver_list_cache(menu_list_type_t type, unsigned action); void menu_driver_list_delete(file_list_t *list, size_t i, size_t list_size); diff --git a/menu/menu_entries_cbs_left.c b/menu/menu_entries_cbs_left.c index 6549684817..067cf7f3b2 100644 --- a/menu/menu_entries_cbs_left.c +++ b/menu/menu_entries_cbs_left.c @@ -162,7 +162,7 @@ static int action_left_mainmenu(unsigned type, const char *label, switch (push_list) { case 1: - menu_driver_list_cache(true, action); + menu_driver_list_cache(MENU_LIST_HORIZONTAL, action); if (cbs && cbs->action_content_list_switch) return cbs->action_content_list_switch( diff --git a/menu/menu_entries_cbs_right.c b/menu/menu_entries_cbs_right.c index 8a1e1861d0..527d3dcfd1 100644 --- a/menu/menu_entries_cbs_right.c +++ b/menu/menu_entries_cbs_right.c @@ -168,7 +168,7 @@ static int action_right_mainmenu(unsigned type, const char *label, switch (push_list) { case 1: - menu_driver_list_cache(true, action); + menu_driver_list_cache(MENU_LIST_HORIZONTAL, action); if (cbs && cbs->action_content_list_switch) return cbs->action_content_list_switch( diff --git a/menu/menu_list.c b/menu/menu_list.c index f16a951444..7c1e7409ad 100644 --- a/menu/menu_list.c +++ b/menu/menu_list.c @@ -278,7 +278,7 @@ void menu_list_pop_stack(menu_list_t *list) if (file_list_get_size(list->menu_stack) <= 1) return; - menu_driver_list_cache(false, 0); + menu_driver_list_cache(MENU_LIST_PLAIN, 0); menu_list_pop(list->menu_stack, &menu->navigation.selection_ptr); menu_set_refresh(); diff --git a/menu/menu_list.h b/menu/menu_list.h index a6b1100cc3..304a38cfb4 100644 --- a/menu/menu_list.h +++ b/menu/menu_list.h @@ -32,6 +32,12 @@ typedef struct menu_list file_list_t *selection_buf; } menu_list_t; +typedef enum +{ + MENU_LIST_PLAIN = 0, + MENU_LIST_HORIZONTAL, +} menu_list_type_t; + typedef struct menu_file_list_cbs { int (*action_iterate)(const char *label, unsigned action);