src/window.c
author ali@juiblex.co.uk
Mon Jan 29 20:22:01 2007 +0000 (2007-01-29)
changeset 0 acc07f1f4b1e
permissions -rw-r--r--
Initial check-in. Mostly sort of works. Ish.
     1 /*
     2  * $Id: window.c,v 1.5 2004/12/30 09:07:47 ali Exp $
     3  * Copyright (C) 2007 J. Ali Harlow
     4  * Min Hack may be freely redistributed.  See license for details. 
     5  */
     6 
     7 #include <stdlib.h>
     8 #include <stdio.h>
     9 #include <string.h>
    10 #include "minhack.h"
    11 
    12 int message_win=-1;
    13 int map_win=-1;
    14 
    15 int minhack_create_nhwindow(int type)
    16 {
    17     int window;
    18     for(window=0;window<no_windows;window++)
    19 	if (!windows[window].in_use)
    20 	    break;
    21     if (window==no_windows)
    22 	windows=realloc(windows,++no_windows*sizeof(*windows));
    23     windows[window].in_use=nhproxy_true;
    24     windows[window].type=type;
    25     windows[window].menu=NULL;
    26     switch(type)
    27     {
    28 	case NHPROXY_EXT_NHW_MESSAGE:
    29 	    windows[window].win=newwin(1,0,0,0);
    30 	    if (message_win<0)
    31 		message_win=window;
    32 	    break;
    33 	case NHPROXY_EXT_NHW_STATUS:
    34 	    windows[window].win=newwin(2,0,LINES-2,0);
    35 	    break;
    36 	case NHPROXY_EXT_NHW_MAP:
    37 	    if (map_win<0)
    38 		map_win=window;
    39 	    /* Fall through */
    40 	case NHPROXY_EXT_NHW_MENU:
    41 	case NHPROXY_EXT_NHW_TEXT:
    42 	    windows[window].win=NULL;
    43 	    break;
    44     }
    45     return window;
    46 }
    47 
    48 void minhack_clear_nhwindow(int window, int rows, int cols, int layers)
    49 {
    50     if (windows[window].type==NHPROXY_EXT_NHW_MAP)
    51     {
    52 	if (windows[window].win)
    53 	    delwin(windows[window].win);
    54 	windows[window].win=newwin(rows,cols,1,0);
    55     }
    56     else
    57 	werase(windows[window].win);
    58 }
    59 
    60 void minhack_display_nhwindow(int window, nhproxy_bool_t blocking)
    61 {
    62     wrefresh(windows[window].win);
    63 }
    64 
    65 void minhack_destroy_nhwindow(int window)
    66 {
    67     minhack_free_menu(window);
    68     if (windows[window].win)
    69     {
    70 	delwin(windows[window].win);
    71 	windows[window].win=NULL;
    72     }
    73     if (window==message_win)
    74 	message_win=-1;
    75     else if (window==map_win)
    76 	map_win=-1;
    77     windows[window].in_use=nhproxy_false;
    78 }