/***********************************************************************
 * 
 *  G F O ! 
 *  by Chee Chew
 *      and 
 *     Ken Duda 
 *
 *  (c) 1990
 *
 *  This software is free for distribution.  This notice, however, may 
 *  not be altered.
 *  
 *  Enjoy! (and punt... )
 *
 ***********************************************************************/

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/keysym.h>

#ifdef _IBMR2
#include <sys/select.h>
#endif

#define NUM_TILE_PIXMAPS 16

#define project_x(w,x,y,z) ((w)->center_x + \
			    (((x)-(w)->max_x)*(w)->center_x*(w)->z_offset + (w)->x_adjust)/ \
			    (((z)+ (w)->z_offset) * (w)->max_x + (w)->z_adjust))
#define project_y(w,x,y,z) ((w)->center_y + \
			    (((y)-(w)->max_y)*(w)->center_y*(w)->z_offset + (w)->y_adjust)/ \
			    (((z)+(w)->z_offset) * (w)->max_y + (w)->z_adjust))
#define copy_gc bdraw_gc
#define MAX_FACES 3

typedef struct t_XC { 
  Display *dsp;
  int scr;
  Window mwin, swin;
  int pmwidth, pmheight;
  int width, height;		/* Of main window */
  GC bdraw_gc, berase_gc;	/* Draw and erase blocks */
  GC sdraw_gc, serase_gc;	/* Draw and erase in the score window */
  Pixmap tile_pixmaps[NUM_TILE_PIXMAPS];
  Pixmap wellpixmap;		/* All drawing on the well goes here first */
  GC wellgc,  wellclear;        /* For the well pixmap */
  GC tilegc[NUM_TILE_PIXMAPS];
  GC wfill_gc;
  XColor bgcolor[NUM_TILE_PIXMAPS];
  XFontStruct *scorefont, *roundfont;
  int planes;
  int (*CopyFunction)(Display *d, Drawable src, Drawable dest, 
		       GC gc, int x, int y,
		       unsigned int w,unsigned int h, 
		       int dest_x, int dest_y);
  int DontSaveUnder;

  /* End of game window stuff */ 
  char *message;
  Window endwin;
  GC endgc;

  /* Level Stack stuff */
  Window level_win[NUM_TILE_PIXMAPS];

  /* High score stuff */
  Window hswin;
  int hswidth;
  int hsheight;
  GC hsdraw_gc /* , hserase_gc */ ;
  Pixmap hstitle, hsrank[3], hsno;
  int hstitlewidth, hsrankwidth[3], hsnowidth;
  int hstitleheight, hsrankheight[3], hsnoheight;
  XFontStruct *hsfont;

  /* Between board face */
  Pixmap face[MAX_FACES];
  XFontStruct *facefont;
  unsigned int face_height, face_width;
} XC; 

struct t_Game;

int XCopyColorArea(Display *d, Drawable src, Drawable dest, GC gc, 
		    int x, int y,
		    unsigned int w,unsigned int h, int dest_x, int dest_y);


void x_event_loop(void (*button_fn)(int x, int y, int button, int pressed),
	     void (*inout_fn)(int entered, struct t_Game *g),
	     void (*key_fn)(char key, struct t_Game *g),
	     void (*config_fn)(struct t_Game *g, XC *xc, int width, int height),
	     void (*refresh_mwin)(struct t_Game *g, int x, int y, int width, int height),
	     void (*refresh_swin)(struct t_Game *g,int x, int y, int width, int height),
	     XC *xc,
	     int ousecs,
	     struct t_Game *g);



