Beispiel #1
0
static void refresh_map_window()
{
    int mapwinx, mapwiny, maph, mapw, mapwinw, mapwinh, mapx, mapy;
    WINDOW *map_window = curses_get_nhwin(MAP_WIN);
    boolean border = curses_window_has_border(MAP_WIN);
    
    curses_get_window_xy(MAP_WIN, &mapwinx, &mapwiny);
    curses_get_window_size(MAP_WIN, &mapwinh, &mapwinw);
    maph = ROWNO;
    mapw = COLNO;
    mapx = u.ux - (mapwinw / 2);
    if ((mapx + mapwinw) > mapw)
    {
        mapx = mapw - mapwinw;
    }
    if (mapx < 0)
    {
        mapx = 0;
    }
    mapy = u.uy - (mapwinh / 2);
    if ((mapy + mapwinh) > maph)
    {
        mapy = maph - mapwinh;
    }
    if (mapy < 0)
    {
        mapy = 0;
    }
    prefresh(map_window, mapy, mapx, mapwiny, mapwinx, mapwiny + mapwinh - 1, 
     mapwinx + mapwinw - 1);
}
Beispiel #2
0
void curses_clear_unhighlight_message_window()
{
    int mh, mw, count;
    boolean border = curses_window_has_border(MESSAGE_WIN);
    WINDOW *win = curses_get_nhwin(MESSAGE_WIN);

    turn_lines = 1;
    
    curses_get_window_size(MESSAGE_WIN, &mh, &mw); 
    
    mx = 0;
    
    if (border)
    {
        mx++;
    }
       
    if (mh == 1)
    {
        curses_clear_nhwin(MESSAGE_WIN);
    }
    else
    {
        mx += mw;    /* Force new line on new turn */
        
        if (border)
        {

            for (count = 0; count < mh; count++)
            {
                mvwchgat(win, count+1, 1, mw, COLOR_PAIR(8), A_NORMAL, NULL);
            }
        }
        else
        {
            for (count = 0; count < mh; count++)
            {
                mvwchgat(win, count, 0, mw, COLOR_PAIR(8), A_NORMAL, NULL);
            }
        }

        wrefresh(win);
    }
}
Beispiel #3
0
static void scroll_window(winid wid)
{
    int wh, ww, s_top, s_bottom;
    boolean border = curses_window_has_border(wid);
    WINDOW *win = curses_get_nhwin(wid);
    
    curses_get_window_size(wid, &wh, &ww);
    if (wh == 1)
    {
        curses_clear_nhwin(wid);
        return;
    }
    if (border)
    {
        s_top = 1;
        s_bottom = wh;
    }
    else
    {
        s_top = 0;
        s_bottom = wh - 1;
    }
    scrollok(win, TRUE);
    wsetscrreg(win, s_top, s_bottom);
    scroll(win);
    scrollok(win, FALSE);
    if (wid == MESSAGE_WIN)
    {
        if (border)
            mx = 1;
        else
            mx = 0;
    }
    if (border)
    {
        box(win, 0, 0);
    }
    wrefresh(win);
}
Beispiel #4
0
void curses_more()
{
    int height, width;
    WINDOW *win = curses_get_nhwin(MESSAGE_WIN);

    curses_get_window_size(MESSAGE_WIN, &height, &width);
    curses_toggle_color_attr(win, MORECOLOR, NONE, ON);
    mvwprintw(win, my, mx - 1, ">>");
    curses_toggle_color_attr(win, MORECOLOR, NONE, OFF);
    wrefresh(win);
    wgetch(win);
    if (height == 1)
    {
        curses_clear_unhighlight_message_window();
    }
    else
    {
        mvwprintw(win, my, mx - 1, "  ");
        scroll_window(MESSAGE_WIN);
        turn_lines = 1;
    }
}
Beispiel #5
0
void curses_line_input_dialog(const char *prompt, char *answer, int buffer)
{
    int map_height, map_width, maxwidth, remaining_buf, winx, winy, count;
    WINDOW *askwin, *bwin;
    char input[buffer];
    char *tmpstr;
    int prompt_width = strlen(prompt) + buffer + 1;
    int prompt_height = 1;
    int height = prompt_height;

    maxwidth = term_cols - 2;

    if (iflags.window_inited)
    {
        curses_get_window_size(MAP_WIN, &map_height, &map_width);
        if ((prompt_width + 2) > map_width)
            maxwidth = map_width - 2;
    }
    
    if (prompt_width > maxwidth)
    {
        prompt_height = curses_num_lines(prompt, maxwidth);
        height = prompt_height;
        prompt_width = maxwidth;
        tmpstr = curses_break_str(prompt, maxwidth, prompt_height);
        remaining_buf = buffer - (strlen(tmpstr) - 1);
        if (remaining_buf > 0 )
        {
            height += (remaining_buf / prompt_width);
            if ((remaining_buf % prompt_width) > 0)
            {
                height++;
            }
        }
    }
    
    if (iflags.window_inited)
    {
        bwin = curses_create_window(prompt_width, height, UP);
        wrefresh(bwin);
        getbegyx(bwin, winy, winx);
        askwin = newwin(height, prompt_width, winy + 1, winx + 1);
    }
    else
    {
        bwin = curses_create_window(prompt_width, height, CENTER);
        wrefresh(bwin);
        getbegyx(bwin, winy, winx);
        askwin = newwin(height, prompt_width, winy + 1, winx + 1);
    }
    for (count = 0; count < prompt_height; count++)
    {
        tmpstr = curses_break_str(prompt, maxwidth, count + 1);
        if (count == (prompt_height - 1))    /* Last line */
        {
            mvwprintw(askwin, count, 0, "%s ", tmpstr);
        }
        else
        {
            mvwaddstr(askwin, count, 0, tmpstr);
        }
        free(tmpstr);
    }
    
    echo();
    curs_set(1);
    wgetnstr(askwin, input, buffer-1);
    curs_set(0);
    strcpy(answer, input);
    werase(bwin);
    delwin(bwin);
    curses_destroy_win(askwin);
    noecho();
}
Beispiel #6
0
int curses_ext_cmd()
{
    int count, letter, prompt_width, startx, starty, winx, winy;
    int messageh, messagew;
    int ret = -1;
    char cur_choice[BUFSZ];
    int matches = 0;
    WINDOW *extwin = NULL;

    if (iflags.extmenu)
    {
        return extcmd_via_menu();
    }
    
    if (iflags.wc_popup_dialog) /* Prompt in popup window */
    {
        startx = 1;
        starty = 1;
        extwin = curses_create_window(25, 1, UP);
    }
    else
    {
        curses_get_window_xy(MESSAGE_WIN, &winx, &winy);
        curses_get_window_size(MESSAGE_WIN, &messageh, &messagew);
        
        if (curses_window_has_border(MESSAGE_WIN))
        {
            winx++;
            winy++;
        }
        
        winy += messageh - 1;
        extwin = newwin(1, 25, winy, winx);
        startx = 0;
        starty = 0;
        pline("#");
    }

    cur_choice[0] = '\0';

    while (1)
    {
        wmove(extwin, starty, startx);
        waddstr(extwin, "# ");
        wmove(extwin, starty, startx + 2);
        curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, ON);
        waddstr(extwin, cur_choice);
        curses_toggle_color_attr(extwin, NONE, A_UNDERLINE, OFF);
        wmove(extwin, starty, strlen(cur_choice) + startx + 2);
        wprintw(extwin, "          ", cur_choice);

        if (matches == 1)
        {
            wmove(extwin, starty, strlen(cur_choice) + startx + 2);
            wprintw(extwin, "%s          ", extcmdlist[ret].ef_txt
             + strlen(cur_choice));
        }

        wrefresh(extwin);
        letter = getch();
	    prompt_width = strlen(cur_choice);
        matches = 0;

        if (letter == '\033')
        {
            ret = -1;
            break;
        }

        if ((letter == '\r') || (letter == '\n'))
        {
            break;
        }

        if ((letter == '\b') || (letter == KEY_BACKSPACE))
        {
            if (prompt_width == 0)
            {
                ret = -1;
                break;
            }
            else
            {
                cur_choice[prompt_width - 1] = '\0';
                letter = '*';
                prompt_width--;
            }
        }
        
        for (count = 0; extcmdlist[count].ef_txt; count++)
        {
            if (strlen(extcmdlist[count].ef_txt) > prompt_width)
            {
                if (strncasecmp(cur_choice, extcmdlist[count].ef_txt,
                 prompt_width) == 0)
                {
                    if ((extcmdlist[count].ef_txt[prompt_width] ==
			 lowc(letter)) || letter == '*')
                    {
                        if ((matches == 0) && (letter != '*'))
                        {
                            ret = count;
                            cur_choice[prompt_width] = letter;
                            cur_choice[prompt_width + 1] = '\0';
                        }

                        matches++;
                    }
                }
            }
	    }
	}    
    
    curses_destroy_win(extwin);
    return ret;
}
Beispiel #7
0
int curses_character_input_dialog(const char *prompt, const char *choices, char def)
{
    WINDOW *askwin = NULL;
    int answer, count, maxwidth, map_height, map_width;
    char *linestr;
    char askstr[BUFSZ + QBUFSZ];
    char choicestr[QBUFSZ];
    int prompt_width = strlen(prompt);
    int prompt_height = 1;
    boolean any_choice = FALSE;
    boolean accept_count = FALSE;

    if (invent || (moves > 1))
    {
        curses_get_window_size(MAP_WIN, &map_height, &map_width);
    }
    else
    {
        map_height = term_rows;
        map_width = term_cols;
    }
    
    maxwidth = map_width - 2;
    
    if (choices != NULL)
    {
        for (count = 0; choices[count] != '\0'; count++)
        {
            if (choices[count] == '#')   /* Accept a count */
            {
                accept_count = TRUE;
            }
        }
        choicestr[0] = ' ';
        choicestr[1] = '[';
        for (count = 0; choices[count] != '\0'; count++)
        {
            if (choices[count] == '\033')   /* Escape */
            {
                break;
            }
            choicestr[count + 2] = choices[count];
        }
        choicestr[count + 2] = ']';
        if (((def >= 'A') && (def <= 'Z')) || ((def >= 'a') && (def <= 'z')))
        {
            choicestr[count + 3] = ' ';
            choicestr[count + 4] = '(';
            choicestr[count + 5] = def;
            choicestr[count + 6] = ')';
            choicestr[count + 7] = '\0';
        }
        else    /* No usable default choice */
        {
            choicestr[count + 3] = '\0';
            def = '\0'; /* Mark as no default */
        }
        strcpy(askstr, prompt);
        strcat(askstr, choicestr);
    }
    else
    {
        strcpy(askstr, prompt);
        any_choice = TRUE;
    }
    
    prompt_width = strlen(askstr);
    
    if ((prompt_width + 2) > maxwidth)
    {
        prompt_height = curses_num_lines(askstr, maxwidth);
        prompt_width = map_width - 2;
    }

    if (iflags.wc_popup_dialog)
    {
        askwin = curses_create_window(prompt_width, prompt_height, UP);
        for (count = 0; count < prompt_height; count++)
        {
            linestr = curses_break_str(askstr, maxwidth, count + 1);
            mvwaddstr(askwin, count + 1, 1, linestr);
            free(linestr);
        }
    
        wrefresh(askwin);
    }
    else
    {
        linestr = curses_copy_of(askstr);
        pline("%s", linestr);
        free(linestr);
        curs_set(1);
    }

    while (1)
    {
        answer = getch();
        answer = curses_convert_keys(answer);

        if (answer==KEY_ESC)
        {
            if (choices == NULL)
            {
                break;
            }
            answer = def;
            for (count = 0; choices[count] != '\0'; count++)
            {
                if (choices[count] == 'q') /* q is preferred over n */
                {
                    answer = 'q';
                }
                else if ((choices[count] == 'n') && answer != 'q')
                {
                    answer = 'n';
                }
            }
            break;
        }
        else if ((answer == '\n') || (answer == '\r') ||
         (answer == ' '))
        {
            if ((choices != NULL) && (def != '\0'))
            {
                answer = def;
            }
            break;
        }
        
        if (digit(answer))
        {
            if (accept_count)
            {
                if (answer != '0')
                {
                    yn_number = curses_get_count(answer - '0');
                    touchwin(askwin);
                    refresh();
                }
                
                answer = '#';
                break;
            }
        }
        
        if (any_choice)
        {
            break;
        }
        
        if (choices != NULL)
        {
            for (count = 0; count < strlen(choices); count++)
            {
                if (choices[count] == answer)
                {
                    break;
                }
            }
            if (choices[count] == answer)
            {
                break;
            }
        }
    }

    if (iflags.wc_popup_dialog)
    {
        /* Kludge to make prompt visible after window is dismissed
        when inputting a number */
        if (digit(answer))
        {
            linestr = curses_copy_of(askstr);
            pline("%s", linestr);
            free(linestr);
            curs_set(1);
        }

        curses_destroy_win(askwin);
    }
    else
    {
        curses_clear_unhighlight_message_window();
        curs_set(0);
    }

    return answer;
}
Beispiel #8
0
boolean curses_map_borders(int *sx, int *sy, int *ex, int *ey, int ux,
 int uy)
{
    static int width = 0;
    static int height = 0;
    static int osx = 0;
    static int osy = 0;
    static int oex = 0;
    static int oey = 0;
    static int oux = -1;
    static int ouy = -1;
    
    if ((oux == -1) || (ouy == -1))
    {
        oux = u.ux;
        ouy = u.uy;
    }
    
    if (ux == -1)
    {
        ux = oux;
    }
    else
    {
        oux = ux;
    }

    if (uy == -1)
    {
        uy = ouy;
    }
    else
    {
        ouy = uy;
    }

    curses_get_window_size(MAP_WIN, &height, &width);
    
#ifdef MAP_SCROLLBARS
    if (width < COLNO)
    {
        height--;  /* room for horizontal scrollbar */
    }

    if (height < ROWNO)
    {
        width--;  /* room for vertical scrollbar */

        if (width == COLNO)
        {
            height--;
        }
    }
#endif  /* MAP_SCROLLBARS */

    if (width >= COLNO)
    {
        *sx = 0;
        *ex = COLNO - 1;
    }
    else
    {
        *ex = (width / 2) + ux;
        *sx = *ex - (width - 1);
        
        if (*ex >= COLNO)
        {
            *sx = COLNO - width;
            *ex = COLNO - 1;
        }
        else if (*sx < 0)
        {
            *sx = 0;
            *ex = width - 1;
        }
    }
    
    if (height >= ROWNO)
    {
        *sy = 0;
        *ey = ROWNO - 1;
    }
    else
    {
        *ey = (height / 2) + uy;
        *sy = *ey - (height - 1);
        
        if (*ey >= ROWNO)
        {
            *sy = ROWNO - height;
            *ey = ROWNO - 1;
        }
        else if (*sy < 0)
        {
            *sy = 0;
            *ey = height - 1;
        }
    }

    if ((*sx != osx) || (*sy != osy) || (*ex != oex) || (*ey != oey) ||
     map_clipped)
    {
        osx = *sx;
        osy = *sy;
        oex = *ex;
        oey = *ey;
        return TRUE;
    }
    
    return FALSE;
}
Beispiel #9
0
WINDOW *curses_create_window(int width, int height, orient orientation)
{
    int mapx, mapy, maph, mapw = 0;
    int startx = 0;
    int starty = 0;
    WINDOW *win;
    boolean map_border = FALSE;
    int mapb_offset = 0;
        
    if ((orientation == UP) || (orientation == DOWN) ||
     (orientation == LEFT) || (orientation == RIGHT))
    {
        if (invent || (moves > 1))
        {
            map_border = curses_window_has_border(MAP_WIN);
            curses_get_window_xy(MAP_WIN, &mapx, &mapy);
            curses_get_window_size(MAP_WIN, &maph, &mapw);
        }
        else
        {
            map_border = TRUE;
            mapx = 0;
            mapy = 0;
            maph = term_rows;
            mapw = term_cols;
        }
    }
    
    if (map_border)
    {
        mapb_offset = 1;
    }
    
    width += 2;    /* leave room for bounding box */
    height += 2;
    
    if ((width > term_cols) || (height > term_rows))
        panic("curses_create_window: Terminal too small for dialog window");
    switch (orientation)
    {
        case CENTER:
        {
            startx = (term_cols / 2) - (width / 2);
            starty = (term_rows / 2) - (height / 2);
            break;
        }
        case UP:
        {
            if (invent || (moves > 1))
            {
                startx = (mapw / 2) - (width / 2) + mapx + mapb_offset;
            }
            else
            {
                startx = 0;
            }
            
            starty = mapy + mapb_offset;
            break;
        }
        case DOWN:
        {
            if (invent || (moves > 1))
            {
                startx = (mapw / 2) - (width / 2) + mapx + mapb_offset;
            }
            else
            {
                startx = 0;
            }
            
            starty = height - mapy - 1 - mapb_offset;
            break;
        }
        case LEFT:
        {
            if (map_border && (width < term_cols))
                startx = 1;
            else
                startx = 0;
            starty = term_rows - height;
            break;
        }
        case RIGHT:
        {
            if (invent || (moves > 1))
            {
                startx = (mapw + mapx + (mapb_offset * 2)) - width;
            }
            else
            {
                startx = term_cols - width;
            }
            
            starty = 0;
            break;
        }
        default:
        {
            panic("curses_create_window: Bad orientation");
        }
    }
    
    if (startx < 0)
    {
        startx = 0;
    }
    
    if (starty < 0)
    {
        starty = 0;
    }
  
    win = newwin(height, width, starty, startx);
    curses_toggle_color_attr(win, DIALOG_BORDER_COLOR, NONE, ON);
    box(win, 0, 0);
    curses_toggle_color_attr(win, DIALOG_BORDER_COLOR, NONE, OFF);
    return win;
}
Beispiel #10
0
void curses_message_win_puts(const char *message, boolean recursed)
{
    int height, width, linespace;
    char *tmpstr;
    WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
    boolean border = curses_window_has_border(MESSAGE_WIN);
    int message_length = strlen(message);
    int border_space = 0;
    static long suppress_turn = -1;

    if (strncmp("Count:", message, 6) == 0)
    {
        curses_count_window(message);
        return;
    }
    
    if (suppress_turn == moves)
    {
        return;
    }
    
    curses_get_window_size(MESSAGE_WIN, &height, &width);
    if (border)
    {
        border_space = 1;
        if (mx < 1)
        {
            mx = 1;
        }
        if (my < 1)
        {
            my = 1;
        }
    }
    
    linespace = ((width + border_space) - 3) - mx;
    
    if (strcmp(message, "#") == 0)  /* Extended command or Count: */
    {
        if ((strcmp(toplines, "#") != 0) && (my >= (height - 1 +
         border_space)) && (height != 1)) /* Bottom of message window */
        {
            scroll_window(MESSAGE_WIN);
            mx = width;
            my--;
            strcpy(toplines, message);
        }
        
        return;
    }

    if (!recursed)
    {
        strcpy(toplines, message);
        mesg_add_line((char *) message);
    }
    
    if (linespace < message_length)
    {
        if (my >= (height - 1 + border_space)) /* bottom of message win */
        {
            if ((turn_lines > height) || (height == 1))
            {
                /* Pause until key is hit - Esc suppresses any further
                messages that turn */
                if (curses_more() == '\033')
                {
                    suppress_turn = moves;
                    return;
                }
            }
            else
            {
                scroll_window(MESSAGE_WIN);
                turn_lines++;
            }
        }
        else
        {
            if (mx != border_space)
            {
                my++;
                mx = border_space;
            }
        }
    }

    if (height > 1)
    {
        curses_toggle_color_attr(win, NONE, A_BOLD, ON);
    }
    
    if ((mx == border_space) && ((message_length + 2) > width))
    {
        tmpstr = curses_break_str(message, (width - 2), 1);
        mvwprintw(win, my, mx, "%s", tmpstr);
        mx += strlen(tmpstr);
        if (strlen(tmpstr) < (width - 2))
        {
            mx++;
        }
        free(tmpstr);
        if (height > 1)
        {
            curses_toggle_color_attr(win, NONE, A_BOLD, OFF);
        }
        wrefresh(win);
        curses_message_win_puts(curses_str_remainder(message, (width - 2), 1),
         TRUE);
    }
    else
    {
        mvwprintw(win, my, mx, "%s", message);
        curses_toggle_color_attr(win, NONE, A_BOLD, OFF);
        mx += message_length + 1;
    }
    wrefresh(win);
}
Beispiel #11
0
void curses_count_window(const char *count_text)
{
    int startx, starty, winx, winy;
    int messageh, messagew;
    static WINDOW *countwin = NULL;

    if ((count_text == NULL) && (countwin != NULL))
    {
        delwin(countwin);
        countwin = NULL;
        counting = FALSE;
        return;
    }
    
    counting = TRUE;

    if (iflags.wc_popup_dialog) /* Display count in popup window */
    {
        startx = 1;
        starty = 1;
        
        if (countwin == NULL)
        {
            countwin = curses_create_window(25, 1, UP);
        }
    
    }
    else /* Display count at bottom of message window */
    {
        curses_get_window_xy(MESSAGE_WIN, &winx, &winy);
        curses_get_window_size(MESSAGE_WIN, &messageh, &messagew);
        
        if (curses_window_has_border(MESSAGE_WIN))
        {
            winx++;
            winy++;
        }
        
        winy += messageh - 1;
        
        if (countwin == NULL)
        {
            pline("#");
#ifndef PDCURSES
            countwin = newwin(1, 25, winy, winx);
#endif  /* !PDCURSES */
        }
#ifdef PDCURSES
        else
        {
            curses_destroy_win(countwin);
        }
        
        countwin = newwin(1, 25, winy, winx);
#endif  /* PDCURSES */
        startx = 0;
        starty = 0;
    }
    
    mvwprintw(countwin, starty, startx, "%s", count_text);
    wrefresh(countwin);
}
Beispiel #12
0
void curses_message_win_puts(const char *message, boolean recursed)
{
    int height, width, linespace, count;
    char *tmpstr;
    WINDOW *win = curses_get_nhwin(MESSAGE_WIN);
    boolean border = curses_window_has_border(MESSAGE_WIN);
    int message_length = strlen(message);
    int border_space = 0;

    if (!recursed)
    {
        strcpy(toplines, message);
        mesg_add_line((char *) message);
    }

    curses_get_window_size(MESSAGE_WIN, &height, &width);
    if (border)
    {
        border_space = 1;
        if (mx < 1)
        {
            mx = 1;
        }
        if (my < 1)
        {
            my = 1;
        }
    }

    linespace = ((width + border_space) - 3) - mx;

    if (linespace < message_length)
    {
        if (my >= (height - 1 + border_space)) /* bottom of message win */
        {
            if (turn_lines == height)
            {
                curses_more();
            }
            else
            {
                scroll_window(MESSAGE_WIN);
                turn_lines++;
            }
        }
        else
        {
            if (mx != border_space)
            {
                my++;
                mx = border_space;
            }
        }
    }

    if (height > 1)
    {
        curses_toggle_color_attr(win, NONE, ATR_BOLD, ON);
    }

    if ((mx == border_space) && ((message_length + 2) > width))
    {
        tmpstr = curses_break_str(message, (width - 2), 1);
        mvwprintw(win, my, mx, tmpstr);
        mx += strlen(tmpstr);
        free(tmpstr);
        if (height > 1)
        {
            curses_toggle_color_attr(win, NONE, ATR_BOLD, OFF);
        }
        wrefresh(win);
        curses_message_win_puts(curses_str_remainder(message, (width - 2), 1),
                                TRUE);
    }
    else
    {
        mvwprintw(win, my, mx, message);
        curses_toggle_color_attr(win, NONE, ATR_BOLD, OFF);
    }
    wrefresh(win);
    mx += message_length + 1;
}