//*********************************************************************************** //Student Name: Prem Somu //Instructor: Dr. Wahab //Class: CS 476 - Systems Programming //Description: gDraw is a program that allows 2 or more people to collaborate over //a white board. //To execute: gDraw ... //*********************************************************************************** #include #include #include #include #include #include #include #include #include #define BUFFERSIZE 80 #define WIDTH 200 #define HEIGHT 200 #define MAXUSERS 10 #define TRUE 1 #define FALSE 0 #define MAX(A,B) ((A) > (B) ? (A) : (B)) #define SB_WIDTH 100 #define SB_HEIGHT 38 #define SB_LONGLABEL 50 #define SB_CURSOR XC_hand1 #define SB_INPUTMASK ExposureMask|EnterWindowMask|LeaveWindowMask|ButtonPressMask|ButtonReleaseMask #define floorButton 0 #define clearButton 1 #define quitButton 2 int clear(),Exit(),stat(),out(); struct { Window window; char label[SB_LONGLABEL]; int (*func)(); int num; }MenuButton[MAXUSERS][3]; int charwidth, charascent,chardescent; char buffer[BUFFERSIZE]; int bufsize = BUFFERSIZE; KeySym keysym; long statinout; int charcount,y=TRUE,guy; int NC,MAX[MAXUSERS]; char input[MAXUSERS][50]; char user[MAXUSERS][50]; XFontStruct *font_info; Display *display[MAXUSERS]; Window root[MAXUSERS],window[MAXUSERS][2]; GC draw[MAXUSERS],erase[MAXUSERS]; Colormap cmap; XColor color,ignore; char *red="red",*green="green",*yellow="yellow",*cyan="cyan",*white="white"; long fgcolor,bgcolor; char xxx[50]; main(argc,argv) int argc; char **argv; { int k; int screen,pointx,pointy; long eventmask = ButtonPressMask|ExposureMask|KeyPressMask|ButtonMotionMask|ButtonReleaseMask; long gcmask = GCForeground|GCBackground|GCLineWidth|GCCapStyle|GCJoinStyle; XEvent event; XGCValues gcval; XSetWindowAttributes setwinattr; int oldx,oldy,curx,cury; int i=0,j=0,l,i1,j1,j2,count = 0,x,k0,k1,k2; if(argc == 1) NC = 1; else NC = argc - 1; for(i=0;i MAX[i1]) MAX[i1] = count; count = 0; } for(i=0;i= XK_space && keysym <= XK_asciitilde) PutChar (buffer,i); else if (keysym == XK_BackSpace || keysym ==XK_Delete) DelChar(buffer,i); } break; default: fprintf(stderr,"UnExpected Event : %d\n",event.type); } } } } } } load_font(j1) int j1; { char *fontname = "9x15"; if ((font_info = XLoadQueryFont(display[j1], fontname)) == NULL) { (void) fprintf(stderr,"Could not get font\n"); exit( -1 ); } XSetFont(display[j1], draw[j1], font_info->fid); charwidth = font_info -> max_bounds.width; charascent = font_info -> max_bounds.ascent; chardescent = font_info -> max_bounds.descent; } defineCtrl(j2) int j2; { KeySym modlist[j2][2]; unsigned int list_len = 1; modlist[j2][0] = XK_Control_L; XRebindKeysym(display[j2],XK_q,modlist[j2],list_len,"quit",4); } PutChar(buffer,i) char buffer[]; int i; { int winx, winy,j3; int rwinx, rwiny; unsigned int maskret; Window rootret, childret; for(j3=0;j3type ) { case Expose: ExposeButton( j,id ); break; case EnterNotify: XDrawRectangle( display[j], MenuButton[j][id].window, draw[j], 1,1, SB_WIDTH-3, SB_HEIGHT-3 ); break; case LeaveNotify: ExposeButton( j,id ); break; case ButtonPress: if ( event->xbutton.button == Button1 ) { XDrawRectangle( display[j], MenuButton[j][id].window, draw[j], 0,0, SB_WIDTH-1,SB_HEIGHT-1 ); } break; case ButtonRelease: if(id == 0) {redraw(id,j,stat); } else if(id == 1) clear(j); else Exit(j,stat,id); break; default: break; } } ExposeButton( j,id ) int j; int id; { int width, center; XClearWindow( display[j], MenuButton[j][id].window ); width = XTextWidth( font_info, MenuButton[j][id].label, strlen(MenuButton[j][id].label) ); center = MAX((SB_WIDTH-width)/2,4); XDrawString( display[j], MenuButton[j][id].window, draw[j], center, (font_info->ascent)*2, MenuButton[j][id].label, strlen(MenuButton[j][id].label) ); XFlush(display[j]); } redraw(id,j,fun) int id,j; int (*fun)(); { int bgcolor,z,x; int screen; XSetWindowAttributes setwinattr; Cursor tempcursor; if(y){ for(z=0;z MAX[j]) MAX[j] = count; count = 0; } strcpy(xxx,input[0]); }