\File{xgraphics.c},{12:30},{May 15 1997}
\L{\LB{\C{}\/* X graphics routines to display the slice *\/\CE{}}}
\L{\LB{\C{}\/* This code currently does not work, but is included because}}
\L{\LB{}\Tab{8}{the errors should be relatively minor and have not yet}}
\L{\LB{}\Tab{8}{been found *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#include} \S{}\"xgraphics.h\"\SE{}}}
\L{\LB{}}
\L{\LB{\K{static} Display  *D;}}
\L{\LB{\K{static} Visual   *V;}}
\L{\LB{\K{static} Colormap C;}}
\L{\LB{\K{int}      S,Loop,Point;}}
\L{\LB{\K{static} Window   W;}}
\L{\LB{\K{static} GC       Gc,GcRev;}}
\L{\LB{\K{static} XColor   Colors[NCOLORS];}}
\L{\LB{\K{static} XSetWindowAttributes Attr;}}
\L{\LB{\K{static} XVisualInfo Info;}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\K{float}    x,y,r,z;}}
\L{\LB{\K{int}      i,j;}}
\L{\LB{\K{double} alpha;}}
\L{\LB{\K{char} readme[100];}}
\L{\LB{\K{char} * sp;}}
\L{\LB{\K{char} *sp2;}}
\L{\LB{\K{int} val;}}
\L{\LB{\K{int} SIZE, WIDTH, HEIGHT, NPTS;}}
\L{\LB{}}
\L{\LB{\K{void}}}
\L{\LB{\Proc{initialize\_graphics}initialize\_graphics() \{}}
\L{\LB{}\Tab{8}{}}
\L{\LB{   \C{}\/* Set up the basics *\/\CE{}}}
\L{\LB{}}
\L{\LB{  SIZE = WIDTH = HEIGHT = NPTS;}}
\L{\LB{  D = XOpenDisplay(\S{}\"\"\SE{});}}
\L{\LB{  S = DefaultScreen(D);}}
\L{\LB{  \K{if} (XMatchVisualInfo(D,S,DEPTH,PseudoColor,\&Info) == 0) \{}}
\L{\LB{    printf(\S{}\"Display can not handle \%d bit pseudo color\!n\"\SE{},DEPTH);}}
\L{\LB{    \K{return};}}
\L{\LB{  \}}}
\L{\LB{  V = Info.visual;}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{  \C{}\/* Allocate some colors *\/\CE{}}}
\L{\LB{  }}
\L{\LB{  \K{for} (i = 0; i \< NCOLORS; ++i) \{}}
\L{\LB{    Colors[i].pixel = i;}}
\L{\LB{    Colors[i].red = sqrt(i)*16*255;}}
\L{\LB{    Colors[i].green = sqrt(i)*16*255;}}
\L{\LB{    Colors[i].blue = sqrt(i)*16*255;}}
\L{\LB{    Colors[i].flags = DoRed \| DoGreen \| DoBlue; }}
\L{\LB{  \}}}
\L{\LB{  }}
\L{\LB{  C = XCreateColormap(D,RootWindow(D,S),V,AllocAll);}}
\L{\LB{  \K{if}(C == NULL)}}
\L{\LB{    fprintf(stderr, \S{}\"Damnit\!n\"\SE{});}}
\L{\LB{  XStoreColors(D,C,Colors,NCOLORS); }}
\L{\LB{  Attr.colormap = C;}}
\L{\LB{  Attr.background\_pixel = WhitePixel(D,S);}}
\L{\LB{  Attr.border\_pixel = BlackPixel(D,S);}}
\L{\LB{  W = XCreateWindow(D,DefaultRootWindow (D),0,0,WIDTH,HEIGHT,100,}}
\L{\LB{}\Tab{16}{    DEPTH,InputOutput,V,CWColormap\|CWBackPixel\|CWBorderPixel,\&Attr);}}
\L{\LB{  XStoreName(D, W, \S{}\"ximage output\"\SE{});}}
\L{\LB{  XMapRaised(D, W);}}
\L{\LB{  Gc = XCreateGC (D, W, 0L, (XGCValues *) 0);}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{void}}}
\L{\LB{\Proc{update\_image}update\_image (\K{char} **data) \{}}
\L{\LB{}\Tab{8}{\K{static} XImage   *I;}}
\L{\LB{}\Tab{8}{\K{static} \K{int} created = 0;}}
\L{\LB{}}
\L{\LB{}\Tab{8}{\K{if}(!created)\{}}
\L{\LB{}\Tab{16}{I = XCreateImage(D, V, DEPTH, ZPixmap, 0, data, WIDTH, HEIGHT, DEPTH, 0);}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}}
\L{\LB{}\Tab{8}{XPutImage(D,W,Gc,I,0,0,0,0,NPTS,NPTS);}}
\L{\LB{\}}}
\L{\LB{}}
\L{\LB{\K{int} get\_mouse\_x() \{}}
\L{\LB{  Window *rr, *cr;}}
\L{\LB{  \K{int} *rx, *ry;}}
\L{\LB{  \K{int} *wx, *wy;}}
\L{\LB{  \K{unsigned} \K{int} *mask;}}
\L{\LB{  XQueryPointer(D,W,rr,cr,rx,ry,wx,wy,mask);}}
\L{\LB{  \K{return} *wx;}}
\L{\LB{\}}}
