void menu_connect_start(component *c, void *userdata) { scene *s = userdata; connect_menu_data *local = menu_get_userdata(c->parent); ENetAddress address; const char *addr = textinput_value(local->addr_input); s->gs->role = ROLE_CLIENT; // Free old saved address, and set new free(settings_get()->net.net_connect_ip); settings_get()->net.net_connect_ip = strdup(addr); // Set up enet host local->host = enet_host_create(NULL, 1, 2, 0, 0); if(local->host == NULL) { DEBUG("Failed to initialize ENet client"); return; } // Disable connect button and address input field component_disable(local->connect_button, 1); component_disable(local->addr_input, 1); menu_select(c->parent, local->cancel_button); // Set address enet_address_set_host(&address, addr); address.port = settings_get()->net.net_connect_port; ENetPeer *peer = enet_host_connect(local->host, &address, 2, 0); if(peer == NULL) { DEBUG("Unable to connect to %s", addr); enet_host_destroy(local->host); local->host = NULL; } time(&local->connect_start); }
int main(int argc, char* argv[]) { Menu* menu = menu_create(5); menu_add_title(menu, "Topwise company"); menu_add_title(menu, "Hello"); menu_add_item(menu, "hello", hello_print, (void*)HELLO_MSG, NULL); menu_add_item(menu, "weather", hello_print, (void*)WEATHER_MSG, NULL); menu_select(menu, 0); menu_select(menu, 1); menu_destroy(menu); return 0; }
void keyboard(unsigned char c, int x, int y) { switch (c) { case 27: exit(0); break; case ' ': menu_select(1); break; case 's': case 'S': menu_select(2); break; case 'm': case 'M': menu_select(3); break; #ifdef GL_EXT_texture_filter_anisotropic case 'f': case 'F': menu_select(4); break; #endif #ifdef GL_EXT_texture_lod_bias case 'a': case 'A': lodBias += 0.95; case '+': lodBias += 0.05; glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, lodBias); glutPostRedisplay(); printf("texture lod bias = %f\n", lodBias); break; case 'z': case 'Z': lodBias -= 0.95; case '-': lodBias -= 0.05; glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, lodBias); glutPostRedisplay(); printf("texture lod bias = %f\n", lodBias); break; #endif } }
/* * Handle character death */ void death_screen(void) { bool done = FALSE; const region area = { 51, 2, 0, N_ELEMENTS(death_actions) }; /* Retire in the town in a good state */ if (p_ptr->total_winner) { p_ptr->depth = 0; my_strcpy(p_ptr->died_from, "Ripe Old Age", sizeof(p_ptr->died_from)); p_ptr->exp = p_ptr->max_exp; p_ptr->lev = p_ptr->max_lev; p_ptr->au += 10000000L; display_winner(); } /* Get time of death */ (void)time(&death_time); print_tomb(); death_knowledge(); enter_score(&death_time); /* Flush all input and output */ flush(); message_flush(); /* Display and use the death menu */ if (!death_menu) { death_menu = menu_new_action(death_actions, N_ELEMENTS(death_actions)); death_menu->flags = MN_CASELESS_TAGS; } menu_layout(death_menu, &area); while (!done) { ui_event e = menu_select(death_menu, EVT_KBRD); if (e.type == EVT_KBRD) { if (e.key.code == KTRL('X')) break; } else if (e.type == EVT_SELECT) { done = get_check("Do you want to quit? "); } } /* Save dead player */ if (!savefile_save(savefile)) { msg("death save failed!"); message_flush(); } }
/** * Display list of curses to choose from */ int curse_menu(struct object *obj) { menu_iter menu_f = { 0, 0, get_curse_display, get_curse_action, 0 }; struct menu *m = menu_new(MN_SKIN_SCROLL, &menu_f); int row; unsigned int length = 0; int i, count = 0; size_t array_size = z_info->curse_max * sizeof(struct curse_menu_data); struct curse_menu_data *available = mem_zalloc(array_size); static region area = { 20, 1, -1, -2 }; /* Count and then list the curses */ for (i = 1; i < z_info->curse_max; i++) { if (obj->curses[i].power) { available[count].index = i; available[count].power = obj->curses[i].power; length = MAX(length, strlen(curses[i].name)); count++; } } if (!count) { mem_free(available); return 0; } /* Set up the menu */ menu_setpriv(m, count, available); m->header = "Remove which curse?"; m->selections = lower_case; m->flags = (MN_PVT_TAGS); m->browse_hook = curse_menu_browser; /* Set up the item list variables */ selection = 0; /* Set up the menu region */ area.page_rows = m->count + 1; area.row = 1; area.col = (Term->wid - 1 - length) / 2; if (area.col <= 3) area.col = 0; area.width = MAX(length + 1, strlen(m->header)); for (row = area.row; row < area.row + area.page_rows; row++) prt("", row, MAX(0, area.col - 1)); menu_layout(m, &area); /* Choose */ menu_select(m, 0, true); /* Clean up */ mem_free(available); mem_free(m); /* Result */ return selection; }
/** * Handle character death */ void death_screen(void) { const region area = { 51, 2, 0, N_ELEMENTS(death_actions) }; /* Dump bones file */ make_bones(); /* Handle retirement */ if (p_ptr->total_winner) kingly(); /* Save dead player */ if (!old_save()) { msg_print("death save failed!"); message_flush(); } /* Get time of death */ #ifdef _WIN32_WCE { unsigned long fake_time(unsigned long *fake_time_t); fake_time(&death_time); } #else (void) time(&death_time); #endif /* You are dead */ print_tomb(); /* Hack - Know everything upon death */ death_knowledge(); /* Enter player in high score list */ enter_score(&death_time); /* Flush all input keys */ flush(); /* Flush messages */ msg_print(NULL); if (!death_menu) { death_menu = menu_new_action(death_actions, N_ELEMENTS(death_actions)); death_menu->flags = MN_CASELESS_TAGS; } menu_layout(death_menu, &area); do { menu_select(death_menu, 0); } while (!get_check("Do you want to quit? ")); }
/** * Display list of monster traps. */ bool trap_menu(void) { menu_type menu; menu_iter menu_f = { trap_tag, 0, trap_display, trap_action, 0 }; region area = { 15, 1, 48, -1 }; ui_event_data evt = { EVT_NONE, 0, 0, 0, 0 }; size_t i, num = 0; u16b *choice; /* See how many traps available */ if (player_has(PF_EXTRA_TRAP)) num = 1 + (p_ptr->lev / 4); else num = 1 + (p_ptr->lev / 6); /* Create the array */ choice = C_ZNEW(num, u16b); /* Obvious */ for (i = 0; i < num; i++) { choice[i] = i; } /* Clear space */ area.page_rows = num + 2; /* Return here if there are no traps */ if (!num) { FREE(choice); return FALSE; } /* Save the screen and clear it */ screen_save(); /* Help text */ /* Set up the menu */ WIPE(&menu, menu); menu_init(&menu, MN_SKIN_SCROLL, &menu_f); menu.title = "Choose an advanced monster trap (ESC to cancel):"; menu_setpriv(&menu, num, choice); menu_layout(&menu, &area); prt("", area.row + 1, area.col); /* Select an entry */ evt = menu_select(&menu, 0); /* Free memory */ FREE(choice); /* Load screen */ screen_load(); return (evt.type != EVT_ESCAPE); }
/** * Display list of curses to choose from */ struct curse *curse_menu(struct object *obj) { menu_iter menu_f = { 0, 0, get_curse_display, get_curse_action, 0 }; struct menu *m = menu_new(MN_SKIN_SCROLL, &menu_f); int row; unsigned int length = 0; int count = 0; struct curse *curse = obj->curses; struct curse **available; static region area = { 20, 1, -1, -2 }; /* Count and then list the curses */ while (curse) { count++; curse = curse->next; } if (!count) { return NULL; } available = mem_zalloc(count * sizeof(struct curse *)); count = 0; for (curse = obj->curses; curse; curse = curse->next) { available[count++] = curse; length = MAX(length, strlen(curse->name)); } /* Set up the menu */ menu_setpriv(m, count, available); m->header = "Remove which curse?"; m->selections = lower_case; m->flags = (MN_PVT_TAGS); m->browse_hook = curse_menu_browser; /* Set up the item list variables */ selection = NULL; /* Set up the menu region */ area.page_rows = m->count + 1; area.row = 1; area.col = (Term->wid - 1 - length) / 2; if (area.col <= 3) area.col = 0; area.width = MAX(length + 1, strlen(m->header)); for (row = area.row; row < area.row + area.page_rows; row++) prt("", row, MAX(0, area.col - 1)); menu_layout(m, &area); /* Choose */ menu_select(m, 0, true); /* Clean up */ mem_free(m); /* Result */ return selection; }
int ogl_mjksift_main(int argc, char **argv) { int minify_menu, rate_menu; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutCreateWindow("mjksift"); glutDisplayFunc(ogl_mjksift_redraw); glMatrixMode(GL_PROJECTION); gluPerspective( /* field of view in degree */ 40.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 70.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0.0, 0.0, 5.0, /* eye is at (0,0,30) */ 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.); /* up is in positive Y direction */ depth = mjk_depth; width = mjk_width; height = mjk_height; bits = mjk_image; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gluBuild2DMipmaps(GL_TEXTURE_2D, depth, width, height, GL_RGB, GL_UNSIGNED_BYTE, bits); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glEnable(GL_TEXTURE_2D); glutVisibilityFunc(ogl_mjksift_visibility); minify_menu = glutCreateMenu(minify_select); glutAddMenuEntry("Nearest", GL_NEAREST); glutAddMenuEntry("Linear", GL_LINEAR); glutAddMenuEntry("Nearest mipmap nearest", GL_NEAREST_MIPMAP_NEAREST); glutAddMenuEntry("Linear mipmap nearest", GL_LINEAR_MIPMAP_NEAREST); glutAddMenuEntry("Nearest mipmap linear", GL_NEAREST_MIPMAP_LINEAR); glutAddMenuEntry("Linear mipmap linear", GL_LINEAR_MIPMAP_LINEAR); rate_menu = glutCreateMenu(rate_select); glutAddMenuEntry(" 2/sec", 500); glutAddMenuEntry(" 6/sec", 166); glutAddMenuEntry("10/sec", 100); glutAddMenuEntry("20/sec", 50); glutAddMenuEntry("30/sec", 33); glutAddMenuEntry("60/sec", 16); glutCreateMenu(menu_select); glutAddMenuEntry("Toggle sifting", 1); glutAddMenuEntry("Toggle scaling", 2); glutAddSubMenu("Minimum frame rate", rate_menu); glutAddSubMenu("Minify modes", minify_menu); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); menu_select(3); generateTexturedSurface(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
void menu_select(struct menu *menu, struct menu_item *item) { if (menu->child) return menu_select(menu->child, item); if (menu->selector) menu->selector->owner->selector = NULL; menu->selector = item; item->owner->selector = item; }
static void watchfile_view(struct menu *menu) { /* initialize menus */ watchfile_menu_init(); watchfile_scroll = 0; /* configure menus */ for (int i = 0; i < WATCHFILE_VIEW_ROWS; ++i) { if (i < watchfile_entries.size) menu_item_enable(watchfile_items[i]); else menu_item_disable(watchfile_items[i]); } if (watchfile_entries.size > 0) menu_select(&watchfile_menu, watchfile_items[0]); else menu_select(&watchfile_menu, watchfile_return); menu_enter(menu, &watchfile_menu); }
int main(void) { const char *items[] = {"fee fie", "huff and puff", "mirror mirror", "tick tock", NULL}; const char *prompt = "Which is from the three pigs?"; printf("You chose %s.\n", menu_select(items, prompt)); return EXIT_SUCCESS; }
// This is the main function, where the code starts. All C programs // must have a main() function defined somewhere. int main() { // set up the 3pi initialize(); // This is the "main loop" - it will run forever. while(1) { menu_select(); } }
/** * Display list of places to jump to. */ bool jump_menu(int level, int *location) { menu_type menu; menu_iter menu_f = { jump_tag, 0, jump_display, jump_action, 0 }; region area = { 15, 1, 48, -1 }; ui_event_data evt = { EVT_NONE, 0, 0, 0, 0 }; int cursor = 0, j = 0; size_t i; u16b *choice; /* Dungeon only is easy */ if (OPT(adult_dungeon)) { *location = level + 1; return TRUE; } /* Create the array */ choice = C_ZNEW(15, u16b); /* Get the possible stages */ for (i = 0; i < NUM_STAGES; i++) if ((stage_map[i][DEPTH] == level) && (stage_map[i][LOCALITY] != 0)) choice[j++] = i; /* Clear space */ area.page_rows = j + 2; /* Save the screen and clear it */ screen_save(); /* Set up the menu */ WIPE(&menu, menu); menu.title = "Which region do you want to be transported to?"; menu.cmd_keys = " \n\r"; menu_init(&menu, MN_SKIN_SCROLL, &menu_f); menu_setpriv(&menu, j, choice); menu_layout(&menu, &area); /* Select an entry */ evt = menu_select(&menu, cursor); /* Set it */ if (evt.type == EVT_SELECT) *location = place; /* Free memory */ FREE(choice); /* Load screen */ screen_load(); return (evt.type != EVT_ESCAPE); }
/************************************************************************ * * * Purpose: Handles the main menu * * * * Proposito: Maneja el menu principal * * * * Passed: None * * Argumento: Nada * * Returned: None * * Retorno: Nada * * Note: * * * * * ************************************************************************/ void menu_mainmenu(void) { menu_drawmain(); while (1) { readbuttons(); if (enter==PRESSED) { return; } if ((up==!PRESSED)&&(down==PRESSED)) { i+=1; menu_select(i,0); } if ((up==PRESSED)&&(down==!PRESSED)) { i-=1; menu_select(i,0); } if (right==PRESSED) { if (i) { menu_submenu(i); } if (i==0) { menu_drawmain(); } } button = !PRESSED; } }
// Gekuerzte Main-Funktion int main(void) { while (1) { // In Endlosschleife wechseln wdt_reset(); // Watchdog zuruecksetzen if (get_key_press(1 << KEY1)) // 1 - Zurueck menu_exit(&menu_context); if( get_key_press(1 << KEY2)) // 2 - Hoch menu_prev_entry(&menu_context); if (get_key_press(1 << KEY3)) // 3 - Runter menu_next_entry(&menu_context); if (get_key_press(1 << KEY4)) // 4 - Ok menu_select(&menu_context); } }
/** * Display list of svals to be ignored. */ static bool sval_menu(int tval, const char *desc) { struct menu *menu; region area = { 1, 2, -1, -1 }; ignore_choice *choices; int n_choices = ignore_collect_kind(tval, &choices); if (!n_choices) return false; /* Sort by name in ignore menus except for categories of items that are * aware from the start */ switch (tval) { case TV_LIGHT: case TV_MAGIC_BOOK: case TV_PRAYER_BOOK: case TV_DRAG_ARMOR: case TV_GOLD: /* leave sorted by sval */ break; default: /* sort by name */ sort(choices, n_choices, sizeof(*choices), cmp_ignore); } /* Save the screen and clear it */ screen_save(); clear_from(0); /* Help text */ prt(format("Ignore the following %s:", desc), 0, 0); /* Run menu */ menu = menu_new(MN_SKIN_COLUMNS, &ignore_sval_menu); menu_setpriv(menu, n_choices, choices); menu->cmd_keys = "Tt"; menu_layout(menu, &area); menu_set_cursor_x_offset(menu, 1); /* Place cursor in brackets. */ menu_select(menu, 0, false); /* Free memory */ mem_free(choices); /* Load screen */ screen_load(); return true; }
/* * Handle character death */ void death_screen(void) { const region area = { 51, 2, 0, N_ELEMENTS(death_actions) }; /* Retire in the town in a good state */ if (p_ptr->total_winner) { p_ptr->depth = 0; my_strcpy(p_ptr->died_from, "Ripe Old Age", sizeof(p_ptr->died_from)); p_ptr->exp = p_ptr->max_exp; p_ptr->lev = p_ptr->max_lev; p_ptr->au += 10000000L; display_winner(); } /* Save dead player */ if (!savefile_save(savefile)) { msg("death save failed!"); message_flush(); } /* Get time of death */ (void)time(&death_time); print_tomb(); death_knowledge(); enter_score(&death_time); /* Flush all input and output */ flush(); message_flush(); if (!death_menu) { death_menu = menu_new_action(death_actions, N_ELEMENTS(death_actions)); death_menu->flags = MN_CASELESS_TAGS; } menu_layout(death_menu, &area); do { menu_select(death_menu, 0); } while (!get_check("Do you want to quit? ")); }
/** * Run the spell menu, without selections. */ static void spell_menu_browse(struct menu *m, const char *noun) { struct spell_menu_data *d = menu_priv(m); screen_save(); region_erase_bordered(&m->active); prt(format("Browsing %ss. ('?' to toggle description)", noun), 0, 0); d->browse = TRUE; menu_select(m, 0, TRUE); screen_load(); }
int main(void) { game_t game; menu_t main_menu; VMGPFONT small_font; int submenus[1]; bool_t done = FALSE; small_font.width = 4; small_font.height = 6; small_font.bpp = 1; small_font.palindex = 1; small_font.chartbl = SMALL_FONT+16; /* Which characters are present in the font? */ small_font.fontdata = SMALL_FONT+16+256; /* The pixel data */ get_screen_size(&screen_w, &screen_h); game_init(&game); menu_init(&main_menu, &small_font, main_menu_msgs, 0, game.p_title_screen->height, screen_w, screen_h); while (!done) { /* Display title screen */ vSetTransferMode(MODE_BLOCK); vClearScreen(vRGB(0,0,0)); vDrawObject(0,0, game.p_title_screen); switch(menu_select(&main_menu, ~0, submenus)) { case 1: break; case 6: return 1; case -1: default: break; } vSetTransferMode(MODE_TRANS); vPlayResource(NULL,0,SOUND_FLAG_STOP); level_goto(&game, &levels[submenus[0]], pt(0, 80)); do_game(&game); } return 0; }
/** * Create Spoiler files */ void do_cmd_spoilers(void) { if (!spoil_menu) { spoil_menu = menu_new_action(spoil_actions, N_ELEMENTS(spoil_actions)); spoil_menu->selections = lower_case; spoil_menu->title = "Create spoilers"; } screen_save(); clear_from(0); menu_layout(spoil_menu, &SCREEN_REGION); menu_select(spoil_menu, 0, false); screen_load(); }
/** * Run the spell menu, without selections. */ static void spell_menu_browse(menu_type * m, const char *noun) { struct spell_menu_data *d = menu_priv(m); screen_save(); region_erase_bordered(&m->active); prt(format("Browsing %ss. Press Escape to exit.", noun), 0, 0); d->browse = TRUE; menu_select(m, 0, TRUE); screen_load(); }
static void wiz_gf_demo(void) { menu_type *m = menu_new(MN_SKIN_SCROLL, &gf_iter); region loc = { 0, 0, 0, 0 }; menu_setpriv(m, GF_MAX, NULL); m->title = "GF_ types display"; menu_layout(m, &loc); screen_save(); clear_from(0); menu_select(m, 0, FALSE); screen_load(); }
// This is the main function, where the code starts. All C programs // must have a main() function defined somewhere. int main() { // if any button is pressed, go into the old version of the test code if(button_is_pressed(ALL_BUTTONS)) test(); // activate the simpler test code // set up the robot initialize(); // This is the "main loop" - it will run forever. while(1) { menu_select(); } }
/* * Display list of svals to be squelched. */ static bool sval_menu(int tval, const char *desc) { menu_type *menu; region area = { 1, 2, -1, -1 }; squelch_choice *choices; int n_choices = squelch_collect_kind(tval, &choices); if (!n_choices) return false; /* sort by name in squelch menus except for categories of items that are aware from the start */ switch (tval) { case TV_LIGHT: case TV_MAGIC_BOOK: case TV_PRAYER_BOOK: case TV_DRAG_ARMOR: case TV_GOLD: /* leave sorted by sval */ break; default: /* sort by name */ sort(choices, n_choices, sizeof(*choices), cmp_squelch); } /* Save the screen and clear it */ screen_save(); clear_from(0); /* Help text */ prt(format("Squelch the following %s:", desc), 0, 0); /* Run menu */ menu = menu_new(MN_SKIN_COLUMNS, &squelch_sval_menu); menu_setpriv(menu, n_choices, choices); menu_layout(menu, &area); menu_select(menu, 0, false); /* Free memory */ FREE(choices); /* Load screen */ screen_load(); return true; }
/* * Choose and create an instance of an object kind */ static void wiz_create_item(void) { menu_type *menu = menu_new(MN_SKIN_COLUMNS, &wiz_create_item_menu); menu->selections = all_letters; menu->title = "What kind of object?"; screen_save(); clear_from(0); menu_setpriv(menu, N_ELEMENTS(tvals), tvals); menu_layout(menu, &wiz_create_item_area); menu_select(menu, 0); screen_load(); }
int FileTest::test() { char s[80],fname[80]; do{ int choice=menu_select(); switch(choice) { case 1: { printf("\t行号:"); gets(s); int linenum=Strtoint(s); enter(linenum); } break; case 2: { delete_text(); } break; case 3: { list(); } break; case 4: { printf("\t文件名:"); gets(fname); save(fname); } break; case 5: { printf("\t文件名:"); gets(fname); load(fname); } break; case 6: { exit(0); } break; } }while(1); }
int main(void) { char choice; init_list(); /* initialize the structure array */ for(;;) { choice = menu_select(); switch(choice) { case 1: enter(); break; case 2: del(); break; case 3: list(); break; case 4: return 0; } } }
int menu_dynamic_select(menu_type *m) { ui_event e = menu_select(m, 0, TRUE); struct menu_entry *entry; int cursor = m->cursor; //if (e.type == EVT_ESCAPE) if (e == EVT_ESCAPE) return -1; for (entry = menu_priv(m); cursor; cursor--) { entry = entry->next; assert(entry); } return entry->value; }
/** * Run the spell menu to select a spell. */ static int spell_menu_select(menu_type *m, const char *noun, const char *verb) { struct spell_menu_data *d = menu_priv(m); screen_save(); region_erase_bordered(&m->active); prt(format("%^s which %s? ", verb, noun), 0, 0); screen_save(); menu_select(m, 0); screen_load(); screen_load(); return d->selected_spell; }