From 2ac057241a3b96fc71d9e320ac23e455a0a11368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Stenberg?= Date: Sun, 26 May 2002 17:03:17 +0000 Subject: [PATCH] Added support for nested menus git-svn-id: svn://svn.rockbox.org/rockbox/trunk@707 a1c6a512-1295-4272-9138-f99709370657 --- apps/menu.c | 96 +++++++++++++++++++++++++++++++---------------------- apps/menu.h | 5 +-- 2 files changed, 60 insertions(+), 41 deletions(-) diff --git a/apps/menu.c b/apps/menu.c index 36cb6152fb..027f1fcbea 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -16,48 +16,66 @@ * KIND, either express or implied. * ****************************************************************************/ - +#include #include "lcd.h" #include "menu.h" #include "button.h" #include "kernel.h" #include "debug.h" -/* Global values for menuing */ -static int menu_top; -static int menu_bottom; -static int cursor; -static struct menu_items* items; -static int itemcount; +struct menu { + int menu_top; + int menu_bottom; + int cursor; + struct menu_items* items; + int itemcount; +}; + +#define MAX_MENUS 4 + +static struct menu menus[MAX_MENUS]; +static bool inuse[MAX_MENUS] = { false }; /* * Move the cursor to a particular id, * target: where you want it to be */ -static void put_cursor(int target) +static void put_cursor(int m, int target) { - lcd_puts(0, cursor, " "); - cursor = target; - lcd_puts(0, cursor, "-"); + lcd_puts(0, menus[m].cursor, " "); + menus[m].cursor = target; + lcd_puts(0, menus[m].cursor, "-"); } -/* We call the function pointer related to the current cursor position */ -static void execute_menu_item(void) +int menu_init(struct menu_items* mitems, int count) { - /* call the proper function for this line */ - items[cursor].function(); + int i; + + for ( i=0; i menu_bottom) - menu_bottom = i; + for (i = 0; i < menus[m].itemcount; i++) { + lcd_puts(1, i, menus[m].items[i].desc); + if (i < menus[m].menu_top) + menus[m].menu_top = i; + if (i > menus[m].menu_bottom) + menus[m].menu_bottom = i; } - lcd_puts(0, cursor, "-"); + lcd_puts(0, menus[m].cursor, "-"); lcd_update(); } -void menu_run(void) +void menu_run(int m) { int key; - menu_draw(); + menu_draw(m); while(1) { key = button_get(); @@ -97,12 +115,12 @@ void menu_run(void) #else case BUTTON_LEFT: #endif - if (cursor == menu_top) { + if (menus[m].cursor == menus[m].menu_top) { /* wrap around to menu bottom */ - put_cursor(menu_bottom); + put_cursor(m, menus[m].menu_bottom); } else { /* move up */ - put_cursor(cursor-1); + put_cursor(m, menus[m].cursor-1); } break; @@ -111,12 +129,12 @@ void menu_run(void) #else case BUTTON_RIGHT: #endif - if (cursor == menu_bottom) { + if (menus[m].cursor == menus[m].menu_bottom) { /* wrap around to menu top */ - put_cursor(menu_top); + put_cursor(m, menus[m].menu_top); } else { /* move down */ - put_cursor(cursor+1); + put_cursor(m, menus[m].cursor+1); } break; @@ -127,10 +145,10 @@ void menu_run(void) /* Erase current display state */ lcd_clear_display(); - execute_menu_item(); + menus[m].items[menus[m].cursor].function(); /* Return to previous display state */ - menu_draw(); + menu_draw(m); break; #ifdef HAVE_RECORDER_KEYPAD diff --git a/apps/menu.h b/apps/menu.h index 5aafe9bf9a..accfbda267 100644 --- a/apps/menu.h +++ b/apps/menu.h @@ -26,7 +26,8 @@ struct menu_items { void (*function) (void); }; -void menu_init(struct menu_items* items, int count); -void menu_run(void); +int menu_init(struct menu_items* items, int count); +void menu_exit(int menu); +void menu_run(int menu); #endif /* End __MENU_H__ */