#ifndef _XWINDOW
#define _XWINDOW
#include <stream.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/extensions/shape.h>
#include <Imlib.h>

extern  Display*         TheDisplay;
typedef unsigned long    ulong;
typedef unsigned int     uint;
typedef unsigned char    uchar;

class xwindow
{
protected:
  Window                TheWindow;
  GC                    TheGC;
  XSizeHints            TheHints;
  int                   TheScreen;
  Colormap              CMap;
  ulong                 ForegroundColor;
  ulong                 BackgroundColor;
  ImlibData*            ImData;
  XSetWindowAttributes  XWinAttr;
  ImlibImage*           ImImage;
  Pixmap                PMap,PMask;
public:
                        xwindow      (int Width,int Height,char* FG,char* BG);
	  void          setBGImage   (char* ImageFileName);
	  void          setBGTile    (char* ImageFileName);
  inline  ulong         colorID      (char* ColorName)
  {
    XColor Exact; XColor NewColor;
    if(XAllocNamedColor(TheDisplay,CMap,ColorName,&Exact,&NewColor)==0)
    {
      cerr<<form("Can't allocate the color specified by \"%s\".\n",ColorName);
      return BlackPixel(TheDisplay,TheScreen);
    }
    else return NewColor.pixel;
  }
  inline  void          setForeground(ulong PixelVal)
  { XSetForeground(TheDisplay,TheGC,PixelVal); }
  inline  void          setBackground(ulong PixelVal)
  { XSetBackground(TheDisplay,TheGC,PixelVal); }
  inline  void          setForeground(char* ColorName)
  { setForeground(colorID(ColorName));}
  inline  void          setBackground(char* ColorName)
  { setBackground(colorID(ColorName));}
  inline  void          clearScreen(void)
  { XClearWindow(TheDisplay,TheWindow);}
  inline  void          close(void)
  {
    XFreeGC(TheDisplay,TheGC);XDestroyWindow(TheDisplay,TheWindow);
  }
  inline  void          drawLine (int X1,int Y1,int X2,int Y2)
  {
    setForeground(ForegroundColor);
    XSetLineAttributes(TheDisplay,TheGC,1,LineSolid,CapButt,JoinMiter);
    XDrawLine(TheDisplay,TheWindow,TheGC,X1,Y1,X2,Y2);
  }
  inline                mapRaised(void) {  XMapRaised(TheDisplay,TheWindow);}
};

#endif









