

/* x-stuff.h */

#ifndef __INC_XSTUFF__
#define __INC_XSTUFF__

#include "misc.h"
#include "image.h"
#include "keyword.h"

typedef struct {ulong window;} xWindow;
typedef struct {unsigned long color; boolean ok;} xColor;
typedef struct {void *gc;} xPen;
typedef enum { xNoEvent, xKeyPress, xButtonDown, xButtonUp, xMotion,
               xLeaveWindow, xEnterWindow, xVisibilityChange } xEventType;
typedef struct {
  xEventType type;
  unsigned int value;
  unsigned int xpos, ypos;
} xEvent;

extern xColor xWhite;                        /* colors and pixels */
extern xColor xBlack;                        /* setup by xOpenDisplay() */
extern xColor xRed;
extern xColor xOrange;
extern xColor xYellow;
extern xColor xLime;
extern xColor xSlate;
extern xColor xBlue;
extern xColor xGreen;
extern xColor xPurple;

extern uchar  xWhitePixel;
extern uchar  xBlackPixel;
extern uchar  xRedPixel;
extern uchar  xOrangePixel;
extern uchar  xYellowPixel;
extern uchar  xLimePixel;
extern uchar  xSlatePixel;
extern uchar  xBluePixel;
extern uchar  xGreenPixel;
extern uchar  xPurplePixel;

extern xColor   xGrayMap[256];
extern uchar    xGrayMapPixels[256];


extern boolean  xAllocateGreyColorMap(void);
extern xColor   xAllocateColor(RGB rgb);
extern xColor   xAllocateNamedColor(char *name);
/* xPen xMakePen() -- below */
extern boolean  xOpenDisplay();
extern void     xCloseDisplay();
extern void     xFlushDisplay();
/* extern xWindow  xNewWindow(char *title, int w, int h, int x, int y, &key xColor bg); */
extern void     xClearWindow(xWindow win);
extern void     xKillWindow(xWindow win);
extern xWindow  xShowImage(GrayImage im, char *title, int x, int y);
extern void     xShowImageIn(GrayImage im, xWindow win);
extern void     xShowImageInNoRemap(GrayImage im, xWindow win);
extern void     xDrawPoint(xWindow win, xPen pen, int x, int y);
extern void     xDrawLine(xWindow win, xPen pen, int x1, int y1, int x2, int y2);
extern void     xDrawVector(xWindow win, xPen pen, int x, int y, int dx, int dy);
extern void     xDrawRectangle(xWindow win, xPen pen, int x, int y, int w, int h);
extern void     xDrawString(xWindow win, xPen pen, int x, int y, char *s);
extern int      xGetButton(xWindow win);
extern xEvent   xGetEvent(xWindow win);
extern boolean  xGetPointer(xWindow win, int *x, int *y);
extern void     xSetName(xWindow win, char *title);


/* for Sajit */
extern uchar   *xGetRainbowMapUchar(); 
extern boolean  xAllocateRainbowMap(void);
extern xWindow  xShowColorImage(GrayImage im, char *title, int x, int y);
extern void     xShowColorImageIn(GrayImage im, xWindow win);

typedef enum { xFuncClear = 0x0,
               xFuncSet   = 0xf,
               xFuncXor   = 0x6,
               xFuncAnd   = 0x1,
               xFuncCopy  = 0x3,
               xFuncOr    = 0x7 } xPenFuncs;
typedef enum { xStyleSolid = 0} xPenStyles;
typedef enum { xFillSolid  = 0} xPenFills;

kwDefType(xPenKW, xColor fg;
                  xColor bg;
                  xPenFuncs func;
                  int width;
                  xPenStyles style;
                  xPenFills fill;);

extern xPen xMakePen_(kwArgDecl(xPenKW));

#define  xMakePen(kwargs...)     (kwCall(xMakePen_, 0, xPenKW, kwargs))


kwDefType(xNewWinKW, xColor bg;);

extern xWindow  xNewWindow_(char *title, int w, int h, int x, int y);

#define  xNewWindow(t, w, h, x, y, kwargs...) \
               (kwCall(xNewWindow_, 5, xNewWinKW, (t), (w), (h), (x), (y), kwargs))
                            

#endif
