// Pick up items at (pos). void Pickup::pick_up( const tripoint &pos, int min ) { int veh_root_part = 0; int cargo_part = -1; vehicle *veh = g->m.veh_at (pos, veh_root_part); bool from_vehicle = false; if( min != -1 ) { switch( interact_with_vehicle( veh, pos, veh_root_part ) ) { case DONE: return; case ITEMS_FROM_CARGO: cargo_part = veh->part_with_feature( veh_root_part, "CARGO", false ); from_vehicle = cargo_part >= 0; break; case ITEMS_FROM_GROUND: // Nothing to change, default is to pick from ground anyway. break; } } if (g->m.has_flag("SEALED", pos)) { return; } if( !from_vehicle ) { bool isEmpty = (g->m.i_at(pos).empty()); // Hide the pickup window if this is a toilet and there's nothing here // but water. if ((!isEmpty) && g->m.furn(pos) == f_toilet) { isEmpty = true; for( auto maybe_water : g->m.i_at(pos) ) { if( maybe_water.typeId() != "water") { isEmpty = false; break; } } } if (isEmpty && (min != -1 || !OPTIONS["AUTO_PICKUP_ADJACENT"] )) { return; } } // which items are we grabbing? std::vector<item> here; if( from_vehicle ) { auto vehitems = veh->get_items(cargo_part); here.resize( vehitems.size() ); std::copy( vehitems.rbegin(), vehitems.rend(), here.begin() ); } else { auto mapitems = g->m.i_at(pos); here.resize( mapitems.size() ); std::copy( mapitems.rbegin(), mapitems.rend(), here.begin() ); } if (min == -1) { if( g->check_zone( "NO_AUTO_PICKUP", pos ) ) { here.clear(); } // Recursively pick up adjacent items if that option is on. if( OPTIONS["AUTO_PICKUP_ADJACENT"] && g->u.pos() == pos ) { //Autopickup adjacent direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST}; for( auto &elem : adjacentDir ) { tripoint apos = tripoint( direction_XY( elem ), 0 ); apos += pos; if( g->m.has_flag( "SEALED", apos ) ) { continue; } if( g->check_zone( "NO_AUTO_PICKUP", apos ) ) { continue; } pick_up( apos, min ); } } } // Not many items, just grab them if ((int)here.size() <= min && min != -1) { g->u.assign_activity( ACT_PICKUP, 0 ); g->u.activity.placement = pos - g->u.pos(); g->u.activity.values.push_back( from_vehicle ); // Only one item means index is 0. g->u.activity.values.push_back( 0 ); // auto-pickup means pick up all. g->u.activity.values.push_back( 0 ); return; } if(min != -1) { // don't bother if we're just autopickup-ing g->temp_exit_fullscreen(); } bool sideStyle = use_narrow_sidebar(); // Otherwise, we have Autopickup, 2 or more items and should list them, etc. int maxmaxitems = sideStyle ? TERMY : getmaxy(g->w_messages) - 3; int itemsH = std::min(25, TERMY / 2); int pickupBorderRows = 3; // The pickup list may consume the entire terminal, minus space needed for its // header/footer and the item info window. int minleftover = itemsH + pickupBorderRows; if(maxmaxitems > TERMY - minleftover) { maxmaxitems = TERMY - minleftover; } const int minmaxitems = sideStyle ? 6 : 9; std::vector<pickup_count> getitem( here.size() ); int maxitems = here.size(); maxitems = (maxitems < minmaxitems ? minmaxitems : (maxitems > maxmaxitems ? maxmaxitems : maxitems )); int itemcount = 0; if (min == -1) { //Auto Pickup, select matching items if( !select_autopickup_items( here, getitem) ) { // If we didn't find anything, bail out now. return; } } else { int pickupH = maxitems + pickupBorderRows; int pickupW = getmaxx(g->w_messages); int pickupY = VIEW_OFFSET_Y; int pickupX = getbegx(g->w_messages); int itemsW = pickupW; int itemsY = sideStyle ? pickupY + pickupH : TERMY - itemsH; int itemsX = pickupX; WINDOW *w_pickup = newwin(pickupH, pickupW, pickupY, pickupX); WINDOW *w_item_info = newwin(itemsH, itemsW, itemsY, itemsX); WINDOW_PTR w_pickupptr( w_pickup ); WINDOW_PTR w_item_infoptr( w_item_info ); int ch = ' '; int start = 0, cur_it; int new_weight = g->u.weight_carried(), new_volume = g->u.volume_carried(); bool update = true; mvwprintw(w_pickup, 0, 0, _("PICK UP")); int selected = 0; int iScrollPos = 0; if(g->was_fullscreen) { g->draw_ter(); } // Now print the two lists; those on the ground and about to be added to inv // Continue until we hit return or space do { static const std::string pickup_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;"; int idx = -1; for (int i = 1; i < pickupH; i++) { mvwprintw(w_pickup, i, 0, " "); } if (ch >= '0' && ch <= '9') { ch = (char)ch - '0'; itemcount *= 10; itemcount += ch; if( itemcount < 0 ) { itemcount = 0; } } else if ( ch == KEY_PPAGE) { iScrollPos--; } else if ( ch == KEY_NPAGE) { iScrollPos++; } else if ( ch == '<' ) { if ( start > 0 ) { start -= maxitems; } else { start = (int)( (here.size()-1) / maxitems ) * maxitems; } selected = start; mvwprintw(w_pickup, maxitems + 2, 0, " "); } else if ( ch == '>' ) { if ( start + maxitems < (int)here.size() ) { start += maxitems; } else { start = 0; } iScrollPos = 0; selected = start; mvwprintw(w_pickup, maxitems + 2, pickupH, " "); } else if ( ch == KEY_UP ) { selected--; iScrollPos = 0; if ( selected < 0 ) { selected = here.size() - 1; start = (int)( here.size() / maxitems ) * maxitems; if (start >= (int)here.size()) { start -= maxitems; } } else if ( selected < start ) { start -= maxitems; } } else if ( ch == KEY_DOWN ) { selected++; iScrollPos = 0; if ( selected >= (int)here.size() ) { selected = 0; start = 0; } else if ( selected >= start + maxitems ) { start += maxitems; } } else if ( selected >= 0 && ( ( ch == KEY_RIGHT && !getitem[selected]) || ( ch == KEY_LEFT && getitem[selected] ) ) ) { idx = selected; } else if ( ch == '`' ) { std::string ext = string_input_popup( _("Enter 2 letters (case sensitive):"), 3, "", "", "", 2); if(ext.size() == 2) { int p1 = pickup_chars.find(ext.at(0)); int p2 = pickup_chars.find(ext.at(1)); if ( p1 != -1 && p2 != -1 ) { idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2; } } } else { idx = ( ch <= 127 ) ? pickup_chars.find(ch) : -1; iScrollPos = 0; } if( idx >= 0 && idx < (int)here.size()) { if( getitem[idx] ) { if( getitem[idx].count != 0 && getitem[idx].count < here[idx].charges ) { item temp = here[idx]; temp.charges = getitem[idx].count; new_weight -= temp.weight(); new_volume -= temp.volume(); } else { new_weight -= here[idx].weight(); new_volume -= here[idx].volume(); } } if (itemcount != 0 || getitem[idx].count == 0) { if (itemcount >= here[idx].charges || !here[idx].count_by_charges()) { // Ignore the count if we pickup the whole stack anyway // or something that is not counted by charges (tools) itemcount = 0; } getitem[idx].count = itemcount; itemcount = 0; } // Note: this might not change the value of getitem[idx] at all! getitem[idx].pick = ( ch == KEY_RIGHT ? true : ( ch == KEY_LEFT ? false : !getitem[idx] ) ); if ( ch != KEY_RIGHT && ch != KEY_LEFT) { selected = idx; start = (int)( idx / maxitems ) * maxitems; } if (getitem[idx]) { if (getitem[idx].count != 0 && getitem[idx].count < here[idx].charges) { item temp = here[idx]; temp.charges = getitem[idx].count; new_weight += temp.weight(); new_volume += temp.volume(); } else { new_weight += here[idx].weight(); new_volume += here[idx].volume(); } } else { getitem[idx].count = 0; } update = true; } werase(w_item_info); if ( selected >= 0 && selected <= (int)here.size() - 1 ) { std::vector<iteminfo> vThisItem, vDummy; here[selected].info(true, vThisItem); draw_item_info(w_item_info, "", "", vThisItem, vDummy, iScrollPos, true, true); } draw_custom_border(w_item_info, false); mvwprintw(w_item_info, 0, 2, "< "); trim_and_print(w_item_info, 0, 4, itemsW - 8, c_white, "%s >", here[selected].display_name().c_str()); wrefresh(w_item_info); if (ch == ',') { int count = 0; for (size_t i = 0; i < here.size(); i++) { if (getitem[i]) { count++; } else { new_weight += here[i].weight(); new_volume += here[i].volume(); } getitem[i].pick = true; } if (count == (int)here.size()) { for (size_t i = 0; i < here.size(); i++) { getitem[i].pick = false; } new_weight = g->u.weight_carried(); new_volume = g->u.volume_carried(); } update = true; } for (cur_it = start; cur_it < start + maxitems; cur_it++) { mvwprintw(w_pickup, 1 + (cur_it % maxitems), 0, " "); if (cur_it < (int)here.size()) { nc_color icolor = here[cur_it].color_in_inventory(); if (cur_it == selected) { icolor = hilite(icolor); } if (cur_it < (int)pickup_chars.size() ) { mvwputch(w_pickup, 1 + (cur_it % maxitems), 0, icolor, char(pickup_chars[cur_it])); } else { int p = cur_it - pickup_chars.size(); int p1 = p / pickup_chars.size(); int p2 = p % pickup_chars.size(); mvwprintz(w_pickup, 1 + (cur_it % maxitems), 0, icolor, "`%c%c", char(pickup_chars[p1]), char(pickup_chars[p2])); } if (getitem[cur_it]) { if (getitem[cur_it].count == 0) { wprintz(w_pickup, c_ltblue, " + "); } else { wprintz(w_pickup, c_ltblue, " # "); } } else { wprintw(w_pickup, " - "); } std::string item_name = here[cur_it].display_name(); if (OPTIONS["ITEM_SYMBOLS"]) { item_name = string_format("%c %s", here[cur_it].symbol(), item_name.c_str()); } trim_and_print(w_pickup, 1 + (cur_it % maxitems), 6, pickupW - 4, icolor, "%s", item_name.c_str()); } } int pw = pickupW; const char *unmark = _("[left] Unmark"); const char *scroll = _("[up/dn] Scroll"); const char *mark = _("[right] Mark"); mvwprintw(w_pickup, maxitems + 1, 0, unmark); mvwprintw(w_pickup, maxitems + 1, (pw - std::strlen(scroll)) / 2, scroll); mvwprintw(w_pickup, maxitems + 1, pw - std::strlen(mark), mark); const char *prev = _("[<] Prev"); const char *all = _("[,] All"); const char *next = _("[>] Next"); mvwprintw(w_pickup, maxitems + 2, 0, prev); mvwprintw(w_pickup, maxitems + 2, (pw - std::strlen(all)) / 2, all); mvwprintw(w_pickup, maxitems + 2, pw - std::strlen(next), next); if (update) { // Update weight & volume information update = false; for (int i = 9; i < pickupW; ++i) { mvwaddch(w_pickup, 0, i, ' '); } mvwprintz(w_pickup, 0, 9, (new_weight > g->u.weight_capacity() ? c_red : c_white), _("Wgt %.1f"), convert_weight(new_weight) + 0.05); // +0.05 to round up wprintz(w_pickup, c_white, "/%.1f", convert_weight(g->u.weight_capacity())); mvwprintz(w_pickup, 0, 24, (new_volume > g->u.volume_capacity() ? c_red : c_white), _("Vol %d"), new_volume); wprintz(w_pickup, c_white, "/%d", g->u.volume_capacity()); } wrefresh(w_pickup); ch = (int)getch(); } while (ch != ' ' && ch != '\n' && ch != KEY_ENTER && ch != KEY_ESCAPE); bool item_selected = false; // Check if we have selected an item. for( auto selection : getitem ) { if( selection ) { item_selected = true; } } if( (ch != '\n' && ch != KEY_ENTER) || !item_selected ) { w_pickupptr.reset(); w_item_infoptr.reset(); add_msg(_("Never mind.")); g->reenter_fullscreen(); g->refresh_all(); return; } } // At this point we've selected our items, register an activity to pick them up. g->u.assign_activity( ACT_PICKUP, 0 ); g->u.activity.placement = pos - g->u.pos(); g->u.activity.values.push_back( from_vehicle ); if( min == -1 ) { // Auto pickup will need to auto resume since there can be several of them on the stack. g->u.activity.auto_resume = true; } std::reverse( getitem.begin(), getitem.end() ); for( size_t i = 0; i < here.size(); i++ ) { if( getitem[i] ) { g->u.activity.values.push_back( i ); g->u.activity.values.push_back( getitem[i].count ); } } g->reenter_fullscreen(); }
/* * Display a menu for choosing among a number of options */ int dialog_menu(const char *title, const char *prompt, const void *selected, int *s_scroll) { int i, j, x, y, box_x, box_y; int height, width, menu_height; int key = 0, button = 0, scroll = 0, choice = 0; int first_item = 0, max_choice; WINDOW *dialog, *menu; do_resize: height = getmaxy(stdscr); width = getmaxx(stdscr); if (height < 15 || width < 65) return -ERRDISPLAYTOOSMALL; height -= 4; width -= 5; menu_height = height - 10; max_choice = MIN(menu_height, item_count()); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); wbkgdset(dialog, dlg.dialog.atr & A_COLOR); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); menu_width = width - 6; box_y = height - menu_height - 5; box_x = (width - menu_width) / 2 - 1; /* create new window for the menu */ menu = subwin(dialog, menu_height, menu_width, y + box_y + 1, x + box_x + 1); keypad(menu, TRUE); /* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, dlg.menubox_border.atr, dlg.menubox.atr); if (menu_width >= 80) item_x = (menu_width - 70) / 2; else item_x = 4; /* Set choice to default item */ item_foreach() if (selected && (selected == item_data())) choice = item_n(); /* get the saved scroll info */ scroll = *s_scroll; if ((scroll <= choice) && (scroll + max_choice > choice) && (scroll >= 0) && (scroll + max_choice <= item_count())) { first_item = scroll; choice = choice - scroll; } else { scroll = 0; } if ((choice >= max_choice)) { if (choice >= item_count() - max_choice / 2) scroll = first_item = item_count() - max_choice; else scroll = first_item = choice - max_choice / 2; choice = choice - scroll; } /* Print the menu */ for (i = 0; i < max_choice; i++) { print_item(first_item + i, i, i == choice); } wnoutrefresh(menu); print_arrows(dialog, item_count(), scroll, box_y, box_x + item_x + 1, menu_height); print_buttons(dialog, height, width, 0); wmove(menu, choice, item_x + 1); wrefresh(menu); while (key != KEY_ESC) { key = wgetch(menu); if (key < 256 && isalpha(key)) key = tolower(key); if (strchr("ynmh", key)) i = max_choice; else { for (i = choice + 1; i < max_choice; i++) { item_set(scroll + i); j = first_alpha(item_str(), "YyNnMmHh"); if (key == tolower(item_str()[j])) break; } if (i == max_choice) for (i = 0; i < max_choice; i++) { item_set(scroll + i); j = first_alpha(item_str(), "YyNnMmHh"); if (key == tolower(item_str()[j])) break; } } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '-' || key == '+' || key == KEY_PPAGE || key == KEY_NPAGE) { /* Remove highligt of current item */ print_item(scroll + choice, choice, FALSE); if (key == KEY_UP || key == '-') { if (choice < 2 && scroll) { /* Scroll menu down */ do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else choice = MAX(choice - 1, 0); } else if (key == KEY_DOWN || key == '+') { print_item(scroll+choice, choice, FALSE); if ((choice > max_choice - 3) && (scroll + max_choice < item_count())) { /* Scroll menu up */ do_scroll(menu, &scroll, 1); print_item(scroll+max_choice - 1, max_choice - 1, FALSE); } else choice = MIN(choice + 1, max_choice - 1); } else if (key == KEY_PPAGE) { scrollok(menu, TRUE); for (i = 0; (i < max_choice); i++) { if (scroll > 0) { do_scroll(menu, &scroll, -1); print_item(scroll, 0, FALSE); } else { if (choice > 0) choice--; } } } else if (key == KEY_NPAGE) { for (i = 0; (i < max_choice); i++) { if (scroll + max_choice < item_count()) { do_scroll(menu, &scroll, 1); print_item(scroll+max_choice-1, max_choice - 1, FALSE); } else { if (choice + 1 < max_choice) choice++; } } } else choice = i; print_item(scroll + choice, choice, TRUE); print_arrows(dialog, item_count(), scroll, box_y, box_x + item_x + 1, menu_height); wnoutrefresh(dialog); wrefresh(menu); continue; /* wait for another key press */ } switch (key) { case KEY_LEFT: case TAB: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 2 : (button > 2 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(menu); break; case ' ': case 's': case 'y': case 'n': case 'm': case '/': case 'h': case '?': case 'z': case '\n': /* save scroll info */ *s_scroll = scroll; delwin(menu); delwin(dialog); item_set(scroll + choice); item_set_selected(1); switch (key) { case 'h': case '?': return 2; case 's': case 'y': return 3; case 'n': return 4; case 'm': return 5; case ' ': return 6; case '/': return 7; case 'z': return 8; case '\n': return button; } return 0; case 'e': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(menu); break; case KEY_RESIZE: on_key_resize(); delwin(menu); delwin(dialog); goto do_resize; } } delwin(menu); delwin(dialog); return key; /* ESC pressed */ }
extern void get_bg_part(void) { int error_code, i, recs=0, count = 0, last_count = -1; static partition_info_msg_t *part_info_ptr = NULL; static partition_info_msg_t *new_part_ptr = NULL; static block_info_msg_t *bg_info_ptr = NULL; static block_info_msg_t *new_bg_ptr = NULL; uint16_t show_flags = 0; partition_info_t part; db2_block_info_t *block_ptr = NULL; db2_block_info_t *found_block = NULL; ListIterator itr; List nodelist = NULL; bitstr_t *nodes_req = NULL; if (!(params.cluster_flags & CLUSTER_FLAG_BG)) return; if (params.all_flag) show_flags |= SHOW_ALL; if (part_info_ptr) { error_code = slurm_load_partitions(part_info_ptr->last_update, &new_part_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg(part_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_part_ptr = part_info_ptr; } } else { error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr, show_flags); } if (error_code) { if (quiet_flag != 1) { if (!params.commandline) { mvwprintw(text_win, main_ycord, 1, "slurm_load_partitions: %s", slurm_strerror(slurm_get_errno())); main_ycord++; } else { printf("slurm_load_partitions: %s\n", slurm_strerror(slurm_get_errno())); } } return; } if (bg_info_ptr) { error_code = slurm_load_block_info(bg_info_ptr->last_update, &new_bg_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_block_info_msg(bg_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_bg_ptr = bg_info_ptr; } } else { error_code = slurm_load_block_info((time_t) NULL, &new_bg_ptr, show_flags); } if (error_code) { if (quiet_flag != 1) { if (!params.commandline) { mvwprintw(text_win, main_ycord, 1, "slurm_load_block: %s", slurm_strerror(slurm_get_errno())); main_ycord++; } else { printf("slurm_load_block: %s\n", slurm_strerror(slurm_get_errno())); } } return; } if (block_list) { /* clear the old list */ list_flush(block_list); } else { block_list = list_create(_block_list_del); } if (!params.commandline) if ((new_bg_ptr->record_count - text_line_cnt) < (getmaxy(text_win) - 4)) text_line_cnt--; if (params.hl) nodes_req = get_requested_node_bitmap(); for (i = 0; i < new_bg_ptr->record_count; i++) { if (nodes_req) { int overlap = 0; bitstr_t *loc_bitmap = bit_alloc(bit_size(nodes_req)); inx2bitstr(loc_bitmap, new_bg_ptr->block_array[i].mp_inx); overlap = bit_overlap(loc_bitmap, nodes_req); FREE_NULL_BITMAP(loc_bitmap); if (!overlap) continue; } if (params.io_bit && new_bg_ptr->block_array[i].ionode_str) { int overlap = 0; bitstr_t *loc_bitmap = bit_alloc(bit_size(params.io_bit)); inx2bitstr(loc_bitmap, new_bg_ptr->block_array[i].ionode_inx); overlap = bit_overlap(loc_bitmap, params.io_bit); FREE_NULL_BITMAP(loc_bitmap); if (!overlap) continue; } block_ptr = xmalloc(sizeof(db2_block_info_t)); block_ptr->bg_block_name = xstrdup(new_bg_ptr->block_array[i].bg_block_id); block_ptr->mp_str = xstrdup(new_bg_ptr->block_array[i].mp_str); block_ptr->nodelist = list_create(_nodelist_del); _make_nodelist(block_ptr->mp_str, block_ptr->nodelist); block_ptr->state = new_bg_ptr->block_array[i].state; memcpy(block_ptr->bg_conn_type, new_bg_ptr->block_array[i].conn_type, sizeof(block_ptr->bg_conn_type)); if (params.cluster_flags & CLUSTER_FLAG_BGL) block_ptr->bg_node_use = new_bg_ptr->block_array[i].node_use; block_ptr->ionode_str = xstrdup(new_bg_ptr->block_array[i].ionode_str); block_ptr->cnode_cnt = new_bg_ptr->block_array[i].cnode_cnt; itr = list_iterator_create(block_list); while ((found_block = (db2_block_info_t*)list_next(itr))) { if (!strcmp(block_ptr->mp_str, found_block->mp_str)) { block_ptr->letter_num = found_block->letter_num; break; } } list_iterator_destroy(itr); if (!found_block) { last_count++; _marknodes(block_ptr, last_count); } block_ptr->job_list = list_create(slurm_free_block_job_info); if (new_bg_ptr->block_array[i].job_list) { block_job_info_t *found_job; ListIterator itr = list_iterator_create( new_bg_ptr->block_array[i].job_list); while ((found_job = list_next(itr))) { block_job_info_t *block_job = xmalloc(sizeof(block_job_info_t)); block_job->job_id = found_job->job_id; list_append(block_ptr->job_list, block_job); } list_iterator_destroy(itr); } if (block_ptr->bg_conn_type[0] >= SELECT_SMALL) block_ptr->size = 0; list_append(block_list, block_ptr); } if (!params.no_header) _print_header_part(); if (new_part_ptr) recs = new_part_ptr->record_count; else recs = 0; for (i = 0; i < recs; i++) { part = new_part_ptr->partition_array[i]; if (!part.nodes || (part.nodes[0] == '\0')) continue; /* empty partition */ nodelist = list_create(_nodelist_del); _make_nodelist(part.nodes, nodelist); if (block_list) { itr = list_iterator_create(block_list); while ((block_ptr = (db2_block_info_t*) list_next(itr)) != NULL) { if (_in_slurm_partition(nodelist, block_ptr->nodelist)) { block_ptr->slurm_part_name = xstrdup(part.name); } } list_iterator_destroy(itr); } list_destroy(nodelist); } /* Report the BG Blocks */ if (block_list) { itr = list_iterator_create(block_list); while ((block_ptr = (db2_block_info_t*) list_next(itr)) != NULL) { if (params.commandline) block_ptr->printed = 1; else { if (count>=text_line_cnt) block_ptr->printed = 1; } _print_rest(block_ptr); count++; } list_iterator_destroy(itr); } if (params.commandline && params.iterate) printf("\n"); part_info_ptr = new_part_ptr; bg_info_ptr = new_bg_ptr; return; }
void render::render_CharMenu(Character& chara, int curPos){ clear(); texture.loadFromFile(FRAME_SIDE, ren); texture.render(ren, 0, 0); Point offset; offset.m_x = getmaxx() / 2; offset.m_y = getmaxy() / 2; SDL_Color textColor = {0xD8, 0xC6, 0x91}; //Print Title texture.loadFromRenderedText(chara.getName().c_str(), textColor, ren, font_comic50); texture.render(ren, offset.m_x - texture.getWidth() / 2, 5); char tmp[100]; //Print Informations sprintf(tmp, "Name : %s", chara.getName().c_str()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 100); sprintf(tmp, "Level : %d", chara.getLevel()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 130); sprintf(tmp, "Role : %s", chara.getRoleName().c_str()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 160); sprintf(tmp, "HP : %d + %d", chara.getBaseHP(), chara.getAdditionalHP()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 190); sprintf(tmp, "MP : %d + %d", chara.getBaseMP(), chara.getAdditionalMP()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 220); sprintf(tmp, "Attack : %d + %d", chara.getBaseAttack(), chara.getAdditionalAttack()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 250); sprintf(tmp, "Defense : %d + %d", chara.getBaseDefense(), chara.getAdditionalDefense()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 280); if(curPos == 0)textColor = { 0xF4, 0xF0, 0xDD };{ texture.loadFromRenderedText("Head : ", textColor, ren, font_comic16); texture.render(ren, 20, 100); texture.loadFromRenderedText(chara.getHead().getName().c_str(), textColor, ren, font_comic16); texture.render(ren, 40, 120); }textColor = {0xD8, 0xC6, 0x91}; if(curPos == 1)textColor = { 0xF4, 0xF0, 0xDD };{ texture.loadFromRenderedText("Armor : ", textColor, ren, font_comic16); texture.render(ren, 20, 150); texture.loadFromRenderedText(chara.getArmor().getName().c_str(), textColor, ren, font_comic16); texture.render(ren, 40, 170); }textColor = {0xD8, 0xC6, 0x91}; if(curPos == 2)textColor = { 0xF4, 0xF0, 0xDD };{ texture.loadFromRenderedText("Legs : ", textColor, ren, font_comic16); texture.render(ren, 20, 200); texture.loadFromRenderedText(chara.getLegs().getName().c_str(), textColor, ren, font_comic16); texture.render(ren, 40, 220); }textColor = {0xD8, 0xC6, 0x91}; if(curPos == 3)textColor = { 0xF4, 0xF0, 0xDD };{ texture.loadFromRenderedText("Shoes : ", textColor, ren, font_comic16); texture.render(ren, 20, 250); texture.loadFromRenderedText(chara.getShoes().getName().c_str(), textColor, ren, font_comic16); texture.render(ren, 40, 270); }textColor = {0xD8, 0xC6, 0x91}; if(curPos == 4)textColor = { 0xF4, 0xF0, 0xDD };{ texture.loadFromRenderedText("Weapon : ", textColor, ren, font_comic16); texture.render(ren, 20, 300); texture.loadFromRenderedText(chara.getWeapon().getName().c_str(), textColor, ren, font_comic16); texture.render(ren, 40, 320); }textColor = {0xD8, 0xC6, 0x91}; if(curPos == 5)textColor = { 0xF4, 0xF0, 0xDD };{ texture.loadFromRenderedText("Show Skills", textColor, ren, font_comic16); texture.render(ren, 20, 350); }textColor = {0xD8, 0xC6, 0x91}; update(); }
int worldfactory::show_worldgen_tab_modselection(WINDOW *win, WORLDPTR world) { // Use active_mod_order of the world, // saves us from writting 'world->active_mod_order' all the time. std::vector<std::string> &active_mod_order = world->active_mod_order; { std::vector<std::string> tmp_mod_order; // clear active_mod_order and re-add all the mods, his ensures // that changes (like changing depencies) get updated tmp_mod_order.swap(active_mod_order); for(size_t i = 0; i < tmp_mod_order.size(); i++) { mman_ui->try_add(tmp_mod_order[i], active_mod_order); } } const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; // lots of small windows so that each section can be drawn to independently of the others as necessary WINDOW *w_header1, *w_header2, *w_shift, *w_list, *w_active, *w_description; w_header1 = newwin(1, FULL_SCREEN_WIDTH / 2 - 5, 3 + iOffsetY, 1 + iOffsetX); w_header2 = newwin(1, FULL_SCREEN_WIDTH / 2 - 4, 3 + iOffsetY, FULL_SCREEN_WIDTH / 2 + 3 + iOffsetX); w_shift = newwin(13, 5, 3 + iOffsetY, FULL_SCREEN_WIDTH / 2 - 3 + iOffsetX); w_list = newwin(11, FULL_SCREEN_WIDTH / 2 - 4, 5 + iOffsetY, iOffsetX); w_active = newwin(11, FULL_SCREEN_WIDTH / 2 - 4, 5 + iOffsetY, FULL_SCREEN_WIDTH / 2 + 2 + iOffsetX); w_description = newwin(4, FULL_SCREEN_WIDTH - 2, 19 + iOffsetY, 1 + iOffsetX); draw_modselection_borders(win); std::vector<std::string> headers; headers.push_back(_("Mod List")); headers.push_back(_("Mod Load Order")); std::vector<WINDOW *> header_windows; header_windows.push_back(w_header1); header_windows.push_back(w_header2); int tab_output = 0; int last_active_header = 0; size_t active_header = 0; size_t useable_mod_count = mman_ui->usable_mods.size(); int startsel[2] = {0, 0}; int cursel[2] = {0, 0}; bool redraw_headers = true; bool redraw_shift = true; bool redraw_description = true; bool redraw_list = true; bool redraw_active = true; bool selection_changed = false; input_context ctxt("MODMANAGER_DIALOG"); ctxt.register_cardinal(); ctxt.register_action("HELP_KEYBINDINGS"); ctxt.register_action("QUIT"); ctxt.register_action("NEXT_TAB"); ctxt.register_action("PREV_TAB"); ctxt.register_action("CONFIRM"); ctxt.register_action("ADD_MOD"); ctxt.register_action("REMOVE_MOD"); ctxt.register_action("SAVE_DEFAULT_MODS"); while (tab_output == 0) { if (redraw_headers) { for (size_t i = 0; i < headers.size(); ++i) { werase(header_windows[i]); const int header_x = (getmaxx(header_windows[i]) - headers[i].size()) / 2; mvwprintz(header_windows[i], 0, header_x , c_cyan, "%s", headers[i].c_str()); if (active_header == i) { mvwputch(header_windows[i], 0, header_x - 3, c_red, '<'); mvwputch(header_windows[i], 0, header_x + headers[i].size() + 2, c_red, '>'); } wrefresh(header_windows[i]); } redraw_list = true; redraw_active = true; redraw_shift = true; redraw_headers = false; } if (selection_changed) { if (active_header == 0) { redraw_list = true; } if (active_header == 1) { redraw_shift = true; redraw_active = true; } selection_changed = false; redraw_description = true; } if (redraw_description) { werase(w_description); MOD_INFORMATION *selmod = NULL; if (mman_ui->usable_mods.empty()) { // Do nothing, leave selmod == NULL } else if (active_header == 0) { selmod = mman->mod_map[mman_ui->usable_mods[cursel[0]]]; } else if (!active_mod_order.empty()) { selmod = mman->mod_map[active_mod_order[cursel[1]]]; } if (selmod != NULL) { fold_and_print(w_description, 0, 1, getmaxx(w_description) - 1, c_white, mman_ui->get_information(selmod)); } redraw_description = false; wrefresh(w_description); } if (redraw_list) { werase(w_list); calcStartPos(startsel[0], cursel[0], getmaxy(w_list), useable_mod_count); if (useable_mod_count == 0) { center_print(w_list, 0, c_red, _("--NO AVAILABLE MODS--")); } else { std::stringstream list_output; for (size_t i = startsel[0], c = 0; i < useable_mod_count && c < getmaxy(w_list); ++i, ++c) { if ((ssize_t)i != cursel[0]) { list_output << std::string(3, ' '); } else { if (active_header == 0) { list_output << "<color_yellow>"; } else { list_output << "<color_blue>"; } list_output << ">></color> "; } list_output << mman->mod_map[mman_ui->usable_mods[i]]->name << "\n"; } fold_and_print(w_list, 0, 1, getmaxx(w_list) - 1, c_white, list_output.str()); } draw_scrollbar(w_list, cursel[0], getmaxy(w_list), useable_mod_count, 0, 0); wrefresh(w_list); } if (redraw_active) { werase(w_active); const int active_count = active_mod_order.size(); calcStartPos(startsel[1], cursel[1], getmaxy(w_active), active_count); if (active_count == 0) { center_print(w_active, 0, c_red, _("--NO ACTIVE MODS--")); } else { std::stringstream list_output; for (int i = startsel[1], c = 0; i < active_count && c < getmaxy(w_active); ++i, ++c) { if (i != cursel[1]) { list_output << std::string(3, ' '); } else { if (active_header == 1) { list_output << "<color_yellow>"; } else { list_output << "<color_blue>"; } list_output << ">></color> "; } list_output << mman->mod_map[active_mod_order[i]]->name << "\n"; } fold_and_print(w_active, 0, 1, getmaxx(w_active) - 1, c_white, list_output.str()); } draw_scrollbar(w_active, cursel[1], getmaxy(w_active), active_count, 0, 0); wrefresh(w_active); } if (redraw_shift) { werase(w_shift); if (active_header == 1) { std::stringstream shift_display; // get shift information for whatever is visible in the active list for (size_t i = startsel[1], c = 0; i < active_mod_order.size() && c < getmaxy(w_active); ++i, ++c) { if (mman_ui->can_shift_up(i, active_mod_order)) { shift_display << "<color_blue>+</color> "; } else { shift_display << "<color_dkgray>+</color> "; } if (mman_ui->can_shift_down(i, active_mod_order)) { shift_display << "<color_blue>-</color>"; } else { shift_display << "<color_dkgray>-</color>"; } shift_display << "\n"; } fold_and_print(w_shift, 2, 1, getmaxx(w_shift), c_white, shift_display.str()); } redraw_shift = false; wrefresh(w_shift); } refresh(); last_active_header = active_header; const int next_header = (active_header == 1) ? 0 : 1; const int prev_header = (active_header == 0) ? 1 : 0; int selection = (active_header == 0) ? cursel[0] : cursel[1]; int last_selection = selection; unsigned int next_selection = selection + 1; int prev_selection = selection - 1; if (active_header == 0) { next_selection = (next_selection >= useable_mod_count) ? 0 : next_selection; prev_selection = (prev_selection < 0) ? useable_mod_count - 1 : prev_selection; } else { next_selection = (next_selection >= active_mod_order.size()) ? 0 : next_selection; prev_selection = (prev_selection < 0) ? active_mod_order.size() - 1 : prev_selection; } const std::string action = ctxt.handle_input(); if (action == "DOWN") { selection = next_selection; } else if (action == "UP") { selection = prev_selection; } else if (action == "RIGHT") { active_header = next_header; } else if (action == "LEFT") { active_header = prev_header; } else if (action == "CONFIRM") { if (active_header == 0 && !mman_ui->usable_mods.empty()) { // try-add mman_ui->try_add(mman_ui->usable_mods[cursel[0]], active_mod_order); redraw_active = true; redraw_shift = true; } else if (active_header == 1 && !active_mod_order.empty()) { // try-rem mman_ui->try_rem(cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; if (active_mod_order.empty()) { // switch back to other list, we can't change // anything in the empty active mods list. active_header = 0; } } } else if (action == "ADD_MOD") { if (active_header == 1 && active_mod_order.size() > 1) { mman_ui->try_shift('+', cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; } } else if (action == "REMOVE_MOD") { if (active_header == 1 && active_mod_order.size() > 1) { mman_ui->try_shift('-', cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; } } else if (action == "NEXT_TAB") { tab_output = 1; } else if (action == "PREV_TAB") { tab_output = -1; } else if (action == "SAVE_DEFAULT_MODS") { if(mman->set_default_mods(active_mod_order)) { popup(_("Saved list of active mods as default")); draw_modselection_borders(win); redraw_headers = true; } } else if (action == "QUIT") { tab_output = -999; } // RESOLVE INPUTS if (last_active_header != (ssize_t)active_header) { redraw_headers = true; redraw_shift = true; redraw_description = true; } if (last_selection != selection) { if (active_header == 0) { redraw_list = true; cursel[0] = selection; } else { redraw_active = true; redraw_shift = true; cursel[1] = selection; } redraw_description = true; } if (active_mod_order.empty()) { redraw_active = true; cursel[1] = 0; } if (active_header == 1) { if (active_mod_order.empty()) { cursel[1] = 0; } else { if (cursel[1] < 0) { cursel[1] = 0; } else if (cursel[1] >= (ssize_t)active_mod_order.size()) { cursel[1] = active_mod_order.size() - 1; } } } // end RESOLVE INPUTS } werase(w_header1); werase(w_header2); werase(w_shift); werase(w_list); werase(w_active); werase(w_description); delwin(w_header1); delwin(w_header2); delwin(w_shift); delwin(w_list); delwin(w_active); delwin(w_description); return tab_output; }
void displaygraphics (int n, struct process* pr1){ int gd = DETECT, gm = VGAMAX; int x, y, i, j; struct process *base = pr1; char m[] = "PBS"; char p[100]; char id[50]; initgraph (&gd, &gm, 0); moveto (0, 0); x = getmaxx (); y = getmaxy (); setcolor (BLUE); rectangle (0, 0, x, y); line (0, y / 3, x, y / 3); setfontcolor (RED); for(i=0; i<n; ++i,++base){ sprintf (p, "Process %d", i + 1); outtextxy (x / n * i, 20, p); sprintf (p, "ID %5u", base->pid); outtextxy (x / n * i, 50, p); sprintf (p, "AT%5u", base->at); outtextxy (x / n * i, 60, p); sprintf (p, "BT %5u", base->bt); outtextxy (x / n * i, 70, p); sprintf (p, "Priority %5u", base->Priority); outtextxy (x / n * i, 90, p); line (x / n * i, 0, x / n * i, y / 3); } //Second Block of Display outtextxy (x / 3, 5 + y / 3, m); setcolor (BLUE); bar (x / 3 + 20, y / 3 + 30, x / 3 + 100, y / 3 + 100); sorting (n, pr1, 20); for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ if ( (pr1[i].Priority) == (pr2[j].Priority) ){ setcolor (BLUE); bar (x / 3 + 20, y / 3 + 30, x / 3 + 100, y / 3 + 100); sprintf (id, "pid%d", pr2[j].pid); outtextxy (x / 3 + 30, y / 3 + 55, id); delay (2000); setfontcolor (BLUE); } } setfontcolor (RED); } setcolor (BLUE); line (0, 2 * y / 3, x, 2 * y / 3); // Third Block of Graphics for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ if ( (pr1[i].Priority) == (pr2[j].Priority) ){ sprintf (id, "pid%d", pr2[j].pid); outtextxy (x / n * i, 2 * (y / 3) + 50, id); delay (2000); } } line (x / n * i, 2 * y / 3, x / n * i ,y); } delay (2000); outtextxy (x - 150, y - 20, "Tapasweni Pathak"); while (!kbhit ()); closegraph (); }
int main() { mkdir(Menufold); char sorcepath[100]; int i; char Ch; fstream fin; fstream foutMenu; fstream foutDesk; screenMain(); stanterdScreen(50,1,9); strcpy(sorcepath,"C:\\MISION\\HELP\\Ad_Book.PIF"); fin.open("C:\\MISION\\VISION\\Ad_Book.PIF",ios::nocreate|ios::in); if(!fin) { cout<<"\n\n\n\n\n\n\n\n\n\n\n\t\t\tFirst Use INSTAL.EXE\n\n\n\n\n"; getch(); exit(0); } fin.close(); fin.open(sorcepath,ios::nocreate|ios::in|ios::binary); if(fin) { foutDesk.open(Desktop,ios::out|ios::trunc|ios::binary); foutMenu.open(StartMenu,ios::out|ios::trunc|ios::binary); } else { cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tError In Process\n\n\t\t\t\tAborted !"; getch(); exit(0); } while(fin) { fin.get(Ch); foutDesk.put(Ch); foutMenu.put(Ch); } fin.close(); foutDesk.close(); foutMenu.close(); cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tDesktop Shortcut Is Created\n\n\t\t\tFile Is Added To Start Menu \n\n\n\n"; fin.open("C:\\MISION\\help\\help.htm",ios::nocreate|ios::in); foutMenu.open(StartMenuhtm,ios::out|ios::trunc|ios::binary); while(fin) { fin.get(Ch); foutMenu.put(Ch); }; fin.close(); foutMenu.close(); stanterdScreen(50,1,9); forMyCollege(); delay(250); Report(11,"Graphics&Header","dreamBlitzer"); Report(11,"Mouse","CCoder"); Report(11,"Data Management","MadCoder"); Report(11,"File & Storage","Looxers"); Report(11,"Desktop & Menu","dreamBlitzer"); setcolor(11); sprintf(msg1,"Thank You"); outtextxy(((getmaxx()-(textwidth(msg1)))/2),getmaxy()/2-50,msg1); initMouse(); showMouse(); setMouseCurserPosition(50,50); outtextxy(180,275,"Press Esc To Exit . . . !"); do { i=getBiosKey(); } while(i!=ESC); return(0); }
// Pick up items at (posx, posy). void Pickup::pick_up(int posx, int posy, int min) { //min == -1 is Autopickup if (g->m.has_flag("SEALED", posx, posy)) { return; } if (!g->u.can_pickup(min != -1)) { // no message on autopickup (-1) return; } int veh_root_part = 0; int cargo_part = -1; vehicle *veh = g->m.veh_at (posx, posy, veh_root_part); bool from_vehicle = false; if( min != -1 ) { cargo_part = interact_with_vehicle( veh, posx, posy, veh_root_part ); from_vehicle = cargo_part >= 0; if( cargo_part == -2 ) { return; } } if( !from_vehicle ) { bool isEmpty = (g->m.i_at(posx, posy).empty()); // Hide the pickup window if this is a toilet and there's nothing here // but water. if ((!isEmpty) && g->m.furn(posx, posy) == f_toilet) { isEmpty = true; for (size_t i = 0; isEmpty && i < g->m.i_at(posx, posy).size(); i++) { if (g->m.i_at(posx, posy)[i].typeId() != "water") { isEmpty = false; } } } if (isEmpty && (min != -1 || !OPTIONS["AUTO_PICKUP_ADJACENT"] )) { return; } } // which items are we grabbing? std::vector<item> here = (from_vehicle) ? veh->parts[cargo_part].items : g->m.i_at(posx, posy); if (min == -1) { if (g->checkZone("NO_AUTO_PICKUP", posx, posy)) { here.clear(); } // Recursively pick up adjacent items if that option is on. if( OPTIONS["AUTO_PICKUP_ADJACENT"] && g->u.posx == posx && g->u.posy == posy ) { //Autopickup adjacent direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST}; for (int i = 0; i < 8; i++) { point apos = direction_XY(adjacentDir[i]); apos.x += posx; apos.y += posy; if( g->m.has_flag( "SEALED", apos.x, apos.y ) ) { continue; } if( g->checkZone( "NO_AUTO_PICKUP", apos.x, apos.y ) ) { continue; } pick_up( apos.x, apos.y, min ); } } } // Not many items, just grab them if ((int)here.size() <= min && min != -1) { g->u.assign_activity( ACT_PICKUP, 0 ); g->u.activity.placement = point( posx, posy ); g->u.activity.values.push_back( from_vehicle ); // Only one item means index is 0. g->u.activity.values.push_back( 0 ); // auto-pickup means pick up all. g->u.activity.values.push_back( 0 ); return; } if(min != -1) { // don't bother if we're just autopickup-ing g->temp_exit_fullscreen(); } bool sideStyle = use_narrow_sidebar(); // Otherwise, we have Autopickup, 2 or more items and should list them, etc. int maxmaxitems = sideStyle ? TERMY : getmaxy(g->w_messages) - 3; int itemsH = std::min(25, TERMY / 2); int pickupBorderRows = 3; // The pickup list may consume the entire terminal, minus space needed for its // header/footer and the item info window. int minleftover = itemsH + pickupBorderRows; if(maxmaxitems > TERMY - minleftover) { maxmaxitems = TERMY - minleftover; } const int minmaxitems = sideStyle ? 6 : 9; std::vector<bool> getitem; getitem.resize(here.size(), false); int maxitems = here.size(); maxitems = (maxitems < minmaxitems ? minmaxitems : (maxitems > maxmaxitems ? maxmaxitems : maxitems )); int pickupH = maxitems + pickupBorderRows; int pickupW = getmaxx(g->w_messages); int pickupY = VIEW_OFFSET_Y; int pickupX = getbegx(g->w_messages); int itemsW = pickupW; int itemsY = sideStyle ? pickupY + pickupH : TERMY - itemsH; int itemsX = pickupX; WINDOW *w_pickup = newwin(pickupH, pickupW, pickupY, pickupX); WINDOW *w_item_info = newwin(itemsH, itemsW, itemsY, itemsX); int ch = ' '; int start = 0, cur_it; int new_weight = g->u.weight_carried(), new_volume = g->u.volume_carried(); bool update = true; mvwprintw(w_pickup, 0, 0, _("PICK UP")); int selected = 0; int last_selected = -1; int itemcount = 0; std::map<int, unsigned int> pickup_count; // Count of how many we'll pick up from each stack if (min == -1) { //Auto Pickup, select matching items if( !select_autopickup_items( here, getitem) ) { // If we didn't find anything, bail out now. return; } } else { if(g->was_fullscreen) { g->draw_ter(); } // Now print the two lists; those on the ground and about to be added to inv // Continue until we hit return or space do { static const std::string pickup_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;"; int idx = -1; for (int i = 1; i < pickupH; i++) { mvwprintw(w_pickup, i, 0, " "); } if (ch >= '0' && ch <= '9') { ch = (char)ch - '0'; itemcount *= 10; itemcount += ch; } else if ((ch == '<' || ch == KEY_PPAGE) && start > 0) { start -= maxitems; selected = start; mvwprintw(w_pickup, maxitems + 2, 0, " "); } else if ((ch == '>' || ch == KEY_NPAGE) && start + maxitems < (int)here.size()) { start += maxitems; selected = start; mvwprintw(w_pickup, maxitems + 2, pickupH, " "); } else if ( ch == KEY_UP ) { selected--; if ( selected < 0 ) { selected = here.size() - 1; start = (int)( here.size() / maxitems ) * maxitems; if (start >= (int)here.size()) { start -= maxitems; } } else if ( selected < start ) { start -= maxitems; } } else if ( ch == KEY_DOWN ) { selected++; if ( selected >= (int)here.size() ) { selected = 0; start = 0; } else if ( selected >= start + maxitems ) { start += maxitems; } } else if ( selected >= 0 && ( ( ch == KEY_RIGHT && !getitem[selected]) || ( ch == KEY_LEFT && getitem[selected] ) ) ) { idx = selected; } else if ( ch == '`' ) { std::string ext = string_input_popup( _("Enter 2 letters (case sensitive):"), 3, "", "", "", 2); if(ext.size() == 2) { int p1 = pickup_chars.find(ext.at(0)); int p2 = pickup_chars.find(ext.at(1)); if ( p1 != -1 && p2 != -1 ) { idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2; } } } else { idx = pickup_chars.find(ch); } if( idx >= 0 && idx < (int)here.size()) { if (itemcount != 0 || pickup_count[idx] == 0) { if (itemcount >= here[idx].charges || !here[idx].count_by_charges()) { // Ignore the count if we pickup the whole stack anyway // or something that is not counted by charges (tools) itemcount = 0; } pickup_count[idx] = itemcount; itemcount = 0; } getitem[idx] = ( ch == KEY_RIGHT ? true : ( ch == KEY_LEFT ? false : !getitem[idx] ) ); if ( ch != KEY_RIGHT && ch != KEY_LEFT) { selected = idx; start = (int)( idx / maxitems ) * maxitems; } if (getitem[idx]) { if (pickup_count[idx] != 0 && (int)pickup_count[idx] < here[idx].charges) { item temp = here[idx].clone(); temp.charges = pickup_count[idx]; new_weight += temp.weight(); new_volume += temp.volume(); } else { new_weight += here[idx].weight(); new_volume += here[idx].volume(); } } else if (pickup_count[idx] != 0 && (int)pickup_count[idx] < here[idx].charges) { item temp = here[idx].clone(); temp.charges = pickup_count[idx]; new_weight -= temp.weight(); new_volume -= temp.volume(); pickup_count[idx] = 0; } else { new_weight -= here[idx].weight(); new_volume -= here[idx].volume(); } update = true; } if ( selected != last_selected ) { last_selected = selected; werase(w_item_info); if ( selected >= 0 && selected <= (int)here.size() - 1 ) { std::vector<iteminfo> vThisItem, vDummy; here[selected].info(true, &vThisItem); draw_item_info(w_item_info, "", vThisItem, vDummy, 0, true, true); } draw_border(w_item_info); mvwprintz(w_item_info, 0, 2, c_white, "< %s >", here[selected].display_name().c_str()); wrefresh(w_item_info); } if (ch == ',') { int count = 0; for (size_t i = 0; i < here.size(); i++) { if (getitem[i]) { count++; } else { new_weight += here[i].weight(); new_volume += here[i].volume(); } getitem[i] = true; } if (count == (int)here.size()) { for (size_t i = 0; i < here.size(); i++) { getitem[i] = false; } new_weight = g->u.weight_carried(); new_volume = g->u.volume_carried(); } update = true; } for (cur_it = start; cur_it < start + maxitems; cur_it++) { mvwprintw(w_pickup, 1 + (cur_it % maxitems), 0, " "); if (cur_it < (int)here.size()) { nc_color icolor = here[cur_it].color(&g->u); if (cur_it == selected) { icolor = hilite(icolor); } if (cur_it < (int)pickup_chars.size() ) { mvwputch(w_pickup, 1 + (cur_it % maxitems), 0, icolor, char(pickup_chars[cur_it])); } else { int p = cur_it - pickup_chars.size(); int p1 = p / pickup_chars.size(); int p2 = p % pickup_chars.size(); mvwprintz(w_pickup, 1 + (cur_it % maxitems), 0, icolor, "`%c%c", char(pickup_chars[p1]), char(pickup_chars[p2])); } if (getitem[cur_it]) { if (pickup_count[cur_it] == 0) { wprintz(w_pickup, c_ltblue, " + "); } else { wprintz(w_pickup, c_ltblue, " # "); } } else { wprintw(w_pickup, " - "); } wprintz(w_pickup, icolor, "%s", here[cur_it].display_name().c_str()); } } int pw = pickupW; const char *unmark = _("[left] Unmark"); const char *scroll = _("[up/dn] Scroll"); const char *mark = _("[right] Mark"); mvwprintw(w_pickup, maxitems + 1, 0, unmark); mvwprintw(w_pickup, maxitems + 1, (pw - strlen(scroll)) / 2, scroll); mvwprintw(w_pickup, maxitems + 1, pw - strlen(mark), mark); const char *prev = _("[pgup] Prev"); const char *all = _("[,] All"); const char *next = _("[pgdn] Next"); if (start > 0) { mvwprintw(w_pickup, maxitems + 2, 0, prev); } mvwprintw(w_pickup, maxitems + 2, (pw - strlen(all)) / 2, all); if (cur_it < (int)here.size()) { mvwprintw(w_pickup, maxitems + 2, pw - strlen(next), next); } if (update) { // Update weight & volume information update = false; for (int i = 9; i < pickupW; ++i) { mvwaddch(w_pickup, 0, i, ' '); } mvwprintz(w_pickup, 0, 9, (new_weight >= g->u.weight_capacity() ? c_red : c_white), _("Wgt %.1f"), g->u.convert_weight(new_weight)); wprintz(w_pickup, c_white, "/%.1f", g->u.convert_weight(g->u.weight_capacity())); mvwprintz(w_pickup, 0, 24, (new_volume > g->u.volume_capacity() - 2 ? c_red : c_white), _("Vol %d"), new_volume); wprintz(w_pickup, c_white, "/%d", g->u.volume_capacity() - 2); } wrefresh(w_pickup); ch = (int)getch(); } while (ch != ' ' && ch != '\n' && ch != KEY_ESCAPE); if (ch != '\n') { werase(w_pickup); wrefresh(w_pickup); werase(w_item_info); wrefresh(w_item_info); delwin(w_pickup); delwin(w_item_info); add_msg(_("Never mind.")); g->reenter_fullscreen(); g->refresh_all(); return; } } // At this point we've selected our items, register an activity to pick them up. g->u.assign_activity( ACT_PICKUP, 0 ); g->u.activity.placement = point( posx, posy ); g->u.activity.values.push_back( from_vehicle ); if( min == -1 ) { // Auto pickup will need to auto resume since there can be several of them on the stack. g->u.activity.auto_resume = true; } for (size_t i = 0; i < here.size(); i++) { if( getitem[i] ) { g->u.activity.values.push_back( i ); g->u.activity.values.push_back( pickup_count[i] ); } } g->reenter_fullscreen(); werase(w_pickup); wrefresh(w_pickup); werase(w_item_info); wrefresh(w_item_info); delwin(w_pickup); delwin(w_item_info); }
/* Runs the host editor. Another big use for this is to open sites * that are in your host list. */ int HostWindow(void) { int c; char cmd[256]; volatile BookmarkPtr toOpen; vsigproc_t si; int maxy, maxx; int lmaxy; si = (sigproc_t) (-1); if (gWinInit) { gHostListWin = NULL; gHostWin = NULL; gHostWin = newwin(LINES, COLS, 0, 0); if (gHostWin == NULL) return (-1); curs_set(0); cbreak(); /* Set the clear flag for the first update. */ wclear(gHostWin); keypad(gHostWin, TRUE); /* For arrow keys. */ #ifdef HAVE_NOTIMEOUT notimeout(gHostWin, TRUE); #endif #ifdef HAVE_SIGSETJMP if (sigsetjmp(gHostWinJmp, 1) == 0) { #else /* HAVE_SIGSETJMP */ if (setjmp(gHostWinJmp) == 0) { #endif /* HAVE_SIGSETJMP */ /* Gracefully cleanup the screen if the user ^C's. */ si = NcSignal(SIGINT, SigIntHostWin); /* Initialize the page start and select a host to be * the current one. */ gHostListWinStart = 0; gHilitedHost = 0; if (gNumBookmarks == 0) gCurHostListItem = NULL; else gCurHostListItem = &gBookmarkTable[gHilitedHost]; /* Initially, we don't want to connect to any site in * the host list. */ toOpen = NULL; getmaxyx(gHostWin, maxy, maxx); WAttr(gHostWin, kBold, 1); WAddCenteredStr(gHostWin, 0, "NcFTP Bookmark Editor"); WAttr(gHostWin, kBold, 0); DrawStrAt(gHostWin, 3, 2, "Open selected site: <enter>"); DrawStrAt(gHostWin, 4, 2, "Edit selected site: /ed"); DrawStrAt(gHostWin, 5, 2, "Delete selected site: /del"); DrawStrAt(gHostWin, 6, 2, "Duplicate selected site: /dup"); DrawStrAt(gHostWin, 7, 2, "Add a new site: /new"); DrawStrAt(gHostWin, 9, 2, "Up one: <u>"); DrawStrAt(gHostWin, 10, 2, "Down one: <d>"); DrawStrAt(gHostWin, 11, 2, "Previous page: <p>"); DrawStrAt(gHostWin, 12, 2, "Next page: <n>"); DrawStrAt(gHostWin, 14, 2, "Capital letters selects first"); DrawStrAt(gHostWin, 15, 2, " site starting with the letter."); DrawStrAt(gHostWin, 17, 2, "Exit the bookmark editor: <x>"); /* Initialize the scrolling host list window. */ if (maxx < 110) { gHostListWinWide = 0; gHostListWin = subwin( gHostWin, LINES - 7, 40, 3, COLS - 40 - 2 ); } else { gHostListWinWide = COLS - 42; gHostListWin = subwin( gHostWin, LINES - 7, gHostListWinWide, 3, 38 ); } if (gHostListWin == NULL) return (-1); lmaxy = getmaxy(gHostListWin); gHostListPageSize = lmaxy; DrawHostList(); wmove(gHostWin, maxy - 1, 0); UpdateHostWindows(1); for (;;) { c = HostWinGetKey(); if (gNeedToClearMsg) { wmove(gHostWin, maxy - 2, 0); wclrtoeol(gHostWin); wrefresh(gHostWin); } if ((c >= 'A') && (c <= 'Z')) { /* isupper can coredump if wgetch returns a meta key. */ HostWinZoomTo(c); } else if (c == '/') { /* Get an "extended" command. Sort of like vi's * :colon commands. */ HostWinGetStr(cmd, sizeof(cmd)); if (ISTREQ(cmd, "ed")) HostWinEdit(); else if (ISTREQ(cmd, "dup")) HostWinDup(); else if (ISTREQ(cmd, "del")) HostWinDelete(); else if (ISTREQ(cmd, "new")) HostWinNew(); else HostWinMsg("Invalid bookmark editor command."); } else switch(c) { case 10: /* ^J == newline */ goto enter; case 13: /* ^M == carriage return */ goto enter; #ifdef KEY_ENTER case KEY_ENTER: Trace(1, " [0x%04X, %s]\n", c, "ENTER"); #endif enter: if (gCurHostListItem == NULL) HostWinMsg("Nothing to open. Try 'open sitename' from the main screen."); else { toOpen = (BookmarkPtr) gCurHostListItem; goto done; } break; case kControl_L: UpdateHostWindows(1); break; case 'u': case 'k': /* vi up key */ case 'h': /* vi left key */ HostListLineUp(); break; #ifdef KEY_UP case KEY_UP: Trace(1, " [0x%04X, %s]\n", c, "UP"); HostListLineUp(); break; #endif #ifdef KEY_LEFT case KEY_LEFT: Trace(1, " [0x%04X, %s]\n", c, "LEFT"); HostListLineUp(); break; #endif case 'd': case 'j': /* vi down key */ case 'l': /* vi right key */ HostListLineDown(); break; #ifdef KEY_DOWN case KEY_DOWN: Trace(1, " [0x%04X, %s]\n", c, "DOWN"); HostListLineDown(); break; #endif #ifdef KEY_RIGHT case KEY_RIGHT: Trace(1, " [0x%04X, %s]\n", c, "RIGHT"); HostListLineDown(); break; #endif case 'p': HostListPageUp(); break; #ifdef KEY_PPAGE case KEY_PPAGE: Trace(1, " [0x%04X, %s]\n", c, "PPAGE"); HostListPageUp(); break; #endif case 'n': HostListPageDown(); break; #ifdef KEY_NPAGE case KEY_NPAGE: Trace(1, " [0x%04X, %s]\n", c, "NPAGE"); HostListPageDown(); break; #endif case 'x': case 'q': goto done; default: HostWinMsg("Invalid key."); Trace(1, " [0x%04X, %s]\n", c, "<invalid>"); break; } } } NcSignal(SIGINT, (FTPSigProc) SIG_IGN); done: if (gHostListWin != NULL) delwin(gHostListWin); if (gHostWin != NULL) delwin(gHostWin); gHostListWin = gHostWin = NULL; if (si != (sigproc_t) (-1)) NcSignal(SIGINT, si); if (toOpen != (BookmarkPtr) 0) { /* If the user selected a site to open, connect to it now. */ if (gStandAlone != 0) { LaunchNcFTP(toOpen->bookmarkName); /*NOTREACHED*/ Exit(0); } else if (gBookmarkSelectionFile != NULL) { WriteSelectedBMToFile(toOpen->bookmarkName); } return (kNoErr); } } return (kNoErr); } /* HostWindow */ main_void_return_t main(int argc, const char **argv) { int result; int argi; gStandAlone = 1; gBookmarkSelectionFile = NULL; InitUserInfo(); if (LoadBookmarkTable() < 0) { exit(7); } if (argc > 1) { /* The following hack is used by NcFTP * to get the number of columns without * having to link with curses/termcap. * This simplifies things since the * system may or may not have a good * curses implementation, and we don't * want to complicate NcFTP itself with * that. */ argi = 1; if (strcmp(argv[1], "--dimensions") == 0) { result = PrintDimensions(0); exit((result == 0) ? 0 : 1); } else if (strcmp(argv[1], "--dimensions-terse") == 0) { result = PrintDimensions(1); exit((result == 0) ? 0 : 1); } else if (strcmp(argv[1], "--debug") == 0) { SetDebug(1); argi++; } /* Requested that we were run from ncftp. */ gStandAlone = 0; if ((argc > argi) && (argv[argi][0] == '/')) gBookmarkSelectionFile = (const char *) argv[argi]; if (gNumBookmarks < 1) exit(7); } result = FTPInitLibrary(&gLib); if (result < 0) { (void) fprintf(stderr, "ncftp: init library error %d (%s).\n", result, FTPStrError(result)); exit(1); } result = FTPInitConnectionInfo(&gLib, &gConn, kDefaultFTPBufSize); if (result < 0) { (void) fprintf(stderr, "ncftp: init connection info error %d (%s).\n", result, FTPStrError(result)); exit(1); } if (gDebug > 0) OpenTrace(); InitPrefs(); LoadFirewallPrefs(0); LoadPrefs(); InitWindows(); Trace(1, "Terminal size is %d columns by %d rows.\n", gScreenWidth, gScreenHeight); HostWindow(); if (gDebug > 0) CloseTrace(); EndWin(); exit(0); } /* main */
void graphicize() { clrscr(); int gd = DETECT, gm, errorcode; int rect[8]={0}; initgraph(&gd, &gm, "c://turboc3/tc/bgi"); errorcode = graphresult(); if (errorcode != grOk) { cout << ":: Graphics error ::"; cout << "\nCheck the BGI Directory Path for Graphics Files"; getch(); exit(1); } int gmx=getmaxx(); int gmy=getmaxy(); setviewport((gmx-600)/2, (gmy-200)/2, ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); setbkcolor(3); setcolor(1); line(0,0,600,0);line(0,30,600,30);line(0,60,600,60); line(0,90,600,90);line(0,120,600,120);line(0,150,600,150); line(0,180,600,180); int r; int l; for(l=0;l<gsize;l++) { rect[0]=gtable[l][1]; rect[1]=(gtable[l][0]-1)*30; rect[2]=gtable[l][2]; rect[3]=(gtable[l][0]-1)*30; rect[4]=gtable[l][2]; rect[5]=gtable[l][0]*30; rect[6]=gtable[l][1]; rect[7]=gtable[l][0]*30; setfillstyle(SOLID_FILL,6); fillpoly(4,rect); } setviewport((gmx-600)/2+3, (gmy-200)/2-20, ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); outtextxy(0,5,"01"); outtextxy(20,5,"02"); outtextxy(40,5,"03"); outtextxy(60,5,"04"); outtextxy(80,5,"05"); outtextxy(100,5,"06"); outtextxy(120,5,"07"); outtextxy(140,5,"08"); outtextxy(160,5,"09"); outtextxy(180,5,"10"); outtextxy(200,5,"11"); outtextxy(220,5,"12"); outtextxy(240,5,"13"); outtextxy(260,5,"14"); outtextxy(280,5,"15"); outtextxy(300,5,"16"); outtextxy(320,5,"17"); outtextxy(340,5,"18"); outtextxy(360,5,"19"); outtextxy(380,5,"20"); outtextxy(400,5,"21"); outtextxy(420,5,"22"); outtextxy(440,5,"23"); outtextxy(460,5,"24"); outtextxy(480,5,"25"); outtextxy(500,5,"26"); outtextxy(520,5,"27"); outtextxy(540,5,"28"); outtextxy(560,5,"29"); outtextxy(580,5,"30"); setviewport((gmx-600)/2, (gmy-200)/2-20, ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); line(0,0,600,0); for(r=0;r<31;r++) { line(20*r,0,20*r,200); } setviewport((gmx-600)/2, 50 , ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); setcolor(4); settextstyle(DEFAULT_FONT,HORIZ_DIR,3); outtext("GANNT CHART"); setviewport((gmx-600)/2, 80 , ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); setcolor(8); settextstyle(DEFAULT_FONT,HORIZ_DIR,1); outtext("No. of Processes : "); if(n==1) outtext("1"); if(n==2) outtext("2"); if(n==3) outtext("3"); if(n==4) outtext("4"); if(n==5) outtext("5"); if(n==6) outtext("6"); setviewport((gmx-600)/2, 100 , ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); outtext("Scheduling Method : "); if(choice=='1') outtext("FCFS - First Come First Serve"); if(choice=='2') outtext("SJF - Shortest Job First"); if(choice=='3') outtext("SRTF - Shortest Remaining Time First"); if(choice=='4') outtext("RR - Round Robin"); setviewport((gmx-600)/2-10, (gmy-200)/2, ((gmx-600)/2)+600, ((gmy-200)/2)+200, 1); setcolor(1); outtextxy(0,25-15,"1"); outtextxy(0,55-15,"2"); outtextxy(0,85-15,"3"); outtextxy(0,115-15,"4"); outtextxy(0,145-15,"5"); outtextxy(0,175-15,"6"); getch(); closegraph(); }
main() { int driver = DETECT, mode; char c; int k1[] = { 0, 0, 20, 0, 20, 60, 30, 60, 30, 100, 0, 100, 0, 0 }; int k2[] = { 40, 0, 50, 0, 50, 60, 60, 60, 60, 100, 30, 100, 30, 60, 40, 60, 40, 0 }; int k3[] = { 70, 0, 90, 0, 90, 100, 60, 100, 60, 60, 70, 60, 70, 0 }; int k4[] = { 90, 0, 110, 0, 110, 60, 120, 60, 120, 100, 90, 100, 90, 0 }; int k5[] = { 130, 0, 140, 0, 140, 60, 150, 60, 150, 100, 120, 100, 120, 60, 130, 60, 130, 0 }; int k6[] = { 160, 0, 170, 0, 170, 60, 180, 60, 180, 100, 150, 100, 150, 60, 160, 60, 160, 0 }; int k7[] = { 190, 0, 210, 0, 210, 100, 180, 100, 180, 60, 190, 60, 190, 0 }; int k8[] = { 210, 0, 230, 0, 230, 60, 240, 60, 240, 100, 210, 100, 210, 0 }; int k9[] = { 250, 0, 260, 0, 260, 60, 270, 60, 270, 100, 240, 100, 240, 60, 250, 60, 250, 0 }; int k10[] = { 280, 0, 300, 0, 300, 100, 270, 100, 270, 60, 280, 60, 280, 0 }; int k11[] = { 300, 0, 330, 0, 330, 100, 300, 100, 300, 0 }; int k12[] = { 330, 0, 360, 0, 360, 100, 330, 100, 330, 0 }; initgraph(&driver, &mode, ""); int maxx = getmaxx(); int maxy = getmaxy(); for (long j = 0; j <= 300; j++) { putpixel(random(maxx), random(maxy), 4); delay(1); } setfillstyle(SOLID_FILL, BLACK); bar(89, 39, 571, 261); setlinestyle(SOLID_LINE, 3, 3); line(90, 50, 90, 250); //outline line(100, 40, 540, 40); line(100, 260, 540, 260); line(550, 250, 550, 50); arc(100, 50, 90, 180, 10); arc(100, 250, 180, 270, 10); arc(540, 250, 270, 360, 10); arc(540, 50, 0, 90, 10); circle(200, 90, 35); setfillstyle(SOLID_FILL, 9); floodfill(200, 90, WHITE); circle(482, 95, 42); setfillstyle(SOLID_FILL, 3); floodfill(482, 95, WHITE); setlinestyle(SOLID_LINE, 1, 1); rectangle(270, 60, 370, 130); setfillstyle(SOLID_FILL, 14); floodfill(290, 80, WHITE); rectangle(270, 130, 295, 140); setfillstyle(SOLID_FILL, 5); floodfill(280, 135, WHITE); rectangle(295, 130, 320, 140); setfillstyle(SOLID_FILL, 5); floodfill(300, 135, WHITE); rectangle(320, 130, 345, 140); setfillstyle(SOLID_FILL, 5); floodfill(330, 135, WHITE); rectangle(345, 130, 370, 140); setfillstyle(SOLID_FILL, 5); floodfill(350, 135, WHITE); rectangle(120, 60, 145, 70); setfillstyle(SOLID_FILL, 1); floodfill(130, 65, WHITE); rectangle(120, 90, 145, 100); setfillstyle(SOLID_FILL, 1); floodfill(130, 95, WHITE); ellipse(132, 125, 0, 360, 11, 8); setfillstyle(SOLID_FILL, RED); floodfill(132, 125, WHITE); circle(230, 130, 5); setfillstyle(SOLID_FILL, RED); floodfill(230, 130, WHITE); rectangle(387, 60, 427, 75); setfillstyle(SOLID_FILL, 10); floodfill(395, 70, WHITE); rectangle(385, 90, 403, 110); setfillstyle(SOLID_FILL, 6); floodfill(390, 100, WHITE); rectangle(411, 90, 430, 110); setfillstyle(SOLID_FILL, 6); floodfill(420, 100, WHITE); rectangle(387, 120, 427, 135); setfillstyle(SOLID_FILL, 10); floodfill(395, 130, WHITE); rectangle(150, 260, 510, 250); setfillstyle(SOLID_FILL, 8); floodfill(180, 255, WHITE); circle(500, 120, 6); setfillstyle(SOLID_FILL, 8); floodfill(500, 120, WHITE); setviewport(225, 300, 530, 410, 1); int poly1[] = { 0, 2, 12, 60, 22, 54, 18, 28, 35, 2, 0, 2 }; int poly2[] = { 10, 10, 23, 10, 14, 20, 10, 10 }; int poly3[] = { 50, 0, 60, 2, 60, 45, 50, 42, 50, 0 }; int poly4[] = { 71, 70, 83, 13, 105, 74, 87, 53, 71, 70 }; int poly5[] = { 85, 30, 90, 45, 83, 43, 85, 30 }; int poly6[] = { 110, 53, 120, 2, 130, 57, 148, 0, 135, 84, 132, 84, 118, 29, 110, 53 }; int poly7[] = { 177, 2, 200, 35, 180, 85, 160, 33, 177, 2 }; int poly8[] = { 178, 20, 190, 35, 179, 70, 166, 34, 178, 20 }; drawpoly(6, poly1); setfillstyle(SOLID_FILL, RED); fillpoly(6, poly1); drawpoly(4, poly2); setfillstyle(SOLID_FILL, BLACK); fillpoly(4, poly2); drawpoly(5, poly3); setfillstyle(SOLID_FILL, RED); fillpoly(5, poly3); drawpoly(5, poly4); setfillstyle(SOLID_FILL, RED); fillpoly(5, poly4); drawpoly(4, poly5); setfillstyle(SOLID_FILL, BLACK); fillpoly(4, poly5); drawpoly(8, poly6); setfillstyle(SOLID_FILL, RED); fillpoly(8, poly6); drawpoly(5, poly7); setfillstyle(SOLID_FILL, RED); fillpoly(5, poly7); drawpoly(5, poly8); setfillstyle(SOLID_FILL, BLACK); fillpoly(5, poly8); setviewport(150, 150, 510, 250, 1); pnobody(); c = getch(); do { switch (c) { case 'q': { setfillstyle(SOLID_FILL, GREEN); fillpoly(7, k1); pno(261); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k1); break; } case 'w': { setfillstyle(SOLID_FILL, RED); fillpoly(9, k2); pno(293); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k2); pnobody(); break; } case 'e': { setfillstyle(SOLID_FILL, GREEN); fillpoly(7, k3); pno(329); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k3); pnobody(); break; } case 'r': { setfillstyle(SOLID_FILL, RED); fillpoly(7, k4); pno(350); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k4); pnobody(); break; } case 't': { setfillstyle(SOLID_FILL, GREEN); fillpoly(9, k5); pno(392); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k5); pnobody(); break; } case 'y': { setfillstyle(SOLID_FILL, RED); fillpoly(9, k6); pno(440); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k6); pnobody(); break; } case 'u': { setfillstyle(SOLID_FILL, GREEN); fillpoly(7, k7); pno(493); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k7); pnobody(); break; } case 'i': { setfillstyle(SOLID_FILL, RED); fillpoly(7, k8); pno(523); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k8); pnobody(); break; } case 'o': { setfillstyle(SOLID_FILL, GREEN); fillpoly(9, k9); pno(587); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k9); pnobody(); break; } case 'p': { setfillstyle(SOLID_FILL, RED); fillpoly(7, k10); pno(659); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k10); pnobody(); break; } case '[': { setfillstyle(SOLID_FILL, GREEN); fillpoly(5, k11); pno(698); setfillstyle(SOLID_FILL, BLUE); fillpoly(5, k11); pnobody(); break; } case ']': { setfillstyle(SOLID_FILL, RED); fillpoly(5, k12); pno(784); setfillstyle(SOLID_FILL, BLUE); fillpoly(5, k12); pnobody(); break; } case '1': { setfillstyle(SOLID_FILL, YELLOW); bar(20, 0, 40, 60); pno(311); setfillstyle(SOLID_FILL, BLACK); bar(20, 0, 40, 60); pnobody(); break; } case '2': { setfillstyle(SOLID_FILL, WHITE); bar(50, 0, 70, 60); pno(370); setfillstyle(SOLID_FILL, BLACK); bar(50, 0, 70, 60); pnobody(); break; } case '4': { setfillstyle(SOLID_FILL, YELLOW); bar(110, 0, 130, 60); pno(415); setfillstyle(SOLID_FILL, BLACK); bar(110, 0, 130, 60); pnobody(); break; } case '5': { setfillstyle(SOLID_FILL, WHITE); bar(140, 0, 160, 60); pno(466); setfillstyle(SOLID_FILL, BLACK); bar(140, 0, 160, 60); pnobody(); break; } case '6': { setfillstyle(SOLID_FILL, YELLOW); bar(170, 0, 190, 60); pno(554); setfillstyle(SOLID_FILL, BLACK); bar(170, 0, 190, 60); pnobody(); break; } case '8': { setfillstyle(SOLID_FILL, WHITE); bar(230, 0, 250, 60); pno(662); setfillstyle(SOLID_FILL, BLACK); bar(230, 0, 250, 60); pnobody(); break; } case '9': { setfillstyle(SOLID_FILL, YELLOW); bar(260, 0, 280, 60); pno(740); setfillstyle(SOLID_FILL, BLACK); bar(260, 0, 280, 60); pnobody(); break; } case 'Q': { setfillstyle(SOLID_FILL, GREEN); fillpoly(7, k1); pno(261); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k1); break; } case 'W': { setfillstyle(SOLID_FILL, RED); fillpoly(9, k2); pno(293); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k2); pnobody(); break; } case 'E': { setfillstyle(SOLID_FILL, GREEN); fillpoly(7, k3); pno(329); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k3); pnobody(); break; } case 'R': { setfillstyle(SOLID_FILL, RED); fillpoly(7, k4); pno(350); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k4); pnobody(); break; } case 'T': { setfillstyle(SOLID_FILL, GREEN); fillpoly(9, k5); pno(392); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k5); pnobody(); break; } case 'Y': { setfillstyle(SOLID_FILL, RED); fillpoly(9, k6); pno(440); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k6); pnobody(); break; } case 'U': { setfillstyle(SOLID_FILL, GREEN); fillpoly(7, k7); pno(493); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k7); pnobody(); break; } case 'I': { setfillstyle(SOLID_FILL, RED); fillpoly(7, k8); pno(523); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k8); pnobody(); break; } case 'O': { setfillstyle(SOLID_FILL, GREEN); fillpoly(9, k9); pno(587); setfillstyle(SOLID_FILL, BLUE); fillpoly(9, k9); pnobody(); break; } case 'P': { setfillstyle(SOLID_FILL, RED); fillpoly(7, k10); pno(659); setfillstyle(SOLID_FILL, BLUE); fillpoly(7, k10); pnobody(); break; } case ' ': { break; } } c = getch(); } while (c != ' '); setviewport(0, 0, maxx, maxy, 1); cleardevice(); for (j = 0; j <= 1100; j++) { putpixel(random(maxx), random(maxy), 4); delay(1); } setcolor(4); outtextxy(270, 150, "C R E D I T S"); for (int i = 0; i <= 3; i++) { outtextxy(260, 155 + i, "_______________"); } delay(600); outtextxy(150, 200, " #Suvojit Manna:Concept & Design,Core Programing"); outtextxy(160, 205, "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "); delay(600); outtextxy(165, 250, " #Prangshu Shyam:Graphical Assisstance"); outtextxy(180, 255, "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "); delay(600); outtextxy(200, 300, " #Sourav Kundu:Final Compilation"); outtextxy(210, 305, "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ "); getch(); return 0; }
/* * This creates the alphalist widget. */ CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, char *list[], int listSize, chtype fillerChar, chtype highlight, boolean Box, boolean shadow) { /* Set up some variables. */ CDKALPHALIST *alphalist = newCDKObject(CDKALPHALIST, &my_funcs); chtype *chtypeLabel = 0; int parentWidth = getmaxx(cdkscreen->window) - 1; int parentHeight = getmaxy(cdkscreen->window) - 1; int boxWidth = width; int boxHeight = height; int xpos = xplace; int ypos = yplace; int entryWidth = 0; int labelLen = 0; int x, junk2; /* * If the height is a negative value, the height will * be ROWS-height, otherwise, the height will be the * given height. */ boxHeight = setWidgetDimension (parentHeight, height, 0); /* * If the width is a negative value, the width will * be COLS-width, otherwise, the width will be the * given width. */ boxWidth = setWidgetDimension (parentWidth, width, 0); /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { chtypeLabel = char2Chtype (label, &labelLen, &junk2); freeChtype (chtypeLabel); } /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the file selector window. */ alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos); if (alphalist->win == 0) { return (0); } keypad (alphalist->win, TRUE); /* Set some variables. */ ScreenOf(alphalist) = cdkscreen; alphalist->parent = cdkscreen->window; alphalist->highlight = highlight; alphalist->fillerChar = fillerChar; alphalist->boxHeight = boxHeight; alphalist->boxWidth = boxWidth; alphalist->exitType = vNEVER_ACTIVATED; ObjOf(alphalist)->box = Box; alphalist->shadow = shadow; alphalist->shadowWin = 0; /* Do we want a shadow? */ if (shadow) { alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); } /* We need to sort the list before we use it. */ sortList (list, listSize); /* Copy the list information. */ for (x=0; x < listSize; x++) { alphalist->list[x] = copyChar (list[x]); } alphalist->listSize = listSize; /* Create the entry field. */ entryWidth = boxWidth - (labelLen + 4); alphalist->entryField = newCDKEntry (cdkscreen, getbegx(alphalist->win) + 1, getbegy(alphalist->win) + 1, title, label, A_NORMAL, fillerChar, vMIXED, entryWidth, 0, 512, Box, FALSE); setCDKEntryLLChar (alphalist->entryField, ACS_LTEE); setCDKEntryLRChar (alphalist->entryField, ACS_RTEE); /* Set the key bindings for the entry field. */ bindCDKObject (vENTRY, alphalist->entryField, KEY_UP, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_DOWN, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_NPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, CONTROL('F'), adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_PPAGE, adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, CONTROL('B'), adjustAlphalistCB, alphalist); bindCDKObject (vENTRY, alphalist->entryField, KEY_TAB, completeWordCB, alphalist); /* Set up the post-process function for the entry field. */ setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist); /* Create the scrolling list. */ alphalist->scrollField = newCDKScroll (cdkscreen, getbegx(alphalist->win) + 1, getbegy(alphalist->win) + (alphalist->entryField)->titleLines + 3, RIGHT, boxHeight-((alphalist->entryField)->titleLines + 3), boxWidth-3, 0, list, listSize, NONUMBERS, A_REVERSE, Box, FALSE); setCDKScrollULChar (alphalist->scrollField, ACS_LTEE); setCDKScrollURChar (alphalist->scrollField, ACS_RTEE); /* Register this baby. */ registerCDKObject (cdkscreen, vALPHALIST, alphalist); /* Return the file selector pointer. */ return (alphalist); }
void main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int midx, midy,i,j,f; float ar,rr,a; float x [4],y[4]; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initi alization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } midx = getmaxx() / 2; midy = getmaxy() / 2; ar=6.283185307/d; rr=midy; for(f=1;f<=d;f++) { x[0]=midx; y[0]=midy; a=(f-1)*ar; x[1]=cos(a)*rr+midx; y[1]=sin(a)*rr+midy; a=f*ar; x[2]=cos(a)*rr+midx; y[2]=sin(a)*rr+midy; x[3]=x[0]; y[3]=y[0]; for(j=1;j<=r;j++) { for(i=0;i<3;i++) { line(x[i],y[i],x[i+1],y[i+1]); } if(f%2==1) { for(i=3;i>0;i--) { x[i]+=(x[i-1]-x[i])/z; y[i]+=(y[i-1]-y[i])/z; } x[0]=x[3]; y[0]=y[3]; } else { for(i=0;i<3;i++) { x[i]+=(x[i+1]-x[i])/z; y[i]+=(y[i+1]-y[i])/z; } x[3]=x[0]; y[3]=y[0]; }//end if else }//end for j } getch(); closegraph(); }
void main() { int xmax,ymax,gd=0,gm,tx,ty,k; initgraph(&gd,&gm,"c:\\tc\\bgi"); xmax=getmaxx(); ymax=getmaxy(); line(xmax/2,0,xmax/2,ymax); line(0,ymax/2,xmax,ymax/2); int a[10][10],b[10][10],c[10][10],d[10][10],temp[10][10],i,j,n; cout<<"Enter no of vertices:-"; cin>>n; for(i=0;i<n;i++) { cout<<"\nEnter co-ordi of "<<i+1<<"point:"; for(j=0;j<3;j++) { cin>>a[i][j]; } } setcolor(46); int ch1,ch2,y=1,sx,sy; int m=0,q=0,o=0; while(y==1) { for(i=0;i<n-1;i++) { line(xmax/2+a[i][0],ymax/2-a[i][1],xmax/2+a[i+1][0],ymax/2-a[i+1][1]); } line(xmax/2+a[i][0],ymax/2-a[i][1],xmax/2+a[0][0],ymax/2-a[0][1]); setcolor(15); cout<<"\n1.translation \n2.Rotation abt origin\n3.Rotation abt point\n4.Reflection\n5.Scaling"; cout<<"\nEnter ur choice:-"; cin>>ch1; switch(ch1) { case 1: b[0][0]=1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=1;b[1][2]=0; cout<<"\nEnter tx and ty:-"; cin>>tx>>ty; b[2][0]=tx;b[2][1]=ty;b[2][2]=1; break; case 2: cout<<"\n1.90 \t2.180\t3.270\t4.360"; cout<<"\nEnter ur choice:-"; cin>>ch2; switch(ch2) { case 1: b[0][0]=0;b[0][1]=1;b[0][2]=0; b[1][0]=-1;b[1][1]=0;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 2: b[0][0]=-1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=-1;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 3: b[0][0]=0;b[0][1]=-1;b[0][2]=0; b[1][0]=1;b[1][1]=0;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 4: b[0][0]=1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=1;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; } //end rot switch break; case 3: cout<<"\nEnter the co-ords of the fixed point : "; cin>>tx>>ty; temp[0][0]=1;temp[0][1]=0;temp[0][2]=0; temp[1][0]=0;temp[1][1]=1;temp[1][2]=0; temp[2][0]=-tx;temp[2][1]=-ty;temp[2][2]=1; cout<<"\n1.90 \t2.180\t3.270\t4.360"; cout<<"\nEnter ur choice:-"; cin>>ch2; switch(ch2) { case 1: b[0][0]=0;b[0][1]=1;b[0][2]=0; b[1][0]=-1;b[1][1]=0;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 2: b[0][0]=-1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=-1;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 3: b[0][0]=0;b[0][1]=-1;b[0][2]=0; b[1][0]=1;b[1][1]=0;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 4: b[0][0]=1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=1;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; } for(m = 0;m<3;m++) for(q = 0;q<3;q++) for(o = 0;o<3;o++) d[m][q] = d[m][q] + (temp[m][o]*b[o][q]); temp[2][0]=-tx;temp[2][1]=-ty; for(m = 0;m<3;m++) for(q = 0;q<3;q++) b[m][q] = 0; for(m = 0;m<3;m++) for(q = 0;q<3;n++) for(o = 0;o<3;o++) b[m][q] = b[m][q] + (d[m][o]*temp[o][q]); break; case 4: cout<<"\n1.Ref thru x axis \n2.Ref thru y axis\n3.Ref thru x=y axis\n4.Ref thru x=-y axis"; cout<<"\nEnter ur choice:-"; cin>>ch2; switch(ch2) { case 1: b[0][0]=1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=-1;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 2: b[0][0]=-1;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=1;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 3: b[0][0]=0;b[0][1]=1;b[0][2]=0; b[1][0]=1;b[1][1]=0;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; case 4: b[0][0]=0;b[0][1]=-1;b[0][2]=0; b[1][0]=-1;b[1][1]=0;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; } //end ref switch break; case 5: cout<<"\nEnter scaling factors sx and sy:-"; cin>>sx>>sy; b[0][0]=sx;b[0][1]=0;b[0][2]=0; b[1][0]=0;b[1][1]=sy;b[1][2]=0; b[2][0]=0;b[2][1]=0;b[2][2]=1; break; default: cout<<"\nEnter correct choice:-"; continue; }//end switch for(i=0;i<n;i++) { for(j=0;j<3;j++) { c[i][j]=0; for(k=0;k<3;k++) { c[i][j]=c[i][j]+a[i][k]*b[k][j]; } } } setcolor(4); for(i=0;i<n-1;i++) { line(xmax/2+c[i][0],ymax/2-c[i][1],xmax/2+c[i+1][0],ymax/2-c[i+1][1]); } line(xmax/2+c[i][0],ymax/2-c[i][1],xmax/2+c[0][0],ymax/2-c[0][1]); cout<< "do u want to continue(1=yes/0=no):-"; cin>>y; cleardevice(); clrscr(); setcolor(15); line(xmax/2,0,xmax/2,ymax); line(0,ymax/2,xmax,ymax/2); }//end while getch(); }
/* * Display a dialog box with a list of options that can be turned on or off * in the style of radiolist (only one option turned on at a time). */ int dialog_checklist(const char *title, const char *prompt, int height, int width, int list_height) { int i, x, y, box_x, box_y; int key = 0, button = 0, choice = 0, scroll = 0, max_choice; WINDOW *dialog, *list; /* which item to highlight */ item_foreach() { if (item_is_tag('X')) choice = item_n(); if (item_is_selected()) { choice = item_n(); break; } } do_resize: if (getmaxy(stdscr) < (height + 6)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) < (width + 6)) return -ERRDISPLAYTOOSMALL; max_choice = MIN(list_height, item_count()); /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); list_width = width - 6; box_y = height - list_height - 5; box_x = (width - list_width) / 2 - 1; /* create new window for the list */ list = subwin(dialog, list_height, list_width, y + box_y + 1, x + box_x + 1); keypad(list, TRUE); /* draw a box around the list items */ draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, dlg.menubox_border.atr, dlg.menubox.atr); /* Find length of longest item in order to center checklist */ check_x = 0; item_foreach() check_x = MAX(check_x, strlen(item_str()) + 4); check_x = (list_width - check_x) / 2; item_x = check_x + 4; if (choice >= list_height) { scroll = choice - list_height + 1; choice -= scroll; } /* Print the list */ for (i = 0; i < max_choice; i++) { item_set(scroll + i); print_item(list, i, i == choice); } print_arrows(dialog, choice, item_count(), scroll, box_y, box_x + check_x + 5, list_height); print_buttons(dialog, height, width, 0); wnoutrefresh(dialog); wnoutrefresh(list); doupdate(); while (key != KEY_ESC) { key = wgetch(dialog); for (i = 0; i < max_choice; i++) { item_set(i + scroll); if (toupper(key) == toupper(item_str()[0])) break; } if (i < max_choice || key == KEY_UP || key == KEY_DOWN || key == '+' || key == '-') { if (key == KEY_UP || key == '-') { if (!choice) { if (!scroll) continue; /* Scroll list down */ if (list_height > 1) { /* De-highlight current first item */ item_set(scroll); print_item(list, 0, FALSE); scrollok(list, TRUE); wscrl(list, -1); scrollok(list, FALSE); } scroll--; item_set(scroll); print_item(list, 0, TRUE); print_arrows(dialog, choice, item_count(), scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice - 1; } else if (key == KEY_DOWN || key == '+') { if (choice == max_choice - 1) { if (scroll + choice >= item_count() - 1) continue; /* Scroll list up */ if (list_height > 1) { /* De-highlight current last item before scrolling up */ item_set(scroll + max_choice - 1); print_item(list, max_choice - 1, FALSE); scrollok(list, TRUE); wscrl(list, 1); scrollok(list, FALSE); } scroll++; item_set(scroll + max_choice - 1); print_item(list, max_choice - 1, TRUE); print_arrows(dialog, choice, item_count(), scroll, box_y, box_x + check_x + 5, list_height); wnoutrefresh(dialog); wrefresh(list); continue; /* wait for another key press */ } else i = choice + 1; } if (i != choice) { /* De-highlight current item */ item_set(scroll + choice); print_item(list, choice, FALSE); /* Highlight new item */ choice = i; item_set(scroll + choice); print_item(list, choice, TRUE); wnoutrefresh(dialog); wrefresh(list); } continue; /* wait for another key press */ } switch (key) { case 'H': case 'h': case '?': button = 1; /* fall-through */ case 'S': case 's': case ' ': case '\n': item_foreach() item_set_selected(0); item_set(scroll + choice); item_set_selected(1); delwin(list); delwin(dialog); return button; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case 'X': case 'x': key = KEY_ESC; break; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(list); delwin(dialog); on_key_resize(); goto do_resize; } /* Now, update everything... */ doupdate(); } delwin(list); delwin(dialog); return key; /* ESC pressed */ }
/* This prompts for a key of input when in the main host editor window. */ int HostWinGetKey(void) { int c; int uc; int escmode; int maxy; maxy = getmaxy(gHostWin); wmove(gHostWin, maxy - 1, 0); for (escmode = 0; ; escmode++) { uc = (unsigned int) wgetch(gHostWin); c = (int) uc; if (uc > 255) { Trace(1, "[0x%04X]\n", c); } else if (isprint(c) && !iscntrl(c)) { Trace(1, "[0x%04X, %c]\n", c, c); } else if (iscntrl(c)) { Trace(1, "[0x%04X, ^%c]\n", c, (c & 31) | ('A' - 1)); } else { Trace(1, "[0x%04X]\n", c); } /* Some implementations of curses (i.e. Mac OS X) * don't seem to detect the arrow keys on * typical terminal types like "vt100" or "ansi", * so we try and detect them the hard way. */ switch (escmode) { case 0: if (uc != 0x001B) { goto gotch; } /* else ESC key (^[) */ break; case 1: if ((c != '[') && (c != 'O')) { goto gotch; } /* else ANSI ESC sequence continues */ break; case 2: switch (c) { case 'A': case 'a': #ifdef KEY_UP c = KEY_UP; Trace(1, " --> [0x%04X, %s]\n", c, "UP"); #else c = 'k'; /* vi UP */ Trace(1, " --> [0x%04X, %s]\n", c, "k"); #endif break; case 'B': case 'b': #ifdef KEY_DOWN c = KEY_DOWN; Trace(1, " --> [0x%04X, %s]\n", c, "DOWN"); #else c = 'j'; /* vi DOWN */ Trace(1, " --> [0x%04X, %s]\n", c, "j"); #endif break; case 'D': case 'd': #ifdef KEY_LEFT c = KEY_LEFT; Trace(1, " --> [0x%04X, %s]\n", c, "LEFT"); #else c = 'h'; /* vi LEFT */ Trace(1, " --> [0x%04X, %s]\n", c, "h"); #endif break; case 'C': case 'c': #ifdef KEY_RIGHT c = KEY_RIGHT; Trace(1, " --> [0x%04X, %s]\n", c, "RIGHT"); #else c = 'l'; /* vi RIGHT */ Trace(1, " --> [0x%04X, %s]\n", c, "l"); #endif break; } goto gotch; } } gotch: return (c); } /* HostWinGetKey */
void main() { char ch; XO xo; do { ch=getch(); //cout<<(int)ch; // for debug switch(ch) { // arrow keys + Space and Enter for control case 72: xo.move(UP); break; case 77: xo.move(RIGHT);break; case 80: xo.move(DOWN); break; case 75: xo.move(LEFT); break; case ' ': case 13: xo.select(); break; // numpad keys for position case '1': xo.board.move(getmaxx()/4*1,getmaxy()/4*3); break; case '2': xo.board.move(getmaxx()/4*2,getmaxy()/4*3); break; case '3': xo.board.move(getmaxx()/4*3,getmaxy()/4*3); break; case '4': xo.board.move(getmaxx()/4*1,getmaxy()/4*2); break; case '5': xo.board.move(getmaxx()/4*2,getmaxy()/4*2); break; case '6': xo.board.move(getmaxx()/4*3,getmaxy()/4*2); break; case '7': xo.board.move(getmaxx()/4*1,getmaxy()/4*1); break; case '8': xo.board.move(getmaxx()/4*2,getmaxy()/4*1); break; case '9': xo.board.move(getmaxx()/4*3,getmaxy()/4*1); break; // function keys for size case 59: xo.board.resize(getmaxx()/1,getmaxy()/1); break; case 60: xo.board.resize(getmaxx()/2,getmaxy()/2); break; case 61: xo.board.resize(getmaxx()/3,getmaxy()/3); break; case 62: xo.board.resize(getmaxx()/4,getmaxy()/4); break; case 63: xo.board.resize(getmaxx()/5,getmaxy()/5); break; case 64: xo.board.resize(getmaxx()/6,getmaxy()/6); break; case 65: xo.board.resize(getmaxx()/7,getmaxy()/7); break; case 66: xo.board.resize(getmaxx()/8,getmaxy()/8); break; case 67: xo.board.resize(getmaxx()/9,getmaxy()/9); break; } }while(ch!=27); // 27: Escape getch(); }
static int get_position(NCURSES_CONST char *text, NCURSES_CONST char *also, int which, int *xpos, int *ypos) { int result = 0; int x1, y1; char cmd; getyx(stdscr, y1, x1); (void) statusline(); show_position(text, also, which, y1, x1); if (log_in != 0) { if (fscanf(log_in, "%c%d,%d\n", &cmd, &y1, &x1) == 3) { switch (cmd) { case LAST_POS: result = 1; (void) wgetch(stdscr); break; case TEMP_POS: result = 0; wrefresh(stdscr); napms(100); break; default: result = -1; break; } } else { result = -1; } } else { switch (wgetch(stdscr)) { case QUIT: case ESCAPE: case ERR: result = -1; break; case ' ': result = 1; break; case KEY_UP: if (y1 > 0) { --y1; } else { beep(); } break; case KEY_DOWN: if (y1 < getmaxy(stdscr)) { ++y1; } else { beep(); } break; case KEY_LEFT: if (x1 > 0) { --x1; } else { beep(); } break; case KEY_RIGHT: if (x1 < getmaxx(stdscr)) { ++x1; } else { beep(); } break; } } wmove(stdscr, y1, x1); *ypos = y1; *xpos = x1; if (result >= 0) { if (log_out) fprintf(log_out, "%c%d,%d\n", ((result > 0) ? LAST_POS : TEMP_POS), y1, x1); } return result; }
int main() { int gd = DETECT, gm; int i, maxx, midy; /* initialize graphic mode */ initgraph(&gd, &gm, "NULL"); /* maximum pixel in horizontal axis */ maxx = getmaxx(); /* mid pixel in vertical axis */ midy = getmaxy()/2; for (i=0; i < maxx-150; i=i+5) /* loop is run for showing the animation */ { /* clears screen */ cleardevice(); /* draw a white road */ setcolor(WHITE); /* color of the road */ line(0, midy + 37, maxx, midy + 37); /* Draw Car */ setcolor(YELLOW); /* color of the car body */ /* car body */ line(i, midy + 23, i, midy); /* draws the left most line parallel to y-axis */ line(i, midy, 40 + i, midy - 20); line(40 + i, midy - 20, 80 + i, midy - 20); /* draws the roof of the car*/ line(80 + i, midy - 20, 100 + i, midy); /* draws the front mirror part of the car */ line(100 + i, midy, 120 + i, midy); line(120 + i, midy, 120 + i, midy + 23); line(0 + i, midy + 23, 18 + i, midy + 23); arc(30 + i, midy + 23, 0, 180, 12); /* draws the arc to accomodate the wheels */ line(42 + i, midy + 23, 78 + i, midy + 23); arc(90 + i, midy + 23, 0, 180, 12); /* draws the arc to accomodate the wheels */ line(102 + i, midy + 23, 120 + i, midy + 23); /* car body ends */ /* Draw Windows */ /* left window */ line(28 + i, midy, 43 + i, midy - 15); /* left part of left window */ line(43 + i, midy - 15, 57 + i, midy - 15); /* roof of the left window */ line(57 + i, midy - 15, 57 + i, midy); /* right part of left window */ line(57 + i, midy, 28 + i, midy); /* bottom part of the left window */ /* left window ends */ /* right window */ line(62 + i, midy - 15, 77 + i, midy - 15); /* left part of right window */ line(77 + i, midy - 15, 92 + i, midy); /* roof of the rightt window */ line(92 + i, midy, 62 + i, midy); /* right part of right window */ line(62 + i, midy, 62 + i, midy - 15); /* bottom part of the right window */ /* right window ends */ floodfill(5 + i, midy + 22, YELLOW); /* fills the whole car body with yellow color */ setcolor(BLUE); /* color of the wheels */ /* Draw Wheels */ circle(30 + i, midy + 25, 9); circle(90 + i, midy + 25, 9); floodfill(30 + i, midy + 25, BLUE); /* fills the left wheel with blue color */ floodfill(90 + i, midy + 25, BLUE); /* fills the right wheel with blue color */ /* Add delay of 0.1 milli seconds */ delay(100); /* to observe the animation */ } getch(); closegraph(); return 0; }
int worldfactory::show_worldgen_tab_modselection(WINDOW *win, WORLDPTR world) { // Use active_mod_order of the world, // saves us from writting 'world->active_mod_order' all the time. std::vector<std::string> &active_mod_order = world->active_mod_order; { std::vector<std::string> tmp_mod_order; // clear active_mod_order and re-add all the mods, his ensures // that changes (like changing depencies) get updated tmp_mod_order.swap(active_mod_order); for(size_t i = 0; i < tmp_mod_order.size(); i++) { mman_ui->try_add(tmp_mod_order[i], active_mod_order); } } const int iOffsetX = (TERMX > FULL_SCREEN_WIDTH) ? (TERMX - FULL_SCREEN_WIDTH) / 2 : 0; const int iOffsetY = (TERMY > FULL_SCREEN_HEIGHT) ? (TERMY - FULL_SCREEN_HEIGHT) / 2 : 0; // lots of small windows so that each section can be drawn to independently of the others as necessary WINDOW *w_header1, *w_header2, *w_shift, *w_list, *w_active, *w_description; w_header1 = newwin(1, FULL_SCREEN_WIDTH / 2 - 5, 3 + iOffsetY, 1 + iOffsetX); w_header2 = newwin(1, FULL_SCREEN_WIDTH / 2 - 4, 3 + iOffsetY, FULL_SCREEN_WIDTH / 2 + 3 + iOffsetX); w_shift = newwin(13, 5, 3 + iOffsetY, FULL_SCREEN_WIDTH / 2 - 3 + iOffsetX); w_list = newwin(11, FULL_SCREEN_WIDTH / 2 - 4, 5 + iOffsetY, iOffsetX); w_active = newwin(11, FULL_SCREEN_WIDTH / 2 - 4, 5 + iOffsetY, FULL_SCREEN_WIDTH / 2 + 2 + iOffsetX); w_description = newwin(6, FULL_SCREEN_WIDTH - 2, 17 + iOffsetY, 1 + iOffsetX); draw_modselection_borders(win); std::vector<std::string> headers; headers.push_back(_("Mod List")); headers.push_back(_("Mod Load Order")); std::vector<WINDOW *> header_windows; header_windows.push_back(w_header1); header_windows.push_back(w_header2); int tab_output = 0; int active_header = 0, last_active_header = -1; int useable_mod_count = mman_ui->usable_mods.size(); int startsel[2] = {0, 0}; int cursel[2] = {0, 0}; bool redraw_headers = true; bool redraw_shift = true; bool redraw_description = true; bool redraw_list = true; bool redraw_active = true; bool selection_changed = false; while (tab_output == 0) { if (redraw_headers) { for (int i = 0; i < headers.size(); ++i) { werase(header_windows[i]); const int header_x = (getmaxx(header_windows[i]) - headers[i].size()) / 2; mvwprintz(header_windows[i], 0, header_x , c_cyan, headers[i].c_str()); if (active_header == i) { mvwputch(header_windows[i], 0, header_x - 3, c_red, '<'); mvwputch(header_windows[i], 0, header_x + headers[i].size() + 2, c_red, '>'); } wrefresh(header_windows[i]); } redraw_list = true; redraw_active = true; redraw_shift = true; redraw_headers = false; } if (selection_changed) { if (active_header == 0) { redraw_list = true; } if (active_header == 1) { redraw_shift = true; redraw_active = true; } selection_changed = false; redraw_description = true; } if (redraw_description) { werase(w_description); MOD_INFORMATION *selmod = NULL; if (mman_ui->usable_mods.empty()) { // Do nothing, leave selmod == NULL } else if (active_header == 0) { selmod = mman->mod_map[mman_ui->usable_mods[cursel[0]]]; } else if (active_mod_order.size() > 0) { selmod = mman->mod_map[active_mod_order[cursel[1]]]; } if (selmod != NULL) { fold_and_print(w_description, 2, 1, getmaxx(w_description) - 1, c_white, mman_ui->get_information(selmod).c_str()); } center_print(w_description, 0, c_green, _("Press 's' to save the list of active mods as default")); redraw_description = false; wrefresh(w_description); } if (redraw_list) { werase(w_list); calcStartPos(startsel[0], cursel[0], getmaxy(w_list), useable_mod_count); if (useable_mod_count == 0) { center_print(w_list, 0, c_red, _("--NO AVAILABLE MODS--")); } else { std::stringstream list_output; for (int i = startsel[0], c = 0; i < useable_mod_count && c < getmaxy(w_list); ++i, ++c) { if (i != cursel[0]) { list_output << std::string(3, ' '); } else { if (active_header == 0) { list_output << "<color_yellow>"; } else { list_output << "<color_blue>"; } list_output << ">></color> "; } list_output << mman->mod_map[mman_ui->usable_mods[i]]->name << "\n"; } fold_and_print(w_list, 0, 1, getmaxx(w_list) - 1, c_white, list_output.str().c_str()); } draw_scrollbar(w_list, cursel[0], getmaxy(w_list), useable_mod_count, 0, 0); wrefresh(w_list); } if (redraw_active) { werase(w_active); const int active_count = active_mod_order.size(); calcStartPos(startsel[1], cursel[1], getmaxy(w_active), active_count); if (active_count == 0) { center_print(w_active, 0, c_red, _("--NO ACTIVE MODS--")); } else { std::stringstream list_output; for (int i = startsel[1], c = 0; i < active_count && c < getmaxy(w_active); ++i, ++c) { if (i != cursel[1]) { list_output << std::string(3, ' '); } else { if (active_header == 1) { list_output << "<color_yellow>"; } else { list_output << "<color_blue>"; } list_output << ">></color> "; } list_output << mman->mod_map[active_mod_order[i]]->name << "\n"; } fold_and_print(w_active, 0, 1, getmaxx(w_active) - 1, c_white, list_output.str().c_str()); } draw_scrollbar(w_active, cursel[1], getmaxy(w_active), active_count, 0, 0); wrefresh(w_active); } if (redraw_shift) { werase(w_shift); if (active_header == 1) { std::stringstream shift_display; // get shift information for whatever is visible in the active list for (int i = startsel[1], c = 0; i < active_mod_order.size() && c < getmaxy(w_active); ++i, ++c) { if (mman_ui->can_shift_up(i, active_mod_order)) { shift_display << "<color_blue>+</color> "; } else { shift_display << "<color_dkgray>+</color> "; } if (mman_ui->can_shift_down(i, active_mod_order)) { shift_display << "<color_blue>-</color>"; } else { shift_display << "<color_dkgray>-</color>"; } shift_display << "\n"; } fold_and_print(w_shift, 2, 1, getmaxx(w_shift), c_white, shift_display.str().c_str()); } redraw_shift = false; wrefresh(w_shift); } refresh(); last_active_header = active_header; const int next_header = (active_header == 1) ? 0 : 1; const int prev_header = (active_header == 0) ? 1 : 0; int selection = (active_header == 0) ? cursel[0] : cursel[1]; int last_selection = selection; int next_selection = selection + 1; int prev_selection = selection - 1; if (active_header == 0) { next_selection = (next_selection >= useable_mod_count) ? 0 : next_selection; prev_selection = (prev_selection < 0) ? useable_mod_count - 1 : prev_selection; } else { next_selection = (next_selection >= active_mod_order.size()) ? 0 : next_selection; prev_selection = (prev_selection < 0) ? active_mod_order.size() - 1 : prev_selection; } // GATHER INPUT long ch = input(); switch (ch) { case 'j': selection = next_selection; break; case 'k': selection = prev_selection; break; case 'l': active_header = next_header; break; case 'h': active_header = prev_header; break; case '\n': if (active_header == 0 && mman_ui->usable_mods.size() > 0) { // try-add mman_ui->try_add(mman_ui->usable_mods[cursel[0]], active_mod_order); redraw_active = true; redraw_shift = true; } else if (active_header == 1 && active_mod_order.size() > 0) { // try-rem mman_ui->try_rem(cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; if (active_mod_order.empty()) { // switch back to other list, we can't change // anything in the empty active mods list. active_header = 0; } } break; case '+': case '-': if (active_header == 1 && active_mod_order.size() > 1) { mman_ui->try_shift(char(ch), cursel[1], active_mod_order); redraw_active = true; redraw_shift = true; } break; case '>': tab_output = 1; break; case '<': tab_output = -1; break; case 's': case 'S': mman->set_default_mods(active_mod_order); popup("Saved list of active mods as default"); draw_modselection_borders(win); redraw_headers = true; break; case 'q': case 'Q': case KEY_ESCAPE: // exit! tab_output = -999; break; default: break; } // end GATHER INPUT // RESOLVE INPUTS if (last_active_header != active_header) { redraw_headers = true; redraw_shift = true; redraw_description = true; } if (last_selection != selection) { if (active_header == 0) { redraw_list = true; cursel[0] = selection; } else { redraw_active = true; redraw_shift = true; cursel[1] = selection; } redraw_description = true; } if (active_mod_order.size() == 0) { redraw_active = true; cursel[1] = -1; } if (active_header == 1) { if (active_mod_order.size() == 0) { cursel[1] = -1; } else { if (cursel[1] < 0) { cursel[1] = 0; } else if (cursel[1] >= active_mod_order.size()) { cursel[1] = active_mod_order.size() - 1; } } } // end RESOLVE INPUTS } werase(w_header1); werase(w_header2); werase(w_shift); werase(w_list); werase(w_active); werase(w_description); delwin(w_header1); delwin(w_header2); delwin(w_shift); delwin(w_list); delwin(w_active); delwin(w_description); return tab_output; }
void render::render_InvMenu(inventory& inv, int curPos){ std::vector<std::string> nameList = inv.getNameList(curPos); clear(); texture.loadFromFile(FRAME_SIDE, ren); texture.render(ren, 0, 0); Point offset; offset.m_x = getmaxx() / 2; offset.m_y = getmaxy() / 2; SDL_Color textColor = {0xD8, 0xC6, 0x91}; //Print Title texture.loadFromRenderedText("INVENTORY", textColor, ren, font_comic50); texture.render(ren, offset.m_x - texture.getWidth() / 2, 8); char mString[40]; sprintf(mString, "Money: $%d", inv.getMoney()); texture.loadFromRenderedText(mString, textColor, ren, font_comic16); texture.render(ren, 300, 560); for (unsigned int i = 0; i < nameList.size(); i++){ texture.loadFromRenderedText(nameList[i].c_str(), textColor, ren, font_comic16); texture.render(ren, 20, 100 + i * texture.getHeight()); } if(!nameList.empty()){ //Print Selected Options textColor = { 0xF4, 0xF0, 0xDD }; texture.loadFromRenderedText(nameList[0].c_str(), textColor, ren, font_comic16); texture.render(ren, 20, 100); textColor = {0xD8, 0xC6, 0x91}; char tmp[100]; //Print Informations sprintf(tmp, "Name : %s", inv[nameList[0]].item.getName().c_str()); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 100); sprintf(tmp, "Currently Have : %d", inv[nameList[0]].count); texture.loadFromRenderedText(tmp, textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35, 130); texture.loadFromRenderedText("Description : ", textColor, ren, font_comic16); texture.render(ren, 300, 160); unsigned int xoff = (getmaxx() - 260) / 13; unsigned int i; for(i = xoff; inv[nameList[0]].item.getDescription().size() > i; i += xoff){ texture.loadFromRenderedText(inv[nameList[0]].item.getDescription().substr(i - xoff, xoff).c_str(), textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35 + 20, 180 + (i / xoff - 1) * 20); } texture.loadFromRenderedText(inv[nameList[0]].item.getDescription().substr(i - xoff, inv[nameList[0]].item.getDescription().size()).c_str(), textColor, ren, font_comic16); texture.render(ren, getmaxx() * 0.35 + 20, 180 + (i / xoff - 1) * 20); } update(); }
void taylortrack::vis::OutputVisualizer::update_main_window() { // Create Box around main window box(this->main_window_, 0, 0); wmove(this->main_window_, 1, 1); if (this->data_set_) { double x_axis_size = diagram_data_.size(); int height, width; getmaxyx(this->main_window_, height, width); // Not the entire window usable width -= 2; height -= 4; // Calculate values per character int vpc = static_cast<int>(ceil(x_axis_size / static_cast<double>(width))); int actual_size = static_cast<int>(x_axis_size / vpc); // Calculate max value double max_value = 0.0f; for (int i = 0; i < actual_size; ++i) { double current_value = 0; for (int j = 0; j < vpc; ++j) { current_value += diagram_data_[i * vpc + j]; } if (current_value > max_value) { max_value = current_value; } } wprintw(this->main_window_, "Debug-Values: %d %d %d %d %f", vpc, actual_size, COLORS, can_change_color(), max_value); if (max_value > 0.0) { // calculate the value of one square in the terminal double delta = max_value / height; // Add the vpc next values together and draw block if value high enough for (int y = 0; y < height; ++y) { for (int x = 0; x < actual_size; ++x) { double current_value = 0; for (int j = 0; j < vpc; ++j) { current_value += diagram_data_[x * vpc + j]; } if (current_value >= (height - y) * delta) { wmove(this->main_window_, 1 + y, 1 + x); if (x % 2 == 0) { waddch(this->main_window_, ' ' | COLOR_PAIR(3)); } else { waddch(this->main_window_, ' ' | COLOR_PAIR(4)); } } } } } else { height = getmaxy(this->main_window_); height -= 2; wmove(this->main_window_, height / 2, 1); print_center(this->main_window_, "Invalid Data!"); } } else { int height; height = getmaxy(this->main_window_); height -= 2; wmove(this->main_window_, height / 2, 1); print_center(this->main_window_, "Waiting for Data..."); } // flush display buffer and write to screen wrefresh(this->main_window_); }
/* * Display a dialog box with two buttons - Yes and No */ int dialog_yesno(const char *title, const char *prompt, int height, int width) { int i, x, y, key = 0, button = 0; WINDOW *dialog; do_resize: if (getmaxy(stdscr) < (height + 4)) return -ERRDISPLAYTOOSMALL; if (getmaxx(stdscr) < (width + 4)) return -ERRDISPLAYTOOSMALL; /* center dialog box on screen */ x = (COLS - width) / 2; y = (LINES - height) / 2; draw_shadow(stdscr, y, x, height, width); dialog = newwin(height, width, y, x); keypad(dialog, TRUE); draw_box(dialog, 0, 0, height, width, dlg.dialog.atr, dlg.border.atr); wattrset(dialog, dlg.border.atr); mvwaddch(dialog, height - 3, 0, ACS_LTEE); for (i = 0; i < width - 2; i++) waddch(dialog, ACS_HLINE); wattrset(dialog, dlg.dialog.atr); waddch(dialog, ACS_RTEE); print_title(dialog, title, width); wattrset(dialog, dlg.dialog.atr); print_autowrap(dialog, prompt, width - 2, 1, 3); print_buttons(dialog, height, width, 0); while (key != KEY_ESC) { key = wgetch(dialog); switch (key) { case 'Y': case 'y': delwin(dialog); return 0; case 'N': case 'n': delwin(dialog); return 1; case TAB: case KEY_LEFT: case KEY_RIGHT: button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button); print_buttons(dialog, height, width, button); wrefresh(dialog); break; case ' ': case '\n': delwin(dialog); return button; case KEY_ESC: key = on_key_esc(dialog); break; case KEY_RESIZE: delwin(dialog); on_key_resize(); goto do_resize; } } delwin(dialog); return key; /* ESC pressed */ }
int main(void) { /* request autodetection */ int gdriver = DETECT, gmode, errorcode,f=1,t=0; void *arrow; int x, y, maxx,maxy ; unsigned int size; /* initialize graphics and local variables */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ } maxx = getmaxx(); maxy = getmaxy(); x = 0; y = getmaxy()/2; // setbkcolor(LIGHTGRAY); setcolor(YELLOW); /* draw the image to be grabbed */ draw_arrow(x, y); /* calculate the size of the image */ size = imagesize(x, y-az, x+(4*az), y+az); /* allocate memory to hold the image */ arrow = malloc(size); /* grab the image */ getimage(x, y-az, x+(4*az), y+az, arrow); /* repeat until a key is pressed */ while(!kbhit()) { /* erase old image */ putimage(x, y-az, arrow, XOR_PUT); x +=az; if (x >= maxx) { x = 0; } delay(100); az++; x++; y++; /* plot new image */ putimage(x, y-az, arrow, XOR_PUT); delay(100); } /* clean up */ free(arrow); closegraph(); return 0; }
int main(int argc, char **argv) { to_send = (message *)malloc(sizeof(message)); // message struct to talk to server with message *received = (message *)malloc(sizeof(message)); client *me = (client *)malloc(sizeof(client)); // ME! tbuf B = 0; char welcome_msg[100]; signal(SIGINT, sigint_handler); // handle command line args int i; if (argc > 0) { for (i = 0 ; i < argc ; i++) { if (*argv[i] == '-') { switch(*(argv[i] + 1)) { case 'n': strncpy(NAME, argv[++i], sizeof(NAME)); break; case 'h': printf("%s\n", HELP); exit(1); break; case 'l': // local use CONN = 0; me->room_id = 0; break; case 'j': // not creating a room, but joining ROOM_NO = atoi(argv[++i]); break; case 't': DEBUG = 1; break; } } else if(i > 0) { strncpy(filename, argv[i], sizeof(filename)); B = read_from_file(argv[i]); debug("reading done (%s)\n", argv[i]); } } } if (!NAME[0] && CONN) { // name is not set yet and connecting to network printf("%s\n", HELP); exit(1); } if (!B) { B = new_tbuf(); printf("is this it?\n"); } // build socket connection if (CONN) { if ((FROM_SERVER = socket(AF_INET, SOCK_STREAM, 0)) < 0) { fprintf(stderr, "Fatal - Cannot create socket\n"); close(1); } serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(CLIENT_PORT); serv_addr.sin_addr.s_addr = inet_addr(SERVER_ADDR); if (connect(FROM_SERVER, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { fprintf(stderr, "Fatal - Connection to server failed\n"); close(1); } // setup terminal args and handshake with server // 1. join server request strncpy(to_send->cmd, CONN_REQUEST, sizeof(CONN_REQUEST)); strncpy(to_send->content, NAME, sizeof(NAME)); debug("Name sent to server: %s\n", to_send->content); write(FROM_SERVER, to_send, sizeof(message)); read(FROM_SERVER, &to_send->remote_client_id, sizeof(int)); debug("Received from server: %d\n", to_send->remote_client_id); // let us assume that you are creating a room here if (ROOM_NO != -1) { // join a given room me->room = ROOM_NO; strncpy(to_send->cmd, "join", 5); to_send->to_distribute = 1; sprintf(to_send->content, "%d", ROOM_NO); debug("command sent: %s\n", to_send->cmd); send_to_server(to_send, sizeof(message)); room_state *current_room = (room_state *)malloc(sizeof(room_state)); read(FROM_SERVER, current_room, sizeof(room_state)); B = chararr2tbuf(current_room->buf); memcpy(usernames, current_room->usernames, sizeof(usernames)); read(FROM_SERVER, &me->room_id, sizeof(int)); to_send->local_client_id = me->room_id; strncpy(usernames[me->room_id], NAME, sizeof(NAME)); sprintf(welcome_msg, "<SERVER> You have just joined room %d", me->room); } else { // create a room strncpy(to_send->cmd, "new", 4); debug("command sent: %s\n", to_send->cmd); send_to_server(to_send, sizeof(message)); read(FROM_SERVER, &ROOM_NO, sizeof(int)); to_send->local_client_id = 0; // create a room = 0 me->room = ROOM_NO; me->room_id = 0; strncpy(usernames[me->room_id], NAME, sizeof(NAME)); debug("recv from server: in room %d\n", me->room); sprintf(welcome_msg, "<SERVER> You are now the owner of %d", me->room); } to_send->to_distribute = 1; } else { sprintf(welcome_msg, "You are currently running NetScribe locally"); } //getchar(); // setup GUI WINDOW *mainwin = initscr(); cbreak(); noecho(); keypad(mainwin, true); int vis = curs_set(0); int ncols = getmaxx(mainwin); int nlines = getmaxy(mainwin); int begx = getbegx(mainwin); int begy = getbegy(mainwin); debug("%d, %d, %d, %d\n", ncols, nlines, begx, begy); WINDOW *canvas = subwin(mainwin, nlines - 4, // save 2 lines for bottom status ncols, // same as main begy + 2, // save one line for title and one line for 'chat' begx); WINDOW *topbar = subwin(mainwin, 1, ncols, begy, begx); WINDOW *chatbar = subwin(mainwin, 1, ncols, begy + 1, begx); WINDOW *botbar = subwin(mainwin, 1, ncols, nlines - 2, begx); WINDOW *inputbar = subwin(mainwin, 1, ncols, nlines - 1, begx); render_topbar(topbar); render_string(chatbar, welcome_msg); render_botbar(botbar); wrefresh(mainwin); debug("setup done\n"); // setup the select program char c[3]; fd_set readfds, current; FD_ZERO(&readfds); FD_ZERO(¤t); FD_SET(STDIN_FILENO, &readfds); if (CONN) { FD_SET(FROM_SERVER, &readfds); } while (1) { if (!DEBUG) { render_tbuf(B, canvas); // FIXME OVERWRITING STUFF } current = readfds; debug("BEFORE SELECT\n"); if (select(FROM_SERVER + 1, ¤t, NULL, NULL, NULL) < 0) { fprintf(stderr, "Error %d: %s", errno, strerror(errno)); } debug("HELLO!\n"); if (FD_ISSET(FROM_SERVER, ¤t)) { // receive msg from server read(FROM_SERVER, received, sizeof(message)); debug("MSG FROM SERVER: %s\n", received->cmd); int c_user = received->local_client_id; if (strstr(received->cmd, "chat")) { // this is a chat command time_t t; struct tm *tinfo; time(&t); tinfo = localtime(&t); char time_s[20]; if (!strftime(time_s, sizeof(time_s), "%H:%M:%S", tinfo)) { fprintf(stderr, "Error %d: %s", errno, strerror(errno)); exit(1); } char to_put_up[100]; sprintf(to_put_up, "[%s] %s: %s", time_s, usernames[received->local_client_id], received->content); render_string(chatbar, to_put_up); } if (strstr(received->cmd, "join")) { // if new user joins debug("THIS IS A JOIN REQUEST\n"); strncpy(usernames[received->local_client_id], received->content, 16); time_t t; struct tm *tinfo; time(&t); tinfo = localtime(&t); char time_s[20]; if (!strftime(time_s, sizeof(time_s), "%H:%M:%S", tinfo)) { fprintf(stderr, "Error %d: %s", errno, strerror(errno)); exit(1); } char to_put_up[100]; sprintf(to_put_up, "[%s] <SERVER>: %s has joined", time_s, usernames[received->local_client_id]); render_string(chatbar, to_put_up); } if (strstr(received->cmd, "exit")) { // if user exits time_t t; struct tm *tinfo; time(&t); tinfo = localtime(&t); char time_s[20]; if (!strftime(time_s, sizeof(time_s), "%H:%M:%S", tinfo)) { fprintf(stderr, "Error %d: %s", errno, strerror(errno)); exit(1); } char to_put_up[100]; sprintf(to_put_up, "[%s] <SERVER>: %s has exited", time_s, usernames[received->local_client_id]); render_string(chatbar, to_put_up); memset(usernames[received->local_client_id], 0, sizeof(usernames[received->local_client_id])); } if (strstr(received->cmd, SERVER_EXIT)) { // server died :( SERVER_DIED = 1; break; } if (strstr(received->cmd, BUF_REQUEST)) { // you are the owner and the server asked you for the buffer debug("HELLO I GOTCHU\n"); //assert(me->room_id == 0); // i should be the owner room_state *current_state = (room_state *)malloc(sizeof(room_state)); strncpy(current_state->buf, tbuf2chararr(B), 20480); memcpy(current_state->usernames, usernames, sizeof(usernames)); debug("conversion done\n"); write(FROM_SERVER, current_state, sizeof(room_state)); // only except to the RO rule debug("Wrote to server\n"); } if (strstr(received->cmd, "edit")) { memcpy(c, received->content, sizeof(c)); if (c[0] == 27) { switch (c[2]) { case 'C': // move cursor right backward_char(B, c_user); break; case 'D': forward_char(B, c_user); break; } } else if (c[0] == 127) { // backspace delete_char(B, c_user); } else if (0 < c[0] && c[0] < 127) { // other characters insert_char(B, c[0], c_user); } } } if (FD_ISSET(STDIN_FILENO, ¤t)) { // reading from stdin read(STDIN_FILENO, &c, 1); if (c[0] == 24) { // ^X --> exit break; // exit out of the listening loop } switch (mode) { case EDIT_MODE: if (c[0] == 12) { // ^L --> redraw wclear(mainwin); render_topbar(topbar); render_string(chatbar, ""); render_tbuf(B, canvas); wrefresh(mainwin); } else if (c[0] == 15) { // ^O --> saving mode mode = SAVE_MODE; } else if (c[0] == 8) { // ^H --> chat mode = CHAT_MODE; werase(inputbar); wmove(inputbar, 0, 1); waddstr(inputbar, "Chat (press enter to send): "); wrefresh(inputbar); msg_i = 0; } else { // these will be sent strncpy(to_send->cmd, "edit", 5); if (c[0] == 27) { read(STDIN_FILENO, &c[1], 2); switch (c[2]) { case 'C': // move cursor right backward_char(B, me->room_id); break; case 'D': forward_char(B, me->room_id); break; } memcpy(to_send->content, c, 3); } else if (c[0] == 127) { // backspace delete_char(B, me->room_id); memcpy(to_send->content, c, 3); } else if (0 < c[0] && c[0] < 127) { // other characters printf("%c\n", c[0]); insert_char(B, c[0], me->room_id); memcpy(to_send->content, c, 3); } send_to_server(to_send, sizeof(message)); } break; case CHAT_MODE: // when user is inputing things for the chat if (c[0] == 13) { // enter msg[msg_i] = 0; // null terminator strncpy(to_send->cmd, "chat", 5); strncpy(to_send->content, msg, sizeof(to_send->content)); send_to_server(to_send, sizeof(message)); werase(inputbar); wrefresh(inputbar); mode = EDIT_MODE; } else if (0 < c[0] && c[0] < 127) { // other chars msg[msg_i] = c[0]; msg_i++; waddch(inputbar, c[0]); wrefresh(inputbar); } break; case SAVE_MODE: // when user is typing in the to-save filename break; } } } if (CONN && !SERVER_DIED) { // send off closing request strncpy(to_send->cmd, "exit", 5); send_to_server(to_send, sizeof(message)); } curs_set(vis); endwin(); if (SERVER_DIED) { printf("The server has shutdown or the owner of the room has quit\n"); } else { printf("Exiting...\n"); } return 0; }
static gboolean show_suggest_dropdown(GntEntry *entry) { char *suggest = NULL; int len; int offset = 0, x, y; int count = 0; GList *iter; const char *text = NULL; const char *sgst = NULL; int max = -1; if (entry->word) { char *s = get_beginning_of_word(entry); suggest = g_strndup(s, entry->cursor - s); if (entry->scroll < s) offset = gnt_util_onscreen_width(entry->scroll, s); } else suggest = g_strdup(entry->start); len = strlen(suggest); /* Don't need to use the utf8-function here */ if (entry->ddown == NULL) { GntWidget *box = gnt_vbox_new(FALSE); entry->ddown = gnt_tree_new(); gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate); gnt_box_add_widget(GNT_BOX(box), entry->ddown); GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT); gnt_widget_get_position(GNT_WIDGET(entry), &x, &y); x += offset; y++; if (y + 10 >= getmaxy(stdscr)) y -= 11; gnt_widget_set_position(box, x, y); } else gnt_tree_remove_all(GNT_TREE(entry->ddown)); for (count = 0, iter = entry->suggests; iter; iter = iter->next) { text = iter->data; if (g_ascii_strncasecmp(suggest, text, len) == 0 && strlen(text) >= len) { gnt_tree_add_row_after(GNT_TREE(entry->ddown), (gpointer)text, gnt_tree_create_row(GNT_TREE(entry->ddown), text), NULL, NULL); count++; if (max == -1) max = strlen(text) - len; else if (max) max = MIN(max, max_common_prefix(sgst + len, text + len)); sgst = text; } } g_free(suggest); if (count == 0) { destroy_suggest(entry); return FALSE; } else if (count == 1) { char *store = g_strndup(entry->start, entry->end - entry->start); gboolean ret; destroy_suggest(entry); complete_suggest(entry, sgst); ret = (strncmp(store, entry->start, entry->end - entry->start) != 0); g_free(store); return ret; } else { if (max > 0) { GntWidget *ddown = entry->ddown; char *match = g_strndup(sgst + len, max); entry->ddown = NULL; gnt_entry_key_pressed(GNT_WIDGET(entry), match); g_free(match); if (entry->ddown) gnt_widget_destroy(ddown); else entry->ddown = ddown; } gnt_widget_draw(entry->ddown->parent); } return TRUE; }
/* Program extracts from Chapter 13 of
/* * This function creates a widget. */ CDKDSCALE *newCDKDScale (CDKSCREEN *cdkscreen, int xplace, int yplace, char *title, char *label, chtype fieldAttr, int fieldWidth, double start, double low, double high, double inc, double fastInc, int digits, boolean Box, boolean shadow) { CDKDSCALE *widget = 0; int parentWidth = getmaxx(cdkscreen->window); int parentHeight = getmaxy(cdkscreen->window); int boxHeight; int boxWidth; int horizontalAdjust, oldWidth; int xpos = xplace; int ypos = yplace; int x, junk; static const struct { int from; int to; } bindings[] = { { 'u', KEY_UP }, { 'U', KEY_PPAGE }, { CDK_BACKCHAR, KEY_PPAGE }, { CDK_FORCHAR, KEY_NPAGE }, { 'g', KEY_HOME }, { '^', KEY_HOME }, { 'G', KEY_END }, { '$', KEY_END }, }; if ((widget = newCDKObject(CDKDSCALE, &my_funcs)) == 0) return (0); setCDKDScaleBox (widget, Box); boxHeight = (BorderOf(widget) * 2) + 1; boxWidth = fieldWidth + 2*BorderOf(widget); /* Set some basic values of the widget's data field. */ widget->label = 0; widget->labelLen = 0; widget->labelWin = 0; /* * If the fieldWidth is a negative value, the fieldWidth will * be COLS-fieldWidth, otherwise, the fieldWidth will be the * given width. */ fieldWidth = setWidgetDimension (parentWidth, fieldWidth, 0); boxWidth = fieldWidth + 2*BorderOf(widget); /* Translate the label char *pointer to a chtype pointer. */ if (label != 0) { widget->label = char2Chtype (label, &widget->labelLen, &junk); boxWidth = widget->labelLen + fieldWidth + 2; } oldWidth = boxWidth; boxWidth = setCdkTitle(ObjOf(widget), title, boxWidth); horizontalAdjust = (boxWidth - oldWidth) / 2; boxHeight += TitleLinesOf(widget); /* * Make sure we didn't extend beyond the dimensions of the window. */ boxWidth = (boxWidth > parentWidth ? parentWidth : boxWidth); boxHeight = (boxHeight > parentHeight ? parentHeight : boxHeight); fieldWidth = (fieldWidth > (boxWidth - widget->labelLen - 2*BorderOf(widget)) ? (boxWidth - widget->labelLen - 2*BorderOf(widget)) : fieldWidth); /* Rejustify the x and y positions if we need to. */ alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight); /* Make the widget's window. */ widget->win = newwin (boxHeight, boxWidth, ypos, xpos); /* Is the main window null??? */ if (widget->win == 0) { destroyCDKObject(widget); return (0); } /* Create the widget's label window. */ if (widget->label != 0) { widget->labelWin = subwin (widget->win, 1, widget->labelLen, ypos + TitleLinesOf(widget) + BorderOf(widget), xpos + horizontalAdjust + BorderOf(widget)); if (widget->labelWin == 0) { destroyCDKObject(widget); return (0); } } /* Create the widget's data field window. */ widget->fieldWin = subwin (widget->win, 1, fieldWidth, ypos + TitleLinesOf(widget) + BorderOf(widget), xpos + widget->labelLen + horizontalAdjust + BorderOf(widget)); if (widget->fieldWin == 0) { destroyCDKObject(widget); return (0); } keypad (widget->fieldWin, TRUE); keypad (widget->win, TRUE); /* Create the widget's data field. */ ScreenOf(widget) = cdkscreen; widget->parent = cdkscreen->window; widget->shadowWin = 0; widget->boxWidth = boxWidth; widget->boxHeight = boxHeight; widget->fieldWidth = fieldWidth; widget->fieldAttr = (chtype)fieldAttr; widget->current = low; widget->low = low; widget->high = high; widget->current = start; widget->inc = inc; widget->fastinc = fastInc; widget->digits = digits; initExitType(widget); ObjOf(widget)->acceptsFocus = TRUE; ObjOf(widget)->inputWindow = widget->win; widget->shadow = shadow; /* Do we want a shadow??? */ if (shadow) { widget->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1); if (widget->shadowWin == 0) { destroyCDKObject(widget); return (0); } } /* Setup the key bindings. */ for (x = 0; x < (int) SIZEOF(bindings); ++x) bindCDKObject (vDSCALE, widget, bindings[x].from, getcCDKBind, (void *)(long)bindings[x].to); registerCDKObject (cdkscreen, vDSCALE, widget); return (widget); }
extern void get_slurm_part(void) { int error_code, i, j, recs, count = 0; static partition_info_msg_t *part_info_ptr = NULL; static partition_info_msg_t *new_part_ptr = NULL; partition_info_t part; uint16_t show_flags = 0; bitstr_t *nodes_req = NULL; static uint16_t last_flags = 0; if (params.all_flag) show_flags |= SHOW_ALL; if (part_info_ptr) { if (show_flags != last_flags) part_info_ptr->last_update = 0; error_code = slurm_load_partitions(part_info_ptr->last_update, &new_part_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_partition_info_msg(part_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_part_ptr = part_info_ptr; } } else { error_code = slurm_load_partitions((time_t) NULL, &new_part_ptr, show_flags); } last_flags = show_flags; if (error_code) { if (quiet_flag != 1) { if (!params.commandline) { mvwprintw(text_win, main_ycord, 1, "slurm_load_partitions: %s", slurm_strerror(slurm_get_errno())); main_ycord++; } else { printf("slurm_load_partitions: %s\n", slurm_strerror(slurm_get_errno())); } } return; } if (!params.no_header) _print_header_part(); if (new_part_ptr) recs = new_part_ptr->record_count; else recs = 0; if (!params.commandline) if ((recs - text_line_cnt) < (getmaxy(text_win) - 4)) text_line_cnt--; if (params.hl) nodes_req = get_requested_node_bitmap(); for (i = 0; i < recs; i++) { part = new_part_ptr->partition_array[i]; if (nodes_req) { int overlap = 0; bitstr_t *loc_bitmap = bit_alloc(bit_size(nodes_req)); inx2bitstr(loc_bitmap, part.node_inx); overlap = bit_overlap(loc_bitmap, nodes_req); FREE_NULL_BITMAP(loc_bitmap); if (!overlap) continue; } j = 0; while (part.node_inx[j] >= 0) { set_grid_inx(part.node_inx[j], part.node_inx[j + 1], count); j += 2; } if (!params.commandline) { if (i >= text_line_cnt) { part.flags = (int) letters[count%62]; wattron(text_win, COLOR_PAIR(colors[count%6])); _print_text_part(&part, NULL); wattroff(text_win, COLOR_PAIR(colors[count%6])); } } else { part.flags = (int) letters[count%62]; _print_text_part(&part, NULL); } count++; } if (count == 128) count = 0; if (params.commandline && params.iterate) printf("\n"); part_info_ptr = new_part_ptr; return; }
void player::power_bionics() { int HEIGHT = TERMY; int WIDTH = FULL_SCREEN_WIDTH; int START_X = (TERMX - WIDTH) / 2; int START_Y = (TERMY - HEIGHT) / 2; WINDOW *wBio = newwin(HEIGHT, WIDTH, START_Y, START_X); int DESCRIPTION_WIDTH = WIDTH - 2; // Same width as bionics window minus 2 for the borders int DESCRIPTION_HEIGHT = 5; int DESCRIPTION_START_X = getbegx(wBio) + 1; // +1 to avoid border int DESCRIPTION_START_Y = getmaxy(wBio) - DESCRIPTION_HEIGHT - 1; // At the bottom of the bio window, -1 to avoid border WINDOW *w_description = newwin(DESCRIPTION_HEIGHT, DESCRIPTION_WIDTH, DESCRIPTION_START_Y, DESCRIPTION_START_X); int TITLE_WIDTH = DESCRIPTION_WIDTH; int TITLE_HEIGHT = 2; int TITLE_START_X = DESCRIPTION_START_X; int TITLE_START_Y = START_Y + 1; WINDOW *w_title = newwin(TITLE_HEIGHT, TITLE_WIDTH, TITLE_START_Y, TITLE_START_X); int scroll_position = 0; bool redraw = true; bool reassigning = false; bool activating = true; // examination mode if activating = false and reassigning = false std::vector <bionic *> passive; std::vector <bionic *> active; for (size_t i = 0; i < my_bionics.size(); i++) { if (!bionics[my_bionics[i].id]->activated) { passive.push_back(&my_bionics[i]); } else { active.push_back(&my_bionics[i]); } } int HEADER_LINE_Y = TITLE_START_Y + TITLE_HEIGHT; // + lines with text in titlebar int DESCRIPTION_LINE_Y = DESCRIPTION_START_Y - 1; // maximal number of rows in both columns const int bionic_count = std::max(passive.size(), active.size()); // number of rows with bionics shown (+1 for displaying "Passive:"/"Active:") const int bionic_display_height = DESCRIPTION_LINE_Y - HEADER_LINE_Y - 2; int max_scroll_position = bionic_count - bionic_display_height; int second_column = 32; while(true) { // offset for display: bionic with index i is drawn at y=list_start_y+i // the header ("Passive:"/"Active:") is drawn at y=HEADER_LINE_Y+1 // drawing the bionics starts with bionic[scroll_position] const int list_start_y = HEADER_LINE_Y + 2 - scroll_position; if(redraw) { redraw = false; werase(wBio); draw_border(wBio); draw_exam_window(wBio, DESCRIPTION_LINE_Y, (!reassigning && !activating)); for (int i = 1; i < WIDTH - 1; i++) { mvwputch(wBio, HEADER_LINE_Y, i, BORDER_COLOR, LINE_OXOX); // Draw line under title } // Draw symbols to connect additional lines to border mvwputch(wBio, HEADER_LINE_Y, 0, BORDER_COLOR, LINE_XXXO); // |- mvwputch(wBio, HEADER_LINE_Y, WIDTH - 1, BORDER_COLOR, LINE_XOXX); // -| nc_color type; mvwprintz(wBio, HEADER_LINE_Y + 1, 2, c_ltblue, _("Passive:")); if (passive.size() <= 0) { mvwprintz(wBio, list_start_y, 2, c_ltgray, _("None")); } else { for (size_t i = scroll_position; i < passive.size(); i++) { if (list_start_y + i == ((!activating && !reassigning) ? DESCRIPTION_LINE_Y : HEIGHT - 1)) { break; } if (bionics[passive[i]->id]->power_source) { type = c_ltcyan; } else { type = c_cyan; } mvwputch(wBio, list_start_y + i, 2, type, passive[i]->invlet); mvwprintz(wBio, list_start_y + i, 4, type, bionics[passive[i]->id]->name.c_str()); } } mvwprintz(wBio, HEADER_LINE_Y + 1, second_column, c_ltblue, _("Active:")); if (active.size() <= 0) { mvwprintz(wBio, list_start_y, second_column, c_ltgray, _("None")); } else { for (size_t i = scroll_position; i < active.size(); i++) { if (list_start_y + i == ((!activating && !reassigning) ? DESCRIPTION_LINE_Y : HEIGHT - 1)) { break; } if (active[i]->powered && !bionics[active[i]->id]->power_source) { type = c_red; } else if (bionics[active[i]->id]->power_source && !active[i]->powered) { type = c_ltcyan; } else if (bionics[active[i]->id]->power_source && active[i]->powered) { type = c_ltgreen; } else { type = c_ltred; } mvwputch(wBio, list_start_y + i, second_column, type, active[i]->invlet); mvwprintz(wBio, list_start_y + i, second_column + 2, type, (active[i]->powered ? _("%s - ON") : _("%s - %d PU / %d trns")), bionics[active[i]->id]->name.c_str(), bionics[active[i]->id]->power_cost, bionics[active[i]->id]->charge_time); } } if(scroll_position > 0) { mvwputch(wBio, HEADER_LINE_Y + 2, 0, c_ltgreen, '^'); } if(scroll_position < max_scroll_position && max_scroll_position > 0) { mvwputch(wBio, (!activating && !reassigning) ? ((HEADER_LINE_Y + 2) + bionic_display_height - 1) : (HEIGHT - 2), 0, c_ltgreen, 'v'); } } wrefresh(wBio); show_bionics_titlebar(w_title, this, activating, reassigning); long ch = getch(); bionic *tmp = NULL; if (reassigning) { reassigning = false; tmp = bionic_by_invlet(ch); if(tmp == 0) { // Selected an non-existing bionic (or escape, or ...) continue; } redraw = true; const char newch = popup_getkey(_("%s; enter new letter."), bionics[tmp->id]->name.c_str()); wrefresh(wBio); if(newch == ch || newch == ' ' || newch == KEY_ESCAPE) { continue; } bionic *otmp = bionic_by_invlet(newch); // if there is already a bionic with the new invlet, the invlet // is considered valid. if(otmp == 0 && inv_chars.find(newch) == std::string::npos) { // TODO separate list of letters for bionics popup(_("%c is not a valid inventory letter."), newch); continue; } if(otmp != 0) { std::swap(tmp->invlet, otmp->invlet); } else { tmp->invlet = newch; } // TODO: show a message like when reassigning a key to an item? } else if (ch == KEY_DOWN) { if(scroll_position < max_scroll_position) { scroll_position++; redraw = true; } } else if (ch == KEY_UP) { if(scroll_position > 0) { scroll_position--; redraw = true; } } else if (ch == '=') { reassigning = true; } else if (ch == '!') { activating = !activating; if (!reassigning && !activating) { // examination mode werase(w_description); } draw_exam_window(wBio, DESCRIPTION_LINE_Y, (!reassigning && !activating)); redraw = true; } else { tmp = bionic_by_invlet(ch); if(tmp == 0) { // entered a key that is not mapped to any bionic, // -> leave screen break; } const std::string &bio_id = tmp->id; const bionic_data &bio_data = *bionics[bio_id]; if (activating) { if (bio_data.activated) { itype_id weapon_id = weapon.type->id; if (tmp->powered) { tmp->powered = false; g->add_msg(_("%s powered off."), bio_data.name.c_str()); } else if (power_level >= bio_data.power_cost || (weapon_id == "bio_claws_weapon" && bio_id == "bio_claws_weapon")) { int b = tmp - &my_bionics[0]; activate_bionic(b); } // Action done, leave screen break; } else { popup(_("\ You can not activate %s! To read a description of \ %s, press '!', then '%c'."), bio_data.name.c_str(), bio_data.name.c_str(), tmp->invlet); redraw = true; } } else { // Describing bionics, not activating them! draw_exam_window(wBio, DESCRIPTION_LINE_Y, true); // Clear the lines first werase(w_description); fold_and_print(w_description, 0, 0, WIDTH - 2, c_ltblue, bio_data.description.c_str()); wrefresh(w_description); } } }