Index: apps/plugins/jpeg/jpeg.c =================================================================== --- apps/plugins/jpeg/jpeg.c (revision 20993) +++ apps/plugins/jpeg/jpeg.c (working copy) @@ -27,7 +27,6 @@ #include "plugin.h" #include -#include #include #include @@ -323,17 +322,16 @@ return false; } +MENUITEM_FUNCTION(grayscale_item, 0, "Greyscale", + set_option_grayscale, NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(dithering_item, 0, "Dithering", + set_option_dithering, NULL, NULL, Icon_NOICON); +MAKE_MENU(display_menu, "Display Options", NULL, Icon_NOICON, + &grayscale_item, &dithering_item); + static void display_options(void) { - static const struct menu_item items[] = { - { "Greyscale", set_option_grayscale }, - { "Dithering", set_option_dithering }, - }; - - int m = menu_init(items, ARRAYLEN(items), - NULL, NULL, NULL, NULL); - menu_run(m); - menu_exit(m); + rb->do_menu(&display_menu, NULL, NULL, false); } #endif /* HAVE_LCD_COLOR */ @@ -349,7 +347,6 @@ rb->lcd_set_background(LCD_WHITE); #endif #endif - int m; int result; enum menu_id @@ -366,38 +363,27 @@ MIID_RETURN, }; - static const struct menu_item items[] = { - [MIID_QUIT] = - { "Quit", NULL }, - [MIID_TOGGLE_SS_MODE] = - { "Toggle Slideshow Mode", NULL }, - [MIID_CHANGE_SS_MODE] = - { "Change Slideshow Time", NULL }, + MENUITEM_STRINGLIST(menu, "Jpeg Menu", NULL, + "Quit", "Toggle Slideshow Mode", + "Change Slideshow Time", #if PLUGIN_BUFFER_SIZE >= MIN_MEM - [MIID_SHOW_PLAYBACK_MENU] = - { "Show Playback Menu", NULL }, + "Show Playback Menu", #endif #ifdef HAVE_LCD_COLOR - [MIID_DISPLAY_OPTIONS] = - { "Display Options", NULL }, + "Display Options", #endif - [MIID_RETURN] = - { "Return", NULL }, - }; + "Return"); static const struct opt_items slideshow[2] = { { "Disable", -1 }, { "Enable", -1 }, }; - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - result=menu_show(m); + result=rb->do_menu(&menu, NULL, NULL, false); switch (result) { case MIID_QUIT: - menu_exit(m); return 1; break; case MIID_TOGGLE_SS_MODE: @@ -456,7 +442,6 @@ rb->lcd_set_background(LCD_BLACK); #endif rb->lcd_clear_display(); - menu_exit(m); return 0; } Index: apps/plugins/random_folder_advance_config.c =================================================================== --- apps/plugins/random_folder_advance_config.c (revision 20993) +++ apps/plugins/random_folder_advance_config.c (working copy) @@ -19,7 +19,6 @@ * ****************************************************************************/ #include "plugin.h" -#include "lib/oldmenuapi.h" PLUGIN_HEADER @@ -321,15 +320,11 @@ break; case ACTION_STD_CONTEXT: { - int m, len; - static const struct menu_item items[] = { - { "Remove Folder", NULL }, - { "Remove Folder Tree", NULL }, - }; - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); + int len; + MENUITEM_STRINGLIST(menu, "Remove Menu", NULL, + "Remove Folder", "Remove Folder Tree"); - switch (menu_show(m)) + switch (rb->do_menu(&menu, NULL, NULL, false)) { case 0: list->folder[selection][0] = ' '; @@ -351,20 +346,14 @@ } break; } - menu_exit(m); } break; case ACTION_STD_CANCEL: { - int m; - static const struct menu_item items[] = { - { "Save and Exit", NULL }, - { "Ignore Changes and Exit", NULL }, - }; - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); + MENUITEM_STRINGLIST(menu, "Exit Menu", NULL, + "Save and Exit", "Ignore Changes and Exit"); - switch (menu_show(m)) + switch (rb->do_menu(&menu, NULL, NULL, false)) { case 0: save_list(); @@ -372,7 +361,6 @@ exit = true; ret = -2; } - menu_exit(m); } break; } @@ -474,19 +462,16 @@ int main_menu(void) { - int m; bool exit = false; - static const struct menu_item items[] = { - { "Generate Folder List", NULL }, - { "Edit Folder List", NULL }, - { "Export List To Textfile", NULL }, - { "Import List From Textfile", NULL }, - { "Quit", NULL }, - }; - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - switch (menu_show(m)) + MENUITEM_STRINGLIST(menu, "Main Menu", NULL, + "Generate Folder List", + "Edit Folder List", + "Export List To Textfile", + "Import List From Textfile", + "Quit"); + + switch (rb->do_menu(&menu, NULL, NULL, false)) { case 0: /* generate */ #ifdef HAVE_ADJUSTABLE_CPU_FREQ @@ -542,10 +527,8 @@ rb->backlight_on(); break; case 4: - menu_exit(m); return 1; } - menu_exit(m); return exit?1:0; } Index: apps/plugins/test_disk.c =================================================================== --- apps/plugins/test_disk.c (revision 20993) +++ apps/plugins/test_disk.c (working copy) @@ -20,7 +20,6 @@ ****************************************************************************/ #include "plugin.h" -#include "lib/oldmenuapi.h" #include "lib/helper.h" PLUGIN_HEADER @@ -406,11 +405,10 @@ /* this is the plugin entry point */ enum plugin_status plugin_start(const void* parameter) { - static const struct menu_item items[] = { - { "Disk speed", test_speed }, - { "Write & verify", test_fs }, - }; - int m; + MENUITEM_STRINGLIST(menu, "Test Disk Menu", NULL, + "Disk speed", "Write & verify"); + int selected=0; + bool quit = false; int align; DIR *dir; @@ -440,10 +438,21 @@ /* Turn off backlight timeout */ backlight_force_on(); /* backlight control in lib/helper.c */ - m = menu_init(items, sizeof(items) / sizeof(*items), NULL, - NULL, NULL, NULL); - menu_run(m); - menu_exit(m); + while(!quit) + { + switch(rb->do_menu(&menu, &selected, NULL, false)) + { + case 0: + test_speed(); + break; + case 1: + test_fs(); + break; + default: + quit = true; + break; + } + } /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); /* backlight control in lib/helper.c */ Index: apps/plugins/reversi/reversi-gui.c =================================================================== --- apps/plugins/reversi/reversi-gui.c (revision 20993) +++ apps/plugins/reversi/reversi-gui.c (working copy) @@ -47,7 +47,6 @@ #include "reversi-strategy.h" #include "reversi-gui.h" -#include "lib/oldmenuapi.h" #include "lib/playback_control.h" PLUGIN_HEADER @@ -375,24 +374,16 @@ /* Returns true iff USB ws connected while in the menu */ static bool reversi_gui_menu(void) { - int m, index, num_items, i; + int index, num_items, i; int result; - static const struct menu_item items[] = { - { "Start new game", NULL }, - { "Pass the move", NULL }, - { MENU_TEXT_STRAT_BLACK, NULL }, - { MENU_TEXT_STRAT_WHITE, NULL }, - { MENU_TEXT_WRAP_MODE, NULL }, - { "Playback Control", NULL }, - { "Quit", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Reversi Menu", NULL, + "Start new game", "Pass the move", + MENU_TEXT_STRAT_BLACK, MENU_TEXT_STRAT_WHITE, + MENU_TEXT_WRAP_MODE, "Playback Control", "Quit"); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); + result = rb->do_menu(&menu, NULL, NULL, false); - result = menu_show(m); - switch (result) { case 0: /* Start a new game */ reversi_gui_init(); @@ -433,8 +424,6 @@ break; } - menu_exit(m); - return (result == MENU_ATTACHED_USB); } Index: apps/plugins/jewels.c =================================================================== --- apps/plugins/jewels.c (revision 20993) +++ apps/plugins/jewels.c (working copy) @@ -330,59 +330,6 @@ GAME_TYPE_PUZZLE }; -/* menu values */ -#define FONT_HEIGHT 8 -#define MAX_MITEMS 6 -#define MENU_WIDTH 100 - -/* menu results */ -enum menu_result { - MRES_NONE, - MRES_NEW, - MRES_PUZZLE, - MRES_SAVE, - MRES_RESUME, - MRES_SCORES, - MRES_HELP, - MRES_QUIT, - MRES_PLAYBACK, - MRES_EXIT -}; - -/* menu commands */ -enum menu_cmd { - MCMD_NONE, - MCMD_NEXT, - MCMD_PREV, - MCMD_SELECT -}; - -/* menus */ -struct jewels_menu { - char *title; - bool hasframe; - int selected; - int itemcnt; - struct jewels_menuitem { - char *text; - enum menu_result res; - } items[MAX_MITEMS]; -} bjmenu[] = { - {"Jewels", false, 0, 6, - {{"New Game", MRES_NEW}, - {"Puzzle", MRES_PUZZLE}, - {"Resume Saved Game", MRES_RESUME}, - {"High Scores", MRES_SCORES}, - {"Help", MRES_HELP}, - {"Quit", MRES_QUIT}}}, - {"Menu", true, 0, 5, - {{"Audio Playback", MRES_PLAYBACK }, - {"Resume Game", MRES_RESUME}, - {"Save Game", MRES_SAVE}, - {"End Game", MRES_QUIT}, - {"Exit Jewels", MRES_EXIT}}} -}; - /* external bitmaps */ extern const fb_data jewels[]; @@ -677,73 +624,6 @@ } /***************************************************************************** -* jewels_showmenu() displays the chosen menu after performing the chosen -* menu command. -******************************************************************************/ -static enum menu_result jewels_showmenu(struct jewels_menu* menu, - enum menu_cmd cmd) { - int i; - int w, h; - int firstline; - int adj; - int extraline = LCD_HEIGHT <= ((menu->itemcnt+2)*FONT_HEIGHT) ? 0 : 1; - - /* handle menu command */ - switch(cmd) { - case MCMD_NEXT: - menu->selected = (menu->selected+1)%menu->itemcnt; - break; - - case MCMD_PREV: - menu->selected = (menu->selected-1+menu->itemcnt)%menu->itemcnt; - break; - - case MCMD_SELECT: - return menu->items[menu->selected].res; - - default: - break; - } - - /* clear menu area */ - firstline = (LCD_HEIGHT/FONT_HEIGHT-(menu->itemcnt+3))/2; - - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - rb->lcd_fillrect((LCD_WIDTH-MENU_WIDTH)/2, firstline*FONT_HEIGHT, - MENU_WIDTH, (menu->itemcnt+3)*FONT_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - - if(menu->hasframe) { - rb->lcd_drawrect((LCD_WIDTH-MENU_WIDTH)/2-1, firstline*FONT_HEIGHT-1, - MENU_WIDTH+2, (menu->itemcnt+3)*FONT_HEIGHT+2); - rb->lcd_hline((LCD_WIDTH-MENU_WIDTH)/2-1, - (LCD_WIDTH-MENU_WIDTH)/2-1+MENU_WIDTH+2, - (firstline+1)*FONT_HEIGHT); - } - - /* draw menu items */ - rb->lcd_getstringsize(menu->title, &w, &h); - rb->lcd_putsxy((LCD_WIDTH-w)/2, firstline*FONT_HEIGHT, menu->title); - - for(i=0; iitemcnt; i++) { - if(i == menu->selected) { - rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); - } - rb->lcd_putsxy((LCD_WIDTH-MENU_WIDTH)/2, - (firstline+i+1+extraline)*FONT_HEIGHT, - menu->items[i].text); - if(i == menu->selected) { - rb->lcd_set_drawmode(DRMODE_SOLID); - } - } - - adj = (firstline == 0 ? 0 : 1); - rb->lcd_update_rect((LCD_WIDTH-MENU_WIDTH)/2-1, firstline*FONT_HEIGHT-adj, - MENU_WIDTH+2, (menu->itemcnt+3)*FONT_HEIGHT+2*adj); - return MRES_NONE; -} - -/***************************************************************************** * jewels_putjewels() makes the jewels fall to fill empty spots and adds * new random jewels at the empty spots at the top of each row. ******************************************************************************/ @@ -1457,18 +1337,36 @@ } /***************************************************************************** +* jewels_displayscores() displays the high scores +******************************************************************************/ +static char * scores_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) +{ + struct game_context* bj = (struct game_context*)data; + rb->snprintf(buffer, buffer_len, "#%02d: %d", + selected_item+1, bj->highscores[selected_item]); + return buffer; +} +static void jewels_displayscores(struct game_context* bj) +{ + struct simplelist_info info; + rb->simplelist_info_init(&info, "High Scores", NUM_SCORES, (void*)bj); + info.hide_selection = true; + info.get_name = scores_get_name; + rb->simplelist_show_list(&info); +} + + +/***************************************************************************** * jewels_main() is the main game subroutine, it returns the final game status. ******************************************************************************/ static int jewels_main(struct game_context* bj) { - int i, j; int w, h; int button; + struct viewport vp[NB_SCREENS]; char str[18]; - bool startgame = false; - bool inmenu = false; + bool inmenu = true; bool selected = false; - enum menu_cmd cmd = MCMD_NONE; - enum menu_result res; /* the cursor coordinates */ int x=0, y=0; @@ -1479,67 +1377,47 @@ /******************** * menu * ********************/ - rb->lcd_clear_display(); + MENUITEM_STRINGLIST(main_menu,"Jewels",NULL, + "New Game", "Puzzle", "Resume Saved Game", + "High Scores", "Help", "Quit"); + FOR_NB_SCREENS(h) + { + rb->viewport_set_defaults(&vp[h], h); +#if (LCD_DEPTH >= 16) || defined(LCD_REMOTE_DEPTH) && (LCD_REMOTE_DEPTH >= 16) + if (rb->screens[h]->depth >= 16) + { + vp->bg_pattern = LCD_RGBPACK(49, 26, 26); + vp->fg_pattern = LCD_RGBPACK(210, 181, 181); + } +#endif + } - while(!startgame) { - res = jewels_showmenu(&bjmenu[0], cmd); - cmd = MCMD_NONE; + while(inmenu) { - rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]); - rb->lcd_getstringsize(str, &w, &h); - rb->lcd_putsxy((LCD_WIDTH-w)/2, LCD_HEIGHT-8, str); - rb->lcd_update(); - - rb->yield(); - - switch(res) { - case MRES_NEW: - startgame = true; + switch (rb->do_menu(&main_menu, NULL, vp, true)) { + case 0: + inmenu = false; bj->type = GAME_TYPE_NORMAL; - continue; + break; - case MRES_PUZZLE: - startgame = true; + case 1: + inmenu = false; bj->type = GAME_TYPE_PUZZLE; - continue; + break; - case MRES_RESUME: + case 2: if(!jewels_loadgame(bj)) { rb->splash(HZ*2, "Nothing to resume"); - rb->lcd_clear_display(); } else { - startgame = true; + inmenu = false; } - continue; + break; - case MRES_SCORES: - rb->lcd_clear_display(); + case 3: + jewels_displayscores(bj); + break; - /* room for a title? */ - j = 0; - if(LCD_HEIGHT-NUM_SCORES*8 >= 8) { - rb->snprintf(str, 12, "%s", "High Scores"); - rb->lcd_getstringsize(str, &w, &h); - rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, str); - j = 2; - } - - /* print high scores */ - for(i=0; isnprintf(str, 11, "#%02d: %d", i+1, bj->highscores[i]); - rb->lcd_puts(0, i+j, str); - } - - rb->lcd_update(); - while(true) { - button = rb->button_get(true); - if(button != BUTTON_NONE && !(button&BUTTON_REL)) break; - rb->yield(); - } - rb->lcd_clear_display(); - continue; - - case MRES_HELP: + case 4: /* welcome screen to display key bindings */ rb->lcd_clear_display(); rb->snprintf(str, 5, "%s", "Help"); @@ -1694,54 +1572,17 @@ if(button != BUTTON_NONE && !(button&BUTTON_REL)) break; } rb->lcd_clear_display(); - continue; - - case MRES_QUIT: - return BJ_QUIT; - - default: break; - } - /* handle menu button presses */ - button = rb->button_get(true); - switch(button){ -#ifdef JEWELS_SCROLLWHEEL - case JEWELS_PREV: - case (JEWELS_PREV|BUTTON_REPEAT): -#endif - case JEWELS_UP: - case (JEWELS_UP|BUTTON_REPEAT): - cmd = MCMD_PREV; - break; - -#ifdef JEWELS_SCROLLWHEEL - case JEWELS_NEXT: - case (JEWELS_NEXT|BUTTON_REPEAT): -#endif - case JEWELS_DOWN: - case (JEWELS_DOWN|BUTTON_REPEAT): - cmd = MCMD_NEXT; - break; - - case JEWELS_SELECT: - case JEWELS_RIGHT: - cmd = MCMD_SELECT; - break; - -#ifdef JEWELS_CANCEL -#ifdef JEWELS_RC_CANCEL - case JEWELS_RC_CANCEL: -#endif - case JEWELS_CANCEL: + case 5: return BJ_QUIT; -#endif + + case MENU_ATTACHED_USB: + jewels_callback(bj); + return BJ_USB; default: - if(rb->default_event_handler_ex(button, jewels_callback, - (void*) bj) == SYS_USB_CONNECTED) - return BJ_USB; - break; + return BJ_QUIT; } } @@ -1771,162 +1612,142 @@ /********************** * play * **********************/ + MENUITEM_STRINGLIST(ingame_menu,"Menu",NULL, + "Audio Playback", "Resume Game", + "Save Game", "End Game", "Exit Jewels"); + + selected = false; while(true) { - int no_movesavail = false; + bool no_movesavail = false; - if(!inmenu) { - /* refresh the board */ - jewels_drawboard(bj); - - /* display the cursor */ - if(selected) { - rb->lcd_set_drawmode(DRMODE_COMPLEMENT); - rb->lcd_fillrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS, - TILE_WIDTH, TILE_HEIGHT); - rb->lcd_set_drawmode(DRMODE_SOLID); - } else { - rb->lcd_drawrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS, - TILE_WIDTH, TILE_HEIGHT); - } - rb->lcd_update_rect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS, - TILE_WIDTH, TILE_HEIGHT); - } else { - res = jewels_showmenu(&bjmenu[1], cmd); - cmd = MCMD_NONE; - switch(res) { - case MRES_RESUME: + while(inmenu) { + switch (rb->do_menu(&ingame_menu, NULL, vp, true)) { + case 0: + playback_control(NULL); inmenu = false; - selected = false; - continue; + break; - case MRES_PLAYBACK: - playback_control(NULL); - rb->lcd_setfont(FONT_SYSFIXED); + case 1: inmenu = false; - selected = false; break; - case MRES_SAVE: + case 2: rb->splash(HZ, "Saving game..."); jewels_savegame(bj); return BJ_END; - case MRES_QUIT: + case 3: return BJ_END; - case MRES_EXIT: + case 4: return BJ_QUIT_FROM_GAME; + case MENU_ATTACHED_USB: + jewels_callback(bj); + return BJ_USB; + default: + inmenu = false; break; } } + /* refresh the board */ + jewels_drawboard(bj); + + /* display the cursor */ + if(selected) { + rb->lcd_set_drawmode(DRMODE_COMPLEMENT); + rb->lcd_fillrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS, + TILE_WIDTH, TILE_HEIGHT); + rb->lcd_set_drawmode(DRMODE_SOLID); + } else { + rb->lcd_drawrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS, + TILE_WIDTH, TILE_HEIGHT); + } + rb->lcd_update_rect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS, + TILE_WIDTH, TILE_HEIGHT); + /* handle game button presses */ rb->yield(); button = rb->button_get(true); switch(button){ case JEWELS_LEFT: /* move cursor left */ case (JEWELS_LEFT|BUTTON_REPEAT): - if(!inmenu) { - if(selected) { - bj->score += jewels_swapjewels(bj, x, y, SWAP_LEFT); - selected = false; - if (!jewels_movesavail(bj)) no_movesavail = true; - } else { - x = (x+BJ_WIDTH-1)%BJ_WIDTH; - } + if(selected) { + bj->score += jewels_swapjewels(bj, x, y, SWAP_LEFT); + selected = false; + if (!jewels_movesavail(bj)) no_movesavail = true; + } else { + x = (x+BJ_WIDTH-1)%BJ_WIDTH; } break; case JEWELS_RIGHT: /* move cursor right */ case (JEWELS_RIGHT|BUTTON_REPEAT): - if(!inmenu) { - if(selected) { - bj->score += jewels_swapjewels(bj, x, y, SWAP_RIGHT); - selected = false; - if (!jewels_movesavail(bj)) no_movesavail = true; - } else { - x = (x+1)%BJ_WIDTH; - } + if(selected) { + bj->score += jewels_swapjewels(bj, x, y, SWAP_RIGHT); + selected = false; + if (!jewels_movesavail(bj)) no_movesavail = true; } else { - cmd = MCMD_SELECT; + x = (x+1)%BJ_WIDTH; } break; case JEWELS_DOWN: /* move cursor down */ case (JEWELS_DOWN|BUTTON_REPEAT): - if(!inmenu) { - if(selected) { - bj->score += jewels_swapjewels(bj, x, y, SWAP_DOWN); - selected = false; - if (!jewels_movesavail(bj)) no_movesavail = true; - } else { - y = (y+1)%(BJ_HEIGHT-1); - } + if(selected) { + bj->score += jewels_swapjewels(bj, x, y, SWAP_DOWN); + selected = false; + if (!jewels_movesavail(bj)) no_movesavail = true; } else { - cmd = MCMD_NEXT; + y = (y+1)%(BJ_HEIGHT-1); } break; case JEWELS_UP: /* move cursor up */ case (JEWELS_UP|BUTTON_REPEAT): - if(!inmenu) { - if(selected) { - bj->score += jewels_swapjewels(bj, x, y, SWAP_UP); - selected = false; - if (!jewels_movesavail(bj)) no_movesavail = true; - } else { - y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1); - } + if(selected) { + bj->score += jewels_swapjewels(bj, x, y, SWAP_UP); + selected = false; + if (!jewels_movesavail(bj)) no_movesavail = true; } else { - cmd = MCMD_PREV; + y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1); } break; #ifdef JEWELS_SCROLLWHEEL case JEWELS_PREV: /* scroll backwards */ case (JEWELS_PREV|BUTTON_REPEAT): - if(!inmenu) { - if(!selected) { - if(x == 0) { - y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1); - } - x = (x+BJ_WIDTH-1)%BJ_WIDTH; + if(!selected) { + if(x == 0) { + y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1); } - } else { - cmd = MCMD_PREV; + x = (x+BJ_WIDTH-1)%BJ_WIDTH; } break; case JEWELS_NEXT: /* scroll forwards */ case (JEWELS_NEXT|BUTTON_REPEAT): - if(!inmenu) { - if(!selected) { - if(x == BJ_WIDTH-1) { - y = (y+1)%(BJ_HEIGHT-1); - } - x = (x+1)%BJ_WIDTH; + if(!selected) { + if(x == BJ_WIDTH-1) { + y = (y+1)%(BJ_HEIGHT-1); } - } else { - cmd = MCMD_NEXT; + x = (x+1)%BJ_WIDTH; } break; #endif case JEWELS_SELECT: /* toggle selected */ - if(!inmenu) { - selected = !selected; - } else { - cmd = MCMD_SELECT; - } + selected = !selected; break; #ifdef JEWELS_MENU case JEWELS_MENU: #endif case (JEWELS_SELECT|BUTTON_REPEAT): /* show menu */ - if(!inmenu) inmenu = true; + inmenu = true; + selected = false; break; #ifdef JEWELS_CANCEL Index: apps/plugins/pacbox/pacbox.c =================================================================== --- apps/plugins/pacbox/pacbox.c (revision 20993) +++ apps/plugins/pacbox/pacbox.c (working copy) @@ -29,7 +29,6 @@ #include "pacbox.h" #include "pacbox_lcd.h" #include "lib/configfile.h" -#include "lib/oldmenuapi.h" PLUGIN_HEADER PLUGIN_IRAM_DECLARE @@ -138,7 +137,7 @@ static bool pacbox_menu(void) { - int m; + int selected=0; int result; int menu_quit=0; int new_setting; @@ -173,23 +172,14 @@ { "Alternate", -1 }, }; - static const struct menu_item items[] = { - { "Difficulty", NULL }, - { "Pacmen Per Game", NULL }, - { "Bonus Life", NULL }, - { "Ghost Names", NULL }, - { "Display FPS", NULL }, - { "Restart", NULL }, - { "Quit", NULL }, - }; - - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); + MENUITEM_STRINGLIST(menu, "Pacbox Menu", NULL, + "Difficulty", "Pacmen Per Game", "Bonus Life", + "Ghost Names", "Display FPS", "Restart", "Quit"); rb->button_clear_queue(); while (!menu_quit) { - result=menu_show(m); + result=rb->do_menu(&menu, &selected, NULL, false); switch(result) { @@ -243,8 +233,6 @@ } } - menu_exit(m); - if (need_restart) { init_PacmanMachine(settings_to_dip(settings)); } Index: apps/plugins/zxbox/spmain.c =================================================================== --- apps/plugins/zxbox/spmain.c (revision 20993) +++ apps/plugins/zxbox/spmain.c (working copy) @@ -20,7 +20,6 @@ #include "zxmisc.h" #include "zxconfig.h" #include "lib/configfile.h" -#include "lib/oldmenuapi.h" #include "spperif.h" #include "z80.h" @@ -134,25 +133,18 @@ /* set keys */ static void set_keys(void){ - int m; char c; + int selected=0; int result; int menu_quit=0; - static const struct menu_item items[] = { - { "Map Up key", NULL }, - { "Map Down key", NULL }, - { "Map Left key", NULL }, - { "Map Right key", NULL }, - { "Map Fire/Jump key", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Custom keymap", NULL, + "Map Up key", "Map Down key", "Map Left key", + "Map Right key", "Map Fire/Jump key"); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch(result) { @@ -161,7 +153,7 @@ { settings.keymap[0]=c; } - break; + break; case 1: if (!zx_kbd_input((char*) &c)) { @@ -191,41 +183,33 @@ break; } } - - menu_exit(m); } /* select predefined keymap */ static void select_keymap(void){ - int m; + int selected=0; int result; int menu_quit=0; - static const struct menu_item items[] = { - { "2w90z", NULL }, - { "qaopS", NULL }, - { "7658S", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Predefined keymap", NULL, + "2w90z", "qaopS", "7658S"); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch(result) { case 0: - rb->memcpy ( (void*)&settings.keymap[0] , (void*)items[0].desc , sizeof(items[0].desc)); + rb->memcpy ( (void*)&settings.keymap[0] , (void*)"2w90z" , 5); menu_quit=1; - break; + break; case 1: - rb->memcpy ( (void*)&settings.keymap[0] , (void*)items[1].desc , sizeof(items[1].desc)); + rb->memcpy ( (void*)&settings.keymap[0] , (void*)"qaopS" , 5); menu_quit=1; break; case 2: - rb->memcpy ( (void*)&settings.keymap[0] , (void*)items[2].desc , sizeof(items[2].desc)); + rb->memcpy ( (void*)&settings.keymap[0] , (void*)"7658S" , 5); menu_quit=1; break; default: @@ -233,8 +217,6 @@ break; } } - - menu_exit(m); } /* options menu */ @@ -243,20 +225,15 @@ { "No", -1 }, { "Yes", -1 }, }; - int m; + int selected; int result; int menu_quit=0; int new_setting; - static const struct menu_item items[] = { - { "Map Keys to kempston", NULL }, - { "Display Speed", NULL }, - { "Invert Colors", NULL }, - { "Frameskip", NULL }, - { "Sound", NULL }, - { "Volume", NULL }, - { "Predefined keymap", NULL }, - { "Custom keymap", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Options", NULL, + "Map Keys to kempston", "Display Speed", + "Invert Colors", "Frameskip", "Sound", "Volume", + "Predefined keymap", "Custom keymap"); + static struct opt_items frameskip_items[] = { { "0", -1 }, { "1", -1 }, @@ -269,15 +246,12 @@ { "8", -1 }, { "9", -1 }, }; - - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); rb->button_clear_queue(); while (!menu_quit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch(result) { @@ -287,7 +261,7 @@ no_yes, 2, NULL); if (new_setting != settings.kempston ) settings.kempston=new_setting; - break; + break; case 1: new_setting = settings.showfps; rb->set_option("Display Speed",&new_setting,INT, @@ -339,8 +313,6 @@ break; } } - - menu_exit(m); } /* menu */ @@ -349,29 +321,21 @@ #if CONFIG_CODEC == SWCODEC && !defined SIMULATOR rb->pcm_play_stop(); #endif - int m; + int selected=0; int result; int menu_quit=0; int exit=0; char c; - static const struct menu_item items[] = { - { "VKeyboard", NULL }, - { "Play/Pause Tape", NULL }, - { "Save quick snapshot", NULL }, - { "Load quick snapshot", NULL }, - { "Save Snapshot", NULL }, - { "Toggle \"fast\" mode", NULL }, - { "Options", NULL }, - { "Quit", NULL }, - }; + MENUITEM_STRINGLIST(menu, "ZXBox Menu", NULL, + "VKeyboard", "Play/Pause Tape", + "Save quick snapshot", "Load quick snapshot", + "Save Snapshot", "Toggle \"fast\" mode", + "Options", "Quit"); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch(result) { @@ -415,7 +379,6 @@ } } - menu_exit(m); #if defined(HAVE_ADJUSTABLE_CPU_FREQ) rb->cpu_boost(true); #endif Index: apps/plugins/sudoku/sudoku.c =================================================================== --- apps/plugins/sudoku/sudoku.c (revision 20993) +++ apps/plugins/sudoku/sudoku.c (working copy) @@ -60,7 +60,6 @@ #include "plugin.h" #include "lib/configfile.h" -#include "lib/oldmenuapi.h" #ifdef HAVE_LCD_BITMAP @@ -1167,30 +1166,20 @@ bool sudoku_menu(struct sudoku_state_t* state) { - int m; int result; - static const struct menu_item items[] = { - [SM_AUDIO_PLAYBACK] = { "Audio Playback", NULL }, + MENUITEM_STRINGLIST(menu, "Sudoku Menu", NULL, + "Audio Playback", #ifdef HAVE_LCD_COLOR - [SM_NUMBER_DISPLAY] = { "Number Display", NULL }, + "Number Display", #endif #ifdef SUDOKU_BUTTON_POSSIBLE - [SM_SHOW_MARKINGS] = { "Show Markings", NULL }, + "Show Markings", #endif - [SM_SAVE] = { "Save", NULL }, - [SM_RELOAD] = { "Reload", NULL }, - [SM_CLEAR] = { "Clear", NULL }, - [SM_SOLVE] = { "Solve", NULL }, - [SM_GENERATE] = { "Generate", NULL }, - [SM_NEW] = { "New", NULL }, - [SM_QUIT] = { "Quit", NULL }, - }; - - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); + "Save", "Reload", "Clear", "Solve", + "Generate", "New", "Quit"); - result=menu_show(m); + result = rb->do_menu(&menu, NULL, NULL, false); switch (result) { case SM_AUDIO_PLAYBACK: @@ -1235,7 +1224,6 @@ case SM_QUIT: save_sudoku(state); - menu_exit(m); return true; break; @@ -1243,26 +1231,18 @@ break; } - menu_exit(m); - return (result==MENU_ATTACHED_USB); } /* Menu used when user is in edit mode - i.e. creating a new game manually */ int sudoku_edit_menu(struct sudoku_state_t* state) { - int m; int result; - static const struct menu_item items[] = { - { "Save as", NULL }, - { "Quit", NULL }, - }; - - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); + MENUITEM_STRINGLIST(menu, "Edit Menu", NULL, + "Save as", "Quit"); - result=menu_show(m); + result = rb->do_menu(&menu, NULL, NULL, false); switch (result) { case 0: /* Save new game */ @@ -1281,8 +1261,6 @@ break; } - menu_exit(m); - return result; } Index: apps/plugins/fireworks.c =================================================================== --- apps/plugins/fireworks.c (revision 20993) +++ apps/plugins/fireworks.c (working copy) @@ -19,7 +19,6 @@ * ****************************************************************************/ #include "plugin.h" -#include "lib/oldmenuapi.h" #include "lib/helper.h" #include "lib/playback_control.h" @@ -287,17 +286,10 @@ int fps_values[9] = { 20, 25, 30, 35, 40, 45, 50, 55, 60 }; -static const struct menu_item items[] = { - { "Start Demo", NULL }, - { "Auto-Fire", NULL }, - { "Particles Per Firework", NULL }, - { "Particle Life", NULL }, - { "Gravity", NULL }, - { "Show Rockets", NULL }, - { "FPS (Speed)", NULL }, - { "Playback Control", NULL }, - { "Quit", NULL } -}; +MENUITEM_STRINGLIST(menu, "Fireworks Menu", NULL, + "Start Demo", "Auto-Fire", "Particles Per Firework", + "Particle Life", "Gravity", "Show Rockets", + "FPS (Speed)", "Playback Control", "Quit"); /* called on startup. initializes all variables, etc */ void init_all(void) @@ -348,7 +340,7 @@ /* startup/configuration menu. */ void fireworks_menu(void) { - int m, result; + int selected = 0, result; bool menu_quit = false; rb->lcd_setfont(FONT_UI); @@ -359,14 +351,11 @@ rb->lcd_clear_display(); rb->lcd_update(); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - rb->button_clear_queue(); while(!menu_quit) { - result = menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch(result) { @@ -419,8 +408,6 @@ break; } } - - menu_exit(m); } /* this is the plugin entry point */ Index: apps/plugins/test_sampr.c =================================================================== --- apps/plugins/test_sampr.c (revision 20993) +++ apps/plugins/test_sampr.c (working copy) @@ -19,7 +19,6 @@ * ****************************************************************************/ #include "plugin.h" -#include "lib/oldmenuapi.h" /* This plugin generates a 1kHz tone + noise in order to quickly verify * hardware samplerate setup is operating correctly. @@ -285,32 +284,23 @@ MENU_QUIT, }; - static const struct menu_item items[] = - { + MENUITEM_STRINGLIST(menu, "Test Sampr Menu", NULL, #ifndef HAVE_VOLUME_IN_LIST - [MENU_VOL_SET] = - { "Set Volume", NULL }, + "Set Volume", #endif /* HAVE_VOLUME_IN_LIST */ - [MENU_SAMPR_SET] = - { "Set Samplerate", NULL }, - [MENU_QUIT] = - { "Quit", NULL }, - }; + "Set Samplerate", "Quit"); bool exit = false; - int m; + int selected = 0; /* Disable all talking before initializing IRAM */ rb->talk_disable(true); PLUGIN_IRAM_INIT(rb); - m = menu_init(items, ARRAYLEN(items), - NULL, NULL, NULL, NULL); - while (!exit) { - int result = menu_show(m); + int result = rb->do_menu(&menu, &selected, NULL, false); switch (result) { @@ -329,8 +319,6 @@ } } - menu_exit(m); - rb->talk_disable(false); return PLUGIN_OK; Index: apps/plugins/mpegplayer/mpegplayer.c =================================================================== --- apps/plugins/mpegplayer/mpegplayer.c (revision 20993) +++ apps/plugins/mpegplayer/mpegplayer.c (working copy) @@ -1498,7 +1498,7 @@ mpeg_menu_sysevent_clear(); button = rb->button_get_w_tmo(WVS_MIN_UPDATE_INTERVAL); - button = mpeg_menu_sysevent_callback(button, -1); + button = mpeg_menu_sysevent_callback(button, NULL); switch (button) { Index: apps/plugins/mpegplayer/mpeg_settings.c =================================================================== --- apps/plugins/mpegplayer/mpeg_settings.c (revision 20993) +++ apps/plugins/mpegplayer/mpeg_settings.c (working copy) @@ -1,7 +1,6 @@ #include "plugin.h" #include "lib/helper.h" #include "lib/configfile.h" -#include "lib/oldmenuapi.h" #include "mpegplayer.h" #include "mpeg_settings.h" @@ -257,7 +256,7 @@ mpeg_menu_sysevent_id = 0; } -int mpeg_menu_sysevent_callback(int btn, int menu) +int mpeg_menu_sysevent_callback(int btn, const struct menu_item_ex *menu) { switch (btn) { @@ -283,17 +282,6 @@ rb->default_event_handler(id); } -static void format_menu_item(struct menu_item *item, int bufsize, - const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - rb->vsnprintf(item->desc, bufsize, fmt, ap); - - va_end(ap); -} - static bool mpeg_set_option(const char* string, void* variable, enum optiontype type, @@ -691,7 +679,7 @@ button = tmo == TIMEOUT_BLOCK ? rb->button_get(true) : rb->button_get_w_tmo(tmo); - button = mpeg_menu_sysevent_callback(button, -1); + button = mpeg_menu_sysevent_callback(button, NULL); switch (button) { @@ -822,43 +810,31 @@ static int show_start_menu(uint32_t duration) { - int menu_id; + int selected = 0; int result = 0; bool menu_quit = false; /* add the resume time to the menu display */ - char resume_str[32]; + static char resume_str[32]; char hms_str[32]; struct hms hms; - struct menu_item items[] = - { - [MPEG_START_RESTART] = - { "Play from beginning", NULL }, - [MPEG_START_RESUME] = - { resume_str, NULL }, - [MPEG_START_SEEK] = - { "Set start time", NULL }, - [MPEG_START_SETTINGS] = - { "Settings", NULL }, - [MPEG_START_QUIT] = - { "Quit mpegplayer", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Mpegplayer Menu", mpeg_menu_sysevent_callback, + "Play from beginning", resume_str, + "Set start time", "Settings", + "Quit mpegplayer"); ts_to_hms(settings.resume_time, &hms); hms_format(hms_str, sizeof(hms_str), &hms); - format_menu_item(&items[MPEG_START_RESUME], sizeof (resume_str), + rb->snprintf(resume_str, sizeof (resume_str), "Resume at: %s", hms_str); - menu_id = menu_init(items, ARRAYLEN(items), - mpeg_menu_sysevent_callback, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) { mpeg_menu_sysevent_clear(); - result = menu_show(menu_id); + result = rb->do_menu(&menu, &selected, NULL, false); switch (result) { @@ -901,8 +877,6 @@ } } - menu_exit(menu_id); - rb->lcd_clear_display(); rb->lcd_update(); @@ -934,36 +908,26 @@ /** MPEG Menu **/ static void display_options(void) { + int selected = 0; int result; - int menu_id; bool menu_quit = false; - static const struct menu_item items[] = { + MENUITEM_STRINGLIST(menu, "Display Options", mpeg_menu_sysevent_callback, #if MPEG_OPTION_DITHERING_ENABLED - [MPEG_OPTION_DITHERING] = - { "Dithering", NULL }, + "Dithering", #endif - [MPEG_OPTION_DISPLAY_FPS] = - { "Display FPS", NULL }, - [MPEG_OPTION_LIMIT_FPS] = - { "Limit FPS", NULL }, - [MPEG_OPTION_SKIP_FRAMES] = - { "Skip frames", NULL }, + "Display FPS", "Limit FPS", "Skip frames", #ifdef HAVE_BACKLIGHT_BRIGHTNESS - [MPEG_OPTION_BACKLIGHT_BRIGHTNESS] = - { "Backlight brightness", NULL }, + "Backlight brightness", #endif - }; + ); - menu_id = menu_init(items, ARRAYLEN(items), - mpeg_menu_sysevent_callback, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) { mpeg_menu_sysevent_clear(); - result = menu_show(menu_id); + result = rb->do_menu(&menu, &selected, NULL, false); switch (result) { @@ -1014,38 +978,24 @@ if (mpeg_menu_sysevent() != 0) menu_quit = true; } - - menu_exit(menu_id); } static void audio_options(void) { + int selected = 0; int result; - int menu_id; bool menu_quit = false; - static const struct menu_item items[] = { - [MPEG_AUDIO_TONE_CONTROLS] = - { "Tone Controls", NULL }, - [MPEG_AUDIO_CHANNEL_MODES] = - { "Channel Modes", NULL }, - [MPEG_AUDIO_CROSSFEED] = - { "Crossfeed", NULL }, - [MPEG_AUDIO_EQUALIZER] = - { "Equalizer", NULL }, - [MPEG_AUDIO_DITHERING] = - { "Dithering", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Audio Options", mpeg_menu_sysevent_callback, + "Tone Controls", "Channel Modes", "Crossfeed", + "Equalizer", "Dithering"); - menu_id = menu_init(items, ARRAYLEN(items), - mpeg_menu_sysevent_callback, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) { mpeg_menu_sysevent_clear(); - result = menu_show(menu_id); + result = rb->do_menu(&menu, &selected, NULL, false); switch (result) { @@ -1087,8 +1037,6 @@ if (mpeg_menu_sysevent() != 0) menu_quit = true; } - - menu_exit(menu_id); } static void resume_options(void) @@ -1121,33 +1069,24 @@ int mpeg_menu(unsigned flags) { - int menu_id; + int selected = 0; int result; bool menu_quit = false; - int item_count; - char clear_str[32]; + static char clear_str[32]; - struct menu_item items[] = { - [MPEG_MENU_DISPLAY_SETTINGS] = - { "Display Options", NULL }, - [MPEG_MENU_AUDIO_SETTINGS] = - { "Audio Options", NULL }, - [MPEG_MENU_ENABLE_START_MENU] = - { "Resume Options", NULL }, - [MPEG_MENU_CLEAR_RESUMES] = - { clear_str, NULL }, - [MPEG_MENU_QUIT] = - { "Quit mpegplayer", NULL }, - }; + MENUITEM_STRINGLIST(menu_with_quit, "Mpegplayer Menu", + mpeg_menu_sysevent_callback, + "Display Options", "Audio Options", + "Resume Options", clear_str, "Quit mpegplayer"); + MENUITEM_STRINGLIST(menu_without_quit, "Settings", + mpeg_menu_sysevent_callback, + "Display Options", "Audio Options", + "Resume Options", clear_str); + const struct menu_item_ex *menu = &menu_with_quit; - item_count = ARRAYLEN(items); - if (flags & MPEG_MENU_HIDE_QUIT_ITEM) - item_count--; + menu = &menu_without_quit; - menu_id = menu_init(items, item_count, - mpeg_menu_sysevent_callback, NULL, NULL, NULL); - rb->button_clear_queue(); while (!menu_quit) @@ -1155,10 +1094,10 @@ mpeg_menu_sysevent_clear(); /* Format and add resume option to the menu display */ - format_menu_item(&items[MPEG_MENU_CLEAR_RESUMES], sizeof(clear_str), - "Clear all resumes: %u", settings.resume_count); + rb->snprintf(clear_str, sizeof(clear_str), + "Clear all resumes: %u", settings.resume_count); - result = menu_show(menu_id); + result = rb->do_menu(menu, &selected, NULL, false); switch (result) { @@ -1191,8 +1130,6 @@ } } - menu_exit(menu_id); - rb->lcd_clear_display(); rb->lcd_update(); Index: apps/plugins/mpegplayer/mpeg_settings.h =================================================================== --- apps/plugins/mpegplayer/mpeg_settings.h (revision 20993) +++ apps/plugins/mpegplayer/mpeg_settings.h (working copy) @@ -100,7 +100,7 @@ int mpeg_menu(unsigned flags); void mpeg_menu_sysevent_clear(void); long mpeg_menu_sysevent(void); -int mpeg_menu_sysevent_callback(int btn, int menu); +int mpeg_menu_sysevent_callback(int btn, const struct menu_item_ex *menu); void mpeg_menu_sysevent_handle(void); void init_settings(const char* filename); Index: apps/plugins/solitaire.c =================================================================== --- apps/plugins/solitaire.c (revision 20993) +++ apps/plugins/solitaire.c (working copy) @@ -790,37 +790,24 @@ int solitaire_menu(bool in_game) { - int m; + int selected = 0; int result = -1; - int i = 0; - struct menu_item items[6]; + MENUITEM_STRINGLIST(menu, "Solitaire Menu", NULL, + "Start Game", draw_option_string, + "Help", "Audio Playback", "Quit"); + MENUITEM_STRINGLIST(menu_in_game, "Solitaire Menu", NULL, + "Resume Game", "Restart Game", "Help", + "Audio Playback", "Save and Quit", "Quit"); - if( in_game ) - { - items[i++].desc = "Resume Game"; - items[i++].desc = "Restart Game"; - } - else - { - items[i++].desc = "Start Game"; - items[i++].desc = draw_option_string; - } - items[i++].desc = "Help"; - items[i++].desc = "Audio Playback"; - if( in_game ) - { - items[i++].desc = "Save and Quit"; - } - items[i++].desc = "Quit"; - create_draw_option_string(); - m = menu_init(items, i, NULL, NULL, NULL, NULL); + while (result < 0) { - switch (menu_show(m)) + switch (rb->do_menu(in_game? &menu_in_game: &menu, + &selected, NULL, false)) { - case MENU_SELECTED_EXIT: + default: result = MENU_RESUME; break; @@ -866,7 +853,6 @@ break; } } - menu_exit(m); return result; } Index: apps/plugins/doom/rockdoom.c =================================================================== --- apps/plugins/doom/rockdoom.c (revision 20993) +++ apps/plugins/doom/rockdoom.c (working copy) @@ -39,7 +39,6 @@ #include "i_system.h" #include "hu_stuff.h" #include "st_stuff.h" -#include "lib/oldmenuapi.h" #include "lib/helper.h" PLUGIN_HEADER @@ -217,8 +216,8 @@ }; int namemap[7]; -static struct menu_item *addons; -static struct menu_item *demolmp; +static char **addons; +static char **demolmp; char addon[200]; // This sets up the base game and builds up myargv/c bool Dhandle_ver (int dver) @@ -274,14 +273,14 @@ if(argvlist.addonnum) { - snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum].desc); + snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum]); D_AddFile(addon,source_pwad); modifiedgame = true; } if(argvlist.demonum) { - snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum].desc); + snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum]); D_AddFile(addon, source_lmp); G_DeferedPlayDemo(addon); singledemo = true; // quit after one demo @@ -323,21 +322,20 @@ // This is a general function that takes in a menu_item structure and makes a list // of files within it based on matching the string stringmatch to the files. -int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory, char *stringmatch) +int Dbuild_filelistm(char ***names, char *firstentry, char *directory, char *stringmatch) { int i=0; DIR *filedir; struct dirent *dptr; char *startpt; - struct menu_item *temp; + char **temp; filedir=rb->opendir(directory); if(filedir==NULL) { - temp=malloc(sizeof(struct menu_item)); - temp[0].desc=firstentry; - temp[0].function=0; + temp=malloc(sizeof(char *)); + temp[0]=firstentry; *names=temp; return 1; } @@ -351,9 +349,8 @@ filedir=rb->opendir(directory); i++; - temp=malloc(i*sizeof(struct menu_item)); - temp[0].desc=firstentry; - temp[0].function=0; + temp=malloc(i*sizeof(char *)); + temp[0]=firstentry; i=1; while((dptr=rb->readdir(filedir))) @@ -362,8 +359,7 @@ { startpt=malloc(strlen(dptr->d_name)*sizeof(char)); strcpy(startpt,dptr->d_name); - temp[i].desc=startpt; - temp[i].function=0; + temp[i]=startpt; i++; } } @@ -444,7 +440,7 @@ int Oset_keys() { - int m, result; + int selected=0, result; int menuquit=0; @@ -483,36 +479,24 @@ int numdoomkeys=sizeof(doomkeys) / sizeof(*doomkeys); - static const struct menu_item items[] = { - { "Game Right", NULL }, - { "Game Left", NULL }, - { "Game Up", NULL }, - { "Game Down", NULL }, - { "Game Shoot", NULL }, - { "Game Open", NULL }, - { "Game Strafe", NULL }, - { "Game Weapon", NULL }, - { "Game Automap", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Set Keys", NULL, + "Game Right", "Game Left", "Game Up", "Game Down", + "Game Shoot", "Game Open", "Game Strafe", + "Game Weapon", "Game Automap"); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - while(!menuquit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); if(result<0) menuquit=1; else { *keys[result]=translatekey(*keys[result]); - rb->set_option(items[result].desc, keys[result], INT, doomkeys, numdoomkeys, NULL ); + rb->set_option(menu_[result], keys[result], INT, doomkeys, numdoomkeys, NULL ); *keys[result]=translatekey(*keys[result]); } } - menu_exit(m); - return (1); } @@ -525,24 +509,17 @@ { "On", -1 }, }; - int m, result; + int selected=0, result; int menuquit=0; - static const struct menu_item items[] = { - { "Set Keys", NULL }, - { "Sound", NULL }, - { "Timedemo", NULL }, - { "Player Bobbing", NULL }, - { "Weapon Recoil", NULL }, - { "Translucency", NULL }, - { "Fake Contrast", NULL }, - { "Always Run", NULL }, - { "Headsup Display", NULL }, - { "Statusbar Always Red", NULL }, + MENUITEM_STRINGLIST(menu, "Options", NULL, + "Set Keys", "Sound", "Timedemo", "Player Bobbing", + "Weapon Recoil", "Translucency", "Fake Contrast", + "Always Run", "Headsup Display", "Statusbar Always Red", #if(LCD_HEIGHT>LCD_WIDTH) - { "Rotate Screen 90 deg", NULL }, + "Rotate Screen 90 deg", #endif - }; + ); void *options[]={ &enable_sound, @@ -559,36 +536,48 @@ #endif }; - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - while(!menuquit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); if(result==0) Oset_keys(); else if (result > 0) - rb->set_option(items[result].desc, options[result-1], INT, onoff, 2, NULL ); + rb->set_option(menu_[result], options[result-1], INT, onoff, 2, NULL ); else menuquit=1; } - menu_exit(m); - return (1); } -int menuchoice(struct menu_item *menu, int items) +char* choice_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) { - int m, result; - - m = menu_init(menu, items,NULL, NULL, NULL, NULL); + char **names = (char **) data; + (void) buffer; + (void) buffer_len; + return names[selected_item]; +} +int list_action_callback(int action, struct gui_synclist *lists) +{ + (void) lists; + if (action == ACTION_STD_OK) + return ACTION_STD_CANCEL; + return action; +} +bool menuchoice(char **names, int count, int *selected) +{ + struct simplelist_info info; + rb->simplelist_info_init(&info, NULL, count, (void*)names); + info.selection = *selected; + info.get_name = choice_get_name; + info.action_callback = list_action_callback; + if(rb->simplelist_show_list(&info)) + return true; - result= menu_show(m); - menu_exit(m); - if(result=0) - return result; - return 0; + if(info.selection=0) + *selected = info.selection; + return false; } // @@ -596,22 +585,16 @@ // int doom_menu() { - int m; - int result; + int selected=0, result; int status; int gamever; bool menuquit=0; static struct opt_items names[7]; - static const struct menu_item items[] = { - { "Game", NULL }, - { "Addons", NULL }, - { "Demos", NULL }, - { "Options", NULL }, - { "Play Game", NULL }, - { "Quit", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Doom Menu", NULL, + "Game", "Addons", "Demos", + "Options", "Play Game", "Quit"); if( (status=Dbuild_base(names)) == 0 ) // Build up the base wad files (select last added file) { @@ -632,23 +615,20 @@ while (rb->button_get(false) != BUTTON_NONE) rb->yield(); - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - while(!menuquit) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch (result) { case 0: /* Game picker */ rb->set_option("Game WAD", &gamever, INT, names, status, NULL ); break; case 1: /* Addon picker */ - argvlist.addonnum=menuchoice(addons,numadd); + menuchoice(addons,numadd,&argvlist.addonnum); break; case 2: /* Demos */ - argvlist.demonum=menuchoice(demolmp,numdemos); + menuchoice(demolmp,numdemos,&argvlist.demonum); break; case 3: /* Options */ @@ -669,8 +649,6 @@ } } - menu_exit(m); - return (gamever); } Index: apps/plugins/rockboy/menu.c =================================================================== --- apps/plugins/rockboy/menu.c (revision 20993) +++ apps/plugins/rockboy/menu.c (working copy) @@ -8,7 +8,6 @@ #include "rockmacros.h" #include "mem.h" #include "save.h" -#include "lib/oldmenuapi.h" #include "rtc-gb.h" #include "pcm.h" @@ -85,7 +84,7 @@ */ int do_user_menu(void) { bool done=false; - int m, ret=0; + int selected=0, ret=0; int result; int time = 0; @@ -97,20 +96,15 @@ while (rb->button_get(false) != BUTTON_NONE) rb->yield(); - static const struct menu_item items[] = { - {"Load Game", NULL }, - {"Save Game", NULL }, - {"Options", NULL }, - {"Quit", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Rockboy Menu", NULL, + "Load Game", "Save Game", + "Options", "Quit"); pcm_init(); - m = menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - while(!done) { - result=menu_show(m); + result = rb->do_menu(&menu, &selected, NULL, false); switch (result) { @@ -133,8 +127,6 @@ } } - menu_exit(m); - rb->lcd_setfont(0); /* Reset the font */ rb->lcd_clear_display(); /* Clear display for screen size changes */ @@ -288,50 +280,66 @@ } } +/* + * slot_get_name + */ +static char *slot_get_name(int selected_item, void * data, + char * buffer, size_t buffer_len) +{ + char **items = (char**)data; + (void) buffer; + (void) buffer_len; + return items[selected_item]; +} + /* + * list_action_callback + */ +static int list_action_callback(int action, struct gui_synclist *lists) +{ + (void) lists; + if (action == ACTION_STD_OK) + return ACTION_STD_CANCEL; + return action; +} + +/* * do_slot_menu - prompt the user for a load/save memory slot */ static void do_slot_menu(bool is_load) { bool done=false; - char buf[5][20]; - - int m; int result; int i; - - struct menu_item items[] = { - { buf[0] , NULL }, - { buf[1] , NULL }, - { buf[2] , NULL }, - { buf[3] , NULL }, - { buf[4] , NULL }, - }; - + char *items[] = { buf[0], buf[1], buf[2], buf[3], buf[4] }; int num_items = sizeof(items) / sizeof(*items); + struct simplelist_info info; /* create menu items */ for (i = 0; i < num_items; i++) slot_info(buf[i], 20, i); - m = menu_init(items, num_items, NULL, NULL, NULL, NULL); + rb->simplelist_info_init(&info, NULL, num_items, (void *)items); + info.get_name = slot_get_name; + info.action_callback = list_action_callback; while(!done) { - result=menu_show(m); - + if(rb->simplelist_show_list(&info)) + break; + + result = info.selection; if (result= 0 ) done = do_slot(result, is_load); else done = true; } - menu_exit(m); } static void do_opt_menu(void) { bool done=false; - int m; + int selected=0; int result; static const struct opt_items onoff[2] = { @@ -379,63 +387,54 @@ }; #endif - static const struct menu_item items[] = { - { "Max Frameskip", NULL }, - { "Sound" , NULL }, - { "Stats" , NULL }, - { "Set Keys (Buggy)", NULL }, + MENUITEM_STRINGLIST(menu, "Options", NULL, + "Max Frameskip", "Sound", "Stats", "Set Keys (Buggy)", #ifdef HAVE_LCD_COLOR - { "Screen Size" , NULL }, - { "Screen Rotate" , NULL }, - { "Set Palette" , NULL }, + "Screen Size", "Screen Rotate", "Set Palette", #endif - }; + ); - m = menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - options.dirty=1; /* Assume that the settings have been changed */ while(!done) { - - result=menu_show(m); - + result = rb->do_menu(&menu, &selected, NULL, false); + switch (result) { case 0: /* Frameskip */ - rb->set_option(items[0].desc, &options.maxskip, INT, frameskip, + rb->set_option("Max Frameskip", &options.maxskip, INT, frameskip, sizeof(frameskip)/sizeof(*frameskip), NULL ); break; case 1: /* Sound */ if(options.sound>1) options.sound=1; - rb->set_option(items[1].desc, &options.sound, INT, onoff, 2, NULL ); + rb->set_option("Sound", &options.sound, INT, onoff, 2, NULL ); if(options.sound) sound_dirty(); break; case 2: /* Stats */ - rb->set_option(items[2].desc, &options.showstats, INT, onoff, 2, NULL ); + rb->set_option("Stats", &options.showstats, INT, onoff, 2, NULL ); break; case 3: /* Keys */ setupkeys(); break; #ifdef HAVE_LCD_COLOR case 4: /* Screen Size */ - rb->set_option(items[4].desc, &options.scaling, INT, scaling, + rb->set_option("Screen Size", &options.scaling, INT, scaling, sizeof(scaling)/sizeof(*scaling), NULL ); setvidmode(); break; case 5: /* Screen rotate */ - rb->set_option(items[5].desc, &options.rotate, INT, onoff, 2, NULL ); + rb->set_option("Screen Rotate", &options.rotate, INT, onoff, 2, NULL ); setvidmode(); break; case 6: /* Palette */ - rb->set_option(items[6].desc, &options.pal, INT, palette, 17, NULL ); + rb->set_option("Set Palette", &options.pal, INT, palette, 17, NULL ); set_pal(); break; -#endif +#endif default: done=true; break; } } - menu_exit(m); } Index: apps/plugins/viewer.c =================================================================== --- apps/plugins/viewer.c (revision 20993) +++ apps/plugins/viewer.c (working copy) @@ -22,7 +22,6 @@ #include "plugin.h" #include #include "lib/playback_control.h" -#include "lib/oldmenuapi.h" PLUGIN_HEADER @@ -1448,30 +1447,37 @@ &prefs.autoscroll_speed, NULL, 1, 1, 10, NULL); } +MENUITEM_FUNCTION(encoding_item, 0, "Encoding", encoding_setting, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(word_wrap_item, 0, "Word Wrap", word_wrap_setting, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(line_mode_item, 0, "Line Mode", line_mode_setting, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(view_mode_item, 0, "Wide View", view_mode_setting, + NULL, NULL, Icon_NOICON); +#ifdef HAVE_LCD_BITMAP +MENUITEM_FUNCTION(scrollbar_item, 0, "Show Scrollbar", scrollbar_setting, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(page_mode_item, 0, "Overlap Pages", page_mode_setting, + NULL, NULL, Icon_NOICON); +#endif +MENUITEM_FUNCTION(scroll_mode_item, 0, "Scroll Mode", scroll_mode_setting, + NULL, NULL, Icon_NOICON); +MENUITEM_FUNCTION(autoscroll_speed_item, 0, "Auto-Scroll Speed", + autoscroll_speed_setting, NULL, NULL, Icon_NOICON); +MAKE_MENU(option_menu, "Viewer Options", NULL, Icon_NOICON, + &encoding_item, &word_wrap_item, &line_mode_item, &view_mode_item, +#ifdef HAVE_LCD_BITMAP + &scrollbar_item, &page_mode_item, +#endif + &scroll_mode_item, &autoscroll_speed_item); + static bool viewer_options_menu(void) { - int m; bool result; + result = (rb->do_menu(&option_menu, NULL, NULL, false) == MENU_ATTACHED_USB); - static const struct menu_item items[] = { - {"Encoding", encoding_setting }, - {"Word Wrap", word_wrap_setting }, - {"Line Mode", line_mode_setting }, - {"Wide View", view_mode_setting }, #ifdef HAVE_LCD_BITMAP - {"Show Scrollbar", scrollbar_setting }, - {"Overlap Pages", page_mode_setting }, -#endif - {"Scroll Mode", scroll_mode_setting}, - {"Auto-Scroll Speed", autoscroll_speed_setting }, - }; - m = menu_init(items, sizeof(items) / sizeof(*items), - NULL, NULL, NULL, NULL); - - result = menu_run(m); - menu_exit(m); -#ifdef HAVE_LCD_BITMAP - /* Show-scrollbar mode for current view-width mode */ init_need_scrollbar(); #endif @@ -1480,21 +1486,15 @@ static void viewer_menu(void) { - int m; int result; - static const struct menu_item items[] = { - {"Quit", NULL }, - {"Viewer Options", NULL }, - {"Show Playback Menu", NULL }, - {"Return", NULL }, - }; + MENUITEM_STRINGLIST(menu, "Viewer Menu", NULL, + "Quit", "Viewer Options", + "Show Playback Menu", "Return"); - m = menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL); - result=menu_show(m); + result = rb->do_menu(&menu, NULL, NULL, false); switch (result) { case 0: /* quit */ - menu_exit(m); viewer_exit(NULL); done = true; break; @@ -1507,7 +1507,6 @@ case 3: /* return */ break; } - menu_exit(m); viewer_draw(col); } Index: apps/plugins/chessclock.c =================================================================== --- apps/plugins/chessclock.c (revision 20993) +++ apps/plugins/chessclock.c (working copy) @@ -298,7 +298,6 @@ #define FLAGS_SET_INT_SECONDS 1 static char * show_time(int secs); -static int simple_menu(int nr, unsigned char **strarr); static bool pause; @@ -514,53 +513,57 @@ /* MENU */ case CHC_MENU: { - int ret; - char *menu[]={"Delete player", "Restart round", - "Set round time", "Set total time"}; - ret=simple_menu(4, (unsigned char **)menu); - if (ret==-1) { - retval = 3; - done=true; - } else if (ret==-2) { - } else if (ret==0) { - /* delete timer */ - timer_holder[nr].hidden=true; - retval=1; - done=true; - break; - } else if (ret==1) { - /* restart */ - ticks=0; - break; - } else if (ret==2) { - /* set round time */ - int res; - int val=(max_ticks-ticks)/HZ; - res=chessclock_set_int("Round time", - &val, - 10, 0, MAX_TIME, - FLAGS_SET_INT_SECONDS); - if (res==-1) { /*usb*/ - retval = 3; + MENUITEM_STRINGLIST(menu, "Menu", NULL, + "Delete player", "Restart round", + "Set round time", "Set total time"); + + int val, res; + switch(rb->do_menu(&menu, NULL, NULL, false)) + { + case 0: + /* delete timer */ + timer_holder[nr].hidden=true; + retval=1; done=true; - } else if (res==1) { - ticks=max_ticks-val*HZ; - } - } else if (ret==3) { - /* set total time */ - int res; - int val=timer_holder[nr].total_time; - res=chessclock_set_int("Total time", - &val, - 10, 0, MAX_TIME, - FLAGS_SET_INT_SECONDS); - if (res==-1) { /*usb*/ + break; + case 1: + /* restart */ + ticks=0; + break; + case 2: + /* set round time */ + val=(max_ticks-ticks)/HZ; + res=chessclock_set_int("Round time", + &val, + 10, 0, MAX_TIME, + FLAGS_SET_INT_SECONDS); + if (res==-1) { /*usb*/ + retval = 3; + done=true; + } else if (res==1) { + ticks=max_ticks-val*HZ; + } + break; + case 3: + /* set total time */ + val=timer_holder[nr].total_time; + res=chessclock_set_int("Total time", + &val, + 10, 0, MAX_TIME, + FLAGS_SET_INT_SECONDS); + if (res==-1) { /*usb*/ + retval = 3; + done=true; + } else if (res==1) { + timer_holder[nr].total_time=val; + } + break; + case MENU_ATTACHED_USB: retval = 3; done=true; - } else if (res==1) { - timer_holder[nr].total_time=val; - } + break; } + rb->lcd_clear_display(); } break; @@ -664,55 +667,3 @@ return buf; } -/* -1 = USB - -2 = cancel -*/ -static int simple_menu(int nr, unsigned char **strarr) -{ - int show=0; - int button; - rb->lcd_clear_display(); - - while (1) { - if (show>=nr) - show=0; - if (show<0) - show=nr-1; - rb->lcd_puts_scroll(0, FIRST_LINE, strarr[show]); - rb->lcd_update(); - - button = rb->button_get(true); - switch(button) { - case CHC_SETTINGS_INC: - case CHC_SETTINGS_INC | BUTTON_REPEAT: - show++; - break; - - case CHC_SETTINGS_DEC: - case CHC_SETTINGS_DEC | BUTTON_REPEAT: - show--; - break; - - case CHC_SETTINGS_OK: -#ifdef CHC_SETTINGS_OK2 - case CHC_SETTINGS_OK2: -#endif - return show; - break; - - case CHC_SETTINGS_CANCEL: -#ifdef CHC_SETTINGS_CANCEL2 - case CHC_SETTINGS_CANCEL2: -#endif - return -2; /* cancel */ - break; - - default: - if (rb->default_event_handler(button) == SYS_USB_CONNECTED) - return -1; /* been in usb mode */ - break; - } - } -} - -