Commits

hominem_te_esse  committed 915b384

extracted code branching from ItemsList drawing and main drawing method

  • Participants
  • Parent commits 928dc9c

Comments (0)

Files changed (5)

File include/menusys.h

 	/// 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);
 			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->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;
 			}
 
-			if (item->submenu.selected)
-				item->menu.menu->current = result;
-
 			break;
 
 		case GUI_OP_SELECT_MENU:
 
 		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:

File src/menusys.c

 	
 	if (menu == NULL) {
 		menu = AllocMenuItem(item);
+		selected_item = menu;
 		return;
 	}
 	
 }
 
 static void menuNextH() {
-	if (!selected_item) {
-		selected_item = menu;
-	}
+	if(selected_item->next)
+		selected_item = selected_item->next;
+}
+
+static void menuPrevH() {
+	if(selected_item->prev)
+		selected_item = selected_item->prev;
+}
+
+static void menuNextV() {
+	submenu_list_t *cur = selected_item->item->current;
 	
-	if(selected_item->next) {
-		selected_item = selected_item->next;
-		
-		if (!selected_item->item->current)
-			selected_item->item->current = selected_item->item->submenu;
+	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 menuPrevH() {
-	if (!selected_item) {
-		selected_item = menu;
-	}
-	
-	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)
-		selected_item->item->current = cur->next;
-}
-
 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) {
 			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) {
 			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)
 }
 
 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)
 }
 
 void menuHandleInputMain() {
-	if (!selected_item)
-		return;
-
 	if(getKey(KEY_LEFT)) {
 		menuPrevH();
 	} else if(getKey(KEY_RIGHT)) {
 }
 
 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;
 	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;
 	item->menuItem.submenu = NULL;
 	item->menuItem.current = NULL;
 	item->menuItem.pagestart = NULL;
+	item->menuItem.remindLast = 0;
 
 	item->menuItem.refresh = &itemExecRefresh;
 	item->menuItem.execCross = &itemExecCross;
 	item->menuItem.execCircle = &itemExecCircle;
 
 	item->menuItem.hints = NULL;
+
 	moduleUpdateMenu(mode, 0);
 
 	struct gui_update_t *mc = guiOpCreate(GUI_OP_ADD_MENU);
 	mdl->menuItem.submenu = NULL;
 	mdl->menuItem.current = NULL;
 	mdl->menuItem.pagestart = NULL;
+	mdl->menuItem.remindLast = 0;
 
 	// unlock, the rest is deferred
 	guiUnlock();

File src/themes.c

 			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)) {
 					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);