int tela_strlen(tela_t *tela, char *s) { XCharStruct char_struct; int z; XQueryTextExtents(tela->display, XGContextFromGC(tela->gc), s, strlen(s), &z, &z, &z, &char_struct); return char_struct.width; }
tamanho_t tela_tamanho_texto(tela_t *t, char *s) { XCharStruct char_struct; tamanho_t tam; int z; XQueryTextExtents(t->display, XGContextFromGC(t->gc), s, strlen(s), &z, &z, &z, &char_struct); tam.larg= char_struct.width; tam.alt= char_struct.ascent; // + char_struct.descent; return tam; }
static long text_width_xfont(FONT_TYPE which_font, const char *text, int len) { XCharStruct xcs; int width; if (len < 0) len = strlen(text); XQueryTextExtents(disp, FontId[which_font], text, len, &width, &width, &width, &xcs); /* Make the width a multiple of 8 */ /* width = (xcs.width + 7) >> 3; // return width << 3; */ return xcs.width; }
void print_help() { static char str[80]; static int y_str, spacing; static int ascent, descent, dir; static XCharStruct overall; static GC gc; gc = Data_GC[1]; XClearWindow(dpy, help); y_str = 60; sprintf(str,"During run-time, interactive control can be exerted via : "); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); XQueryTextExtents(dpy,(XID)XGContextFromGC(gc),"Hey!", 4,&dir,&ascent,&descent,&overall); spacing = ascent + descent + 5; y_str += 2 * spacing; sprintf(str," - lowers the value of mincolindex, + raises it"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," f or F saves coral to a PPM file"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," h or H or ? displays this message"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," n goes on to the next coral"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," N creates a new replacement coral"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," r or s spins the colorwheel"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," w decrements, W increments the color wheel index"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str," q or Q exits"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); y_str += 2*spacing; sprintf(str,"Press 'h', 'H', or '?' to unmap the help window"); XDrawImageString(dpy,help,gc,x_str,y_str,str,strlen(str)); }
rectangle get_text_rect ( std::string text ) { int direction = 0, font_ascent = 0, font_descent = 0; XCharStruct char_struct; XQueryTextExtents ( m_display, XGContextFromGC(m_gc), text.c_str(), text.size(), &direction, &font_ascent, &font_descent, &char_struct ); rectangle rect ( point(0,0), char_struct.rbearing - char_struct.lbearing, char_struct.ascent - char_struct.descent ); return rect; }
/* function */ void xContour(Display *dpy, Window win,GC gcc, GC gcl, float *cp,int nx, float x[], int ny, float y[], float z[], char lcflag,char *lcf,char *lcc, float *w, int nplaces) /************************************************************************** xContour - draw contour of a two-dimensional array via X *************************************************************************** Input: dpy the display to make the contour win the window to draw in gcc GC for the contour lines gcl GC for the contour labels cp pointer to the contour value nx number of x-coordinates x array of x-coordinates (see notes below) ny number of y-coordinates y array of y-coordinates (see notes below) lcflag flag that defines if we actually are going to have labels Least Significat Bits: z array of nx*ny z(x,y) values (see notes below) w array of nx*ny z(x,y) values (see notes below) *************************************************************************** Notes: The two-dimensional array z is actually passed as a one-dimensional array containing nx*ny values, stored with nx fast and ny slow. The x and y arrays define a grid that is not necessarily uniformly-sampled. Linear interpolation of z values on the grid defined by the x and y arrays is used to determine z values between the gridpoints. The two least significant bits of z are used to mark intersections of the contour with the x,y grid; therefore, the z values will almost always be altered (slightly) by contour. xContour is a modified version of psContour where the use of conmove and condraw call have been changed to match X-Windows. Since XDrawLine requires a start and end point, the use of a manually update of the position variables x0 and y0 is used instead of conmove. if lcflag is zero no labels are drawn The w array is used to restrict the range of contour labeling that occurs only if w<1. As suggested in the reference, the following scheme is used to refer to a cell of the two-dimensional array z: north (0) (ix,iy+1) --------- (ix+1,iy+1) | cell | west (3) | ix,iy | east (1) | | (ix,iy) --------- (ix+1,iy) south (2) *************************************************************************** Reference: Cottafava, G. and Le Moli, G., 1969, Automatic contour map: Commuincations of the ACM, v. 12, n. 7, July, 1969. *************************************************************************** Author: Morten Wendell Pedersen Aarhus University 07/20/96 Heavily based on psContour by Dave Hale, Colorado School of Mines, 06/28/89 and with contour labeling added by: Zhenyue Liu, June 1993 (actually most of the credit should go to these two guys) ***************************************************************************/ { int ix,iy,non,cell,startcell; float d; float xmin = MIN(x[0],x[nx-1]), xmax = MAX(x[0],x[nx-1]); float ymin = MIN(y[0],y[ny-1]), ymax = MAX(y[0],y[ny-1]); float xc=0.0, yc=0.0; /* contour labeling centered at (xc,yc) */ float xw, yw; /* width and length of contour labeling */ float xd, yd; /* point on contour */ float x0, y0; /* start plot values (instead of move operation )*/ float xdmin, xdmax, ydmin, ydmax; /* range of contour */ int id; /* =0 if a point on contour has been used as (xc,yc) */ int cells=0; char str[20]; XCharStruct overall; int dummy; float c=*cp; /* stupid thing I had to do since I couldn't transfer a float without messing up everything but I could transfer a pointer....strange thing I will have to track this thing down one day*/ /* convert a number into a string */ sprintf(str,"%.*g",nplaces,c); /* determine length and width for printing the string */ XQueryTextExtents(dpy,XGContextFromGC(gcl),str,(int) strlen(str),&dummy,&dummy,&dummy,&overall); xw=overall.width; yw=overall.ascent+overall.descent; /* restrict contour labeling from edges */ for (iy=0; iy<ny-1; iy++) for (ix=0,cell=iy*nx; ix<nx-1; ix++,cell++) { if(x[ix]<xmin+2.0*xw || x[ix]>xmax-2.0*xw || y[iy]<ymin+yw || y[iy]>ymax-yw) w[cell] += 1.; } /* count intersections with cell boundaries */ non = 0; /* find all the intersections */ for (iy=0; iy<ny; iy++) { for (ix=0,cell=iy*nx; ix<nx; ix++,cell++) { /* check for intersection with west edge of cell */ if (iy<ny-1 && BTWN(c,z[cell],z[cell+nx])) { SETW(z[cell]); non++; } else { CLRW(z[cell]); } /* check for intersection with south edge of cell */ if (ix<nx-1 && BTWN(c,z[cell],z[cell+1])) { SETS(z[cell]); non++; } else { CLRS(z[cell]); } } } /* follow contours intersecting north boundary */ for (ix=0,startcell=(ny-1)*nx; non>0&&ix<nx-1; ix++,startcell++) { if (SSET(z[startcell])) { d = DELTA(c,z[startcell],z[startcell+1]); x0=(1.0-d)*x[ix]+d*x[ix+1]; y0=y[ny-1]; CLRS(z[startcell]); non--; cell = startcell-nx; id = 1; xdmin = xmax; xdmax = xmin; ydmin = ymax; ydmax = ymin; while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){ x0=xd;y0=yd; non--; if(w[cell]<0.5 && id) { xc = xd; yc = yd; cells = cell; id = 0; } xdmin = MIN(xdmin,xd); xdmax = MAX(xdmax,xd); ydmin = MIN(ydmin,yd); ydmax = MAX(ydmax,yd); } if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) { wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw); labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc); } } } /* follow contours intersecting east boundary */ for (iy=0,startcell=nx-1; non>0&&iy<ny-1; iy++,startcell+=nx) { if (WSET(z[startcell])) { d = DELTA(c,z[startcell],z[startcell+nx]); x0=x[nx-1]; y0=(1.0-d)*y[iy]+d*y[iy+1]; CLRW(z[startcell]); non--; cell = startcell-1; id = 1; xdmin = xmax; xdmax = xmin; ydmin = ymax; ydmax = ymin; while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){ x0=xd;y0=yd; non--; if(w[cell]<0.5 && id) { xc = xd; yc = yd; cells = cell; id = 0; } xdmin = MIN(xdmin,xd); xdmax = MAX(xdmax,xd); ydmin = MIN(ydmin,yd); ydmax = MAX(ydmax,yd); } if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) { wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw); labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc); } } } /* follow contours intersecting south boundary */ for (ix=0,startcell=0; non>0&&ix<nx-1; ix++,startcell++) { if (SSET(z[startcell])) { d = DELTA(c,z[startcell],z[startcell+1]); x0=(1.0-d)*x[ix]+d*x[ix+1]; y0=y[0]; CLRS(z[startcell]); non--; cell = startcell; id = 1; xdmin = xmax; xdmax = xmin; ydmin = ymax; ydmax = ymin; while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){ x0=xd;y0=yd; non--; if(w[cell]<0.5 && id) { xc = xd; yc = yd; cells = cell; id = 0; } xdmin = MIN(xdmin,xd); xdmax = MAX(xdmax,xd); ydmin = MIN(ydmin,yd); ydmax = MAX(ydmax,yd); } if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) { wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw); labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc); } } } /* follow contours intersecting west boundary */ for (iy=0,startcell=0; non>0&&iy<ny-1; iy++,startcell+=nx) { if (WSET(z[startcell])) { d = DELTA(c,z[startcell],z[startcell+nx]); x0=x[0]; y0=(1.0-d)*y[iy]+d*y[iy+1]; CLRW(z[startcell]); non--; cell = startcell; id = 1; xdmin = xmax; xdmax = xmin; ydmin = ymax; ydmax = ymin; while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){ x0=xd;y0=yd; non--; if(w[cell]<0.5 && id) { xc = xd; yc = yd; cells = cell; id = 0; } xdmin = MIN(xdmin,xd); xdmax = MAX(xdmax,xd); ydmin = MIN(ydmin,yd); ydmax = MAX(ydmax,yd); } if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) { wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw); labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc); } } } /* follow interior contours */ for (iy=1; iy<ny-1; iy++) { for (ix=0,startcell=iy*nx; non>0&&ix<nx-1; ix++,startcell++) { /* check south edge of cell */ if (SSET(z[startcell])) { d = DELTA(c,z[startcell],z[startcell+1]); x0=(1.0-d)*x[ix]+d*x[ix+1]; y0=y[iy]; /* clear south edge where we started */ CLRS(z[startcell]); non--; cell = startcell; /* if another intersection exists in this cell */ if (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)) { x0=xd;y0=yd; /* set south edge so that we finish where we started */ SETS(z[startcell]); non++; /* follow the contour */ id = 1; xdmin = xmax; xdmax = xmin; ydmin = ymax; ydmax = ymin; while (connect(dpy, win,gcc,c,nx,x,ny,y,z,&cell,&xd,&yd,&x0,&y0)){ x0=xd;y0=yd; non--; if(w[cell]<0.5 && id) { xc = xd; yc = yd; cells = cell; id = 0; } xdmin = MIN(xdmin,xd); xdmax = MAX(xdmax,xd); ydmin = MIN(ydmin,yd); ydmax = MAX(ydmax,yd); } if(lcflag && id==0 && xdmax+ydmax-xdmin-ydmin>xw+yw) { wcell(nx,x,ny,y,w,cells,xc,yc,xw,yw); labelc(dpy,win,gcl,xc-xw/2,yc-yw/2,xw,yw,str,lcf,lcc); } } } } } /* contour drawing is done */ }
static unsigned char *text_to_bitmap_xfont(FONT_TYPE which_font, const char *text, int *width_return, int *height_return) { Pixmap xpm = None; GC gc2 = None; XImage *ximg = NULL; XCharStruct xcs; XGCValues xgcv; int width, height; int bwidth; int ascent, bit_order; int len; unsigned char *result = NULL; len = strlen(text); XQueryTextExtents(disp, FontId[which_font], text, len, &width, &width, &width, &xcs); ascent = xcs.ascent; height = xcs.descent + ascent; width = xcs.width; /* Make the width a multiple of 8 */ bwidth = width >> 3; /* Width in bytes */ if (width & 7) bwidth++; width = bwidth << 3; xpm = XCreatePixmap(disp, wnd, width, height, 1); if (xpm == None) goto HastaLaVista; xgcv.font = FontId[which_font]; xgcv.background = 0; xgcv.foreground = 0; xgcv.fill_style = FillSolid; gc2 = XCreateGC(disp, xpm, GCBackground | GCForeground | GCFont | GCFillStyle, &xgcv); if (gc2 == None) goto HastaLaVista; XFillRectangle(disp, xpm, gc2, 0, 0, width, height); XSetForeground(disp, gc2, 1); XDrawString(disp, xpm, gc2, 0, ascent, text, len); ximg = XGetImage(disp, xpm, 0, 0, width, height, 1, ZPixmap); if (ximg == NULL) goto HastaLaVista; bit_order = ximg->bitmap_bit_order; XFreeGC(disp, gc2); gc2 = None; XFreePixmap(disp, xpm); xpm = None; result = squeeze_ximage(ximg, bwidth); ximg->data = NULL; *width_return = width; *height_return = height; HastaLaVista: if (xpm) XFreePixmap(disp, xpm); if (gc2) XFreeGC(disp, gc2); if (ximg) XDestroyImage(ximg); return result; }
main() { Window w2; Display *dpy = XOpenDisplay(NIL); assert(dpy); Screen *scr = DefaultScreenOfDisplay(dpy); // CreateWindow Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroyWindow(dpy, w); // CreateWindow with arguments XSetWindowAttributes swa; swa.background_pixel = WhitePixelOfScreen(scr); swa.bit_gravity = NorthWestGravity; swa.border_pixel = BlackPixelOfScreen(scr); swa.colormap = DefaultColormapOfScreen(scr); swa.cursor = None; swa.win_gravity = NorthGravity; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, &swa); // CreateWindow with other arguments XDestroyWindow(dpy, w); Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr)); assert(pixmap); swa.background_pixmap = pixmap; swa.border_pixmap = pixmap; w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap | CWBorderPixmap, &swa); // ChangeWindowAttributes swa.backing_planes = 0x1; swa.backing_pixel = WhitePixelOfScreen(scr); swa.save_under = True; swa.event_mask = KeyPressMask | KeyReleaseMask; swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask; swa.override_redirect = False; XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask | CWDontPropagate | CWOverrideRedirect, &swa); // GetWindowAttributes XWindowAttributes wa; Status success = XGetWindowAttributes(dpy, w, &wa); // DestroyWindow (done) // DestroySubwindows w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XDestroySubwindows(dpy, w); // ChangeSaveSet // Display *dpy2 = XOpenDisplay(NIL); // assert(dpy2); // XAddToSaveSet(dpy2, w); // XCloseDisplay(dpy2); // ReparentWindow w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XReparentWindow(dpy, w2, w, 10, 5); // MapWindow XMapWindow(dpy, w); // MapSubwindows XMapSubwindows(dpy, w); // UnmapWindow XUnmapWindow(dpy, w); // UnmapSubwindows XMapWindow(dpy, w); XUnmapSubwindows(dpy, w2); XMapSubwindows(dpy, w); // ConfigureWindow Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL); XMapWindow(dpy, w3); XWindowChanges wc; wc.x = -5; wc.y = -10; wc.width = 50; wc.height = 40; wc.border_width = 7; wc.sibling = w2; wc.stack_mode = Opposite; XConfigureWindow(dpy, w3, CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, &wc); // CirculateWindow XCirculateSubwindows(dpy, w, RaiseLowest); // GetGeometry Window root; int x, y; unsigned width, height, border_width, depth; XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth); // QueryTree Window parent; Window *children; unsigned nchildren; success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren); XFree(children); // InternAtom Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True); // GetAtomName char *string = XGetAtomName(dpy, XA_PRIMARY); XFree(string); // ChangeProperty XStoreName(dpy, w, "test window"); // DeleteProperty XDeleteProperty(dpy, w, XA_WM_NAME); // GetProperty // TODO // ListProperties int num_prop; Atom *list = XListProperties(dpy, w, &num_prop); XFree(list); // SetSelectionOwner XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000); XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime); // GetSelectionOwner Window wx = XGetSelectionOwner(dpy, XA_PRIMARY); // ConvertSelection XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime); // SendEvent // GrabPointer std::cerr << "Grabbing" << std::endl; int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask, GrabModeSync, GrabModeAsync, w, None, CurrentTime); XSync(dpy, False); // sleep(5); // UngrabPointer std::cerr << "Ungrabbing" << std::endl; XUngrabPointer(dpy, CurrentTime); // GrabButton XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, GrabModeAsync, GrabModeSync, None, None); // UngrabButton XUngrabButton(dpy, 2, LockMask, w); // ChangeActivePointerGrab XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime); // GrabKeyboard XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000); // UngrabKeyboard XUngrabKeyboard(dpy, 13000); // GrabKey XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync, GrabModeSync); // UngrabKey XUngrabKey(dpy, AnyKey, AnyModifier, w); // AllowEvents XAllowEvents(dpy, AsyncPointer, 14000); // GrabServer XGrabServer(dpy); // UngrabServer XUngrabServer(dpy); // QueryPointer Window child; int root_x, root_y, win_x, win_y; unsigned mask; Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask); // GetMotionEvents int nevents; XGetMotionEvents(dpy, w, 15000, 16000, &nevents); // TranslateCoordinates int dest_x, dest_y; XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child); // WarpPointer XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30); // SetInputFocus XSetInputFocus(dpy,w, RevertToPointerRoot, 17000); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000); // GetInputFocus Window focus; int revert_to; XGetInputFocus(dpy, &focus, &revert_to); // QueryKeymap char keys_return[32]; XQueryKeymap(dpy, keys_return); // OpenFont Font fid = XLoadFont(dpy, "cursor"); // CloseFont XUnloadFont(dpy, fid); // QueryFont XFontStruct *fs = XLoadQueryFont(dpy, "cursor"); assert(fs); // QueryTextExtents int direction, font_ascent, font_descent; XCharStruct overall; XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall); XChar2b c2bs; c2bs.byte1 = '$'; c2bs.byte2 = 'B'; XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall); XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, &font_descent, &overall); // ListFonts int actual_count; char **fontList = XListFonts(dpy, "*", 100, &actual_count); XFree((char *)fontList); // ListFontsWithInfo int count; XFontStruct *info; char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info); XFreeFontInfo(names, info, count); // SetFontPath // GetFontPath int npaths; char **charList = XGetFontPath(dpy, &npaths); char **charList2 = new char *[npaths + 1]; memcpy(charList2, charList, npaths * sizeof(char *)); charList2[npaths] = charList2[0]; XSetFontPath(dpy, charList2, npaths + 1); XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value XFreeFontPath(charList); delete [] charList2; // CreatePixmap Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr)); // FreePixmap XFreePixmap(dpy, pix2); // CreateGC Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4); XGCValues gcv; gcv.function = GXand; gcv.plane_mask = 0x1; gcv.foreground = WhitePixelOfScreen(scr); gcv.background = BlackPixelOfScreen(scr); gcv.line_width = 2; gcv.line_style = LineDoubleDash; gcv.cap_style = CapProjecting; gcv.join_style = JoinRound; gcv.fill_style = FillStippled; gcv.fill_rule = EvenOddRule; gcv.arc_mode = ArcPieSlice; gcv.tile = pixmap; gcv.stipple = bitmap; gcv.ts_x_origin = 3; gcv.ts_y_origin = 4; gcv.font = fs -> fid; gcv.subwindow_mode = ClipByChildren; gcv.graphics_exposures = True; gcv.clip_x_origin = 5; gcv.clip_y_origin = 6; gcv.clip_mask = bitmap; gcv.dash_offset = 1; gcv.dashes = 0xc2; GC gc = XCreateGC(dpy, w, GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile | GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset | GCDashList | GCArcMode, &gcv); // ChangeGC gcv.function = GXandReverse; // Only a few of these should appear, since the values are cached on the client side by the Xlib. XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv); // CopyGC GC gc2 = XCreateGC(dpy, w, 0, NIL); XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2); // SetDashes XSetDashes(dpy, gc, 3, "\001\377\001", 3); // SetClipRectangles XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } }; XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted); // FreeGC // done already // ClearArea XClearArea(dpy, w, 30, 10, 10, 100, False); // CopyArea XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10); // CopyPlane // This won't work if the Screen doesn't have at least 3 planes XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4); // PolyPoint XDrawPoint(dpy, w, gc, 1, 2); XPoint points[] = { { 3, 4 }, { 5, 6 } }; XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin); // PolyLine XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious); // PolySegment XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } }; XDrawSegments(dpy, w, gc, segments, SIZEOF(segments)); // PolyRectangle XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyArc XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, { 10, 20, 30, 40, 50, -30 } }; XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // FillPoly XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious); // PolyFillRectangle XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles)); // PolyFillArc XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs)); // PutImage // GetImage XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap); XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30); XSync(dpy, False); // Make the next request starts at the beginning of a packet // PolyText8 XTextItem textItems[3]; textItems[0].chars = "toto"; textItems[0].nchars = strlen(textItems[0].chars); textItems[0].delta = -3; textItems[0].font = fs->fid; textItems[1].chars = "titi"; textItems[1].nchars = strlen(textItems[1].chars); textItems[1].delta = 3; textItems[1].font = None; textItems[2].chars = "tutu"; textItems[2].nchars = strlen(textItems[2].chars); textItems[2].delta = 0; textItems[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems, 3); XTextItem textItems2[3]; textItems2[0].chars = "totox"; textItems2[0].nchars = strlen(textItems2[0].chars); textItems2[0].delta = -3; textItems2[0].font = fs->fid; textItems2[1].chars = "titi"; textItems2[1].nchars = strlen(textItems2[1].chars); textItems2[1].delta = 3; textItems2[1].font = None; textItems2[2].chars = "tutu"; textItems2[2].nchars = strlen(textItems2[2].chars); textItems2[2].delta = 0; textItems2[2].font = fs->fid; XDrawText(dpy, w, gc, 10, 10, textItems2, 3); // PolyText16 XChar2b c2b2[] = { 0, 't', 0, 'x' }; XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } }; XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16)); // ImageText8 XDrawImageString(dpy, w, gc, 10, 10, "toto", 4); // ImageText16 XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1); XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2); // CreateColormap // Don't forget to tell the kids how it was when we had only 8 bits per pixel. Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // FreeColormap XFreeColormap(dpy, colormap); colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None); // CopyColormapAndFree Colormap colormap2 = XCopyColormapAndFree(dpy, colormap); // InstallColormap XInstallColormap(dpy, colormap2); // UninstallColormap XUninstallColormap(dpy, colormap2); // ListInstalledColormaps int num; Colormap *colormapList = XListInstalledColormaps(dpy, w, &num); // AllocColor XColor screen; screen.red = 0; screen.green = 32767; screen.blue = 65535; screen.flags = DoRed | DoGreen | DoBlue; success = XAllocColor(dpy, colormap, &screen); // AllocNamedColor XColor screen2, exact; success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact); // AllocColorCells unsigned long plane_masks, pixels; success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1); // AllocColorPlanes unsigned long rmask, gmask, bmask; success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask); // FreeColors unsigned long pixels2[2] = { screen.pixel, screen2.pixel }; XFreeColors(dpy, colormap, pixels2, 2, 0); // StoreColors success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2); // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells // I want my requests to be sent, however. if (!success) { XSetErrorHandler(errorHandler); } XColor colors[2]; colors[0] = screen; colors[0].pixel = pixels2[0]; colors[1] = screen2; colors[1].pixel = pixels2[1]; XStoreColors(dpy, colormap, colors, 2); // StoreNamedColor XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue); XSync(dpy, False); XSetErrorHandler(NIL); // Restore the default handler // QueryColors screen2.pixel = WhitePixelOfScreen(scr); XQueryColor(dpy, colormap, &screen2); // LookupColor success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen); // CreateCursor Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10); // CreateGlyphCursor Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors); // FreeCursor XFreeCursor(dpy, cursor2); // RecolorCursor XRecolorCursor(dpy, cursor, colors, &exact); // QueryBestSize success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height); // QueryExtension int major_opcode, first_event, first_error; XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error); // ListExtensions int nextensions; char **extensionList = XListExtensions(dpy, &nextensions); for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl; XFree(extensionList); // ChangeKeyboardMapping // GetKeyboardMapping int min_keycodes, max_keycodes; XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes); int keysyms_per_keycode; KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1, &keysyms_per_keycode); XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, max_keycodes - min_keycodes + 1); // ChangeKeyboardControl // GetKeyboardControl XKeyboardState keyboardState; XGetKeyboardControl(dpy, &keyboardState); XKeyboardControl keyboardValues; keyboardValues.key_click_percent = keyboardState.key_click_percent; keyboardValues.bell_percent = keyboardState.bell_percent; keyboardValues.bell_pitch = keyboardState.bell_pitch; keyboardValues.bell_duration = keyboardState.bell_duration; keyboardValues.led = 1; keyboardValues.led_mode = LedModeOn; keyboardValues.key = min_keycodes; keyboardValues.auto_repeat_mode = AutoRepeatModeDefault; XChangeKeyboardControl(dpy, KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration | KBLed | KBLedMode | KBKey | KBAutoRepeatMode, &keyboardValues); // Bell XBell(dpy, 90); // ChangePointerControl // GetPointerControl int accel_numerator, accel_denominator, threshold; XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold); XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold); // SetScreenSaver // GetScreenSaver int timeout, interval, prefer_blanking, allow_exposures; XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures); XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures); // ChangeHosts // ListHosts int nhosts; Bool state; XHostAddress *hostList = XListHosts(dpy, &nhosts, &state); XHostAddress host; host.family = FamilyInternet; host.length = 4; host.address = "\001\002\003\004"; XAddHost(dpy, &host); // SetAccessControl XSetAccessControl(dpy, EnableAccess); // SetCloseDownMode XSetCloseDownMode(dpy, RetainTemporary); // KillClient XKillClient(dpy, AllTemporary); // RotateProperties Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), XInternAtom(dpy, "CUT_BUFFER1", False), XInternAtom(dpy, "CUT_BUFFER2", False) }; XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1); // ForceScreenSaver XForceScreenSaver(dpy, ScreenSaverReset); // SetPointerMapping // GetPointerMapping unsigned char map[64]; int map_length = XGetPointerMapping(dpy, map, 64); XSetPointerMapping(dpy, map, map_length); // SetModifierMapping // GetModifierMapping XModifierKeymap *modmap = XGetModifierMapping(dpy); XSetModifierMapping(dpy, modmap); // NoOperation XNoOp(dpy); for(;;) { XEvent e; XNextEvent(dpy, &e); std::cout << "Got an event of type " << e.type << std::endl; } }
Show_Info() { extern int found_arc, mandel, maxcrit, numattrs, maxhist, minhist; extern double sea_level, sky_level; #ifdef NorthSouth extern double singularity, A_zero, A_one, A_two, A_star, B_zero, B_one; extern double S_singularity, H_one, H_zero, O_B_zero, O_B_one; extern double S_A_zero, S_A_one, S_A_two, S_A_star, S_B_zero, S_B_one; extern double O_S_B_zero, O_S_B_one; extern double pB, A2T, A1T, CT, ET, FT, GT; extern pair GNP, RK; static char *mops[HALF] = { "delta", "s ", "a1 ", "a2 ", "c1 ", "c2 ", "D ", "Kbar ", "Lbar ", "alpha", "beta ", "gamma" }; #endif static int numparams[NUMMAPS]= {12,5,4,12,4,12,2, #ifdef NorthSouth #ifdef Gardini 12,3,2,2, #else 12, #endif #else #ifdef Gardini 3,2,2, #endif #endif 2,3,2,2,2,3,7,4,3,12,2,7,8,4 #ifdef Plendo , 12, 6, 2, 5 #endif }; static int i, x_str, y_str; static GC gc; static char ops[HALF] = { 'A','B','C','D','E','F','G','I','J','K','L','M' }; if (displayplanes > 1) gc = Data_GC[CG]; else gc = Data_GC[1]; XClearWindow(dpy, info); y_str = 20; x_str = 175; sprintf(str,"Iterating the %s Map ",Mapnames[mapindex]); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); XQueryTextExtents(dpy,(XID)XGContextFromGC(gc),"X", 1,&dir,&ascent,&descent,&overall); spacing = ascent + descent + 7; y_str += spacing; x_str = 40; XDrawImageString(dpy,info,gc,x_str,y_str,Mapdefs[2*mapindex], strlen(Mapdefs[2*mapindex])); y_str += spacing; XDrawImageString(dpy,info,gc,x_str,y_str,Mapdefs[2*mapindex+1], strlen(Mapdefs[2*mapindex+1])); x_str = 0; y_str += 2*spacing; #ifdef NorthSouth if (mapindex == 7) { sprintf(str," South North"); XDrawImageString(dpy,info,gc,x_str,y_str, str, strlen(str)); y_str += spacing; for (i=0;i<HALF;i++) { sprintf(str," %s %8.4f %8.4f", mops[i],params[i],params[HALF+i]); XDrawImageString(dpy,info,gc,x_str,y_str, str, strlen(str)); y_str += spacing; } } else #endif /* NorthSouth */ if (mapindex == 24) { sprintf(str," X Y"); XDrawImageString(dpy,info,gc,x_str,y_str, str, strlen(str)); y_str += spacing; for (i=0;i<numparams[mapindex];i++) { sprintf(str," %c = %8.4f %c = %8.4f", ops[i], params[i], tolower(ops[i]), params[HALF+i]); XDrawImageString(dpy,info,gc,x_str,y_str, str, strlen(str)); y_str += spacing; } } else for (i=0;i<numparams[mapindex];i++) { sprintf(str," %c=%lf",ops[i],params[i]); XDrawImageString(dpy,info,gc,x_str,y_str, str, strlen(str)); y_str += spacing; } x_str = 50 + (23*overall.width); y_str = 5*spacing; sprintf(str,"width = %d, height = %d, run = %d", width,height,run); if ((criwidth != width) || (criheight != height)) sprintf(str,"%s, cwidth=%d, cheight=%d",str,criwidth,criheight); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str,"settle = %d, dwell = %d, maxcrit = %d",settle,dwell,maxcrit); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str,"delta = %6.5f, cdelta = %6.5f, radius = %d", delta, cdelt, maxradius); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; if (lyap) { if (p1 < HALF) { #ifdef NorthSouth if (mapindex == 7) sprintf(str,"x-axis = (%lf,%lf), parameter = South %s, range = %lf", min_x, max_x, mops[p1], x_range); else #endif sprintf(str,"x-axis = (%lf,%lf), parameter = %c, range = %lf", min_x, max_x, ops[p1], x_range); } else { #ifdef NorthSouth if (mapindex == 7) sprintf(str,"x-axis = (%lf,%lf), parameter = North %s, range = %lf", min_x, max_x, mops[p1-HALF], x_range); else #endif sprintf(str,"x-axis = (%lf,%lf), parameter = %c, range = %lf", min_x, max_x, tolower(ops[p1-HALF]), x_range); } } else sprintf(str,"x-axis = (%lf,%lf), x-range = %lf",min_x,max_x,x_range); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; if (lyap) { if (p2 < HALF) { #ifdef NorthSouth if (mapindex == 7) sprintf(str,"y-axis = (%lf,%lf), parameter = South %s, range = %lf", min_y, max_y, mops[p2], y_range); else #endif sprintf(str,"y-axis = (%lf,%lf), parameter = %c, range = %lf", min_y, max_y,ops[p2], y_range); } else { #ifdef NorthSouth if (mapindex == 7) sprintf(str,"y-axis = (%lf,%lf), parameter = North %s, range = %lf", min_y, max_y, mops[p2-HALF], y_range); else #endif sprintf(str,"y-axis = (%lf,%lf), parameter = %c, range = %lf", min_y, max_y, tolower(ops[p2-HALF]), y_range); } } else sprintf(str,"y-axis = (%lf,%lf), y-range = %lf",min_y,max_y,y_range); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; if ((c_min_x != min_x) || (c_min_y != min_y) || (c_x_range != x_range) || (c_y_range != y_range)) { sprintf(str,"critical axes = (%lf, %lf) x (%lf, %lf)", c_min_x, c_min_x + c_x_range, c_min_y, c_min_y + c_y_range); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; } if ((t_min_x != min_x) || (t_min_y != min_y) || (t_x_range != x_range) || (t_y_range != y_range)) { sprintf(str,"orbit axes = (%lf, %lf) x (%lf, %lf)", t_min_x, t_min_x + t_x_range, t_min_y, t_min_y + t_y_range); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; } sprintf(str, "numcolors=%d STARTCOLOR=%d MINCOLINDEX=%d histogram=%d sea=%lf sky=%lf", numcolors,STARTCOLOR,MINCOLINDEX,histogram,sea_level,sky_level); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); #ifdef NorthSouth if (mapindex == 7) { y_str += spacing; sprintf(str, "North: A0 =%8.6f A1 =%8.6f A2 =%8.6f A* =%8.6f", A_zero, A_one, A_two, A_star); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str, " H0 =%8.6f H1 =%8.6f B0 =%8.6f (%8.6f) B1 =%8.6f (%8.6f)", H_zero, H_one, B_zero, O_B_zero, B_one, O_B_one); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str, "South: A0 =%8.6f A1 =%8.6f A2 =%8.6f A* =%12.10lf", S_A_zero, S_A_one, S_A_two, S_A_star); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str, " B0 =%8.6f (%8.6f) B1 =%8.6f (%8.6f)", S_B_zero, O_S_B_zero, S_B_one, O_S_B_one); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str,"Singularities in the North and South at %lf and %lf", singularity, S_singularity); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); } else if (mapindex == 8) { y_str += spacing; sprintf(str, "Currently: pB = %8.6f ET = %8.6f FT = %8.6f CT = %8.6f GT = %8.6f", pB, ET, FT, CT, GT); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str, "North rK = %8.4f South rK = %8.4f", RK.x, RK.y); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str,"Singularities in the North and South at %lf and %lf", singularity, S_singularity); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); } else if (mapindex == 9) { y_str += spacing; sprintf(str, "Currently: pB = %8.6f ET = %8.6f FT = %8.6f CT = %8.6f GT = %8.6f", pB, ET, FT, CT, GT); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str, "North GNP = %8.4f South GNP = %8.4f", GNP.x, GNP.y); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; sprintf(str,"Singularities in the North and South at %lf and %lf", singularity, S_singularity); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); } #endif y_str += spacing; sprintf(str,"find = %d, portrait = %d, attractors = %d, critical = %d", find,portrait,attractors,critical); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); y_str += spacing; if (lyap) sprintf(str,"lyap = %d, mandel = %d, initial (x,y) = (%lf,%lf)", lyap,mandel,start_x,start_y); else if (histogram) sprintf(str, "mandel=%d intersections=%d numattrs=%d minhist=%d maxhist=%d", mandel, found_arc, numattrs, minhist, maxhist); else sprintf(str,"mandel = %d, intersections = %d, numattrs = %d", mandel, found_arc, numattrs); XDrawImageString(dpy,info,gc,x_str,y_str,str,strlen(str)); }
static void print_text(gframe_t *frame, char *text) { static int first_call = TRUE; static double text_margin_x, text_margin_y; static double text_line_spacing; char *line; int direction, ascent, descent; double textx, texty; XCharStruct overall; if (first_call) { /* * get margins and line spacing */ text_margin_x = xGetResDouble(Glob->rdisplay, Glob->prog_name, "x_text_margin", X_TEXT_MARGIN) / frame->x->xscale; text_margin_y = xGetResDouble(Glob->rdisplay, Glob->prog_name, "x_text_margin", X_TEXT_MARGIN) / frame->x->yscale; XQueryTextExtents(Glob->rdisplay, Glob->x_text_font->fid, "AaGgJjWwQqYyZz", 14, &direction, &ascent, &descent, &overall); text_line_spacing = ((double) (ascent + descent) * 1.4 / frame->x->yscale); } safe_XClearWindow(Glob->rdisplay, frame->x->drawable); line = strtok(text, "\n\0"); textx = frame->w_xmin + text_margin_x; texty = frame->w_ymax - text_margin_y; while (line != NULL) { GDrawString(XDEV, frame, Glob->text_gc, Glob->x_text_font, frame->psgc, XJ_LEFT, YJ_BELOW, textx, texty,line); texty -= text_line_spacing; line = strtok((char *) NULL, "\n\0"); } /* while */ }
void ptitle ( char *title, int *titleIndex ) #endif /*********************************************************************** * * Copyright 1997, University Corporation for Atmospheric Research. * * ptitle.c * * Image display routine. * * History: * * 11/97 COMET Original copy * 11/97 COMET Changed titleIndex to index starting at "0" * instead of "1"> * 3/98 COMET Added test for title display. * 3/98 COMET Added XFlush() call and reset text attributes. * 3/98 COMET Removed XFlush() and added color setting * 5/99 COMET Return if title length < 2 since a blank title * is lengthened to 1 by MakeMotTitle. * 5/99 COMET Commented out GEMPAK color setting functions * to get correct title color. * ***********************************************************************/ { WindowObjectType *wo; GlobalDataObjectType *gd; TitleObjectType *tot; int ipxm; Pixmap gempixmap; GC gemgc; Dimension width; /* string width in pixels */ Dimension iy, ix; int direction, ascent, descent; int lenstr; int itype = 0, lineWidth; int i, iret, verbose, titleLine; Dimension xmax, ymax; XCharStruct overall; Display *display; char *str; int gcolr, oldcolr; int mode, gtxfn, gtxhw, gtxwid, dtxfn, dtxhw, dtxwid; float gsztext, dsztext; int ibrdr, irrotn, ijust, dbrdr, drrotn, djust; /* chiz */ /*---------------------------------------------------------------------*/ verbose = GetVerboseLevel(); if( verbose > VERBOSE_0 ) printf ( "ptitle\n" ); wo = GetActiveWindowObject(); tot = wo->titleObject; gd = GetGlobalDataObject(); /* * Return if there is no title or if title is toggled off. * MakeMotTitle returns a title of at least one character. */ if ( title == NULL || strlen ( title ) < 2 ) return; if ( ! GetTitleFlag ( gd ) ) return; /* * Remove trailing blanks. */ strbrm ( title ); /* * Set the title line number. */ titleLine = -1 * (*titleIndex + 1); i = *titleIndex; str = strdup ( title ); strbrm ( str ); lenstr = strlen ( str ); /* chiz/Unidata update for xwcmn.h array of pixmaps */ ipxm = gemwindow[current_window].curpxm[0]; gempixmap = gemwindow[current_window].pxms[0][ipxm]; gemgc = gemwindow[current_window].gc; display = GetWindowObjectDisplay( wo ); /* * Make sure the text attributes are set correctly, since we are * bypassing GEMPAK routines to draw the title. */ /* gqtext ( >xfn, >xhw, &gsztext, >xwid, &ibrdr, &irrotn, &ijust, &iret); dstext ( >xfn, >xhw, &gsztext, >xwid, &ibrdr, &irrotn, &ijust, &dtxfn, &dtxhw, &dsztext, &dtxwid, &dbrdr, &drrotn, &djust, &iret); gqcolr ( &gcolr, &iret ); dscolr ( &gcolr, &oldcolr, &iret ); */ /* * Get string width for alignment */ XQueryTextExtents(gemdisplay, XGContextFromGC(gemgc), str, lenstr, &direction, &ascent, &descent, &overall); width = overall.width; lineWidth = ascent + descent; xmax = GetWindowObjectWidth ( wo ); ymax = GetWindowObjectHeight ( wo ); /* * Justify alignment for different value of *itype */ switch (itype) { case 0: /* centered */ ix = (xmax - width) / 2; break; case 1: /* right justified */ ix = xmax - width; break; case -1: /* left justified */ ix = 2; break; default: ix = 2; break; } /* * Draw string on window */ iy = ymax + ((titleLine + 1) * lineWidth) - descent; /* * Define cursor active region for title. */ if ( verbose > VERBOSE_1 ) printf(" title number = %d\n", i ); tot->region[i].x1 = ix; tot->region[i].y1 = iy; tot->region[i].x2 = ix + width; tot->region[i].y2 = iy - lineWidth; if ( verbose > VERBOSE_1 ) { printf(" region: %d,", tot->region[i].x1 ); printf(" %d", tot->region[i].y1 ); printf(" %d,", tot->region[i].x2 ); printf(" %d\n", tot->region[i].y2 ); } /* * Write title. */ XDrawString ( gemdisplay, gempixmap, gemgc, ix, iy, str, lenstr ); /* * Draw rectangle around string. */ /* XDrawRectangle ( gemdisplay, gempixmap, gemgc, tot->region[i].x1, tot->region[i].y2, tot->region[i].x2 - tot->region[i].x1, tot->region[i].y1 - tot->region[i].y2 ); */ Free ( str ); }