int main() { initscr(); start_color(); ITEM *menuitems[6]; MENU *menubar; WINDOW *win,*sub_win; int i,rows,cols; //initcolor(); menuitems[0]=new_item("File",""); menuitems[1]=new_item("Edit",""); menuitems[2]=new_item("Options",""); menuitems[3]=new_item("Window",""); menuitems[4]=new_item("Help",""); menuitems[5]=NULL; //menu_opts_off(menubar,O_ROWMAJOR); menubar=new_menu(menuitems); scale_menu(menubar,&rows,&cols); win=newwin(rows+2,cols+2,2,5); box(win,179,196); sub_win=derwin(win,rows,cols,1,1); set_menu_win(menubar,win); set_menu_sub(menubar,sub_win); post_menu(menubar); wrefresh(win); wgetch(sub_win); unpost_menu(menubar); free_menu(menubar); for(i=0;i<6;i++) free_item(menuitems[i]); endwin(); }
/** * \brief Add a slope. */ void rp::level_generator::add_slope(bear::universe::position_type& pos) { unsigned int ind = rand() % m_slopes.size(); bear::slope* new_slope; new_slope= new bear::slope( *(m_slopes[ind]) ); if ( new_slope->get_steepness() < 0 ) { new_slope->set_top_left(pos); new_item( *new_slope ); pos.x += new_slope->get_width(); pos.y += new_slope->get_steepness(); } else { pos.y += new_slope->get_steepness(); new_slope->set_top_left(pos); new_item( *new_slope ); pos.x += new_slope->get_width(); } } // rp::level_generator::add_slope()
/** * \brief Add a straight_slope. */ void rp::level_generator::add_hole (bear::universe::position_type& pos) { add_straight_slope(pos); // left_hole bear::straight_slope* new_straight_slope_1; bear::universe::position_type p1(pos); p1.y += 5; new_straight_slope_1= new bear::straight_slope( *(m_left_hole) ); new_item( *new_straight_slope_1 ); new_straight_slope_1->set_top_left(p1); pos.x += new_straight_slope_1->get_width(); // create hole hole* new_hole = new hole(); new_hole->set_size(400,50); new_hole->set_top_left(pos + bear::universe::position_type(-100,-50)); new_item( *new_hole ); pos.x += 200; // right_hole bear::straight_slope* new_straight_slope_2; bear::universe::position_type p2(pos); p2.y += 5; new_straight_slope_2 = new bear::straight_slope( *(m_right_hole) ); new_item( *new_straight_slope_2 ); new_straight_slope_2->set_top_left(p2); pos.x += new_straight_slope_2->get_width(); add_straight_slope(pos); } // level_generator::add_hole()
/** * \brief Create a star over the player. */ void ptb::invincibility_effect::create_star() { bear::star* s = new bear::star ( 5, 0.5, bear::visual::color(145, 145, 145), 1, bear::visual::color(200, 200, 20) ); const unsigned int width = 10 + 20 * (double)rand() / RAND_MAX; s->set_size(width, width); s->set_z_position( m_player.get_z_position() + 1 ); s->set_system_angle( rand() ); s->set_system_angle_as_visual_angle(true); s->set_center_of_mass ( m_player.get_left() + m_player.get_width() * (double)rand() / RAND_MAX, m_player.get_bottom() + m_player.get_height() * (double)rand() / RAND_MAX ); new_item(*s); bear::universe::forced_tracking m; m.set_reference_point_on_center(*this); s->set_forced_movement(m); const claw::tween::single_tweener tweener ( 1, 0, 0.4, boost::bind ( &bear::visual::bitmap_rendering_attributes::set_opacity, &(s->get_rendering_attributes()), _1 ), &claw::tween::easing_linear::ease_in ); bear::tweener_item* t = new bear::tweener_item(tweener, s, true); new_item( *t ); } // invincibility_effect::create_star()
/** * \brief Create level bonus objects. */ void ptb::honeypot::create_level_bonus(const std::string& name) { bonus_points* new_bonus = new bonus_points( name, 0 ); new_bonus->set_picture_filename("gfx/ui/bonus-icons/bonus-icons.png"); new_bonus->set_picture_name(name); new_bonus->set_condition ( bear::engine::bool_level_variable_getter(&get_level(), name) ); new_item( *new_bonus ); CLAW_ASSERT(new_bonus->is_valid(), "The bonus isn't correctly initialized" ); new_bonus->set_center_of_mass(get_center_of_mass()); if ( m_id == 1 ) { bonus_points* bonus = new bonus_points( "Honey pots", 5000 ); bonus->set_points ( 5000 * bear::engine::linear_level_variable_getter<unsigned int> (&get_level(), "honeypots_found") ); new_item( *bonus ); CLAW_ASSERT(new_bonus->is_valid(), "The bonus isn't correctly initialized" ); bonus->set_center_of_mass(get_center_of_mass()); } } // honeypot::create_level_bonus()
/** * \brief Create the item representing a new power. * \param fill_color The color inside the effect. * \param border_color The color of the border of the effect. */ void ptb::power_effect::show_change_effect ( const bear::visual::color& fill_color, const bear::visual::color& border_color ) { bear::star* new_decoration = new bear::star( 16, 1, border_color, 2, fill_color ); new_decoration->set_z_position(get_z_position() - 10); new_decoration->set_size( 160, 160 ); new_item( *new_decoration ); new_decoration->set_center_of_mass(get_center_of_mass()); const bear::universe::time_type d(0.5); bear::universe::forced_tracking mvt(d); mvt.set_reference_point_on_center( *this ); new_decoration->set_forced_movement(mvt); bear::decorative_effect* decoration_effect = new bear::decorative_effect; decoration_effect->set_duration(d); bear::visual::color init_color, end_color; init_color.set(1,1,1,1); end_color.set(1,1,1,0); decoration_effect->set_color( init_color, end_color ); decoration_effect->set_item(new_decoration, true); new_item( *decoration_effect ); } // power_effect::show_change_effect()
/* * init_player: * Roll her up */ void init_player(void) { THING *obj; pstats = max_stats; food_left = HUNGERTIME; /* * Give him some food */ obj = new_item(); obj->o_type = FOOD; obj->o_count = 1; add_pack(obj, TRUE); /* * And his suit of armor */ obj = new_item(); obj->o_type = ARMOR; obj->o_which = RING_MAIL; obj->o_arm = a_class[RING_MAIL] - 1; obj->o_flags |= ISKNOW; obj->o_count = 1; cur_armor = obj; add_pack(obj, TRUE); /* * Give him his weaponry. First a mace. */ obj = new_item(); init_weapon(obj, MACE); obj->o_hplus = 1; obj->o_dplus = 1; obj->o_flags |= ISKNOW; add_pack(obj, TRUE); cur_weapon = obj; /* * Now a +1 bow */ obj = new_item(); init_weapon(obj, BOW); obj->o_hplus = 1; obj->o_flags |= ISKNOW; add_pack(obj, TRUE); /* * Now some arrows */ obj = new_item(); init_weapon(obj, ARROW); obj->o_count = rnd(15) + 25; obj->o_flags |= ISKNOW; add_pack(obj, TRUE); }
int main(void) { AddressBook *my_abook; my_abook = lookup("*****@*****.**", "baz", 1); my_abook = new_item("*****@*****.**", "foo"); my_abook = new_item("*****@*****.**", "bar"); get_item(my_abook, "*****@*****.**"); get_item(my_abook, "*****@*****.**"); return(EXIT_SUCCESS); }
/* void updateBuddyList(){ int i; for(i = 1; i <= buddy_count; i++){ char *s = (char *)malloc(100*sizeof(char)); memset(s, '\0', 100); s = strncpy(s, buddies[i].nick, strlen(buddies[i].nick)); strcat(s, "@"); strcat(s, buddies[i].ip); items[i] = new_item(s, ""); } unpost_menu(buddy_menu); post_menu(buddy_menu); //s = strdup(buddies[i].nick); //set_menu_items(buddy_menu, items); wrefresh(buddy_win); char c; while((c = wgetch(buddy_win)) != KEY_F(1)) { switch(c) { case KEY_DOWN: menu_driver(buddy_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(buddy_menu, REQ_UP_ITEM); break; } } } */ void initBuddyList(){ //build list displayName int i; items = (ITEM **)calloc(252, sizeof(ITEM *)); items[0] = new_item("Group",""); for(i = 1; i <= buddy_count; i++){ char *s = (char *)malloc(100*sizeof(char)); memset(s, '\0', 100); s = strncpy(s, buddies[i].nick, strlen(buddies[i].nick)); strcat(s, "@"); strcat(s, buddies[i].ip); //s = strdup(buddies[i].nick); items[i] = new_item(s, ""); } for(i = 0; i < buddy_count; i++){ //printf(displayNames[i]); // items[i] = new_item(displayNames[i], displayNames[i]); // char *name = (char *)malloc(strlen(displayNames[i]) + 1); // name = strncpy(name, displayNames[i], strlen(displayNames[i])); // char *xxx = "Bonsoir"; // name[strlen(displayNames[i])] = '\0'; //name = strncpy(name, displayNames[i], strlen(displayNames[i])); // char *yyy = (char *)malloc(strlen(xxx) + 1); // yyy = strdup(xxx); // items[i] = new_item(yyy, ""); } // keypad(buddy_win, TRUE); buddy_menu = new_menu((ITEM **)items); set_menu_win(buddy_menu, buddy_win); set_menu_sub(buddy_menu, derwin(buddy_win, 0, 0, 0, 0)); //set_menu_sub(buddy_menu, buddy_win); post_menu(buddy_menu); wrefresh(buddy_win); refresh(); /* char c; while((c = wgetch(buddy_win)) != KEY_F(1)) { switch(c) { case KEY_DOWN: menu_driver(buddy_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(buddy_menu, REQ_UP_ITEM); break; } wrefresh(buddy_win); }*/ }
static void add_const(const char* name, double val) { MSymbol* s = get_symbol(name); s->data = new_item(); s->data->n = -1; s->data->val = val; }
/** * \brief This method is called when the toggles switches on. * \param activator The item that activates the toggle, if any. */ void bear::item_creator::on_toggle_on( base_item* activator ) { super::on_toggle_on( activator ); for ( unsigned int index = 0; index != m_items.size(); ++index ) new_item( *(m_items[index]->clone()) ); } // item_creator::on_toggle_on()
void add_wml_hotkey(const std::string& id, const t_string& description, const config& default_hotkey) { if(id == "null") { LOG_G << "Couldn't add wml hotkey with null id and description = '" << description << "'.\n"; return; } else { if(has_hotkey_command(id)) { LOG_G << "Hotkey with id '" << id << "' already exists. Deleting the old hotkey_command.\n"; remove_wml_hotkey(id); } DBG_G << "Added wml hotkey with id = '" << id << "' and description = '" << description << "'.\n"; known_hotkeys.push_back(new hotkey_command(hotkey::HOTKEY_WML, id, description, false, hotkey::SCOPE_GAME, t_string(""))); command_map_[id] = known_hotkeys.size() - 1; if(!default_hotkey.empty() && !has_hotkey_item(id)) { hotkey_item new_item(default_hotkey, true); new_item.set_command(id); if(new_item.valid()) { DBG_G << "added default description for the wml hotkey with id=" + id; add_hotkey(new_item); } else { ERR_CF << "failed to add default hotkey with id=" + id; } } } }
metronome_item * walk_hash(metronome_item ** start, int timestamp, char * key, int force_delete) { metronome_item *item = *start, **prev=start, *next; while(item) { if(key!=NULL && 0 == strcmp(item->key,key) ) { return item; } //如果过期,删除! next = item->next; if(force_delete!=1 && item->timestamp + item->ttl > timestamp ) { prev = &item->next; } else { *prev = next; enif_free(item); //enif_fprintf(stderr, "freed:: %d\n", item); } item = next; } if(key==NULL) { return *start; } else { *prev = new_item(key); return *prev; } }
static input_item_t* BrowseShare( access_t *p_access ) { access_sys_t *p_sys = p_access->p_sys; const char *psz_name; input_item_t *p_item = NULL; if( !p_sys->i_browse_count ) { size_t i_count; if( smb_share_get_list( p_sys->p_session, &p_sys->shares, &i_count ) != DSM_SUCCESS ) return NULL; else p_sys->i_browse_count = i_count; } for( ; !p_item && p_sys->i_browse_idx < p_sys->i_browse_count ; p_sys->i_browse_idx++ ) { psz_name = smb_share_list_at( p_sys->shares, p_sys->i_browse_idx ); if( psz_name[strlen( psz_name ) - 1] == '$') continue; p_item = new_item( p_access, psz_name, ITEM_TYPE_DIRECTORY ); if( !p_item ) return NULL; } return p_item; }
/** * \brief Function called when the explosition starts. */ void rp::zeppelin::explose() { set_transportability(false); kill_interactive_item(); drop(); m_hit = true; util::create_floating_score(*this,750); bear::universe::position_type pos = get_center_of_mass(); pos.x -= get_width()/4; for ( unsigned int i = 0; i != 3; ++i ) { explosion* item = new explosion(15,20,0.6); item->set_z_position(get_z_position() + 1000); item->set_combo_value(get_combo_value()); item->set_center_of_mass(pos); new_item( *item ); CLAW_ASSERT( item->is_valid(), "The explosion of bomb isn't correctly initialized" ); bear::universe::forced_tracking m; m.set_reference_point_on_center(*this); item->set_forced_movement(m); pos.x += get_width()/4; } start_model_action("explose"); } // zeppelin::explose()
void AISUpdate::parseItem(const LLSD& item_map) { LLUUID item_id = item_map["item_id"].asUUID(); LLPointer<LLViewerInventoryItem> new_item(new LLViewerInventoryItem); LLViewerInventoryItem *curr_item = gInventory.getItem(item_id); if (curr_item) { // Default to current values where not provided. new_item->copyViewerItem(curr_item); } BOOL rv = new_item->unpackMessage(item_map); if (rv) { if (curr_item) { mItemsUpdated[item_id] = new_item; // This statement is here to cause a new entry with 0 // delta to be created if it does not already exist; // otherwise has no effect. mCatDescendentDeltas[new_item->getParentUUID()]; } else { mItemsCreated[item_id] = new_item; mCatDescendentDeltas[new_item->getParentUUID()]++; } } else { // *TODO: Wow, harsh. Should we just complain and get out? LL_ERRS() << "unpack failed" << LL_ENDL; } }
// function push // Push a new item or update an existing one's position. // In both cases, it will be the most recently used one. // return // true if item pushed or updated. // false if disk quota exceeds. bool Lru::push(int num, unsigned long size, vector<int>& victims) { if (size > m_quota) { return false; } list<Pair_num_size>::iterator it = find_if(m_list.begin(), m_list.end(), std::bind2nd(Num_match(), size)); Pair_num_size new_item(num, size); if(it == m_list.end()) { // Not found while(m_size + size > m_quota) { // Evacuate occupants. Pair_num_size victim = m_list.front(); m_list.pop_front(); m_size -= victim.second; victims.push_back(victim.first); } // Push it. m_list.push_back(new_item); m_size += size; return true; } else { // found // Just update order ONLY. list<Pair_num_size>::iterator it1 = it; it1++; m_list.splice(it, m_list, it1, m_list.end()); return true; } }
MENU* menu_create(const char *choices[], const char *desc[], int nchoices) { MENU *menu; ITEM **items; int i; items=(ITEM **)calloc(5+1, sizeof(ITEM *)); if(!items) { set_error(ERR_NOMEM); lpr_error("create_menu"); } for(i=0; i<5; ++i) { items[i]=new_item(choices[i], desc[i]); if(choices[i]==SEP) item_opts_off(items[i], O_SELECTABLE); } items[5] = (ITEM *)NULL; menu=new_menu((ITEM **)items); return menu; }
struct result selection_add_item(struct selection *selection, char const *description, selection_action_fn *action) { if (!selection) return result_set_system_error(EINVAL); if (!description) return result_set_system_error(EINVAL); if (!description[0]) return result_set_system_error(EINVAL); int index = selection->items_count; int null_index = index + 1; ++selection->items_count; selection->items = reallocarray_or_die(selection->items, selection->items_count + 1, sizeof(ITEM *)); char name[] = "1"; name[0] += index; char *name_dup = strdup_or_die(name); char *description_dup = strdup_or_die(description); selection->items[index] = new_item(name_dup, description_dup); if (!selection->items[index]) { free_or_die(description_dup); free_or_die(name_dup); return result_system_error(); } struct selection_item *selection_item = calloc_or_die(1, sizeof(struct selection_item)); selection_item->action = action; set_item_userptr(selection->items[index], selection_item); selection->items[null_index] = NULL; return result_success(); }
/** * \brief Initialize a slope. * \param slope A reference to the pointer of the slope. * \param s The steepness. * \param z The z position of the slope. */ void rp::switching::init_slope( bear::slope*& slope, double s, int z ) { if ( slope == NULL ) { slope = new bear::slope; if ( s < 0 ) slope->set_size( get_width(), get_height() / 2 ); else slope->set_size( get_size() ); const double effective_steepness = get_rendering_attributes().is_mirrored() ? -s : s; slope->set_bottom_left( get_bottom_left() ); slope->set_steepness( effective_steepness ); slope->set_top_friction( 0.95 ); slope->set_max_z_for_collision( z + 100 ); slope->set_z_position(z); slope->set_z_shift(100); slope->set_force_z_position(true); new_item(*slope); } else get_layer().add_item(*slope); } // rp::switching::init_slope()
/** * \brief Create a splinter item. * \param splinter_index Index of animation in splinter_animations list. * \param pos Position of item to create. */ void bear::explosion_effect_item::create_splinter_item (unsigned int splinter_index, bear::universe::position_type pos) { bear::decorative_item* item = new bear::decorative_item; item->set_animation(m_splinter_animations[splinter_index]); item->set_kill_when_leaving(true); item->set_kill_when_finished(false); item->set_mass(1); item->set_z_position(get_z_position()); item->set_density(0.002); universe::force_type force; double angle = ( 6.283 * rand() ) / RAND_MAX; double factor = (double)rand() / RAND_MAX / 2.0 + 0.5; force.x = cos(angle) * m_force * factor; force.y = sin(angle) * m_force * factor; item->set_external_force(force); item->set_system_angle(angle); item->set_system_angle_as_visual_angle(true); new_item( *item ); item->set_center_of_mass(pos); CLAW_ASSERT ( item->is_valid(), "A decorative item created by exposion_effect_item isn't correctly " "initialized" ); } // explosion_effect_item::create_splinter_item()
Item* insert_back(Item* listptr, int value){ // Must pass a linked list head if (listptr == NULL) { return NULL; } Item* newitem = new_item(value); // Calling malloc() failed if (newitem == NULL) { return NULL; } // Populate newitem newitem->value = value; newitem->rest = NULL; // Traverse to tip Item* p = listptr; while (p->rest != NULL) { p = p->rest; } // Attack to end and return p->rest = newitem; return listptr; }
/* * leave_pack: * take an item out of the pack */ THING * leave_pack(THING *obj, bool newobj, bool all) { THING *nobj; inpack--; nobj = obj; if (obj->o_count > 1 && !all) { last_pick = obj; obj->o_count--; if (obj->o_group) inpack++; if (newobj) { nobj = new_item(); *nobj = *obj; next(nobj) = NULL; prev(nobj) = NULL; nobj->o_count = 1; } } else { last_pick = NULL; pack_used[obj->o_packch - 'a'] = FALSE; detach(pack, obj); } return nobj; }
static MItem* item_string_marker() { MItem* it = new_item(); it->n = -2; it->next = NULL; return it; }
/** * \brief All players are colliding with the item. * \param p1 The first player. * \param p2 The second player. */ void ptb::link_on_players::on_all_players ( const player_proxy& p1, const player_proxy& p2 ) { player* player_1(p1.get_player_instance()); player* player_2(p2.get_player_instance()); // all players does not mean two players in single player game. if ( (player_1 != NULL) && (player_2 != NULL) ) { if ( !player_1->is_linked_to(*player_2) ) { bear::universe::link* link ( new bear::universe::link ( *player_1, *player_2, m_strength, m_minimal_length, m_maximal_length ) ); if (m_link_visual != NULL) { bear::base_link_visual* vis(m_link_visual->clone()); vis->set_items(player_1, player_2, link->get_id()); new_item(*vis); } } } } // link_on_players::on_all_players()
int main(){ Item* listptr; int i; listptr = new_item(0); for (i=1; i < 6; i++){ listptr=insert_front(listptr, i); } for (i=0; i < 6; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } listptr = remove_item(listptr, 3); for (i=0; i <= 5; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } printf("Index for 3 %d\n", get_index(listptr, 3)); for (i=1; i < 6; i++){ listptr=insert_back(listptr, i); } for (i=0; i < 12; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } set_item(listptr, 9, 15); for (i=0; i < 12; i++){ printf("i %d Item %d\n", i, get(listptr, i)); } set_item(listptr, 10, 15); free_all(listptr); }
unsigned Dialog::combo_box(const vector<wstring>& list_items, unsigned sel_idx, unsigned boxsize, FARDIALOGITEMFLAGS flags) { DialogItem di; di.type = DI_COMBOBOX; di.x1 = x; di.y1 = y; if (boxsize == AUTO_SIZE) { if (flags & DIF_DROPDOWNLIST) { unsigned max_len = 1; for (unsigned i = 0; i < list_items.size(); i++) { if (max_len < list_items[i].size()) max_len = static_cast<unsigned>(list_items[i].size()); } x += max_len + 5; } else x = c_x_frame + client_xs; } else x += boxsize; if (x - c_x_frame > client_xs) client_xs = x - c_x_frame; di.x2 = x - 1 - 1; // -1 for down arrow di.y2 = y; di.flags = flags; for (unsigned i = 0; i < list_items.size(); i++) { if (di.list_idx) new_value(list_items[i]); else di.list_idx = new_value(list_items[i]); } di.list_size = static_cast<unsigned>(list_items.size()); di.list_pos = sel_idx; return new_item(di); }
void printMenus() { int i; MENU *fileMenu, *dirMenu; // Create items fileItems = malloc(numFiles * sizeof(ITEM *)); for (i = 0; i < numFiles; i++) { fileItems[i] = new_item(fileEntries[i]->d_name, NULL); if (fileItems[i] == NULL) break; } fileItems[numFiles] = NULL; dirItems = malloc(numDirs * sizeof(ITEM *)); for (i = 0; i < numDirs; i++) { dirItems[i] = new_item(dirEntries[i]->d_name, NULL); if (dirItems[i] == NULL) break; } dirItems[numDirs] = NULL; // Create menus fileMenu = new_menu(fileItems); dirMenu = new_menu(dirItems); menus = malloc(2 * sizeof(MENU *)); menus[0] = fileMenu; menus[1] = dirMenu; if (fileMenu == NULL || dirMenu == NULL) { fprintf(stderr, "Error creating menus\n"); } // Associate windows and menus set_menu_win(fileMenu, cursesWins[0]); set_menu_sub(fileMenu, derwin(cursesWins[0], LINES / 2, (COLS / 2) - 6, 3, 1)); set_menu_format(fileMenu, (LINES / 2), 1); set_menu_win(dirMenu, cursesWins[1]); set_menu_sub(dirMenu, derwin(cursesWins[1], LINES / 2, (COLS / 2) - 6, 3, 1)); set_menu_format(dirMenu, (LINES / 2), 1); post_menu(fileMenu); wrefresh(cursesWins[0]); post_menu(dirMenu); wrefresh(cursesWins[1]); }
int mainmenu(int height, int width) { int ret; ITEM **menu_items; MENU *main_menu; int n_choices, i; clean_main_menu(); build_main_menu(instance_path); n_choices = menu_size; menu_items = (ITEM **) calloc(n_choices + 1, sizeof (ITEM *)); for (i = 0; i < n_choices; ++i) { menu_items[i] = new_item(menu_values[i], menu_values[i]); set_item_userptr(menu_items[i], (void *) menu_selected); } menu_items[n_choices] = (ITEM *) NULL; main_menu = new_menu((ITEM **) menu_items); menu_opts_off(main_menu, O_SHOWDESC); set_menu_sub(main_menu, derwin(stdscr, 10, 50, 6, 10)); post_menu(main_menu); attron(A_BOLD); mvprintw(0, 0, name); mvprintw(0, width - strlen(vers), vers); attroff(A_BOLD); refresh(); pos_menu_cursor(main_menu); while ((i = getch()) != KEY_F(4)) { switch (i) { case KEY_DOWN: menu_driver(main_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(main_menu, REQ_UP_ITEM); break; case 10: { ITEM *cur; int (*p)(char *); cur = current_item(main_menu); p = (int (*)(char *))item_userptr(cur); ret = p((char *) item_name(cur)); pos_menu_cursor(main_menu); goto menu_sel; } } } if (i == KEY_F(4)) { ret = menu_size - 1; } menu_sel: unpost_menu(main_menu); free_menu(main_menu); for (i = 0; i < n_choices; ++i) free_item(menu_items[i]); return ret; }
int main(int argc, char const *argv[]) { ITEM **my_items; int c; MENU *my_menu; WINDOW *my_menu_win; int n_choices, i; initscr(); start_color(); cbreak(); noecho(); keypad(stdscr, TRUE); init_pair(1, COLOR_RED, COLOR_BLACK); n_choices = ARRAY_SIZE(choices); my_items = (ITEM **) calloc(n_choices, sizeof(ITEM *)); for (i = 0; i < n_choices; ++i) my_items[i] = new_item(choices[i], choices[i]); my_menu = new_menu((ITEM **) my_items); my_menu_win = newwin(10, 40, 4, 4); keypad(my_menu_win, TRUE); set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 6, 38, 3, 1)); set_menu_mark(my_menu, " * "); box(my_menu_win, 0, 0); print_in_middle(my_menu_win, 1, 0, 40, "My Menu", COLOR_PAIR(1)); mvwaddch(my_menu_win, 2, 0, ACS_LTEE); mvwhline(my_menu_win, 2, 1, ACS_HLINE, 38); mvwaddch(my_menu_win, 2, 39, ACS_RTEE); mvprintw(LINES - 2, 0, "F1 to exit"); refresh(); post_menu(my_menu); wrefresh(my_menu_win); while ((c = wgetch(my_menu_win)) != KEY_F(1)) { switch (c) { case KEY_DOWN: menu_driver(my_menu, REQ_DOWN_ITEM); break; case KEY_UP: menu_driver(my_menu, REQ_UP_ITEM); break; } wrefresh(my_menu_win); } unpost_menu(my_menu); free_menu(my_menu); for (i = 0; i < n_choices; ++i) free_item(my_items[i]); endwin(); return 0; }