static void tetrom_colors_menu(int x, int y) { const char *menu[7] = {"I", "J", "L", "O", "S", "T", "Z"}; menuhandler handlers[7] = { op_tcolor, op_tcolor, op_tcolor, op_tcolor, op_tcolor_gt4, op_tcolor_gt4, op_tcolor_gt4 }; int i = 0; if (y+6 >= term_height) y -= 7; drawbox(x, y, 19, 6, (char *) 0); x++; y++; drawmenu(menu, 4, 0, x, y, handlers); drawmenu(menu+4, 3, -1, x+9, y, handlers+4); autorep_a_b_btns = 1; while (1) { setcurs(x, y+i%4); refreshwin(-1); switch (handle_menuitem_2cols(menu, 7, &i, 4, x, y+i%4, handlers, getkeypress_block(SINGLE_PL))) { case 0: case 2: autorep_a_b_btns = 0; if (i >= 4) x -= 9; clearbox(x-1, y-1, 19, 6); return; case 3: x += i>=4 ? 9 : -9; setcurs(x, y+i%4); printmenuitem(menu[i], 1); } } }
static int hiscore_entername_menu(char *name, const char **menu, int x, int y) { int pos = 0; int i = 0; int k; while (1) { drawmenu(menu, 2, i-2, x, y+2, NULL); textbox: setcurs(x, y); printtextbox(name, pos); movefwd(3); printsavebutton(!i && pos==7); if (!i) x += pos; setcurs(x, y+i); refreshwin(-1); autorep_a_b_btns = 1; k = getkeypress_block(SINGLE_PL) & 0xFF; autorep_a_b_btns = 0; if (k == ESC) return 0; if (!i) { x -= pos; switch (k) { case STARTBTN: return 1; case '\t': if (pos < 7) break; case MVDOWN: i = 2; continue; } pos = hiscore_editname(name, pos, k); goto textbox; } switch (k) { case STARTBTN: case A_BTN: if (i==2) return 2; case 'q': exit(0); case MVUP: i = i==2 ? 0 : 2; break; case '\t': i = i==2 ? 3 : 0; break; case MVDOWN: if (i < 3) i++; } if (!i && pos==7) { pos = 6; while (pos && name[pos-1]==' ') pos--; } } }
int dropdownlist(const char **items, int n, int i, int x, int y) { int w = getdropdownwidth(items, n); int j; while (is_outside_screen(0, y+n+1)) y--; setattr_standout(); drawbox(x, y, w+2, n+2, NULL); x++; y++; setcurs(x, y); for (j = 0; j < n; j++) { printdropdownitem(items[j], i==j, w); newln(x); } while (1) { setcurs(x-1, y+i); refreshwin(-1); switch (getkeypress_block(SINGLE_PL) & 0xFF) { case STARTBTN: case A_BTN: goto out; case 'q': exit(0); case MVUP: if (!i) continue; j = -1; break; case '\t': if (i == n-1) { j = -i; break; } case MVDOWN: if (i < n-1) { j = 1; break; } case MVRIGHT: continue; default: i = -1; goto out; } setcurs(x, y+i); printdropdownitem(items[i], 0, w); i += j; setcurs(x, y+i); printdropdownitem(items[i], 1, w); } out: clearbox(x-1, y-1, w+2, n+2); return i+1; }
int openmenu(const char **menu, int n, int i, int x, int y, menuhandler *handlers) { drawmenu(menu, n, i, x, y, handlers); while (1) { setcurs(x, y+i); refreshwin(-1); /* refresh active window */ switch (handle_menuitem(menu, n, &i, x, y+i, handlers, getkeypress_block(SINGLE_PL))) { case 0: return 0; case 2: return i+1; #if !NO_MENU case 3: return openmenu(menu, n, i, x, y, handlers); #endif } } }