From 9d510ed8cea51964918712cb202e403718310d3d Mon Sep 17 00:00:00 2001 From: Hominem te esse Date: Wed, 9 Mar 2011 23:39:07 +0100 Subject: [PATCH] extracted code branching from ItemsList drawing and main drawing method --- include/menusys.h | 2 ++ src/gui.c | 20 +++++++++----- src/menusys.c | 80 +++++++++++++++++-------------------------------------- src/opl.c | 4 +++ src/themes.c | 21 +-------------- 5 files changed, 45 insertions(+), 82 deletions(-) diff --git a/include/menusys.h b/include/menusys.h index 54cb812..c19fc16 100644 --- a/include/menusys.h +++ b/include/menusys.h @@ -51,6 +51,8 @@ typedef struct menu_item { /// submenu, selection and page start (only used in static mode) struct submenu_list *submenu, *current, *pagestart; + short remindLast; + void (*refresh)(struct menu_item *curMenu); void (*execCross)(struct menu_item *curMenu); diff --git a/src/gui.c b/src/gui.c index 93ce49f..18050a0 100644 --- a/src/gui.c +++ b/src/gui.c @@ -724,13 +724,15 @@ static void guiHandleOp(struct gui_update_t* item) { result = submenuAppendItem(item->menu.subMenu, item->submenu.icon_id, item->submenu.text, item->submenu.id, item->submenu.text_id); - if (!item->menu.menu->submenu) { - item->menu.menu->submenu = *item->menu.subMenu; - item->menu.menu->current = *item->menu.subMenu; - } - - if (item->submenu.selected) + if (!item->menu.menu->submenu) { // first subitem in list + item->menu.menu->submenu = result; item->menu.menu->current = result; + item->menu.menu->pagestart = result; + } else if (item->submenu.selected) { // remember last game feat. + item->menu.menu->current = result; + item->menu.menu->pagestart = result; + item->menu.menu->remindLast = 1; + } break; @@ -748,8 +750,12 @@ static void guiHandleOp(struct gui_update_t* item) { case GUI_OP_SORT: submenuSort(item->menu.subMenu); - item->menu.menu->pagestart = NULL; item->menu.menu->submenu = *item->menu.subMenu; + + if (!item->menu.menu->remindLast) + item->menu.menu->current = item->menu.menu->submenu; + + item->menu.menu->pagestart = item->menu.menu->current; break; case GUI_OP_ADD_HINT: diff --git a/src/menusys.c b/src/menusys.c index 07e59c6..d4c9178 100644 --- a/src/menusys.c +++ b/src/menusys.c @@ -165,6 +165,7 @@ void menuAppendItem(menu_item_t* item) { if (menu == NULL) { menu = AllocMenuItem(item); + selected_item = menu; return; } @@ -381,67 +382,50 @@ void submenuSort(submenu_list_t** submenu) { } static void menuNextH() { - if (!selected_item) { - selected_item = menu; - } - - if(selected_item->next) { + if(selected_item->next) selected_item = selected_item->next; - - if (!selected_item->item->current) - selected_item->item->current = selected_item->item->submenu; - } } static void menuPrevH() { - if (!selected_item) { - selected_item = menu; - } - - if(selected_item->prev) { + if(selected_item->prev) selected_item = selected_item->prev; - - if (!selected_item->item->current) - selected_item->item->current = selected_item->item->submenu; - } } static void menuNextV() { - if (!selected_item) - return; - submenu_list_t *cur = selected_item->item->current; - if(cur && cur->next) + if(cur && cur->next) { selected_item->item->current = cur->next; + + // if the current item is beyond the page start, move the page start one page down + cur = selected_item->item->pagestart; + int itms = ((items_list_t*) gTheme->itemsList->extended)->displayedItems + 1; + while (--itms && cur) + if (selected_item->item->current == cur) + return; + else + cur = cur->next; + + selected_item->item->pagestart = selected_item->item->current; + } } static void menuPrevV() { - if (!selected_item) - return; - submenu_list_t *cur = selected_item->item->current; - // if the current item is on the page start, move the page start one page up before moving the item - if (selected_item->item->pagestart) { + if(cur && cur->prev) { + selected_item->item->current = cur->prev; + + // if the current item is on the page start, move the page start one page up if (selected_item->item->pagestart == cur) { int itms = ((items_list_t*) gTheme->itemsList->extended)->displayedItems + 1; // +1 because the selection will move as well - while (--itms && selected_item->item->pagestart->prev) selected_item->item->pagestart = selected_item->item->pagestart->prev; } - } else - selected_item->item->pagestart = cur; - - if(cur && cur->prev) { - selected_item->item->current = cur->prev; } } static void menuNextPage() { - if (!selected_item) - return; - submenu_list_t *cur = selected_item->item->pagestart; if (cur) { @@ -450,13 +434,11 @@ static void menuNextPage() { cur = cur->next; selected_item->item->current = cur; + selected_item->item->pagestart = selected_item->item->current; } } static void menuPrevPage() { - if (!selected_item) - return; - submenu_list_t *cur = selected_item->item->pagestart; if (cur) { @@ -465,21 +447,16 @@ static void menuPrevPage() { cur = cur->prev; selected_item->item->current = cur; - selected_item->item->pagestart = cur; + selected_item->item->pagestart = selected_item->item->current; } } static void menuFirstPage() { - if (!selected_item) - return; - selected_item->item->current = selected_item->item->submenu; + selected_item->item->pagestart = selected_item->item->current; } static void menuLastPage() { - if (!selected_item) - return; - submenu_list_t *cur = selected_item->item->current; if (cur) { while (cur->next) @@ -593,12 +570,7 @@ void menuHandleInputMenu() { } void menuRenderMain() { - if (!menu) - return; - - if (!selected_item) - selected_item = menu; - + // selected_item can't be NULL here as we only allow to switch to "Main" rendering when there is at least one device activated theme_element_t* elem = gTheme->mainElems.first; while (elem) { if (elem->drawElem) @@ -609,9 +581,6 @@ void menuRenderMain() { } void menuHandleInputMain() { - if (!selected_item) - return; - if(getKey(KEY_LEFT)) { menuPrevH(); } else if(getKey(KEY_RIGHT)) { @@ -649,6 +618,7 @@ void menuHandleInputMain() { } void menuRenderInfo() { + // selected_item->item->current can't be NULL here as we only allow to switch to "Info" rendering when there is at least one item menuRequestConfig(); theme_element_t* elem = gTheme->infoElems.first; diff --git a/src/opl.c b/src/opl.c index 1a57958..5b4e04d 100644 --- a/src/opl.c +++ b/src/opl.c @@ -70,6 +70,7 @@ static void clearIOModuleT(opl_io_module_t *mod) { mod->menuItem.current = NULL; mod->menuItem.submenu = NULL; mod->menuItem.pagestart = NULL; + mod->menuItem.remindLast = 0; mod->menuItem.refresh = NULL; mod->menuItem.text = NULL; mod->menuItem.text_id = -1; @@ -225,6 +226,7 @@ static void initMenuForListSupport(int mode) { item->menuItem.submenu = NULL; item->menuItem.current = NULL; item->menuItem.pagestart = NULL; + item->menuItem.remindLast = 0; item->menuItem.refresh = &itemExecRefresh; item->menuItem.execCross = &itemExecCross; @@ -233,6 +235,7 @@ static void initMenuForListSupport(int mode) { item->menuItem.execCircle = &itemExecCircle; item->menuItem.hints = NULL; + moduleUpdateMenu(mode, 0); struct gui_update_t *mc = guiOpCreate(GUI_OP_ADD_MENU); @@ -296,6 +299,7 @@ static void updateMenuFromGameList(opl_io_module_t* mdl) { mdl->menuItem.submenu = NULL; mdl->menuItem.current = NULL; mdl->menuItem.pagestart = NULL; + mdl->menuItem.remindLast = 0; // unlock, the rest is deferred guiUnlock(); diff --git a/src/themes.c b/src/themes.c index e2eee82..43864c7 100644 --- a/src/themes.c +++ b/src/themes.c @@ -654,26 +654,7 @@ static void drawItemsList(struct menu_list* menu, struct submenu_list* item, con posY -= elem->height >> 1; } - int icnt = itemsList->displayedItems; - int found = 0; submenu_list_t *ps = menu->item->pagestart; - - // verify the item is in visible range - while (icnt-- && ps) { - if (ps == item) { - found = 1; - break; - } - ps = ps->next; - } - - // page not properly aligned? - if (!found) - menu->item->pagestart = item; - - // reset to page start after cur. item visibility determination - ps = menu->item->pagestart; - int others = 0; u64 color; while (ps && (others++ < itemsList->displayedItems)) { @@ -690,7 +671,7 @@ static void drawItemsList(struct menu_list* menu, struct submenu_list* item, con if (itemsList->decoratorImage->defaultTexture) rmDrawPixmap(&itemsList->decoratorImage->defaultTexture->source, posX, posY, ALIGN_NONE, DECORATOR_SIZE, DECORATOR_SIZE, elem->scaled, gDefaultCol); } - fntRenderText(elem->font, posX + DECORATOR_SIZE, ALIGN_NONE, posY, elem->width, elem->height, submenuItemGetText(&ps->item), color); + fntRenderText(elem->font, posX + DECORATOR_SIZE, posY, ALIGN_NONE, elem->width, elem->height, submenuItemGetText(&ps->item), color); } else fntRenderText(elem->font, posX, posY, ALIGN_NONE, elem->width, elem->height, submenuItemGetText(&ps->item), color); -- 2.11.4.GIT