/*	Text mode popup window package (popup.h)	*/

/*	Center window code	*/
#define	CTRWIN	999

/*	video ram text-cell structure */
typedef struct texel_struct {
	unsigned char ch;
	unsigned char attr;
} texel;

/*	A structure to hold the box type, and a set of window colors */
typedef struct wincolors_struct {
	char border_type;
	unsigned char border_color, text_color, title_color, hilite_color;
	} wincolors;

/*	popup windows save the image underneath, tiled windows don't */
enum windowtype {popup, tile};

/* A structure to hold information for each window */
typedef struct winstruct {
	char *name;		/* window title */
	void *image;	/* ptr to image save area */
	struct winstruct *under, *over; /* ptrs to window below and above
																	on popup stack */
	wincolors wc;						/* colors for the window */
	char xul,yul,xlr,ylr,wd,ht;	/* window coord's and sizes */
	char xsave,ysave;					/* saved cursor position */
	enum windowtype wtype;
} windesc;

extern windesc		*base_win;		/* can be used to access whole screen */
extern windesc		*curr_win;		/* current window in use */
extern wincolors	defcolors;		/* predefined color sets */
extern wincolors	invcolors;
extern wincolors	monocolors;
extern wincolors	errcolors;
extern wincolors	msgcolors;
extern wincolors	graycolors;

/* macros for easy use in removing and selecting window */
#define rmv_win(w)	view_win(w,0)
#define slct_win(w)	view_win(w,1)

/* Now the prototypes for the popup functions */
extern void init_win(void);
extern windesc *draw_win(int x, int y, int wd, int ht, char *title,
									enum windowtype wt, wincolors *wc);
extern void view_win(windesc *this, int move_to_top);
extern void clr_win(void);
extern void draw_box(int xul,int yul,int xlr,int ylr,int btype,int attr);
extern void centerstr(int xul,int yul,int xlr,int ylr,char *s, unsigned char a);
extern void mprintf(char *fmt,...);
extern void prtfstr(int x,int y,char *fmt,unsigned char attr, int wd,...);
extern void swap_image(windesc *w);

/* Includes for sayerr.c */
/* the first set of macros include line number and name of source file */
#define SWRNF	0,1,__LINE__,__FILE__
#define SERRF	0,2,__LINE__,__FILE__
#define SMSGF	0,0,__LINE__,__FILE__
#define FWRNF	1,1,__LINE__,__FILE__
#define FERRF	1,2,__LINE__,__FILE__
#define FMSGF	1,0,__LINE__,__FILE__

/* the second set do not */
#define SWRN	0,1,0,""
#define SERR	0,2,0,""
#define SMSG	0,0,0,""
#define FWRN	1,1,0,""
#define FERR	1,2,0,""
#define FMSG	1,0,0,""

extern int errx;		/* default error coordinates */
extern int erry;
extern windesc *errw;	/* error window pointer */
extern int msgx;			/* same for messages */
extern int msgy;
extern windesc *msgw;
extern void numnewlines(char *s,int *n,int *w);
extern void popmsg(int x, int y, char *msg, char *title,
							char soundout, wincolors *wc);
extern void reperr(int level, char *msg);
extern void repmsg(char *msg);
extern void sayerr(int ferr,int errflag,int lno,char *pname,char *fmt,...);
extern void beep(void);
extern unsigned int getkey(void);
