void init_xterm(int move) { XEvent ev; system(command); while (1) { XMaskEvent(dpy, SubstructureNotifyMask, &ev); if (ev.type == CreateNotify || ev.type == MapNotify) { termwin = ev.xcreatewindow.window; break; } } XSetWindowBorderWidth(dpy, termwin, 0); if (move) { resize_inc = get_height_inc(); height = get_optimal_height(resize_inc * opt_height); resize_term(opt_width, height); XMoveWindow(dpy, win, opt_x, -(height + opt_bw)); XSync(dpy, False); } XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); XSync(dpy, False); }
void tdu_interface_resize_handler (int sig) { int lines, columns; tdu_interface_get_screen_size(&lines, &columns); resize_term(lines, columns); delwin(main_window); delwin(status_window); wrefresh(curscr); /* according to ncurses/test/view.c, linux needs this. */ main_window = newwin(LINES - 1, COLS, 0, 0); status_window = newwin(1, COLS, LINES - 1, 0); keypad(main_window, TRUE); scrollok(main_window, 1); tdu_interface_compute_visible_lines(); prev_start_line = -1; /* force complete refresh */ if (cursor_line > (start_line + visible_lines - 1)) { start_line = cursor_line - (visible_lines - 1); } tdu_interface_display(); }
/* Does window event processing (e.g. exposure events). A noop for the tty and X window-ports. */ void curses_get_nh_event() { #ifdef PDCURSES if (is_termresized()) { resize_term(0, 0); getmaxyx(base_term, term_rows, term_cols); curses_create_main_windows(); curses_last_messages(); doredraw(); } #endif #ifdef NCURSES_VERSION /* Is there a better way to detect ncurses? */ if (is_term_resized(term_rows, term_cols)) { if (!isendwin()) { endwin(); } refresh(); getmaxyx(base_term, term_rows, term_cols); curses_create_main_windows(); curses_last_messages(); doredraw(); } #endif }
void init () { int c, x, y, i; srand (time(NULL)); initscr (); raw (); nodelay(stdscr,1); noecho(); curs_set(0); nonl(); keypad(stdscr,1); resize_term(25,80); #ifdef PDCURSES PDC_set_title("Cymon's Games - Alleytris"); #endif start_color(); for (c = 0; c < COLORS; c++) if (c == COLOR_WHITE) init_pair(c, COLOR_BLACK, c); else init_pair(c, COLOR_WHITE, c); /* Allocate the memory required for the board buffer here */ buf = (int **)malloc(sizeof(int *) * (HEIGHT + 1)); for (i = 0; i < HEIGHT + 1; i++) { buf[i] = (int*)malloc(sizeof(int) * (col_width + 2)); } x = (COLS - col_width - 15) / 2; y = (LINES - HEIGHT) / 2; clear (); refresh (); pwin = newwin(HEIGHT + 1, col_width * 2 + 2, y, x); nwin = newwin(6, 10, y + 1, x + col_width * 2 + 5); iwin = newwin(15, 15, y + 8, x + col_width * 2 + 3); wattrset (iwin, COLOR_PAIR (COLORS / 2)); wfillrect (iwin, 1, 1, 14, 13); box (iwin, 0,0); drawmsg (iwin, 4, 1, 10, instruct); wrefresh (iwin); }
// Show the events details void event_details(int z_index) { erase(); titlebar(); refresh(); resize_term(25, 80); attron(COLOR_PAIR(3)); mvprintw(2, 1, "View Details"); mvprintw(3, 1, "------------"); mvprintw(5, 1, "Event Name\t: %s", myVector[z_index].name); mvprintw(7, 1, "Date\t\t: %i %s %i", myVector[z_index].day, mon_name(myVector[z_index].nmon), myVector[z_index].year); mvprintw(9, 1, "Time\t\t: "); formatted_time(9, 18, myVector[z_index].hour, myVector[z_index].min); mvprintw(11, 1, "Location\t: %s", myVector[z_index].loc); //mvprintw(13, 1, "Description\t: "); attron(COLOR_PAIR(6)); mvprintw(17, 1, "Press ESC to go back..."); refresh(); /*WINDOW *wdesc; wdesc = newwin(3, 60, 13, 18); wattron(wdesc, COLOR_PAIR(3)); mvwprintw(wdesc, 0, 0, "%s", myVector[z_index].desc); wrefresh(wdesc);*/ int key; do { key = getch(); } while (key != 27); list_events(); }
//Initialize curses, colors, windows, and the game objects. bool Game::init_game() { initscr(); start_color(); resize_term(35, 82); raw(); noecho(); keypad(stdscr, TRUE); curs_set(0); init_pair(0, COLOR_WHITE, COLOR_BLACK); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_BLACK, COLOR_WHITE); init_pair(4, COLOR_MAGENTA, COLOR_BLACK); message_win = subwin(stdscr, 2, 80, 0, 1); wmove(message_win, 1, 0); message_line_1[0] = message_line_0[0] = '\0'; level_win = subwin(stdscr, 30, 80, 2, 1); stats_win = subwin(stdscr, 3, 80, 32, 1); inventory_win = newwin(0, 0, 0, 0); current_level = 0; floors[current_level] = new Level(level_win, this); num_levels = 1; player = new Player(floors[current_level], this); floors[current_level]->add_agent(player); deaders = (Agent_List *)malloc(sizeof(Agent_List)); //need to free this and children in destructor deaders->next = NULL; game_over = game_won = game_lost = false; return true; }
void resize() { XEvent ev; if (!XGrabPointer (dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask, GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) == GrabSuccess) return; resize_inc = get_height_inc(); while (1) { XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | PointerMotionHintMask, &ev); switch (ev.type) { case MotionNotify: if (ev.xmotion.y >= resize_inc) { height = ev.xmotion.y - ev.xmotion.y % resize_inc; height = get_optimal_height(height); resize_term(opt_width, height); break; case ButtonRelease: XUngrabPointer(dpy, CurrentTime); return; } } } }
/* Initializes PDCurses and game startup */ int initGame(int argc, char *argv[]) { int c; srand (time(NULL)); initscr(); raw(); nodelay(stdscr,1); noecho(); curs_set(0); nonl(); if (has_colors()) start_color(); for (c = 0; c < COLORS; c++) { if (c == COLOR_WHITE) init_pair(c,COLOR_BLACK,c); else init_pair(c,COLOR_WHITE,c); } /* Special color pair used for drawing player */ init_pair(10,COLOR_YELLOW,COLOR_BLACK); init_pair(11,COLOR_GREEN,COLOR_BLACK); width = 80; height = 20; clear(); refresh(); /* Resize the terminal window */ resize_term(height,width); win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); helpwindow = newwin(0,0,0,0); stats = newwin(20,20,0,60); /* create the character stats window */ encounterwin = newwin(3,19,10,20); if (win == NULL || stats == NULL || helpwindow == NULL) { endwin(); return 1; } savetty(); resize_term(0,0); game_state = GAME_MENU; return 0; }
void init_curses(){ initscr(); init_colors(); cbreak(); noecho(); keypad(stdscr, TRUE); curs_set(0); resize_term(70, 150); }
static void init_stdscr( void) { const char *default_mode_text = getenv( "MYCURSES_MODE"); if( default_mode_text) default_mode_index = (int)( *default_mode_text - '0'); resize_term( text_mode_ysizes[default_mode_index], text_mode_xsizes[default_mode_index]); backup_screen = (char *)malloc( scr_xsize * scr_ysize * 2); memcpy( backup_screen, DISPMEM, scr_xsize * scr_ysize * 2); stdscr->wrap_on = 1; }
static void gnmc_resize_handler (gnmc_t *mon) { screen_t *screen; int32_t rows,cols,i; box_list_t **boxes; struct winsize size; if (ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { resize_term(size.ws_row, size.ws_col); wrefresh(curscr); } if (mon->top_screen != NULL) { screen_destroy (mon->top_screen); } getmaxyx (stdscr,rows,cols); for (i=0;i<mon->nscrs;i++) { screen = mon->main_scrs[i]; boxes = screen->boxes; if (i == STAT_SCR) { screen_redraw (screen,rows/2,cols/2,0,0); box_redraw_all (*boxes,screen); } else if (i == MIX_SCR) { screen_redraw (screen,rows/2,cols/2,0,cols/2); box_redraw_all (*boxes,screen); } else if (i == COMP_SCR) { screen_redraw (screen,rows/2,cols/2,rows/2,0); box_redraw_all (*boxes,screen); } else if (i == TRANS_SCR) { screen_redraw (screen,rows/2,cols/2,rows/2,cols/2); box_redraw_all (*boxes,screen); } } wclear (stdscr); touchwin (stdscr); update_panels (); doupdate (); return; }
void init() { log_f.open("cerr.txt", std::ios_base::out); // NOTE: Must be done before first trace output std::cerr.rdbuf(log_f.rdbuf()); //redirect std::cerr TRACE_FUNC_BEGIN; cleanup(); window_ = initscr(); curs_set(0); // Hide the cursor resize_term(scr_h, scr_w); start_color(); if (!has_colors()) { endwin(); TRACE << "Your terminal does not support color" << std::endl; assert(false); } const auto nr_clr_cmb = COLORS * COLORS; TRACE << "Nr color pairs available : " << COLOR_PAIRS << std::endl << "Nr colors : " << COLORS << std::endl << "Nr color combinations : " << nr_clr_cmb << std::endl; if (COLOR_PAIRS < nr_clr_cmb) { endwin(); TRACE << "Supported color pairs is " << COLOR_PAIRS << ", need at least " << nr_clr_cmb << std::endl; assert(false); } for (short f = 0; f < COLORS; ++f ) { for (short b = 0; b < COLORS; ++b ) { init_pair(f * COLORS + b, f, b); } } is_inited_ = true; TRACE_FUNC_END; }
void resizeTest(WINDOW *dummy) { WINDOW *win1; int nwidth = 135, nheight = 52; int owidth = COLS, oheight = LINES; savetty(); resize_term(nheight, nwidth); clear(); refresh(); win1 = newwin(10, 50, 14, 25); if (win1 == NULL) { endwin(); return; } #ifdef A_COLOR if (has_colors()) { init_pair(3, COLOR_BLUE, COLOR_WHITE); wattrset(win1, COLOR_PAIR(3)); } wclear(win1); #endif mvwaddstr(win1, 0, 0, "The screen may now be resized"); mvwprintw(win1, 1, 4, "Given size: %d by %d", nwidth, nheight); mvwprintw(win1, 2, 4, "Actual size: %d by %d", COLS, LINES); Continue(win1); wclear(win1); resetty(); mvwaddstr(win1, 0, 0, "The screen should now be reset"); mvwprintw(win1, 1, 6, "Old size: %d by %d", owidth, oheight); mvwprintw(win1, 2, 6, "Size now: %d by %d", COLS, LINES); Continue(win1); delwin(win1); clear(); refresh(); }
void screen_resize(struct mpdclient *c) { if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) { screen_exit(); fprintf(stderr, "%s\n", _("Error: Screen too small")); exit(EXIT_FAILURE); } #ifdef PDCURSES resize_term(LINES, COLS); #else resizeterm(LINES, COLS); #endif screen.cols = COLS; screen.rows = LINES; title_bar_resize(&screen.title_bar, screen.cols); /* main window */ screen.main_window.cols = screen.cols; screen.main_window.rows = screen.rows-4; wresize(screen.main_window.w, screen.main_window.rows, screen.cols); wclear(screen.main_window.w); /* progress window */ progress_bar_resize(&screen.progress_bar, screen.cols, screen.rows - 2, 0); progress_bar_paint(&screen.progress_bar); /* status window */ status_bar_resize(&screen.status_bar, screen.cols, screen.rows - 1, 0); status_bar_paint(&screen.status_bar, c->status, c->song); screen.buf_size = screen.cols; g_free(screen.buf); screen.buf = g_malloc(screen.cols); /* resize all screens */ screen_list_resize(screen.main_window.cols, screen.main_window.rows); /* ? - without this the cursor becomes visible with aterm & Eterm */ curs_set(1); curs_set(0); screen_paint(c); }
void screen(int h, int w){ initscr(); if (has_colors()) { start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(BGD, COLOR_WHITE, COLOR_BLACK); //2 init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_RED, COLOR_BLACK); init_pair(5,COLOR_CYAN,COLOR_BLACK); init_pair(6,COLOR_MAGENTA,COLOR_BLACK); init_pair(7,COLOR_BLUE,COLOR_BLACK); } noecho(); curs_set(0); keypad(stdscr, TRUE); raw(); resize_term(h,w); }
void update_geom(Window last_focused) { /* Determine the position of the currently selected window and open console on that screen */ int x, y, w, h; x = y = w = h = -1; XWindowAttributes wa; if (!get_screen_geom(last_focused, &x, &y, &w, &h)) return; XGetWindowAttributes(dpy, win, &wa); if (wa.width != w) { opt_width = w; resize_term(opt_width, height); } opt_x = x + opt_x_orig; opt_y = y + opt_y_orig; }
static void curses_winch_handler(int signum) { struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; /* unused */ unsigned short ws_ypixel; /* unused */ } ws; /* terminal size changed */ if (ioctl(1, TIOCGWINSZ, &ws) == -1) return; resize_term(ws.ws_row, ws.ws_col); curses_calc_pad(); invalidate = 1; /* some systems require this */ signal(SIGWINCH, curses_winch_handler); }
static void curses_winch_check(void) { struct winsize { unsigned short ws_row; unsigned short ws_col; unsigned short ws_xpixel; /* unused */ unsigned short ws_ypixel; /* unused */ } ws; if (!got_sigwinch) { return; } got_sigwinch = false; if (ioctl(1, TIOCGWINSZ, &ws) == -1) { return; } resize_term(ws.ws_row, ws.ws_col); invalidate = 1; }
static int _restore_mode(int i) { if (ctty[i].been_set == TRUE) { memcpy(SP, &(ctty[i].saved), sizeof(SCREEN)); if (ctty[i].saved.raw_out) raw(); PDC_restore_screen_mode(i); if ((LINES != ctty[i].saved.lines) || (COLS != ctty[i].saved.cols)) resize_term(ctty[i].saved.lines, ctty[i].saved.cols); PDC_curs_set(ctty[i].saved.visibility); PDC_gotoyx(ctty[i].saved.cursrow, ctty[i].saved.curscol); } return ctty[i].been_set ? OK : ERR; }
resizeterm(int ToLines, int ToCols) { int result = OK; SP->_sig_winch = FALSE; T((T_CALLED("resizeterm(%d,%d) old(%d,%d)"), ToLines, ToCols, screen_lines, screen_columns)); if (is_term_resized(ToLines, ToCols)) { #if USE_SIGWINCH ungetch(KEY_RESIZE); /* so application can know this */ clearok(curscr, TRUE); /* screen contents are unknown */ #endif result = resize_term(ToLines, ToCols); } returnCode(result); }
static void ncurses_handle_resize(caca_display_t *dp) { struct winsize size; #if defined HAVE_SYS_IOCTL_H if(ioctl(fileno(stdout), TIOCGWINSZ, &size) == 0) { dp->resize.w = size.ws_col; dp->resize.h = size.ws_row; #if defined HAVE_RESIZE_TERM resize_term(dp->resize.h, dp->resize.w); #else resizeterm(dp->resize.h, dp->resize.w); #endif wrefresh(curscr); return; } #endif /* Fallback */ dp->resize.w = caca_get_canvas_width(dp->cv); dp->resize.h = caca_get_canvas_height(dp->cv); }
int set_text_mode( const unsigned mode) { static const unsigned char modes[TOTAL_N_TEXT_MODES] = { 3, 3, 3, 42, 38, 34, 34, 34, 34 }; /* for a 16-high font, use 0x14 */ /* for a 14-high font, use 0x11 */ /* for an 8-high font, use 0x12 */ static const unsigned char font_sizes[TOTAL_N_TEXT_MODES] = { 0x14, 0x11, 0x12, 0, 0, 0, 0x12, 0x14, 0x11 }; union _REGS regset; regset.w.ax = modes[mode]; int386( 0x10, ®set, ®set); if( font_sizes[mode]) { regset.h.ah = 0x11; regset.h.al = font_sizes[mode]; regset.h.bl = 0x00; int386( 0x10, ®set, ®set); } resize_term( text_mode_ysizes[mode], text_mode_xsizes[mode]); return( 0); }
Screen::Screen() { initscr(); #ifdef WIN32 PDC_set_title("Harvest Rogue"); resize_term(40, 120); #endif noecho(); cbreak(); keypad(stdscr, TRUE); nodelay(stdscr, FALSE); notimeout(stdscr, TRUE); raw(); curs_set(0); start_color(); clear(); for (short i = 0; i < 16; i++) { init_pair(i + 1, i, CLR_BLACK); } for (short i = 16; i < 32; i++) { init_pair(i + 1, i - 15, CLR_WHITE); } }
/* Draws the main menu */ void showMenu() { int key, old_option = -1, new_option = 0; display_menu(old_option, new_option); while (quit == FALSE && game_state == GAME_MENU) { noecho(); keypad(stdscr, TRUE); raw(); key = getch(); switch(key) { case 10: case 13: case KEY_ENTER: old_option = -1; erase(); wrefresh(win); game_state = command[new_option].state; erase(); display_menu(old_option, new_option); break; case KEY_PPAGE: case KEY_HOME: old_option = new_option; new_option = 0; display_menu(old_option, new_option); break; case KEY_NPAGE: case KEY_END: old_option = new_option; new_option = MAX_OPTIONS - 1; display_menu(old_option, new_option); break; case KEY_UP: old_option = new_option; new_option = (new_option == 0) ? new_option : new_option - 1; display_menu(old_option, new_option); break; case KEY_DOWN: old_option = new_option; new_option = (new_option == MAX_OPTIONS - 1) ? new_option : new_option + 1; display_menu(old_option, new_option); break; #ifdef KEY_RESIZE case KEY_RESIZE: #ifdef PDCURSES resize_term(0, 0); #endif old_option = -1; erase(); display_menu(old_option, new_option); break; #endif case 'Q': case 'q': quit = TRUE; game_state = GAME_DONE; break; } } }
void Shop::shopScreen() { resize_term(30, 180); bool done = false; int y = 0; int x = 0; int weaponTier = 0; int weaponSelection = -1; while(!done) { clear(); mvprintw(0,1,"Welcome to the shop! Press q, esc or select the back button to exit the shop."); mvprintw(2,1,"Money: %d", playerMoney); mvprintw(4,1,"Back"); mvprintw(5,1,"+10 Ammo: 1$ - Current: %d", playerAmmo); mvprintw(6,1,"+1 Bandage: %d$ - Current: %d", bandageCost, playerBandages); switch(playerMeleeDamage) { case 0: mvprintw(7,1,"Tired of shooting? And/or the lack of ammunition? Buy our newest invention! THE DAGGER! - 50$"); break; case 1: mvprintw(7,1,"The dagger is too weak for you? We got just what you need! Buy this finely crafted kitchen knife and continue you ammunition saving! - 100$"); break; case 2: mvprintw(7,1,"Tired of chopping up zombies like vegetables with your finely crafted kitchen knife? This weapon is taken straight from our time machine! THE SWORD! - 200$"); break; case 3: mvprintw(7,1,"Too modern for the good ol' sword? Buy this super advanced weapon taken straight from our lab! THE LASER DAGGER! - 400$"); break; case 4: mvprintw(7,1,"The laser dagger is too short for you? Well.. Guess what? We took a visit to a galaxy far, far away... - 800$"); break; case 5: mvprintw(7,1,"Not happy with your awesome lazor sword? Well, too bad."); break; } mvprintw(8,1,"+1 Stamina Pill: 5$ - Current: %d", playerStaminaPills); int temp1 = playerBulletSpeed/1.2; int temp2 = playerBulletRange*1.2; int temp3 = playerFiringSpeed/1.2; int temp4 = playerClipLimit*1.2; int temp5 = playerReloadingRate/1.2; mvprintw(9,1,"Upgrade your gun's bullet speed - Current: %d - If upgraded: %d - Upgrade cost: %d", playerBulletSpeed, temp1, upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]); mvprintw(10,1,"Upgrade your gun's attack damage - Current: %d - If upgraded: %d - Upgrade cost: %d", playerDamage, playerDamage+1, upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]); mvprintw(11,1,"Upgrade your gun's bullet range - Current: %d - If upgraded: %d - Upgrade cost: %d", playerBulletRange, temp2, upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]); mvprintw(12,1,"Upgrade your gun's fire rate - Current: %d - If upgraded: %d - Upgrade cost: %d", playerFiringSpeed, temp3, upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]); mvprintw(13,1,"Upgrade your gun's clip capacity - Current: %d - If upgraded: %d - Upgrade cost: %d", playerClipLimit, temp4, upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]); mvprintw(14,1,"Upgrade your gun's reload speed - Current: %d - If upgraded: %d - Upgrade cost: %d", playerReloadingRate, temp5, upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]); mvprintw(16,1,"Tier 1"); mvprintw(16,11,"Tier 2"); mvprintw(16,21,"Tier 3"); mvprintw(16,31,"Tier 4"); mvprintw(16,41,"Tier 5"); if(lastTiersUnlocked) { mvprintw(16,51,"Tier 6"); mvprintw(16,61,"Tier 7"); mvprintw(16,71,"Tier 8"); } switch(weaponTier) { case 1: attron(COLOR_PAIR(6)); mvprintw(16,1,"Tier 1"); attroff(COLOR_PAIR(6)); break; case 2: attron(COLOR_PAIR(6)); mvprintw(16,11,"Tier 2"); attroff(COLOR_PAIR(6)); break; case 3: attron(COLOR_PAIR(6)); mvprintw(16,21,"Tier 3"); attroff(COLOR_PAIR(6)); break; case 4: attron(COLOR_PAIR(6)); mvprintw(16,31,"Tier 4"); attroff(COLOR_PAIR(6)); break; case 5: attron(COLOR_PAIR(6)); mvprintw(16,41,"Tier 5"); attroff(COLOR_PAIR(6)); break; case 6: attron(COLOR_PAIR(6)); mvprintw(16,51,"Tier 6"); attroff(COLOR_PAIR(6)); break; case 7: attron(COLOR_PAIR(6)); mvprintw(16,61,"Tier 7"); attroff(COLOR_PAIR(6)); break; case 8: attron(COLOR_PAIR(6)); mvprintw(16,71,"Tier 8"); attroff(COLOR_PAIR(6)); break; } if(weaponTier != 0) { mvprintw(18,1,"Current Weapon: %s - Weapon Worth: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[0][0], weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, playerBulletSpeed, playerDamage, playerBulletRange, playerFiringSpeed, playerClipLimit, playerReloadingRate); if(weapons[0][weaponTier-1][7] == 1) { attron(COLOR_PAIR(6)); mvprintw(20,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[0][weaponTier-1], weapons[0][weaponTier-1][0], weapons[0][weaponTier-1][1], weapons[0][weaponTier-1][2], weapons[0][weaponTier-1][3], weapons[0][weaponTier-1][4], weapons[0][weaponTier-1][5], weapons[0][weaponTier-1][6] + weapons[0][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(6)); } else if(playerMoney >= weapons[0][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2) { attron(COLOR_PAIR(7)); mvprintw(20,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[0][weaponTier-1], weapons[0][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[0][weaponTier-1][1], weapons[0][weaponTier-1][2], weapons[0][weaponTier-1][3], weapons[0][weaponTier-1][4], weapons[0][weaponTier-1][5], weapons[0][weaponTier-1][6] + weapons[0][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(7)); } else { attron(COLOR_PAIR(5)); mvprintw(20,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[0][weaponTier-1], weapons[0][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[0][weaponTier-1][1], weapons[0][weaponTier-1][2], weapons[0][weaponTier-1][3], weapons[0][weaponTier-1][4], weapons[0][weaponTier-1][5], weapons[0][weaponTier-1][6] + weapons[0][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(5)); } if(weapons[1][weaponTier-1][7] == 1) { attron(COLOR_PAIR(6)); mvprintw(22,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[1][weaponTier-1], weapons[1][weaponTier-1][0], weapons[1][weaponTier-1][1], weapons[1][weaponTier-1][2], weapons[1][weaponTier-1][3], weapons[1][weaponTier-1][4], weapons[1][weaponTier-1][5], weapons[1][weaponTier-1][6] + weapons[1][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(6)); } else if(playerMoney >= weapons[1][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2) { attron(COLOR_PAIR(7)); mvprintw(22,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[1][weaponTier-1], weapons[1][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[1][weaponTier-1][1], weapons[1][weaponTier-1][2], weapons[1][weaponTier-1][3], weapons[1][weaponTier-1][4], weapons[1][weaponTier-1][5], weapons[1][weaponTier-1][6] + weapons[1][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(7)); } else { attron(COLOR_PAIR(5)); mvprintw(22,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[1][weaponTier-1], weapons[1][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[1][weaponTier-1][1], weapons[1][weaponTier-1][2], weapons[1][weaponTier-1][3], weapons[1][weaponTier-1][4], weapons[1][weaponTier-1][5], weapons[1][weaponTier-1][6] + weapons[1][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(5)); } if(weapons[2][weaponTier-1][7] == 1) { attron(COLOR_PAIR(6)); mvprintw(24,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[2][weaponTier-1], weapons[2][weaponTier-1][0], weapons[2][weaponTier-1][1], weapons[2][weaponTier-1][2], weapons[2][weaponTier-1][3], weapons[2][weaponTier-1][4], weapons[2][weaponTier-1][5], weapons[2][weaponTier-1][6] + weapons[2][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(6)); } else if(playerMoney >= weapons[2][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2) { attron(COLOR_PAIR(7)); mvprintw(24,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[2][weaponTier-1], weapons[2][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[2][weaponTier-1][1], weapons[2][weaponTier-1][2], weapons[2][weaponTier-1][3], weapons[2][weaponTier-1][4], weapons[2][weaponTier-1][5], weapons[2][weaponTier-1][6] + weapons[2][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(7)); } else { attron(COLOR_PAIR(5)); mvprintw(24,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[2][weaponTier-1], weapons[2][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[2][weaponTier-1][1], weapons[2][weaponTier-1][2], weapons[2][weaponTier-1][3], weapons[2][weaponTier-1][4], weapons[2][weaponTier-1][5], weapons[2][weaponTier-1][6] + weapons[2][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(5)); } if(weapons[3][weaponTier-1][7] == 1) { attron(COLOR_PAIR(6)); mvprintw(26,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[3][weaponTier-1], weapons[3][weaponTier-1][0], weapons[3][weaponTier-1][1], weapons[3][weaponTier-1][2], weapons[3][weaponTier-1][3], weapons[3][weaponTier-1][4], weapons[3][weaponTier-1][5], weapons[3][weaponTier-1][6] + weapons[3][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(6)); } else if(playerMoney >= weapons[3][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2) { attron(COLOR_PAIR(7)); mvprintw(26,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[3][weaponTier-1], weapons[3][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[3][weaponTier-1][1], weapons[3][weaponTier-1][2], weapons[3][weaponTier-1][3], weapons[3][weaponTier-1][4], weapons[3][weaponTier-1][5], weapons[3][weaponTier-1][6] + weapons[3][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(7)); } else { attron(COLOR_PAIR(5)); mvprintw(26,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[3][weaponTier-1], weapons[3][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[3][weaponTier-1][1], weapons[3][weaponTier-1][2], weapons[3][weaponTier-1][3], weapons[3][weaponTier-1][4], weapons[3][weaponTier-1][5], weapons[3][weaponTier-1][6] + weapons[3][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(5)); } if(weapons[4][weaponTier-1][7] == 1) { attron(COLOR_PAIR(6)); mvprintw(28,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[4][weaponTier-1], weapons[4][weaponTier-1][0], weapons[4][weaponTier-1][1], weapons[4][weaponTier-1][2], weapons[4][weaponTier-1][3], weapons[4][weaponTier-1][4], weapons[4][weaponTier-1][5], weapons[4][weaponTier-1][6] + weapons[4][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(6)); } else if(playerMoney >= weapons[4][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2) { attron(COLOR_PAIR(7)); mvprintw(28,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[4][weaponTier-1], weapons[4][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[4][weaponTier-1][1], weapons[4][weaponTier-1][2], weapons[4][weaponTier-1][3], weapons[4][weaponTier-1][4], weapons[4][weaponTier-1][5], weapons[4][weaponTier-1][6] + weapons[4][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(7)); } else { attron(COLOR_PAIR(5)); mvprintw(28,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[4][weaponTier-1], weapons[4][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[4][weaponTier-1][1], weapons[4][weaponTier-1][2], weapons[4][weaponTier-1][3], weapons[4][weaponTier-1][4], weapons[4][weaponTier-1][5], weapons[4][weaponTier-1][6] + weapons[4][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(5)); } if(weapons[4][weaponTier-1][8] == 8 && weapons[4][weaponTier-1][7] == 1) { attron(COLOR_PAIR(9)); mvprintw(28,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[4][weaponTier-1], weapons[4][weaponTier-1][0], weapons[4][weaponTier-1][1], weapons[4][weaponTier-1][2], weapons[4][weaponTier-1][3], weapons[4][weaponTier-1][4], weapons[4][weaponTier-1][5], weapons[4][weaponTier-1][6] + weapons[4][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(9)); } else if(weapons[4][weaponTier-1][8] == 8 && playerMoney >= weapons[4][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2) { attron(COLOR_PAIR(10)); mvprintw(28,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[4][weaponTier-1], weapons[4][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[4][weaponTier-1][1], weapons[4][weaponTier-1][2], weapons[4][weaponTier-1][3], weapons[4][weaponTier-1][4], weapons[4][weaponTier-1][5], weapons[4][weaponTier-1][6] + weapons[4][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(10)); } else if(weapons[4][weaponTier-1][8] == 8) { attron(COLOR_PAIR(8)); mvprintw(28,1,"%s - Weapon Cost: %d - Bullet Speed: %d - Bullet Damage: %d - Bullet Range: %d - Weapon Fire Rate: %d - Weapon Max Clip: %d - Weapon Reload Rate: %d", weaponNames[4][weaponTier-1], weapons[4][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2, weapons[4][weaponTier-1][1], weapons[4][weaponTier-1][2], weapons[4][weaponTier-1][3], weapons[4][weaponTier-1][4], weapons[4][weaponTier-1][5], weapons[4][weaponTier-1][6] + weapons[4][weaponTier-1][6]/100*playerReloadingModifier); attroff(COLOR_PAIR(8)); } } move(4+y, x*10); addch('>'); int input = getch(); switch(input) { case KEY_UP: if(y > 0) { if(y > 10) { y -= 2; if(y+2 == 16) { y -= 2; } } else { y--; } x = 0; } break; case KEY_DOWN: if(y < 24) { if(y < 10) { y++; } else { if(y == 10 || weaponTier != 0) { y += 2; if(y-2 == 12) { y += 2; } } } x = 0; } break; case KEY_RIGHT: if(!lastTiersUnlocked) { if(x < 4) { x++; } } else { if(x < 7) { x++; } } if(y != 8) { y = 12; } break; case KEY_LEFT: if(x > 0) { x--; } break; case ' ': switch(y) { case 0: done = true; break; case 1: if(playerMoney >= 1) { playerMoney -= 1; playerAmmo += 10; playerAmountBought++; } break; case 2: if(playerMoney >= bandageCost) { playerMoney -= 5; playerBandages++; bandageCost *= 1.5; playerAmountBought++; } break; case 3: if(playerMoney >= meleeCost && playerMeleeDamage < 5) { playerMeleeDamage++; playerMoney -= meleeCost; meleeCost *= 2; playerAmountBought++; } break; case 4: if(playerMoney >= 5) { playerMoney -= 5; playerStaminaPills++; playerAmountBought++; } case 5: if(playerMoney >= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] && playerBulletSpeed != temp1) { playerMoney -= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][1] = playerBulletSpeed/1.2; playerBulletSpeed = playerBulletSpeed/1.2; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0] += upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] *= 1.5; playerAmountBought++; } break; case 6: if(playerMoney >= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]) { playerMoney -= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][2] = playerDamage+1; playerDamage = playerDamage+1; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0] += upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] *= 1.5; playerAmountBought++; } break; case 7: if(playerMoney >= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] && playerBulletRange != temp2) { playerMoney -= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][3] = playerBulletRange*1.2; playerBulletRange = playerBulletRange*1.2; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0] += upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] *= 1.5; playerAmountBought++; } break; case 8: if(playerMoney >= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] && playerFiringSpeed != temp3) { playerMoney -= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][4] = playerFiringSpeed/1.2; playerFiringSpeed = playerFiringSpeed/1.2; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0] += upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] *= 1.5; playerAmountBought++; } break; case 9: if(playerMoney >= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] && playerClipLimit != temp4) { playerMoney -= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][5] = playerClipLimit*1.2; playerClipLimit= playerClipLimit*1.2; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0] += upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] *= 1.5; playerAmountBought++; } break; case 10: if(playerMoney >= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] && playerReloadingRate != temp5) { playerMoney -= upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][6] = playerReloadingRate/1.2; playerReloadingRate = playerReloadingRate/1.2; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0] += upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]]; upgradeCost[playerCurrentWeapon[0]][playerCurrentWeapon[1]] *= 1.5; playerAmountBought++; } break; case 12: switch(x) { case 0: weaponTier = 1; break; case 1: weaponTier = 2; break; case 2: weaponTier = 3; break; case 3: weaponTier = 4; break; case 4: weaponTier = 5; break; case 5: weaponTier = 6; break; case 6: weaponTier = 7; break; case 7: weaponTier = 8; break; } break; case 16: weaponSelection = 0; break; case 18: weaponSelection = 1; break; case 20: weaponSelection = 2; break; case 22: weaponSelection = 3; break; case 24: weaponSelection = 4; break; } break; case 'q': done = true; break; case 27: done = true; break; } if(weaponSelection != -1) { if(playerMoney >= weapons[weaponSelection][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2 && weapons[weaponSelection][weaponTier-1][7] == 0) { playerMoney -= weapons[weaponSelection][weaponTier-1][0]-weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][0]/2; weapons[playerCurrentWeapon[0]][playerCurrentWeapon[1]][7] = 0; weapons[weaponSelection][weaponTier-1][7] = 1; playerCurrentWeapon = {weaponSelection, weaponTier-1}; playerBulletSpeed = weapons[weaponSelection][weaponTier-1][1]; playerDamage = weapons[weaponSelection][weaponTier-1][2]; playerBulletRange = weapons[weaponSelection][weaponTier-1][3]; playerFiringSpeed = weapons[weaponSelection][weaponTier-1][4]; playerClipLimit = weapons[weaponSelection][weaponTier-1][5]; playerReloadingRate = weapons[weaponSelection][weaponTier-1][6] += weapons[weaponSelection][weaponTier-1][6]/100*playerReloadingModifier; for(int i = 0; i < 10; i++) playerSpecialWeaponTypes[i] = false; if(weapons[weaponSelection][weaponTier-1][8] != 0) { playerSpecialWeaponTypes[0] = true; playerSpecialWeaponTypes[weapons[weaponSelection][weaponTier-1][8]] = true; } for(int i = 0; i < 30; i++) { playerWeaponName[i] = weaponNames[weaponSelection][weaponTier-1][i]; } if(playerClip > playerClipLimit) { playerAmmo += playerClip - playerClipLimit; playerClip = playerClipLimit; } playerAmountBought++; } } weaponSelection = -1; refresh(); } resize_term(30, 80); }
void curses_init_options() { set_wc_option_mod_status(WC_ALIGN_MESSAGE|WC_ALIGN_STATUS|WC_COLOR| WC_HILITE_PET|WC_POPUP_DIALOG, SET_IN_GAME); set_wc2_option_mod_status(WC2_GUICOLOR, SET_IN_GAME); /* Remove a few options that are irrelevant to this windowport */ set_option_mod_status("DECgraphics", SET_IN_FILE); set_option_mod_status("perm_invent", SET_IN_FILE); set_option_mod_status("eight_bit_tty", SET_IN_FILE); /* Make sure that DECgraphics is not set to true via the config file, as this will cause display issues. We can't disable it in options.c in case the game is compiled with both tty and curses.*/ if (iflags.DECgraphics) { switch_graphics(CURS_GRAPHICS); } #ifdef PDCURSES /* PDCurses for SDL, win32 and OS/2 has the ability to set the terminal size programatically. If the user does not specify a size in the config file, we will set it to a nice big 110x32 to take advantage of some of the nice features of this windowport. */ if (iflags.wc2_term_cols == 0) { iflags.wc2_term_cols = 110; } if (iflags.wc2_term_rows == 0) { iflags.wc2_term_rows = 32; } resize_term(iflags.wc2_term_rows, iflags.wc2_term_cols); getmaxyx(base_term, term_rows, term_cols); /* This is needed for an odd bug with PDCurses-SDL in Windows */ # ifdef WIN32 switch_graphics(ASCII_GRAPHICS); if (iflags.IBMgraphics) { switch_graphics(IBM_GRAPHICS); } else if (iflags.cursesgraphics) { switch_graphics(CURS_GRAPHICS); } else { switch_graphics(ASCII_GRAPHICS); } # endif /* WIN32 */ #endif /* PDCURSES */ if (!iflags.wc2_windowborders) { iflags.wc2_windowborders = 3; /* Set to auto if not specified */ } if (!iflags.wc2_petattr) { iflags.wc2_petattr = A_UNDERLINE; } else /* Pet attribute specified, so hilite_pet should be true */ { iflags.hilite_pet = TRUE; } }
void colorTest(WINDOW *win) { static const short colors[] = { COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE }; static const char *colornames[] = { "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE", "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE" }; chtype fill = ACS_BLOCK; int i, j, tmarg, col1, col2, col3, col4, ch; if (!has_colors()) return; do { tmarg = (LINES - 19) / 2; col1 = (COLS - 60) / 2; col2 = col1 + 15; col3 = col2 + 15; col4 = col3 + 15; attrset(A_BOLD); mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros"); attrset(A_NORMAL); mvaddstr(tmarg + 3, col2 + 2, "A_NORMAL"); mvaddstr(tmarg + 3, col3 + 3, "A_BOLD"); mvaddstr(tmarg + 3, col4 + 3, "A_BLINK"); for (i = 0; i < 8; i++) { init_pair((short)(i + 4), colors[i], background_index); mvaddstr(tmarg + i + 5, col1, colornames[i]); for (j = 0; j < 12; j++) { mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4)); mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD); mvaddch(tmarg + i + 5, col4 + j, fill | COLOR_PAIR(i + 4) | A_BLINK); } attrset( COLOR_PAIR( i + 4) | A_BLINK); mvaddstr( tmarg + i + 5, col4 + 5, "Text"); attrset( COLOR_PAIR( i + 4) | A_BOLD); mvaddstr( tmarg + i + 5, col3 + 5, "Text"); attroff( A_BOLD); mvaddstr( tmarg + i + 5, col2 + 5, "Text"); attrset( A_NORMAL); } mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS); mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS); #ifdef CHTYPE_LONG #if( CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */ attrset(A_ITALIC); mvprintw( tmarg + 15, col3, "Italic"); attrset(A_ITALIC | A_BLINK); mvprintw( tmarg + 15, col4, "Italic Blink"); attrset(A_BOLD | A_ITALIC); mvprintw( tmarg + 17, col4, "Italic Bold"); attrset(A_BOLD | A_ITALIC | A_BLINK); mvprintw( tmarg + 18, col4, "Italic Blink Bold"); #endif #endif attrset(A_BOLD); mvprintw( tmarg + 16, col3, "Bold"); attrset(A_BLINK); mvprintw( tmarg + 17, col3, "Blink"); attrset(A_BLINK | A_BOLD); mvprintw( tmarg + 16, col4, "Blink Bold"); /* end BJG addenda */ attrset(A_NORMAL); mvaddstr(tmarg + 19, 3, "Press any key to continue"); ch = getch(); # ifdef PDCURSES if( ch == KEY_RESIZE) { erase(); resize_term(0, 0); } # endif } while( ch == KEY_RESIZE); if (can_change_color()) { struct { short red, green, blue; } orgcolors[16]; int MAXCOL = (COLORS >= 16) ? 16 : 8; if (MAXCOL < 8) return; for (i = 0; i < MAXCOL; i++) color_content((short)i, &(orgcolors[i].red), &(orgcolors[i].green), &(orgcolors[i].blue)); attrset(A_BOLD); mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example "); attrset(A_NORMAL); refresh(); for (i = 0; i < 8; i++) { init_color(colors[i], (short)(i * 125), 0, (short)(i * 125)); if (MAXCOL == 16) init_color((short)(colors[i] + 8), 0, (short)(i * 125), 0); } mvaddstr(tmarg + 19, 3, "Press any key to continue"); getch(); for (i = 0; i < MAXCOL; i++) init_color((short)i, orgcolors[i].red, orgcolors[i].green, orgcolors[i].blue); } /* BJG additions: */ if( COLORS == 256 && LINES >= 18) do /* show off all 256 colors */ { tmarg = LINES / 2 - 8; erase( ); for( i = 0; i < 256; i++) { char tbuff[4]; const int col = COLS / 2 - 24; if( i >= 16) init_pair((short)i, (short)i, COLOR_BLACK); attrset( COLOR_PAIR( i) | A_REVERSE); sprintf( tbuff, "%02x ", i); mvaddstr( tmarg + i / 16, col + (i % 16) * 3, tbuff); } #ifdef A_LEFTLINE attrset( A_LEFTLINE); mvaddstr( tmarg + 17, col1, "A_LEFTLINE"); #endif #ifdef A_UNDERLINE attrset( A_UNDERLINE); mvaddstr( tmarg + 18, col1, "A_UNDERLINE"); #endif #ifdef A_RIGHTLINE attrset( A_RIGHTLINE); mvaddstr( tmarg + 19, col1, "A_RIGHTLINE"); #endif # if(CHTYPE_LONG >= 2) /* following types don't exist otherwise: */ attrset( A_OVERLINE); mvaddstr( tmarg + 17, col2, "A_OVERLINE"); attrset( A_STRIKEOUT); mvaddstr( tmarg + 18, col2, "A_STRIKEOUT"); attrset( A_OVERLINE | A_UNDERLINE); mvaddstr( tmarg + 19, col2, "Over/underlined"); #endif attrset(A_NORMAL); refresh( ); ch = getch( ); # ifdef PDCURSES if( ch == KEY_RESIZE) resize_term(0, 0); # endif } while( ch == KEY_RESIZE); }
int main(int argc, char *argv[]) { WINDOW *win; int key, old_option = -1, new_option = 0, i; bool quit = FALSE; setlocale(LC_ALL, ""); if (initTest(&win, argc, argv)) return 1; for( i = 1; i < argc; i++) if( argv[i][0] == '-') switch( argv[i][1]) { case 'l': case 'L': setlocale( LC_ALL, argv[i] + 2); break; case 'i': case 'I': background_index = (short)atoi( argv[i] + 2); break; #ifdef PDCURSES case 'b': case 'B': PDC_set_blink( TRUE); break; case 'm': case 'M': PDC_return_key_modifiers( TRUE); break; case 'r': /* allow user-resizable windows */ { int min_lines, max_lines, min_cols, max_cols; if( sscanf( argv[i] + 2, "%d,%d,%d,%d", &min_lines, &max_lines, &min_cols, &max_cols) == 4) { ttytype[0] = min_lines; ttytype[1] = max_lines; ttytype[2] = min_cols; ttytype[3] = max_cols; } } break; #endif default: break; } #ifdef A_COLOR if (has_colors()) { init_pair(1, COLOR_WHITE, COLOR_BLUE); wbkgd(win, COLOR_PAIR(1)); } else #endif wbkgd(win, A_REVERSE); #ifdef PDCURSES /* for x11, sdl1, and win32a, treat the close of the windows as KEY_EXIT */ PDC_set_function_key( FUNCTION_KEY_SHUT_DOWN, KEY_EXIT ); #endif erase(); display_menu(old_option, new_option); while (1) { noecho(); keypad(stdscr, TRUE); raw(); #ifdef PDCURSES mouse_set(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION); #endif key = getch(); switch(key) { #ifdef PDCURSES case KEY_MOUSE: { const int tmarg = (LINES - (MAX_OPTIONS + 2)) / 2; int selected_opt; request_mouse_pos(); selected_opt = MOUSE_Y_POS - tmarg; if( selected_opt >= 0 && selected_opt < MAX_OPTIONS) { old_option = new_option; new_option = selected_opt; display_menu( old_option, new_option); } } if( (Mouse_status.button[0] & BUTTON_ACTION_MASK) == BUTTON_DOUBLE_CLICKED) key = 10; else break; #endif case 10: case 13: case KEY_ENTER: old_option = -1; erase(); refresh(); (*command[new_option].function)(win); erase(); display_menu(old_option, new_option); break; case KEY_PPAGE: case KEY_HOME: old_option = new_option; new_option = 0; display_menu(old_option, new_option); break; case KEY_NPAGE: case KEY_END: old_option = new_option; new_option = MAX_OPTIONS - 1; display_menu(old_option, new_option); break; case KEY_UP: old_option = new_option; new_option = (new_option == 0) ? new_option : new_option - 1; display_menu(old_option, new_option); break; case KEY_DOWN: old_option = new_option; new_option = (new_option == MAX_OPTIONS - 1) ? new_option : new_option + 1; display_menu(old_option, new_option); break; case KEY_RESIZE: # ifdef PDCURSES resize_term(0, 0); # endif old_option = -1; erase(); display_menu(old_option, new_option); break; case 'Q': case 'q': quit = TRUE; } if (quit == TRUE) break; } delwin(win); endwin(); return 0; }
Screen::Screen( World * const wor, Player * const pl) : VirtScreen(wor, pl), updated(false), cleaned(false) { //ifdefs are adjustments for windows console, added by Panzerschrek #ifdef Q_OS_WIN32 AllocConsole(); freopen( "conout$", "w", stdout ); freopen( "conin$", "r", stdin ); #endif #ifdef Q_OS_WIN32 resize_term( (SCREEN_SIZE + 2) + (2 + 5) + (2 + 3), SCREEN_SIZE * 4 + 4 ); #else set_escdelay(10); #endif initscr(); start_color(); raw(); //send typed keys directly noecho(); //do not print typed symbols keypad(stdscr, TRUE); //use arrows curs_set(0); //invisible cursor //all available color pairs (maybe some of them will not be used) const short colors[]={ //do not change colors order! COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE }; for (short i=BLACK_BLACK; i<=WHITE_WHITE; ++i) { init_pair(i, colors[(i-1)/8], colors[(i-1)%8]); } leftWin =newwin(SCREEN_SIZE+2, SCREEN_SIZE*2+2, 0, 0); rightWin=newwin(SCREEN_SIZE+2, SCREEN_SIZE*2+2, 0, SCREEN_SIZE*2+2); hudWin=newwin(3, (SCREEN_SIZE*2+2)*2, SCREEN_SIZE+2, 0); notifyWin=newwin(0, COLS, SCREEN_SIZE+2+3, 0); scrollok(notifyWin, TRUE); notifyLog=fopen("messages.txt", "a"); QSettings sett(QDir::currentPath()+"/freg.ini", QSettings::IniFormat); sett.beginGroup("screen_curses"); shiftFocus=sett.value("focus_shift", 0).toInt(); actionMode=sett.value("action_mode", USE).toInt(); command =sett.value("last_command", "hello").toString(); addstr("Press any key."); qsrand(getch()); Notify("Game started."); input=new IThread(this); input->start(); timer=new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(Print())); timer->start(100); }
int main(int argc, char *argv[]) { KeySym key; XEvent event; int hidden = 1; int fullscreen = 0; int i, tmp; int old_height = 0; Window tmpwin, last_focused, current_focused; XWindowAttributes wa; /* strip the path from argv[0] if there is one */ progname = strrchr(argv[0], '/'); if (!progname) progname = argv[0]; else progname++; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-h")) { printf("%s:\n" "-e: program to execute\n" "you can configure me via xresources:\n" "%s*foo:value\n" "foo can be any standard xterm/urxvt/st xresource or:\n" "resource default value\n\n" "term: xterm\n" "restart: 0\n" "xOffset: 0\n" "yOffset: 0\n" "xrandrSupport: 0\n" "screenWidth: Display width\n" "consoleHeight: 10\n" "aniDelay: 40\n" "stepSize; 1\n" "toggleKey: ControlAlt+y\n" "keySmaller: Control+KP_Subtract\n" "keyBigger: Control+KP_Add\n" "keyFull: Alt+F11\n", progname, progname); exit(0); } } if (!(dpy = XOpenDisplay(NULL))) { fprintf(stderr, " can not open dpy %s", XDisplayName(NULL)); } screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); XSetErrorHandler(handle_xerror); cursor = XCreateFontCursor(dpy, XC_double_arrow); get_defaults(); init_win(); init_command(argc, argv); init_xterm(1); while (1) { XNextEvent(dpy, &event); switch (event.type) { case FocusOut: /* Always keep input focus when visible */ if (!hidden) XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); break; case EnterNotify: XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); XSync(dpy, False); break; case LeaveNotify: if (last_focused && event.xcrossing.detail != NotifyInferior) { XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime); XSync(dpy, False); } break; case KeyPress: key = XKeycodeToKeysym(dpy, event.xkey.keycode, 0); if (key == opt_key) { if (!hidden) { XGetInputFocus(dpy, ¤t_focused, &revert_to); if (last_focused && current_focused == termwin) XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime); /* else XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); */ if (opt_step && !fullscreen) roll(UP); XUnmapWindow(dpy, win); hidden = 1; XSync(dpy, False); } else { XGetInputFocus(dpy, &last_focused, &revert_to); last_focused = get_toplevel_parent(last_focused); if (opt_step && !fullscreen) { XGrabServer(dpy); roll(DOWN); XUngrabServer(dpy); } else if (opt_xrandr) update_geom(last_focused); XMoveWindow(dpy, win, opt_x, opt_y); XMapWindow(dpy, win); XRaiseWindow(dpy, win); XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); hidden = 0; XSync(dpy, False); XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); XSync(dpy, False); } break; } if (!hidden) { if (key == opt_key_full) { if (!fullscreen) { old_height = height; height = get_optimal_height(get_display_height()); fullscreen = 1; } else { height = old_height; fullscreen = 0; } } /* update height inc just in case something changed for the * terminal, i.e. font size */ resize_inc = get_height_inc(); if (key == opt_key_bigger) height += resize_inc; if (key == opt_key_smaller) height -= resize_inc; if (height < resize_inc) height = resize_inc; height = get_optimal_height(height); resize_term(opt_width, height); XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); XSync(dpy, False); } break; case ButtonPress: resize(); XSync(dpy, False); break; case UnmapNotify: if (event.xunmap.window == termwin) { if (opt_restart) { if (opt_restart_hidden) { roll(UP); hidden = 1; } init_xterm(0); XSync(dpy, False); if (opt_restart_hidden && last_focused) XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime); else XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime); } else { if (last_focused) XSetInputFocus(dpy, last_focused, RevertToPointerRoot, CurrentTime); XSync(dpy, False); exit(0); } } break; } } return 0; }