#include "Xroutines.h" void SetWidth(environment * env, int width){ XGCValues values; values.line_width = width; XChangeGC(env->disp, env->gc,GCLineWidth,&values); } void SetPixel(environment * env, int x, int y ){ XDrawPoint (env->disp, XtWindowOfObject(env->db), env->gc, x, y); } void DrawLine(int x1, int y1, int x2, int y2, environment * env){ XDrawLine(env->disp, XtWindowOfObject(env->db), env->gc,x1,y1,x2,y2); } void Get_Image_From_Server(environment * env) { env->the_screen = XGetImage(env->disp,XtWindowOfObject(env->db),0,0, env->xmax, env->ymax, AllPlanes,XYPixmap); } unsigned long Get_Pixel(environment * env, int x,int y){ return(XGetPixel(env->the_screen,x,y)); } void Clear_Screen(environment * env){ XSetForeground(env->disp,env->gc,env->bg); XFillRectangle(env->disp, XtWindowOfObject(env->db),env->gc ,0,0,env->xmax,env->ymax); XSetForeground(env->disp,env->gc,env->fg); } void SetDashList(environment * env, char * dash_list, int offset, int count){ XSetDashes(env->disp, env->gc,offset,dash_list,count); } void SetDashStyle(environment * env, char * token){ XGCValues values; if (!strcmp("solid",token)) { values.line_style = LineSolid; } if (!strcmp("onoff",token)) { values.line_style = LineOnOffDash; } if (!strcmp("double",token)) { values.line_style = LineDoubleDash; } XChangeGC(env->disp, env->gc,GCLineStyle,&values); return; } void SetCapStyle(environment * env, char * token){ XGCValues values; if (!strcmp("round",token)) { values.cap_style = CapRound; } if (!strcmp("butt",token)) { values.cap_style = CapButt; } if (!strcmp("project",token)) { values.cap_style = CapProjecting; } XChangeGC(env->disp, env->gc,GCCapStyle,&values); return; } int Set_Color(environment * env, int color) { XGCValues value_return; XGetGCValues(env->disp,env->gc,GCForeground,&value_return); if (color) { XSetForeground(env->disp,env->gc,env->bg); } else { XSetForeground(env->disp,env->gc,env->fg); } if (value_return.foreground == env->fg) { return (1); } else { return (0); } } void realize_environment(Widget mf, environment * env){ XColor red,green,sr,er; Window w_list[3]; w_list[0] = XtWindow(XtParent(mf)); w_list[1] = XtWindow(mf); w_list[2] = XtWindow(env->db); env->cm = XCreateColormap(env->disp,XtWindow(env->db), DefaultVisual(env->disp,XDefaultScreen(env->disp)),AllocNone); XSetWindowColormap(env->disp, XtWindow(env->db), env->cm); XSetWindowColormap(env->disp, XtWindow(mf), env->cm); XSetWindowColormap(env->disp, XtWindow(XtParent(mf)), env->cm); if (XSetWMColormapWindows(env->disp, XtWindow(XtParent(mf)),w_list,2)==0) { printf("Could not set colormap property\n"); } /* if(XAllocNamedColor(env->disp,env->cm,"blue",&sr,&er)==0) { red = er; } else{ red = sr; } */ if(XAllocNamedColor(env->disp,env->cm,"LawnGreen",&sr,&er)==0) { green = er; } else{ green = sr; } sr.red = 95*256; sr.green = 146*256; sr.blue = 158*256; sr.flags = DoRed||DoGreen||DoBlue; if (XAllocColor(env->disp, env->cm, &sr) != 0) { red = sr; } else { printf("Could not allocate background color, using Black\n"); red.pixel = BlackPixel(env->disp,DefaultScreen(env->disp)); } env->fg = green.pixel; env->bg = red.pixel; XSetForeground(env->disp,env->gc,env->fg); XSetBackground(env->disp,env->gc,env->bg); } void setup_environment(environment * env){ int screen_num; env->disp = XtDisplay(env->db); screen_num = DefaultScreen(env->disp); env->gc = DefaultGC(env->disp,screen_num); env->the_screen = NULL; }