示例#1
0
winid curses_get_wid(int type)
{
	winid ret;
    static winid menu_wid = 20; /* Always even */
    static winid text_wid = 21; /* Always odd */

	switch (type)
	{
		case NHW_MESSAGE:
		{
			return MESSAGE_WIN;
			break;
		}
		case NHW_MAP:
		{
			return MAP_WIN;
			break;
		}
		case NHW_STATUS:
		{
			return STATUS_WIN;
			break;
		}
		case NHW_MENU:
		{
			ret = menu_wid;
			break;
		}
		case NHW_TEXT:
		{
			ret = text_wid;
			break;
		}
		default:
		{
			panic("curses_get_wid: unsupported window type");
			ret = -1;   /* Not reached */
		}
	}

	while (curses_window_exists(ret))
	{
	    ret += 2;
	    if ((ret + 2) > 10000)    /* Avoid "wid2k" problem */
	    {
	        ret -= 9900;
	    }
	}

	if (type == NHW_MENU)
	{
	    menu_wid += 2;
	}
	else
	{
	    text_wid += 2;
	}

	return ret;
}
示例#2
0
void curses_create_main_windows()
{
    int message_x = 0;
    int message_y = 0;
    int status_x = 0;
    int status_y = 0;
    int map_x = 0;
    int map_y = 0;
    int message_height = 0;
    int message_width = 0;
    int status_height = 0;
    int status_width = 0;
    int map_height = 0;
    int map_width = 0;
    int min_message_height = 1;
    int message_orientation = 0;
    int status_orientation = 0;
    int border_space = 0;
    int hspace = term_cols - 80;
    boolean borders = FALSE;

    switch (iflags.wc2_windowborders)
    {
        case 1: /* On */
        {
            borders = TRUE;
            break;
        }
        case 2: /* Off */
        {
            borders = FALSE;
            break;
        }
        case 3: /* Auto */
        {
            if ((term_cols > 81) && (term_rows > 25))
            {
                borders = TRUE;
            }
            break;
        }
        default:
        {
            borders = FALSE;
        }
    }

    
    if (borders)
    {
        border_space = 2;
        hspace -= border_space;
    }
    
    if ((term_cols - border_space) < COLNO)
    {
        min_message_height++;
    }
    
    /* Determine status window orientation */    
    if (!iflags.wc_align_status || (iflags.wc_align_status == ALIGN_TOP)
     || (iflags.wc_align_status == ALIGN_BOTTOM))
    {
        if (!iflags.wc_align_status)
        {
            iflags.wc_align_status = ALIGN_BOTTOM;
        }
        status_orientation = iflags.wc_align_status;
    }
    else    /* left or right alignment */
    {
        /* Max space for player name and title horizontally */
        if ((hspace >= 26) && (term_rows >= 24))
        {
            status_orientation = iflags.wc_align_status;
            hspace -= (26 + border_space);
        }
        else
        {
            status_orientation = ALIGN_BOTTOM;
        }
    }
    
    /* Determine message window orientation */    
    if (!iflags.wc_align_message || (iflags.wc_align_message == ALIGN_TOP)
     || (iflags.wc_align_message == ALIGN_BOTTOM))
    {
        if (!iflags.wc_align_message)
        {
            iflags.wc_align_message = ALIGN_TOP;
        }
        message_orientation = iflags.wc_align_message;
    }
    else    /* left or right alignment */
    {
        if ((hspace - border_space) >= 25)   /* Arbitrary */
        {
            message_orientation = iflags.wc_align_message;
        }
        else
        {
            message_orientation = ALIGN_TOP;
        }
    }
    
    /* Determine window placement and size - 16 possible combos
       If anyone wants to try to generalize this, be my guest! */
    if ((status_orientation == ALIGN_TOP) &&
     (message_orientation == ALIGN_TOP))
    {
        status_x = 0;
        status_y = 0;
        status_width = (term_cols - border_space);
        status_height = 2;
        message_x = 0;
        message_y = status_y + (status_height + border_space);
        message_width = (term_cols - border_space);
        message_height = term_rows - (status_height + ROWNO + (border_space * 3));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_x = 0;
        map_y = message_y + (message_height + border_space);
        map_width = (term_cols - border_space);
        map_height = term_rows - (status_height + message_height + (border_space * 3));
    }
    else if ((status_orientation == ALIGN_TOP) &&
     (message_orientation == ALIGN_RIGHT))
    {
        status_x = 0;
        status_y = 0;
        status_height = 2;
        message_height = (term_rows - border_space);
        message_width = term_cols - (COLNO + (border_space * 2));
        status_width = term_cols - (message_width + (border_space * 2));
        message_x = status_x + (status_width + border_space);
        message_y = 0;
        map_x = 0;
        map_y = status_y + (status_height + border_space);
        map_width = status_width;
        map_height = term_rows - (status_height + (border_space * 2));
    }
    else if ((status_orientation == ALIGN_TOP) &&
     (message_orientation == ALIGN_BOTTOM))
    {
        status_x = 0;
        status_y = 0;
        status_width = (term_cols - border_space);
        status_height = 2;
        map_x = 0;
        map_y = status_y + (status_height + border_space);
        map_width = (term_cols - border_space);
        message_height = term_rows - (status_height + ROWNO + (border_space * 3));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_height = term_rows - (status_height + message_height + (border_space * 3));
        message_x = 0;
        message_y = map_y + (map_height + border_space);
        message_width = (term_cols - border_space);
    }
    else if ((status_orientation == ALIGN_TOP) &&
     (message_orientation == ALIGN_LEFT))
    {
        message_x = 0;
        message_y = 0;
        message_height = (term_rows - border_space);
        message_width = term_cols - (COLNO + (border_space * 2));
        status_x = message_x + (message_width + border_space);
        status_y = 0;
        status_height = 2;
        status_width = term_cols - (message_width + (border_space * 2));
        map_x = status_x;
        map_y = status_y + (status_height + border_space);
        map_height = term_rows - (status_height + (border_space * 2));
        map_width = status_width;
    }
    if ((status_orientation == ALIGN_RIGHT) &&
     (message_orientation == ALIGN_TOP))
    {
        status_width = 26;
        status_height = (term_rows - border_space);
        status_x = term_cols - (status_width + border_space);
        status_y = 0;
        message_x = 0;
        message_y = 0;
        message_width = term_cols - (status_width + (border_space * 2));
        message_height = term_rows - (ROWNO + (border_space * 2));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_x = 0;
        map_y = message_y + (message_height + border_space);
        map_width = term_cols - (status_width + (border_space * 2));
        map_height = term_rows - (message_height + (border_space * 2));
    }
    else if ((status_orientation == ALIGN_RIGHT) &&
     (message_orientation == ALIGN_RIGHT))
    {
        map_x = 0;
        map_y = 0;
        map_height = (term_rows - border_space);
        status_width = 26;
        message_width = term_cols - (COLNO + status_width + (border_space * 3));
        map_width = term_cols - (status_width + message_width + (border_space * 3));
        message_x = map_x + (map_width + border_space);
        message_y = 0;
        message_height = (term_rows - border_space);
        status_x = message_x + (message_width + border_space);
        status_y = 0;
        status_height = (term_rows - border_space);
    }
    else if ((status_orientation == ALIGN_RIGHT) &&
     (message_orientation == ALIGN_BOTTOM))
    {
        map_x = 0;
        map_y = 0;
        status_width = 26;
        map_width = term_cols - (status_width + (border_space * 2));
        message_height = term_rows - (ROWNO + (border_space * 2));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_height = term_rows - (message_height + (border_space * 2));
        message_x = 0;
        message_y = map_y + (map_height + border_space);
        message_width = map_width;
        status_x = map_x + (map_width + border_space);
        status_y = 0;
        status_height = (term_rows - border_space);
    }
    else if ((status_orientation == ALIGN_RIGHT) &&
     (message_orientation == ALIGN_LEFT))
    {
        status_x = 0;
        status_y = 0;
        status_height = (term_rows - border_space);
        status_width = 26;
        message_width = term_cols - (status_width + COLNO + (border_space * 3));
        map_x = status_x + (status_width + border_space);
        map_y = 0;
        map_height = (term_rows - border_space);
        map_width = term_cols - (status_width + message_width + (border_space * 3));
        message_x = map_x + (map_width + border_space);
        message_y = 0;
        message_height = (term_rows - border_space);
    }
    if ((status_orientation == ALIGN_BOTTOM) &&
     (message_orientation == ALIGN_TOP))
    {
        message_x = 0;
        message_y = 0;
        message_width = (term_cols - border_space);
        status_height = 2;
        message_height = term_rows - (status_height + ROWNO + (border_space * 3));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_x = 0;
        map_y = message_y + (message_height + border_space);
        map_width = (term_cols - border_space);
        map_height = term_rows - (status_height + message_height + (border_space * 3));
        status_x = 0;
        status_y = map_y + (map_height + border_space);
        status_width = (term_cols - border_space);
    }
    else if ((status_orientation == ALIGN_BOTTOM) &&
     (message_orientation == ALIGN_RIGHT))
    {
        map_x = 0;
        map_y = 0;
        status_height = 2;
        map_height = term_rows - (status_height + (border_space * 2));
        message_width = term_cols - (COLNO + (border_space * 2));
        map_width = term_cols - (message_width + (border_space * 2));
        status_x = 0;
        status_y = map_y + (map_height + border_space);
        status_width = map_width + message_width + border_space;
        message_x = map_x + (map_width + border_space);
        message_y = 0;
        message_height = map_height;
    }
    else if ((status_orientation == ALIGN_BOTTOM) &&
     (message_orientation == ALIGN_BOTTOM))
    {
        map_x = 0;
        map_y = 0;
        message_x = 0;
        status_x = 0;
        message_width = (term_cols - border_space);
        status_height = 2;
        message_height = term_rows - (status_height + ROWNO + (border_space * 3));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_width = (term_cols - border_space);
        map_height = term_rows - (status_height + message_height + (border_space * 3));
        message_y = map_y + (map_height + border_space);
        status_y = message_y + (message_height + border_space);
        status_width = (term_cols - border_space);
    }
    else if ((status_orientation == ALIGN_BOTTOM) &&
     (message_orientation == ALIGN_LEFT))
    {
        message_x = 0;
        message_y = 0;
        message_height = (term_rows - border_space);
        message_width = term_cols - (COLNO + (border_space * 2));
        status_height = 2;
        map_x = message_x + (message_width + border_space);
        map_y = 0;
        map_height = term_rows - (status_height + (border_space * 2));
        map_width = term_cols - (message_width + (border_space * 2));
        status_x = map_x;
        status_y = map_y + (map_height + border_space);
        status_width = term_cols - (message_width + (border_space * 2));
    }
    if ((status_orientation == ALIGN_LEFT) &&
     (message_orientation == ALIGN_TOP))
    {
        status_x = 0;
        status_y = 0;
        status_height = (term_rows - border_space);
        status_width = 26;
        message_x = status_x + (status_width + border_space);
        message_y = 0;
        message_height = term_rows - (ROWNO + (border_space * 2));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        message_width = term_cols - (status_width + (border_space * 2));
        map_x = message_x;
        map_y = message_y + (message_height + border_space);
        map_height = term_rows - (message_height + (border_space * 2));
        map_width = term_cols - (status_width + (border_space * 2));
    }
    else if ((status_orientation == ALIGN_LEFT) &&
     (message_orientation == ALIGN_RIGHT))
    {
        message_x = 0;
        message_y = 0;
        message_height = (term_rows - border_space);
        status_width = 26;
        message_width = term_cols - (status_width + COLNO + (border_space * 3));
        map_x = message_x + (message_width + border_space);
        map_y = 0;
        map_height = (term_rows - border_space);
        map_width = term_cols - (status_width + message_width + (border_space * 3));
        status_x = map_x + (map_width + border_space);
        status_y = 0;
        status_height = (term_rows - border_space);
    }
    else if ((status_orientation == ALIGN_LEFT) &&
     (message_orientation == ALIGN_BOTTOM))
    {
        status_x = 0;
        status_y = 0;
        status_height = (term_rows - border_space);
        status_width = 26;
        map_x = status_x + (status_width + border_space);
        map_y = 0;
        message_height = term_rows - (ROWNO + (border_space * 2));
        if (message_height < min_message_height)
        {
            message_height = min_message_height;
        }
        map_height = term_rows - (message_height + (border_space * 2));
        map_width = term_cols - (status_width + (border_space * 2));
        message_x = status_x + (status_width + border_space);
        message_y = map_y + (map_height + border_space);
        message_width = map_width;
    }
    else if ((status_orientation == ALIGN_LEFT) &&
     (message_orientation == ALIGN_LEFT))
    {
        status_x = 0;
        status_y = 0;
        status_height = (term_rows - border_space);
        status_width = 26;
        message_x = status_x + (status_width + border_space);
        message_y = 0;
        message_height = status_height;
        message_width = term_cols - (COLNO + status_width + (border_space * 3));
        map_x = message_x + (message_width + border_space);
        map_y = 0;
        map_height = message_height;
        map_width = term_cols - (status_width + message_width + (border_space * 3));
    }
    
    if (map_width > COLNO)
    {
        map_width = COLNO;
    }
    
    if (map_height > ROWNO)
    {
        map_height = ROWNO;
    }
    
    if (curses_window_exists(STATUS_WIN))
    {
        curses_del_nhwin(STATUS_WIN);
        curses_del_nhwin(MESSAGE_WIN);
        curses_del_nhwin(MAP_WIN);
        clear();
    }

    curses_add_nhwin(STATUS_WIN, status_height, status_width, status_y,
     status_x, status_orientation, borders);

    curses_add_nhwin(MESSAGE_WIN, message_height, message_width, message_y,
     message_x, message_orientation, borders);

    curses_add_nhwin(MAP_WIN, map_height, map_width, map_y, map_x, 0,
     borders);

    refresh();
    
    curses_refresh_nethack_windows();

    if (iflags.window_inited)
    {
        curses_update_stats(TRUE);
    }
    else
    {
        iflags.window_inited = TRUE;
    }
}