Exemple #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);
}
Exemple #2
0
void curses_move_cursor(winid wid, int x, int y)
{
    int sx, sy, ex, ey;
    int xadj = 0;
    int yadj = 0;

#ifndef PDCURSES
    WINDOW *win = curses_get_nhwin(MAP_WIN);
#endif

    if (wid != MAP_WIN)
    {
        return;
    }

#ifdef PDCURSES
    /* PDCurses seems to not handle wmove correctly, so we use move and
    physical screen coordinates instead */
    curses_get_window_xy(wid, &xadj, &yadj);
#endif
    curs_x = x + xadj;
    curs_y = y + yadj;
    curses_map_borders(&sx, &sy, &ex, &ey, x, y);

    if (curses_window_has_border(wid))
    {
        curs_x++;
        curs_y++;
    }

    if ((x >= sx) && (x <= ex) &&
     (y >= sy) && (y <= ey))
    {
        curs_x -= sx;
        curs_y -= sy;
#ifdef PDCURSES
        move(curs_y, curs_x);
#else
        wmove(win, curs_y, curs_x);
#endif
    }
}
Exemple #3
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;
}
Exemple #4
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;
}
Exemple #5
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);
}