/*#include "matrix.h"*/ #include #include #include #include #define XY_SIZE 512 /****** X11 Graphics ********/ Display *dis ; Window win,win1 ; XSetWindowAttributes att ; GC gc,gc1 ; XGCValues gv ; XEvent eve ; Cursor curs ; Pixmap pix ; XColor co2[256] ; Colormap comap[256] ; unsigned int ppix[256] ; Colormap cmap ; void G_start() { dis = XOpenDisplay(NULL) ; win = XCreateSimpleWindow(dis, RootWindow(dis,0),50, 0, XY_SIZE, XY_SIZE, 2, 1, 0) ; att.override_redirect = 1 ; /* XChangeWindowAttributes(dis, win, CWOverrideRedirect, &att) ; */ att.backing_store = Always ; XChangeWindowAttributes(dis, win, CWBackingStore, &att) ; XSelectInput(dis, win, ButtonPressMask) ; XMapWindow(dis, win) ; /* pix = XCreatePixmap(dis, win, XY_SIZE, XY_SIZE, DefaultDepth(dis,0)) ; gc = XCreateGC(dis, pix, 0, 0) ; */ gc = XCreateGC(dis, win, 0, 0) ; curs = XCreateFontCursor(dis, XC_left_ptr) ; XDefineCursor(dis, win, curs) ; G_color_set() ; } void G_end() { XFreeGC(dis,gc) ; XDestroyWindow(dis, win) ; XCloseDisplay(dis) ; } void G_draw() { XCopyArea(dis, pix, win, gc, 0, 0, XY_SIZE, XY_SIZE, 0, 0) ; XFlush(dis) ; } void G_line( x1,y1,x2,y2 ) short x1,y1,x2,y2 ; { XDrawLine(dis, win, gc, x1, y1, x2, y2) ; } void G_pset(x1,y1) short x1,y1 ; { XDrawPoint(dis, win, gc, x1, y1) ; } void G_ellipse(x,y,r1,r2) int x,y,r1,r2 ; { int x1,y1,x2,y2 ; x1 = x ; y1 = y ; x2 = r1; y2 = r2 ; XDrawArc(dis, win, gc, x1, y1, x2, y2, 0, 360*64) ; } void G_fellipse(x,y,r1,r2) int x,y,r1,r2 ; { int x1,y1,x2,y2 ; x1 = x ; y1 = y ; x2 = r1; y2 = r2 ; XFillArc(dis, win, gc, x1, y1, x2, y2, 0, 360*64) ; } void G_circle(x,y,rr) int x,y,rr ; { int x1,y1,x2,y2 ; x1 = x-rr ; y1 = y-rr ; x2 = y2 = 2*rr ; XDrawArc(dis, win, gc, x1, y1, x2, y2, 0, 360*64) ; } void G_fcircle(x,y,rr) int x,y,rr ; { int x1,y1,x2,y2 ; x1 = x-rr ; y1 = y-rr ; x2 = y2 = 2*rr ; XFillArc(dis, win, gc, x1, y1, x2, y2, 0, 360*64) ; } void G_box( x1,y1,x2,y2 ) short x1,y1,x2,y2 ; { XDrawRectangle(dis, win, gc, x1, y1, x2, y2) ; } void G_fbox( x1,y1,x2,y2 ) short x1,y1,x2,y2 ; { XFillRectangle(dis, win, gc, x1, y1, x2, y2) ; } void G_cls() { XClearWindow(dis, win) ; } void G_lstyle(x1) short x1 ; { if(x1==0) XSetLineAttributes(dis, gc, 4, LineOnOffDash, CapButt, JoinMiter) ; if(x1==1) XSetLineAttributes(dis, gc, 4, LineSolid, CapButt, JoinMiter) ; } MyColor(color) char *color ; { XColor c0,c1 ; cmap = DefaultColormap(dis, 0) ; XAllocNamedColor(dis, cmap, color, &c1, &c0) ; return(c1.pixel) ; } void G_color(color) char *color ; { XSetForeground(dis, gc, MyColor(color)) ; } void G_color_value(r,g,b) int r,g,b ; { XColor c2 ; cmap = DefaultColormap(dis, 0) ; if(r==g && r==b){ c2.red = r*256 ; c2.green = g*256 ; c2.blue = b*256 ; XAllocColor(dis, cmap, &c2) ; XSetForeground(dis, gc, c2.pixel) ; } else{ XSetForeground(dis, gc, ppix[r]) ; } } G_color_set() { int i, mask ; unsigned long *pix; pix = (unsigned long *) malloc(256 * sizeof (long)); cmap = DefaultColormap(dis, 0) ; for(i=0 ; i<256 ; i++){ co2[i].red = (65535 * i) / 255 ; co2[i].green = (65535 * i) / 255 ; co2[i].blue = (65535 * i) / 255 ; if(XAllocColor(dis,cmap,&co2[i]) == 0 ) printf("Color Cell allocation failure %d\n",i) ; ppix[i]=co2[i].pixel ; } } void getmouse_l() { curs = XCreateFontCursor(dis, XC_left_ptr) ; XDefineCursor(dis, win, curs) ; XNextEvent(dis, &eve) ; } void getmouse_r() { curs = XCreateFontCursor(dis, XC_right_ptr) ; XDefineCursor(dis, win, curs) ; XNextEvent(dis, &eve) ; } void G_sleep() { while(1) { getmouse_l() ; if(eve.xbutton.button == 3 ) break ; } }