/* ** Draw a rectangle. The rectangle will have a 3-D appearance if ** flat==0 and a flat appearance if flat==1. ** ** We don't use Tk_Draw3DRectangle() because it doesn't work well ** when the background color is close to pure white or pure black. */ static void HtmlDrawRect( HtmlWidget *htmlPtr, /* The HTML widget */ Drawable drawable, /* Draw it here */ HtmlElement *src, /* Element associated with drawing */ int x, int y, int w, int h, /* Coordinates of the rectangle */ int depth, /* Width of the relief, or the flat line */ int relief /* The relief. TK_RELIEF_FLAT omits 3d */ ){ if( depth>0 ){ int i; GC gcLight, gcDark; XRectangle xrec[1]; if( relief!=TK_RELIEF_FLAT ){ int iLight, iDark; iLight = HtmlGetLightShadowColor(htmlPtr, src->base.style.bgcolor); gcLight = HtmlGetGC(htmlPtr, iLight, FONT_Any); iDark = HtmlGetDarkShadowColor(htmlPtr, src->base.style.bgcolor); gcDark = HtmlGetGC(htmlPtr, iDark, FONT_Any); if( relief==TK_RELIEF_SUNKEN ){ GC gcTemp = gcLight; gcLight = gcDark; gcDark = gcTemp; } }else{ gcLight = HtmlGetGC(htmlPtr, src->base.style.color, FONT_Any); gcDark = gcLight; } xrec[0].x = x; xrec[0].y = y; xrec[0].width = depth; xrec[0].height = h; XFillRectangles(htmlPtr->display, drawable, gcLight, xrec, 1); xrec[0].x = x+w-depth; XFillRectangles(htmlPtr->display, drawable, gcDark, xrec, 1); for(i=0; i<depth && i<h/2; i++){ XDrawLine(htmlPtr->display, drawable, gcLight, x+i, y+i, x+w-i-1, y+i); XDrawLine(htmlPtr->display, drawable, gcDark, x+i, y+h-i-1, x+w-i-1, y+h-i-1); } } if( h>depth*2 && w>depth*2 ){ GC gcBg; XRectangle xrec[1]; gcBg = HtmlGetGC(htmlPtr, src->base.style.bgcolor, FONT_Any); xrec[0].x = x + depth; xrec[0].y = y + depth; xrec[0].width = w - depth*2; xrec[0].height = h - depth*2; XFillRectangles(htmlPtr->display, drawable, gcBg, xrec, 1); } }
void text_with_bar(struct config *c, char *in, int error) { int nww, twb; /* If there was an error, display it instead of drawing a bar */ if(error) { text_with_text(c, in, error); return; } /* Calculate window size */ twb = text_width(&fontbig, c->text); nww = MAX(ww, twb + 30); XRectangle r = { CENTER(nww, barw), (wh/2), barw, barh }; moveresizeclear(nww, wh); draw_text(&fontbig, &fgcol, c->text, CENTER(nww, text_width(&fontbig, c->text)), CENTER(wh/2, fontbig.h)+fontbig.h); XSetForeground(dpy, gc, fgcol.pixel); /* border */ XDrawRectangles(dpy, win, gc, &r, 1); /* and bar */ r.width = (float)atoi(in)/100.0*(float)barw; XFillRectangles(dpy, win, gc, &r, 1); }
void TkDrawInsetFocusHighlight( Tk_Window tkwin, /* Window whose focus highlight ring is to be * drawn. */ GC gc, /* Graphics context to use for drawing the * highlight ring. */ int width, /* Width of the highlight ring, in pixels. */ Drawable drawable, /* Where to draw the ring (typically a pixmap * for double buffering). */ int padding) /* Width of padding outside of widget. */ { XRectangle rects[4]; rects[0].x = padding; rects[0].y = padding; rects[0].width = Tk_Width(tkwin) - (2 * padding); rects[0].height = width; rects[1].x = padding; rects[1].y = Tk_Height(tkwin) - width - padding; rects[1].width = Tk_Width(tkwin) - (2 * padding); rects[1].height = width; rects[2].x = padding; rects[2].y = width + padding; rects[2].width = width; rects[2].height = Tk_Height(tkwin) - 2*width - 2*padding; rects[3].x = Tk_Width(tkwin) - width - padding; rects[3].y = rects[2].y; rects[3].width = width; rects[3].height = rects[2].height; XFillRectangles(Tk_Display(tkwin), drawable, gc, rects, 4); }
ENTRYPOINT void draw_worm (ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); wormstruct *wp = &worms[MI_SCREEN(mi)]; unsigned long wcolor; int i; (void) memset((char *) wp->size, 0, wp->nc * sizeof (int)); for (i = 0; i < wp->nw; i++) { if (MI_NPIXELS(mi) > 2) { wcolor = (i + wp->chromo) % wp->nc; worm_doit(mi, i, wcolor); } else worm_doit(mi, i, (unsigned long) 0); } if (MI_WIN_IS_USE3D(mi)) { if (MI_WIN_IS_INSTALL(mi)) XSetFunction(display, gc, GXor); XSetForeground(display, gc, MI_RIGHT_COLOR(mi)); XFillRectangles(display, window, gc, &(wp->rects[0]), wp->size[0]); XSetForeground(display, gc, MI_LEFT_COLOR(mi)); XFillRectangles(display, window, gc, &(wp->rects[wp->maxsize]), wp->size[1]); if (MI_WIN_IS_INSTALL(mi)) XSetFunction(display, gc, GXcopy); } else if (MI_NPIXELS(mi) > 2) { for (i = 0; i < wp->nc; i++) { XSetForeground(display, gc, MI_PIXEL(mi, i)); XFillRectangles(display, window, gc, &(wp->rects[i * wp->maxsize]), wp->size[i]); } } else { XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi)); XFillRectangles(display, window, gc, &(wp->rects[0]), wp->size[0]); } if (++wp->chromo == (unsigned long) wp->nc) wp->chromo = 0; }
/** Draw a Rectangle in a drawable * \param dr Drawable * \param x X position * \param y Y position * \param w Width * \param h Height * \param color Color of the rectangle */ void draw_rectangle(Drawable dr, int x, int y, uint w, uint h, uint color) { XRectangle r = { x, y, w, h }; XSetForeground(dpy, gc, color); XFillRectangles(dpy, dr, gc, &r, 1); return; }
void drawme() { GC gc; gc = XCreateGC(dpy, root, 0, 0); XRectangle r = { 0, 0, mw, mh }; XSetForeground(dpy, gc, BlackPixel(dpy, screen)); XSetBackground(dpy, gc, WhitePixel(dpy, screen)); XFillRectangles(dpy, win, gc, &r, 1); setstruts(0); }
void XShadeRectangles(Display *display, Drawable drawable, XRectangle *rectangles, int nrectangles) { if (!INIT) { fprintf(stderr, "XShade Error: Tried to fill before INIT called\n"); exit(-1); } XFillRectangles(display, drawable, TileGC, rectangles, nrectangles); }
void XSpadFillRectangles(Display *dsply, Drawable drawable, XRectangle * rectangles, int nrectangles, int hue, int theshade) { XFillRectangles(dsply, drawable, SpadFillGC(dsply, hue, theshade, "XSpadFillRectangle"), rectangles, nrectangles); }
void XDitherRectangles(Display *display, Drawable drawable, GC gc, XRectangle *rectangles, int nrectangles) { if (!DITHERINIT) { fprintf(stderr, "XDither Error: Tried to fill before INIT called\n"); exit(-1); } XFillRectangles(display, drawable, gc, rectangles, nrectangles); }
/* Draw the selection background for the given block */ static void DrawSelectionBackground( HtmlWidget *htmlPtr, /* The HTML widget */ HtmlBlock *pBlock, /* The block whose background is drawn */ Drawable drawable, /* Draw the background on this drawable */ int x, int y /* Virtual coords of top-left of drawable */ ){ int xLeft, xRight; /* Left and right bounds of box to draw */ int yTop, yBottom; /* Top and bottom of box */ HtmlElement *p = 0; /* First element of the block */ Tk_Font font; /* Font */ GC gc; /* GC for drawing */ XRectangle xrec; /* Size of a filled rectangle to be drawn */ if( pBlock==0 || (pBlock->base.flags & HTML_Selected)==0 ){ TestPoint(0); return; } xLeft = pBlock->left - x; if( pBlock==htmlPtr->pSelStartBlock && htmlPtr->selStartIndex>0 ){ if( htmlPtr->selStartIndex >= pBlock->n ){ TestPoint(0); return; } p = pBlock->base.pNext; font = HtmlGetFont(htmlPtr, p->base.style.font); if( font==0 ) return; if( p->base.type==Html_Text ){ xLeft = p->text.x - x + Tk_TextWidth(font, pBlock->z, htmlPtr->selStartIndex); } } xRight = pBlock->right - x; if( pBlock==htmlPtr->pSelEndBlock && htmlPtr->selEndIndex<pBlock->n ){ if( p==0 ){ p = pBlock->base.pNext; font = HtmlGetFont(htmlPtr, p->base.style.font); if( font==0 ) return; } if( p->base.type==Html_Text ){ xRight = p->text.x - x + Tk_TextWidth(font, pBlock->z, htmlPtr->selEndIndex); } } yTop = pBlock->top - y; yBottom = pBlock->bottom - y; gc = HtmlGetGC(htmlPtr, COLOR_Selection, FONT_Any); xrec.x = xLeft; xrec.y = yTop; xrec.width = xRight - xLeft; xrec.height = yBottom - yTop; XFillRectangles(htmlPtr->display, drawable, gc, &xrec, 1); }
/** Render list of filled rectangles, \a prectInit in \a pDrawable on * the back-end server associated with \a pDrawable's screen. If the * offscreen optimization is enabled, only draw when \a pDrawable is at * least partially visible. */ void dmxPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrectFill, xRectangle *prectInit) { DMXScreenInfo *dmxScreen = &dmxScreens[pDrawable->pScreen->myNum]; dmxGCPrivPtr pGCPriv = DMX_GET_GC_PRIV(pGC); Drawable draw; if (DMX_GCOPS_OFFSCREEN(pDrawable)) return; DMX_GCOPS_SET_DRAWABLE(pDrawable, draw); XFillRectangles(dmxScreen->beDisplay, draw, pGCPriv->gc, (XRectangle *)prectInit, nrectFill); dmxSync(dmxScreen, FALSE); }
/** Draw a Graph in a drawable * \param dr Drawable * \param x X position * \param y Y position * \param w Width * \param h Height * \param color Color of the graph * \param data Array of bytes that will be draw */ void draw_graph(Drawable dr, int x, int y, uint w, uint h, uint color, char *data) { uint i; XSetForeground(dpy, gc, color); for(i = 0; i < w; ++i) { XRectangle r = { (x + i), (y + h - data[i]), 1, data[i] }; XFillRectangles(dpy, dr, gc, &r, 1); } return; }
void XFillRectangle( Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height) { XRectangle rectangle; rectangle.x = x; rectangle.y = y; rectangle.width = width; rectangle.height = height; XFillRectangles(display, d, gc, &rectangle, 1); }
static PyObject * PaxGC_FillRectangles(PaxGCObject * self, PyObject *args) { PyObject *arg1; XRectangle *rects_arg1; int nrects_arg1; if (!PyArg_ParseTuple(args, "O", &arg1)) return NULL; if (!checkshortlist(4, arg1, (short**)&rects_arg1, &nrects_arg1)) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "arg1 should be XRectangle[]"); return NULL; } XFillRectangles(self->display, self->drawable, self->gc, rects_arg1, nrects_arg1); PyMem_Free(rects_arg1); Py_INCREF(Py_None); return Py_None; }
static int X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { X11_RenderData *data = (X11_RenderData *) renderer->driverdata; SDL_Window *window = renderer->window; SDL_Rect clip, rect; unsigned long foreground; XRectangle *xrects, *xrect; int i, xcount; clip.x = 0; clip.y = 0; clip.w = window->w; clip.h = window->h; foreground = renderdrawcolor(renderer, 1); XSetForeground(data->display, data->gc, foreground); xrect = xrects = SDL_stack_alloc(XRectangle, count); xcount = 0; for (i = 0; i < count; ++i) { if (!SDL_IntersectRect(rects[i], &clip, &rect)) { continue; } xrect->x = (short)rect.x; xrect->y = (short)rect.y; xrect->width = (unsigned short)rect.w; xrect->height = (unsigned short)rect.h; ++xrect; ++xcount; if (data->makedirty) { SDL_AddDirtyRect(&data->dirty, &rect); } } if (xcount > 0) { XFillRectangles(data->display, data->drawable, data->gc, xrects, xcount); } SDL_stack_free(xpoints); return 0; }
void genericrectangle_test(Boolean fill) { XRectangle *rects; int num_rects = 200; int perimeter = 0, area = 0; int i; long totaltime; char buf[80]; num_rects *= X.percent; rects = (XRectangle *) malloc(sizeof(XRectangle) * num_rects); for (i=0;i<num_rects;++i) { rects[i].x = rects[i].y = 200 - i; rects[i].width = rects[i].height = 2 * i; perimeter += rects[i].width * 2 + rects[i].height * 2; area += rects[i].width * rects[i].height; } XSync(X.dpy,0); start_timer(); if (fill) XFillRectangles(X.dpy,X.win,X.gc,rects,num_rects); else XDrawRectangles(X.dpy,X.win,X.gc,rects,num_rects); XSync(X.dpy,0); totaltime = end_timer(); if (fill) snprintf(buf,sizeof buf,"%d pixels in %.2f seconds.",area,(double)totaltime/1000000.); else snprintf(buf,sizeof buf,"Total line length %d in %.3f seconds.",perimeter, (double)totaltime/1000000.); show_result(buf); free(rects); }
void drawentry(Entry *e) { int x, y, h, len; XRectangle r = { e->x, e->y, e->w, e->h }; const char *l; ulong *col; if(e->pressed) col = dc.press; else if(e->highlighted) col = dc.high; else col = dc.norm; XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); XSetForeground(dpy, dc.gc, dc.norm[ColFG]); r.height -= 1; r.width -= 1; XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); XSetForeground(dpy, dc.gc, col[ColFG]); l = e->label; len = strlen(l); h = dc.font.height; y = e->y + (e->h / 2) - (h / 2) + dc.font.ascent; x = e->x + (e->w / 2) - (textnw(l, len) / 2); if(dc.font.set) { XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, l, len); } else XDrawString(dpy, dc.drawable, dc.gc, x, y, l, len); XCopyArea(dpy, dc.drawable, win, dc.gc, e->x, e->y, e->w, e->h, e->x, e->y); }
int _zbar_window_draw_logo (zbar_window_t *w) { window_state_t *x = w->state; int screen = DefaultScreen(w->display); /* clear to white */ XSetForeground(w->display, x->gc, WhitePixel(w->display, screen)); XFillRectangle(w->display, w->xwin, x->gc, 0, 0, w->width, w->height); if(!x->logo_scale || !x->logo_zbars) return(0); XSetForeground(w->display, x->gc, BlackPixel(w->display, screen)); XFillRectangles(w->display, w->xwin, x->gc, x->logo_bars, 5); XSetLineAttributes(w->display, x->gc, 2 * x->logo_scale, LineSolid, CapRound, JoinRound); XSetForeground(w->display, x->gc, x->logo_colors[0]); XDrawLines(w->display, w->xwin, x->gc, x->logo_z, 4, CoordModeOrigin); if(x->exposed) { XIntersectRegion(x->logo_zbars, x->exposed, x->exposed); XSetRegion(w->display, x->gc, x->exposed); } else XSetRegion(w->display, x->gc, x->logo_zbars); XSetForeground(w->display, x->gc, x->logo_colors[1]); XDrawLines(w->display, w->xwin, x->gc, x->logo_z, 4, CoordModeOrigin); /* reset GC */ XSetLineAttributes(w->display, x->gc, 0, LineSolid, CapButt, JoinMiter); return(0); }
static void X_flush(aa_context * c) { struct xdriverdata *d=c->driverdata; int x, y, attr; int xs = 0, ys = 0; int l, same; int s = 0; int pos; attr = AA_NORMAL; alloctables(d); drawed = 0; area = 0; nrectangles[0] = 0; nrectangles[1] = 0; nrectangles[2] = 0; nrectangles[3] = 0; if (d->previoust == NULL) { d->previoust = malloc(d->width * d->height); d->previousa = calloc(d->width * d->height, 1); memset(d->previoust, ' ', d->width * d->height); } for (y = 0; y < aa_scrheight(c); y++) { s = l = 0; xs = 0; ys = y; for (x = 0; x < aa_scrwidth(c); x++) { pos = x + y * aa_scrwidth(c); if (s > 5 || (c->attrbuffer[pos] != attr && (c->textbuffer[pos] != ' ' || Black[c->attrbuffer[pos]] || Black[attr]))) { if (l - s) MyDrawString(d,attr, xs, ys, &c->textbuffer[xs + ys * aa_scrwidth(c)], l - s); attr = c->attrbuffer[pos]; s = l = 0; xs = x; ys = y; } if ((d->previoust[pos] == c->textbuffer[pos] && d->previousa[pos] == c->attrbuffer[pos]) || (!Black[attr] && d->previoust[pos] == ' ' && c->textbuffer[pos] == ' ' && !Black[d->previousa[pos]])) same = 1; else same = 0; if (xs == x && same) xs++; else { if (same) s++; else s = 0; l++; } } if (l - s) MyDrawString(d,attr, xs, ys, &c->textbuffer[xs + ys * aa_scrwidth(c)], l - s); } if (drawed) { memcpy(d->previousa, c->attrbuffer, d->width * d->height); memcpy(d->previoust, c->textbuffer, d->width * d->height); if (nrectangles[0]) XFillRectangles(d->dp, dr, d->blackGC, &rectangles(0, 0), nrectangles[0]); if (nrectangles[1]) XFillRectangles(d->dp, dr, d->normalGC, &rectangles(1, 0), nrectangles[1]); if (nrectangles[2]) XFillRectangles(d->dp, dr, d->specialGC, &rectangles(2, 0), nrectangles[2]); if (d->cvisible) XDrawLine(d->dp, dr, d->normalGC, d->Xpos * d->realfontwidth, (d->Ypos + 1) * d->fontheight - 1, (d->Xpos + 1) * d->realfontwidth - 1, (d->Ypos + 1) * d->fontheight - 1); for (y = 0; y < d->height; y++) { for (x = 0; x < NATT; x++) { if (nitem[y][x]) { X_setattr(d,x); XDrawText(d->dp, dr, d->currGC, 0, (y + 1) * d->fontheight - d->font_s->descent, &texty(y, x, 0), nitem[y][x]); if (x == 4) XDrawText(d->dp, dr, d->currGC, 1, (y + 1) * d->fontheight - d->font_s->descent, &texty(y, x, 0), nitem[y][x]); } } } if (d->pixmapmode) { if (nrectangles[3] && area < d->width*d->height/2 && nrectangles[3] < 5) { int i; /*fprintf (stderr, "%i %i\n",nrectangles[3], area);*/ for (i = 0; i < nrectangles[3]; i++) XClearArea (d->dp, d->wi, rectangles(3, i).x, rectangles(3,i).y, rectangles(3,i).width, rectangles(3,i).height, 0); } else XClearWindow(d->dp, d->wi); } /*if(!d->pixmapmode) */ XSync(d->dp, 0); } freetables(); }
int main( int argc, char *argv[] ) { Display *w_dis; Window w_win; XSetWindowAttributes w_att; GC w_gc; XEvent w_eve; XPoint p1[10], p2[10]; XSegment s1[10], s2[10]; XArc arc1[10], arc2[10]; XRectangle rect1[10], rect2[10]; char w_title[] = "kt-draw"; char w_icon_title[] = "ICON!"; int i; w_dis = XOpenDisplay( NULL ); w_win = XCreateSimpleWindow( w_dis, RootWindow( w_dis, 0 ),20 ,20 , 500, 400, 2, 0, 1); XSetStandardProperties( w_dis, w_win, w_title, w_icon_title, None, argv, argc, NULL ); w_att.override_redirect = True; XChangeWindowAttributes( w_dis, w_win, CWOverrideRedirect, &w_att ); XSelectInput( w_dis, w_win, ExposureMask ); XMapWindow( w_dis, w_win ); do{ XNextEvent( w_dis, &w_eve); }while( w_eve.type != Expose ); w_gc = XCreateGC( w_dis, w_win, 0, 0 ); XSetForeground( w_dis, w_gc, GetColor( w_dis, "green" )); // sample start XDrawLine( w_dis, w_win, w_gc, 50, 100, 450, 100 ); XDrawLine( w_dis, w_win, w_gc, 50, 100+50, 450, 100+50 ); for( i = 0; i < 10; i++ ) { s1[i].x1 = (i * 5) + 250; s1[i].y1 = 110; s1[i].x2 = (i * 5) + 250; s1[i].y2 = 130; } XDrawSegments( w_dis, w_win, w_gc, s1, 10 ); for( i = 0; i < 10; i++ ) { s2[i].x1 = 310; s2[i].y1 = (i * 4) + 110; s2[i].x2 = 350; s2[i].y2 = (i * 4) + 110; } XDrawSegments( w_dis, w_win, w_gc, s2, 10 ); for( i = 0; i < 10; i++ ) { p1[i].x = (i * 5) + 280; if (i==0 || i==2 || i==4 || i==6 || i==8 ) { p1[i].y = (i * 5) + 200; } else { p1[i].y = (i * (-5)) + 200; } } XDrawLines( w_dis, w_win, w_gc, p1, 10, CoordModeOrigin ); p2[0].x = 340; p2[0].y = 200; for( i = 1; i < 10; i++ ) { p2[i].x = 5; if (i==0 || i==2 || i==4 || i==6 || i==8 ) { p2[i].y = i * 5; } else { p2[i].y = i * (-5); } } XDrawLines( w_dis, w_win, w_gc, p2, 10, CoordModePrevious ); XDrawPoint( w_dis, w_win, w_gc, 55, 105 ); XDrawPoint( w_dis, w_win, w_gc, 55+10, 105+10 ); for( i = 0; i < 10; i++ ) { p1[i].x = (i * 5) + 100; p1[i].y = 300; } XDrawPoints( w_dis, w_win, w_gc, p1, 10, CoordModeOrigin ); p2[0].x = 100; p2[0].y = 310; for( i = 1; i < 10; i++ ) { p2[i].x = 5; p2[i].y = 0; } XDrawPoints( w_dis, w_win, w_gc, p2, 10, CoordModePrevious ); XDrawArc( w_dis, w_win, w_gc, 50, 50, 50, 50, 45*64, 135*64 ); XDrawArc( w_dis, w_win, w_gc, 50+100, 50, 50, 50, (45+30)*64, (135+30)*64 ); for( i = 0; i < 10; i++ ) { arc1[i].x = (i * 15) + 250; arc1[i].y = 50; arc1[i].width = 10; arc1[i].height = 10; arc1[i].angle1 = 0; arc1[i].angle2 = ((i + 1) * 36) * 64; } XDrawArcs( w_dis, w_win, w_gc, arc1, 10 ); for( i = 0; i < 10; i++ ) { arc2[i].x = (i * 15) + 250; arc2[i].y = 50 + 15; arc2[i].width = 10; arc2[i].height = 10; arc2[i].angle1 = 0; arc2[i].angle2 = ((10 - i) * 36) * 64; } XDrawArcs( w_dis, w_win, w_gc, arc2, 10 ); XFillArc( w_dis, w_win, w_gc, 100, 50, 50, 50, 45*64, 135*64 ); XFillArc( w_dis, w_win, w_gc, 100+100, 50, 50, 50, (45+30)*64, (135+30)*64 ); for( i = 0; i < 10; i++ ) { arc1[i].x = (i * 15) + 250; arc1[i].y = 50 + 25; arc1[i].width = 10; arc1[i].height = 10; arc1[i].angle1 = 0; arc1[i].angle2 = ((i + 1) * 36) * 64; } XFillArcs( w_dis, w_win, w_gc, arc1, 10 ); for( i = 0; i < 10; i++ ) { arc2[i].x = (i * 15) + 250; arc2[i].y = 50 + 37; arc2[i].width = 10; arc2[i].height = 10; arc2[i].angle1 = 0; arc2[i].angle2 = ((10 - i) * 36) * 64; } XFillArcs( w_dis, w_win, w_gc, arc2, 10 ); XDrawRectangle( w_dis, w_win, w_gc, 60, 110, 160, 210 ); XDrawRectangle( w_dis, w_win, w_gc, 60+30, 110+30, 160, 210 ); for( i = 0; i < 10; i++ ) { rect1[i].x = (i * 15) + 280; rect1[i].y = 300; rect1[i].width = 10; rect1[i].height = 10; } XDrawRectangles( w_dis, w_win, w_gc, rect1, 10 ); for( i = 0; i < 10; i++ ) { rect2[i].x = (i * 15) + 280; rect2[i].y = 300 + 20; rect2[i].width = 10; rect2[i].height = 10; } XDrawRectangles( w_dis, w_win, w_gc, rect2, 10 ); XFillRectangle( w_dis, w_win, w_gc, 70, 120, 100, 100 ); XFillRectangle( w_dis, w_win, w_gc, 70+100, 120+100, 100, 100 ); for( i = 0; i < 10; i++ ) { rect1[i].x = (i * 15) + 280; rect1[i].y = 300 + 40; rect1[i].width = 10; rect1[i].height = 10; } XFillRectangles( w_dis, w_win, w_gc, rect1, 10 ); for( i = 0; i < 10; i++ ) { rect2[i].x = (i * 15) + 280; rect2[i].y = 300 + 60; rect2[i].width = 10; rect2[i].height = 10; } XFillRectangles( w_dis, w_win, w_gc, rect2, 10 ); // sample end XFlush( w_dis ); printf( "Push return key." ); getchar( ); XDestroyWindow( w_dis , w_win ); XCloseDisplay( w_dis ); return( 0 ); }
static Bool draw_state(ModeInfo * mi, int state) { demonstruct *dp = &demons[MI_SCREEN(mi)]; GC gc; XRectangle *rects; CellList *current; if (!state) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); } else if (MI_NPIXELS(mi) >= NUMSTIPPLES) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, (((int) state - 1) * MI_NPIXELS(mi) / (dp->states - 1)) % MI_NPIXELS(mi))); gc = MI_GC(mi); } else { XGCValues gcv; #ifdef DO_STIPPLE gcv.stipple = dp->pixmaps[(state - 1) % (NUMSTIPPLES - 1)]; #endif /* DO_STIPPLE */ gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), dp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = dp->stippledGC; } if (dp->neighbors == 6) { /* Draw right away, slow */ current = dp->cellList[state]; while (current) { int col, row, ccol, crow; col = current->pt.x; row = current->pt.y; ccol = 2 * col + !(row & 1), crow = 2 * row; dp->shape.hexagon[0].x = dp->xb + ccol * dp->xs; dp->shape.hexagon[0].y = dp->yb + crow * dp->ys; if (dp->xs == 1 && dp->ys == 1) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.hexagon[0].x, dp->shape.hexagon[0].y); else XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.hexagon, 6, Convex, CoordModePrevious); current = current->next; } } else if (dp->neighbors == 4 || dp->neighbors == 8) { /* Take advantage of XDrawRectangles */ int ncells = 0; /* Create Rectangle list from part of the cellList */ if ((rects = (XRectangle *) malloc(dp->ncells[state] * sizeof (XRectangle))) == NULL) { return False; } current = dp->cellList[state]; while (current) { rects[ncells].x = dp->xb + current->pt.x * dp->xs; rects[ncells].y = dp->yb + current->pt.y * dp->ys; rects[ncells].width = dp->xs - (dp->xs > 3); rects[ncells].height = dp->ys - (dp->ys > 3); current = current->next; ncells++; } /* Finally get to draw */ XFillRectangles(MI_DISPLAY(mi), MI_WINDOW(mi), gc, rects, ncells); /* Free up rects list and the appropriate part of the cellList */ (void) free((void *) rects); } else { /* TRI */ current = dp->cellList[state]; while (current) { int col, row, orient; col = current->pt.x; row = current->pt.y; orient = (col + row) % 2; /* O left 1 right */ dp->shape.triangle[orient][0].x = dp->xb + col * dp->xs; dp->shape.triangle[orient][0].y = dp->yb + row * dp->ys; if (dp->xs <= 3 || dp->ys <= 3) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, ((orient) ? -1 : 1) + dp->shape.triangle[orient][0].x, dp->shape.triangle[orient][0].y); else { if (orient) dp->shape.triangle[orient][0].x += (dp->xs / 2 - 1); else dp->shape.triangle[orient][0].x -= (dp->xs / 2 - 1); XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.triangle[orient], 3, Convex, CoordModePrevious); } current = current->next; } } free_state(dp, state); return True; }
static void x_video_updatelist(struct updateblock *ptr, int num) { int width = 8; static int video_updating; u8 *blk; u32 lx = vwxsz, ly = vwysz, mx = 0, my = 0; XRectangle points[17][64], *pptr[17]; int rects = 0, pixels = 0; int offs = (128 - xsize / 2) * vwxm; int total = num, solid = 0; if (!exposed || !num || vwin_iconified || video_updating) return; video_updating = 1; while (num--) { int i; int j; u8 c; int d; ptr->r *= vwym; ptr->c = ptr->c * vwxm; if (video_block_is_solid(ptr, !using_palette, &c)) { XSetForeground(x11_dpy, vgc, cmap[c]); XFillRectangle(x11_dpy, vwin, vgc, ptr->c + offs, ptr->r, vwxm * width, vwym * 8); solid++; } else { /* Reset lists for each color (remember text mode has color==16) */ for (c = 0; c < 17; c++) pptr[c] = points[c]; /* Generate a list of rectangles for each color in the 8x8 block */ for (i = 0; i < 8; i++) { j = 0; while (j < width) { /* Find the longest run of pixels of this color */ c = ptr->data[j]; d = 1; while (j + d < width && ptr->data[j + d] == c) d++; pptr[c]->x = ptr->c + j * vwxm + offs; pptr[c]->y = ptr->r + i * vwym; pptr[c]->width = vwxm * d; pptr[c]->height = vwym; rects++; pixels += pptr[c]->width * pptr[c]->height; pptr[c]++; j += d; } ptr->data += UPDATEBLOCK_ROW_STRIDE; } for (c = 0; c <= 16; c++) { if (pptr[c] > points[c]) { module_logger(&X_Video, _L | L_3, _("Got color %d (%x)\n"), c, cmap[c]); XSetForeground(x11_dpy, vgc, cmap[c]); XFillRectangles(x11_dpy, vwin, vgc, points[c], pptr[c] - points[c]); } } } ptr++; } module_logger(&X_Video, _L | L_2, _("Drew %d rects, %d pixels\n"), rects, pixels); module_logger(&X_Video, _L|L_2, _("%d/%d solid\n"), solid, total); video_updating = 0; }
int main (int argc, char **argv) { /* Variables used for XWindow. */ Display *my_display; /* Display unit. */ Window root_id; /* Root window. */ Window my_window; /* First window opened. */ Window wind_pic; /* Window with picture. */ Window wind_exit; /* Exit window. */ Window wind_scale; /* Color scale window. */ GC my_gc; /* Gc for my_window. */ XSizeHints window_hints; /* Hints for 1st window. */ XEvent event_received; /* Events. */ long input_event_mask; /* Input event mask that are to * be responded to. */ unsigned long black; /* Black pixel value. */ unsigned long white; /* White pixel value. */ int screen=0; /* Used for getting colors. */ XColor colval[MAXCOL]; /* Color values. */ XRectangle rect[MAXARR]; /* Array for drawing rectangles. */ char **a=(char **)NULL; /* Place holder for XSetStandard Properties. */ const char winttl[] = "SEE"; /* Window title. */ const char quit[] = "QUIT"; /* Exit label. */ Font font; /* Structure for setting font. */ /* Other variables. */ FILE *fpr; /* Used to read a file. */ FILE *fpw; /* Used to write a file. */ char file[MAXFIL]; /* File to be read. */ char line[151]; /* Used to read one line of a file. */ size_t main_w, main_h; /* Width & height of main window. */ size_t wide, high; /* Width and height of picture window. */ double pixval[MAXPIX][MAXPIX];/* Pixel value (width, height). */ double min=0.0, max=0.0; /* Minimum & maximum pixel values. */ int i, j, k, m; /* Loop counters. */ double r; /* Temporary variable. */ double dcol; /* Color step. */ double pixbin[MAXCOL + 1]; /* Pixel bins. */ double dpix; /* Delta between pixel bins. */ int color[MAXPIX][MAXPIX]; /* Indicates color. */ int icol; /* Indicates color shading. */ double check; /* Used for finding colors. */ char string[11]; /* Used to write a label. */ int flag=0; /* Color flag. */ int lstarr; /* Last color array. */ int flag_pix; /* 0=>no pix file written, 1=>pix file written. */ char file_pix[MAXFIL]; /* Pix file name. */ unsigned char c; /* Used to write pix file. */ int ret; int ch; struct colstr *array = NULL; /* Array for color information. */ bu_opterr = 0; while ((ch = bu_getopt(argc, argv, "h?")) != -1) { if (bu_optopt == '?') ch = 'h'; switch (ch) { case 'h': fprintf(stderr,"ir-X is interactive; sample session in 'man' page\n"); bu_exit(1,NULL); default: break; } } fprintf(stderr," Program continues running:\n"); array = (struct colstr *)bu_calloc(MAXCOL + EXTRA, sizeof(struct colstr), "allocate colstr array"); /* Get file name to be read. */ printf("Enter name of file to be read (%d char max).\n\t", MAXFIL); (void)fflush(stdout); ret = scanf("%25s", file); if (ret == 0) perror("scanf"); /* Find what color shading to use. */ printf("Indicate type of color shading to use.\n"); printf("\t0 - gray\n"); printf("\t1 - red\n"); printf("\t2 - black-blue-cyan-green-yellow-white\n"); printf("\t3 - black-blue-magenta-red-yellow-white\n"); (void)fflush(stdout); ret = scanf("%d", &icol); if (ret == 0) perror("scanf"); if ((icol != 1) && (icol != 2) && (icol != 3)) icol = 0; /* Determine if a pix file is to be written. */ flag_pix = 0; printf("Do you wish to create a pix file (0-no, 1-yes)?\n\t"); (void)fflush(stdout); ret = scanf("%d", &flag_pix); if (ret == 0) perror("scanf"); if (flag_pix != 1) flag_pix = 0; else { printf("Enter name of the pix file to be created "); printf("(%d char max).\n\t", MAXFIL); (void)fflush(stdout); ret = scanf("%25s", file_pix); if (ret == 0) perror("scanf"); } printf("Zeroing color info array "); (void)fflush(stdout); /* Zero color info array. */ for (i=0; i<(MAXCOL + EXTRA); i++) { array[i].cnt = 0; array[i].more = 0; } lstarr = MAXCOL; printf("- finished zeroing\n"); (void)fflush(stdout); printf("Setting up color scale "); (void)fflush(stdout); /* Set up color scale. */ dcol = (65535.0 + 1.0) / MAXCOL; if (icol == 0) { /* Shades of gray. */ printf("-shades of gray "); (void)fflush(stdout); for (i=0; i<MAXCOL; i++) { colval[i].red = (unsigned short)((double)i * dcol); colval[i].green = (unsigned short)((double)i * dcol); colval[i].blue = (unsigned short)((double)i * dcol); } } else if (icol == 1) { /* Shades of red. */ printf("- shades of red "); (void)fflush(stdout); for (i=0; i<MAXCOL; i++) { colval[i].red = (unsigned short)((double)i * dcol); colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)0; } } else if (icol == 2) { /* Black-blue-cyan-green-yellow-white. */ printf("- black-blue-cyan-green-yellow-white "); (void)fflush(stdout); if (MAXCOL > 1280.0) { printf("Maximum number of colors, %d, is ", MAXCOL); printf("greater than 1280.\n"); printf("This may create problems.\n"); } /* Color step. */ dcol = 1280. / MAXCOL; i = 0; /* Colors (0, 0, 0) to (0, 0, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } /* Colors (0, 0, 255) to (0, 255, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)(check * 256.0); colval[i].blue = (unsigned short)(255 * 256); check += dcol; i++; } /* Colors (0, 255, 255) to (0, 255, 0). */ check = 255.0; while ((check >= 0.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)(check * 256.0); check -= dcol; i++; } /* Colors (0, 255, 0) to (255, 255, 0). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(check * 256.0); colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)0; check += dcol; i++; } /* Colors (255, 255, 0) to (255, 255, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } } else if (icol == 3) { /* Black-blue-magenta-red-yellow-white. */ printf("- black-blue-magenta-red-yellow-white "); (void)fflush(stdout); if (MAXCOL > 1280.0) { printf("Maximum number of colors, %d, is ", MAXCOL); printf("greater than 1280.\n"); printf("This may create problems.\n"); } /* Color step. */ dcol = 1280. / MAXCOL; i = 0; /* Colors (0, 0, 0) to (0, 0, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)0; colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } /* Colors (0, 0, 255) to (255, 0, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(check * 256.0); colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(255 * 256); check += dcol; i++; } /* Colors (255, 0, 255) to (255, 0, 0). */ check = 255.0; while ((check >= 0.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)0; colval[i].blue = (unsigned short)(check * 256.0); check -= dcol; i++; } /* Colors (255, 0, 0) to (255, 255, 0). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)(check * 256.0); colval[i].blue = (unsigned short)0; check += dcol; i++; } /* Colors (255, 255, 0) to (255, 255, 255). */ check = 0.0; while ((check <= 255.0) && (i < MAXCOL)) { colval[i].red = (unsigned short)(255 * 256); colval[i].green = (unsigned short)(255 * 256); colval[i].blue = (unsigned short)(check * 256.0); check += dcol; i++; } } printf("- finished.\n"); (void)fflush(stdout); printf("Reading file "); (void)fflush(stdout); /* Open file for reading. */ fpr = fopen(file, "rb"); /* Check for non-existent file. */ while (fpr == NULL) { printf("\nThis file does not exist, please try again.\n"); (void)fflush(stdout); ret = scanf("%25s", file); if (ret == 0) { bu_exit(EXIT_FAILURE, "ir-X - scanf failure - no file to work with!!\n"); } fpr = fopen(file, "rb"); } /* Read width and height of window. */ (void)bu_fgets(line, 150, fpr); { unsigned long w, h; sscanf(line, "%lu %lu", &w, &h); wide = w; high = h; } /* Check that width and height are not too big. */ if (wide > (size_t)MAXPIX) { printf("The width of the window, %lu, is greater\n", (unsigned long)wide); printf("than the maximum for width, %lu. Press\n", (unsigned long)MAXPIX); printf("delete to end program.\n"); (void)fflush(stdout); } if (high > MAXPIX) { printf("The height of the window, %lu, is greater\n", (unsigned long)wide); printf("than the maximum for height, %lu. Press\n", (unsigned long)MAXPIX); printf("delete to end program.\n"); (void)fflush(stdout); } /* Read pixel values. */ for (i=0; i<(int)high; i++) { for (j=0; j<(int)wide; j++) { (void)bu_fgets(line, 150, fpr); sscanf(line, "%lf", &pixval[j][i]); } } /* Close file. */ (void)fclose(fpr); printf("- file read.\n"); (void)fflush(stdout); /* Print out width and height of window. */ printf("Width: %lu\n", (unsigned long)wide); printf("Height: %lu\n", (unsigned long)high); (void)fflush(stdout); printf("Finding min & max.\n"); (void)fflush(stdout); /* Find minimum and maximum of pixel values. */ for (i=0; (size_t)i<high; i++) { for (j=0; (size_t)j<wide; j++) { if ((j==0) && (i==0)) { min = pixval[j][i]; max = pixval[j][i]; } V_MIN(min, pixval[j][i]); V_MAX(max, pixval[j][i]); } } /* Write minimum and maximum pixel values. */ printf("Minimum: %f\n", min); printf("Maximum: %f\n", max); (void)fflush(stdout); printf("Finding pixel bins "); (void)fflush(stdout); /* Find pixel bins. */ dpix = (max - min) / MAXCOL; pixbin[0] = min; for (i=1; i<MAXCOL; i++) { pixbin[i] = pixbin[i-1] + dpix; } pixbin[MAXCOL] = max; /* Find the color for each pixel. */ for (i=0; (size_t)i<high; i++) { for (j=0; (size_t)j<wide; j++) { /* Determine the color associated with pixval[j][i]. */ m = 0; k = 0; color[j][i] = 0; while ((m == 0) && (k < MAXCOL)) { if ((pixval[j][i] > pixbin[k]) && (pixval[j][i] <= pixbin[k + 1])) { color[j][i] = k; m = 1; } k++; } } } printf("- found pixel bins.\n"); (void)fflush(stdout); printf("Putting color info in arrays "); (void)fflush(stdout); /* Put color info in arrays. */ for (i=0; (size_t)i<high; i++) { for (j=0; (size_t)j<wide; j++) { if (array[color[j][i]].cnt < MAXARR) { array[color[j][i]].x1[array[color[j][i]].cnt] = j; array[color[j][i]].y1[array[color[j][i]].cnt] = i; array[color[j][i]].cnt++; } else { if (array[color[j][i]].more == 0) { if (lstarr < (MAXCOL + EXTRA)) { array[color[j][i]].more = lstarr; k = lstarr; lstarr++; array[k].x1[array[k].cnt] = j; array[k].y1[array[k].cnt] = i; array[k].cnt++; } else { flag = 1; } } else { k = array[color[j][i]].more; if (array[k].cnt < MAXARR) { array[k].x1[array[k].cnt] = j; array[k].y1[array[k].cnt] = i; array[k].cnt++; } else { flag = 1; } } } } } printf("- color info in arrays.\n"); (void)fflush(stdout); if (flag != 0) { printf("There too many pixels of one color. Note that\n"); printf("this means there is something wrong with the\n"); printf("picture!\n"); (void)fflush(stdout); } /* Set up window to be the size that was read. */ /* Open display. */ my_display = XOpenDisplay(NULL); /* Get id of parent (root is parent). */ root_id = DefaultRootWindow(my_display); /* Find value for black & white. */ black = BlackPixel(my_display, DefaultScreen(my_display)); white = WhitePixel(my_display, DefaultScreen(my_display)); /* Create a window & find its id. */ main_w = wide + (unsigned int)150; main_h = high + (unsigned int)150; my_window = XCreateSimpleWindow(my_display, root_id, 0, 0, main_w, main_h, 50, white, black); /* Set appropriate fields in window hits structure. */ /* This is only done for the first window created. */ window_hints.width = (int)main_w; window_hints.height = (int)main_h; window_hints.flags = PSize; /* Inform window manager of hints. */ /* Set XSetStandarProperties instead of XSetNormalHints. */ XSetStandardProperties(my_display, my_window, winttl, winttl, None, a, 0, &window_hints); /* Create picture window & find its id. */ wind_pic = XCreateSimpleWindow(my_display, my_window, 20, 20, wide, high, 5, white, black); /* Create exit window & find its id. */ wind_exit = XCreateSimpleWindow(my_display, my_window, (wide + 30), (high + 65), 80, 30, 5, white, black); /* Create color scale window & find its id. */ wind_scale = XCreateSimpleWindow(my_display, my_window, 10, (high + 50), (2 * MAXCOL), 60, 5, white, black); /* Select input event masks that are to be responded to (exposure). */ input_event_mask = ExposureMask | ButtonPressMask; /* Notify server about input event masks. */ XSelectInput(my_display, my_window, ExposureMask); XSelectInput(my_display, wind_pic, ExposureMask); XSelectInput(my_display, wind_exit, input_event_mask); XSelectInput(my_display, wind_scale, input_event_mask); /* Map window to display so that it will show up. */ XMapWindow(my_display, my_window); /* Map picture window, exit window, & color scale window to display */ /* so that they will show up. */ XMapWindow(my_display, wind_pic); XMapWindow(my_display, wind_exit); XMapWindow(my_display, wind_scale); /* Create graphics context (gc) for my window. */ my_gc = XCreateGC(my_display, my_window, None, NULL); /* Create a loop so that events will occur. */ for (;;) { XNextEvent(my_display, &event_received); switch (event_received.type) { /* Do the following when an expose occurs. */ case Expose: /* Code for expose event. */ /* Draw the picture if the picture window is exposed. */ if (event_received.xexpose.window == wind_pic) { /* START # 1 */ /* Send groups of color to screen. */ for (k=0; k<MAXCOL; k++) { if (array[k].cnt > 0) { for (i=0; i<array[k].cnt; i++) { rect[i].x = array[k].x1[i]; rect[i].y = array[k].y1[i]; rect[i].width = 1; rect[i].height = 1; } m = array[k].cnt; XAllocColor(my_display, DefaultColormap(my_display, screen), &colval[k]); XSetForeground(my_display, my_gc, colval[k].pixel); XFillRectangles(my_display, wind_pic, my_gc, rect, m); /* Send extra array if there is a lot of that color. */ if (array[k].more > 0) { j = array[k].more; for (i=0; i<array[j].cnt; i++) { rect[i].x = array[j].x1[i]; rect[i].y = array[j].y1[i]; rect[i].width = 1; rect[i].height = 1; } m = array[j].cnt; XAllocColor(my_display, DefaultColormap(my_display, screen), &colval[k]); XSetForeground(my_display, my_gc, colval[k].pixel); XFillRectangles(my_display, wind_pic, my_gc, rect, m); } } } } /* END # 1 */ /* If exit window is exposed write label. */ else if (event_received.xexpose.window == wind_exit) { /* START # 2 */ XSetForeground(my_display, my_gc, white); font = XLoadFont(my_display, "8x13bold"); XSetFont(my_display, my_gc, font); XDrawString(my_display, wind_exit, my_gc, 25, 20, quit, strlen(quit)); } /* END # 2 */ /* If color scale window is exposed put up color scale. */ else if (event_received.xexpose.window == wind_scale) { for (i=0; i<MAXCOL; i++) { XAllocColor(my_display, DefaultColormap(my_display, screen), &colval[i]); XSetForeground(my_display, my_gc, colval[i].pixel); XFillRectangle(my_display, wind_scale, my_gc, (i * 2), 0, 2, 30); } /* Write label. */ XSetForeground(my_display, my_gc, white); font = XLoadFont(my_display, "8x13bold"); XSetFont(my_display, my_gc, font); (void)sprintf(string, "%.0f", min); XDrawString(my_display, wind_scale, my_gc, 2, 45, string, strlen(string)); r = min + (max - min) / 4.0; (void)sprintf(string, "%.0f", r); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 / 4 - 8), 45, string, strlen(string)); r = min + (max - min) / 2.0; (void)sprintf(string, "%.0f", r); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 / 2 - 8), 45, string, strlen(string)); r = min + (max - min) * 3. / 4.0; (void)sprintf(string, "%.0f", r); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 * 3 / 4 - 8), 45, string, strlen(string)); (void)sprintf(string, "%.0f", max); XDrawString(my_display, wind_scale, my_gc, (MAXCOL * 2 - 16), 45, string, strlen(string)); } break; /* Do the following if a mouse press occurs. */ case ButtonPress: if (event_received.xbutton.window == wind_exit) { XCloseDisplay(my_display); /* Create pix file if necessary. */ if (flag_pix == 1) { /* START # 1. */ /* Open pix file to be written to. */ fpw = fopen(file_pix, "wb"); /* Write colors to file. */ for (i=high; i>0; i--) { /* START # 2. */ for (j=0; (size_t)j<wide; j++) { /* START # 3. */ c = (unsigned char)((int)(colval[color[j][i-1]].red / 256)); putc(c, fpw); c = (unsigned char)((int) (colval[color[j][i-1]].green / 256)); putc(c, fpw); c = (unsigned char)((int)(colval[color[j][i-1]].blue / 256)); putc(c, fpw); } /* END # 3. */ } /* END # 2. */ /* Close file. */ (void)fclose(fpw); printf("Pix file, %s, has been written.\n", file_pix); (void)fflush(stdout); } /* END # 1. */ bu_free(array, "free colstr array"); return 0; } break; } } bu_free(array, "free colstr array"); return 0; }
/* ** Display a single HtmlBlock. This is where all the drawing ** happens. */ void HtmlBlockDraw( HtmlWidget *htmlPtr, /* The main HTML widget */ HtmlBlock *pBlock, /* Block which needs to be drawn */ Drawable drawable, /* Draw the line on this */ int drawableLeft, /* Virtual coordinate of left edge of drawable */ int drawableTop, /* Virtual coordinate of top edge of drawable */ int drawableWidth, /* Width of the drawable */ int drawableHeight /* Height of the drawable */ ){ Tk_Font font; /* Font to use to render text */ GC gc; /* A graphics context */ HtmlElement *src; /* HtmlElement holding style information */ HtmlElement *pTable; /* The table (when drawing part of a table) */ int x, y; /* Where to draw */ if( pBlock==0 ){ TestPoint(0); return; } src = pBlock->base.pNext; while( src && (src->base.flags & HTML_Visible)==0 ){ src = src->base.pNext; TestPoint(0); } if( src==0 ){ TestPoint(0); return; } if( pBlock->n>0 ){ /* We must be dealing with plain old text */ if( src->base.type==Html_Text ){ x = src->text.x; y = src->text.y; TestPoint(0); }else{ CANT_HAPPEN; return; } if( pBlock->base.flags & HTML_Selected ){ HtmlLock(htmlPtr); DrawSelectionBackground(htmlPtr, pBlock, drawable, drawableLeft, drawableTop); if( HtmlUnlock(htmlPtr) ) return; } gc = HtmlGetGC(htmlPtr, src->base.style.color, src->base.style.font); font = HtmlGetFont(htmlPtr, src->base.style.font); if( font==0 ) return; Tk_DrawChars(htmlPtr->display, drawable, gc, font, pBlock->z, pBlock->n, x - drawableLeft, y - drawableTop); if( src->base.style.flags & STY_Underline ){ Tk_UnderlineChars(htmlPtr->display, drawable, gc, font, pBlock->z, x - drawableLeft, y-drawableTop, 0, pBlock->n); } if( src->base.style.flags & STY_StrikeThru ){ XRectangle xrec; xrec.x = pBlock->left - drawableLeft; xrec.y = (pBlock->top + pBlock->bottom)/2 - drawableTop; xrec.width = pBlock->right - pBlock->left; xrec.height = 1 + (pBlock->bottom - pBlock->top > 15); XFillRectangles(htmlPtr->display, drawable, gc, &xrec, 1); } if( pBlock==htmlPtr->pInsBlock && htmlPtr->insStatus>0 ){ int x; XRectangle xrec; if( htmlPtr->insIndex < pBlock->n ){ x = src->text.x - drawableLeft; x += Tk_TextWidth(font, pBlock->z, htmlPtr->insIndex); }else{ x = pBlock->right - drawableLeft; } if( x>0 ){ TestPoint(0); x--; } xrec.x = x; xrec.y = pBlock->top - drawableTop; xrec.width = 2; xrec.height = pBlock->bottom - pBlock->top; XFillRectangles(htmlPtr->display, drawable, gc, &xrec, 1); } }else{ /* We are dealing with a single HtmlElement which contains something ** other than plain text. */ int top, btm, cntr; int cnt, w; char zBuf[30]; switch( src->base.type ){ case Html_LI: x = src->li.x; y = src->li.y; cntr = (top+btm)/2; switch( src->li.type ){ case LI_TYPE_Enum_1: sprintf(zBuf,"%d.",src->li.cnt); TestPoint(0); break; case LI_TYPE_Enum_A: GetLetterIndex(zBuf,src->li.cnt,1); TestPoint(0); break; case LI_TYPE_Enum_a: GetLetterIndex(zBuf,src->li.cnt,0); TestPoint(0); break; case LI_TYPE_Enum_I: GetRomanIndex(zBuf,src->li.cnt,1); TestPoint(0); break; case LI_TYPE_Enum_i: GetRomanIndex(zBuf,src->li.cnt,0); TestPoint(0); break; default: zBuf[0] = 0; TestPoint(0); break; } gc = HtmlGetGC(htmlPtr, src->base.style.color, src->base.style.font); switch( src->li.type ){ case LI_TYPE_Undefined: case LI_TYPE_Bullet1: XFillArc(htmlPtr->display, drawable, gc, x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7, 0, 360*64); TestPoint(0); break; case LI_TYPE_Bullet2: XDrawArc(htmlPtr->display, drawable, gc, x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7, 0, 360*64); TestPoint(0); break; case LI_TYPE_Bullet3: XDrawRectangle(htmlPtr->display, drawable, gc, x - 7 - drawableLeft, y - 8 - drawableTop, 7, 7); TestPoint(0); break; case LI_TYPE_Enum_1: case LI_TYPE_Enum_A: case LI_TYPE_Enum_a: case LI_TYPE_Enum_I: case LI_TYPE_Enum_i: cnt = strlen(zBuf); font = HtmlGetFont(htmlPtr, src->base.style.font); if( font==0 ) return; w = Tk_TextWidth(font, zBuf, cnt); Tk_DrawChars(htmlPtr->display, drawable, gc, font, zBuf, cnt, x - w - drawableLeft, y - drawableTop); TestPoint(0); break; } break; case Html_HR: { int relief = htmlPtr->ruleRelief; switch( relief ){ case TK_RELIEF_RAISED: case TK_RELIEF_SUNKEN: break; default: relief = TK_RELIEF_FLAT; break; } HtmlDrawRect(htmlPtr, drawable, src, src->hr.x - drawableLeft, src->hr.y - drawableTop, src->hr.w, src->hr.h, 1, relief); break; } case Html_TABLE: { int relief = htmlPtr->tableRelief; switch( relief ){ case TK_RELIEF_RAISED: case TK_RELIEF_SUNKEN: break; default: relief = TK_RELIEF_FLAT; break; } HtmlDrawRect(htmlPtr, drawable, src, src->table.x - drawableLeft, src->table.y - drawableTop, src->table.w, src->table.h, src->table.borderWidth, relief); break; } case Html_TH: case Html_TD: { int depth, relief; pTable = src->cell.pTable; depth = pTable && pTable->table.borderWidth>0; switch( htmlPtr->tableRelief ){ case TK_RELIEF_RAISED: relief = TK_RELIEF_SUNKEN; break; case TK_RELIEF_SUNKEN: relief = TK_RELIEF_RAISED; break; default: relief = TK_RELIEF_FLAT; break; } HtmlDrawRect(htmlPtr, drawable, src, src->cell.x - drawableLeft, src->cell.y - drawableTop, src->cell.w, src->cell.h, depth, relief); break; } case Html_IMG: if( src->image.pImage ){ HtmlDrawImage(src, drawable, drawableLeft, drawableTop, drawableLeft + drawableWidth, drawableTop + drawableHeight); }else if( src->image.zAlt ){ gc = HtmlGetGC(htmlPtr, src->base.style.color, src->base.style.font); font = HtmlGetFont(htmlPtr, src->base.style.font); if( font==0 ) return; Tk_DrawChars(htmlPtr->display, drawable, gc, font, src->image.zAlt, strlen(src->image.zAlt), src->image.x - drawableLeft, src->image.y - drawableTop); TestPoint(0); } break; default: TestPoint(0); break; } } }
/** * \brief emulates a double window border through the border pixmap mechanism */ void set_window_double_border(Display *dpy, Window win, int ibw, unsigned long inner_color, unsigned long outer_color) { XWindowAttributes wa; if (!XGetWindowAttributes(dpy, win, &wa)) return; int bw = wa.border_width; if (bw < 2 || ibw >= bw || ibw < 1) return; int width = wa.width; int height = wa.height; unsigned int depth = wa.depth; int full_width = width + 2 * bw; int full_height = height + 2 * bw; // the inner border is represented through the following pattern: // // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██ ██ // ██████████████████████████ ██ // // ██████████████████████████ ██ XRectangle rectangles[] = { { width, 0, ibw, height + ibw }, { full_width - ibw, 0, ibw, height + ibw }, { 0, height, width + ibw, ibw }, { 0, full_height - ibw, width + ibw, ibw }, { full_width - ibw, full_height - ibw, ibw, ibw } }; Pixmap pix = XCreatePixmap(dpy, win, full_width, full_height, depth); GC gc = XCreateGC(dpy, pix, 0, NULL); /* outer border */ XSetForeground(dpy, gc, outer_color); XFillRectangle(dpy, pix, gc, 0, 0, full_width, full_height); /* inner border */ XSetForeground(dpy, gc, inner_color); XFillRectangles(dpy, pix, gc, rectangles, LENGTH(rectangles)); XSetWindowBorderPixmap(dpy, win, pix); XFreeGC(dpy, gc); XFreePixmap(dpy, pix); }
static Bool draw_state(ModeInfo * mi, int state) { circuitstruct *wp = &circuits[MI_SCREEN(mi)]; GC gc; XGCValues gcv; CellList *current = wp->cellList[state]; if (MI_NPIXELS(mi) > 2) { gc = MI_GC(mi); XSetForeground(MI_DISPLAY(mi), gc, MI_PIXEL(mi, wp->colors[state])); } else { gcv.stipple = wp->pixmaps[state]; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), wp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = wp->stippledGC; } if (wp->neighbors == 6) { /* Draw right away, slow */ while (current) { int col, row, ccol, crow; col = current->pt.x; row = current->pt.y; ccol = 2 * col + !(row & 1), crow = 2 * row; if (wp->vertical) { wp->shape.hexagon[0].x = wp->xb + ccol * wp->xs; wp->shape.hexagon[0].y = wp->yb + crow * wp->ys; } else { wp->shape.hexagon[0].y = wp->xb + ccol * wp->xs; wp->shape.hexagon[0].x = wp->yb + crow * wp->ys; } if (wp->xs <= 1 || wp->ys <= 1) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, wp->shape.hexagon[0].x, wp->shape.hexagon[0].y); else XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, wp->shape.hexagon, 6, Convex, CoordModePrevious); current = current->next; } } else if (wp->neighbors == 4 || wp->neighbors == 8) { XRectangle *rects; /* Take advantage of XFillRectangles */ int nrects = 0; /* Create Rectangle list from part of the cellList */ if ((rects = (XRectangle *) malloc(wp->ncells[state] * sizeof (XRectangle))) == NULL) { return False; } while (current) { rects[nrects].x = wp->xb + current->pt.x * wp->xs; rects[nrects].y = wp->yb + current->pt.y * wp->ys; rects[nrects].width = wp->xs - (wp->xs > 3); rects[nrects].height = wp->ys - (wp->ys > 3); current = current->next; nrects++; } /* Finally get to draw */ XFillRectangles(MI_DISPLAY(mi), MI_WINDOW(mi), gc, rects, nrects); /* Free up rects list and the appropriate part of the cellList */ free(rects); } else { /* TRI */ while (current) { int col, row, orient; Bool small = (wp->xs <= 3 || wp->ys <= 3); col = current->pt.x; row = current->pt.y; orient = (col + row) % 2; /* O left 1 right */ if (wp->vertical) { wp->shape.triangle[orient][0].x = wp->xb + col * wp->xs; wp->shape.triangle[orient][0].y = wp->yb + row * wp->ys; if (small) wp->shape.triangle[orient][0].x += ((orient) ? -1 : 1); else wp->shape.triangle[orient][0].x += (wp->xs / 2 - 1) * ((orient) ? 1 : -1); } else { wp->shape.triangle[orient][0].y = wp->xb + col * wp->xs; wp->shape.triangle[orient][0].x = wp->yb + row * wp->ys; if (small) wp->shape.triangle[orient][0].y += ((orient) ? -1 : 1); else wp->shape.triangle[orient][0].y += (wp->xs / 2 - 1) * ((orient) ? 1 : -1); } if (small) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, wp->shape.triangle[orient][0].x, wp->shape.triangle[orient][0].y); else { XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, wp->shape.triangle[orient], 3, Convex, CoordModePrevious); } current = current->next; } } free_state(wp, state); XFlush(MI_DISPLAY(mi)); return True; }
int TkpDrawEntryBorderAndFocus( Entry *entryPtr, Drawable d, int isSpinbox) { CGRect bounds; TkMacOSXDrawingContext dc; GC bgGC; Tk_Window tkwin = entryPtr->tkwin; int oldWidth = 0; MacDrawable *macDraw = (MacDrawable *) d; const HIThemeFrameDrawInfo info = { .version = 0, .kind = kHIThemeFrameTextFieldSquare, .state = (entryPtr->state == STATE_DISABLED ? kThemeStateInactive : kThemeStateActive), .isFocused = (entryPtr->flags & GOT_FOCUS ? 1 : 0), }; /* * I use 6 as the borderwidth. 2 of the 5 go into the actual frame the 3 * are because the Mac OS Entry widgets leave more space around the Text * than Tk does on X11. */ if (entryPtr->borderWidth != MAC_OSX_ENTRY_BORDER || entryPtr->highlightWidth != MAC_OSX_FOCUS_WIDTH || entryPtr->relief != MAC_OSX_ENTRY_RELIEF) { return 0; } /* * For the spinbox, we have to make the entry part smaller by the size of * the buttons. We also leave 2 pixels to the left (as per the HIG) and * space for one pixel to the right, 'cause it makes the buttons look * nicer. */ if (isSpinbox) { int incDecWidth; oldWidth = Tk_Width(tkwin); ComputeIncDecParameters(Tk_Height(tkwin) - 2 * MAC_OSX_FOCUS_WIDTH, &incDecWidth); Tk_Width(tkwin) -= incDecWidth + 1; } /* * The focus ring is drawn with an Alpha at the outside part of the ring, * so we have to draw over the edges of the ring before drawing the focus * or the text will peep through. */ bgGC = Tk_GCForColor(entryPtr->highlightBgColorPtr, d); TkDrawInsetFocusHighlight(entryPtr->tkwin, bgGC, MAC_OSX_FOCUS_WIDTH, d, 0); /* * Inset the entry Frame by the maximum width of the focus rect, which is * 3 according to the Carbon docs. */ bounds.origin.x = macDraw->xOff + MAC_OSX_FOCUS_WIDTH; bounds.origin.y = macDraw->yOff + MAC_OSX_FOCUS_WIDTH; bounds.size.width = Tk_Width(tkwin) - 2*MAC_OSX_FOCUS_WIDTH; bounds.size.height = Tk_Height(tkwin) - 2*MAC_OSX_FOCUS_WIDTH; if (!TkMacOSXSetupDrawingContext(d, NULL, 1, &dc)) { return 0; } ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation); TkMacOSXRestoreDrawingContext(&dc); if (isSpinbox) { Tk_Width(tkwin) = oldWidth; } return 1; } /* *-------------------------------------------------------------- * * TkpDrawSpinboxButtons -- * * This procedure redraws the buttons of an spinbox widget. It overrides * the generic button drawing code if the spinbox widget parameters are * such that the native widget drawing is a good fit. This version just * returns 0, so platforms that don't do special native drawing don't * have to implement it. * * Results: * 1 if it has drawn the border, 0 if not. * * Side effects: * May draw the entry border into pixmap. * *-------------------------------------------------------------- */ int TkpDrawSpinboxButtons( Spinbox *sbPtr, Drawable d) { CGRect bounds; Tk_Window tkwin = sbPtr->entry.tkwin; int height = Tk_Height(tkwin); int buttonHeight = height - 2 * MAC_OSX_FOCUS_WIDTH; int incDecWidth; TkMacOSXDrawingContext dc; XRectangle rects[1]; GC bgGC; MacDrawable *macDraw = (MacDrawable *) d; HIThemeButtonDrawInfo info = { .version = 0, .adornment = kThemeAdornmentNone, }; /* * FIXME: RAISED really makes more sense */ if (sbPtr->buRelief != TK_RELIEF_FLAT) { return 0; } /* * The actual sizes of the IncDec button are 21 for the normal, 18 for the * small and 15 for the mini. But the spinbox still looks okay if the * entry is a little bigger than this, so we give it a little slop. */ info.kind = ComputeIncDecParameters(buttonHeight, &incDecWidth); if (info.kind == (ThemeButtonKind) 0) { return 0; } if (sbPtr->entry.state == STATE_DISABLED) { info.state = kThemeStateInactive; info.value = kThemeButtonOff; } else if (sbPtr->selElement == SEL_BUTTONUP) { info.state = kThemeStatePressedUp; info.value = kThemeButtonOn; } else if (sbPtr->selElement == SEL_BUTTONDOWN) { info.state = kThemeStatePressedDown; info.value = kThemeButtonOn; } else { info.state = kThemeStateActive; info.value = kThemeButtonOff; } bounds.origin.x = macDraw->xOff + Tk_Width(tkwin) - incDecWidth - 1; bounds.origin.y = macDraw->yOff + MAC_OSX_FOCUS_WIDTH; bounds.size.width = incDecWidth; bounds.size.height = Tk_Height(tkwin) - 2*MAC_OSX_FOCUS_WIDTH; /* * We had to make the entry part of the window smaller so that we wouldn't * overdraw the spin buttons with the focus highlight. So now we have to * draw the highlightbackground. */ bgGC = Tk_GCForColor(sbPtr->entry.highlightBgColorPtr, d); rects[0].x = bounds.origin.x; rects[0].y = 0; rects[0].width = Tk_Width(tkwin); rects[0].height = Tk_Height(tkwin); XFillRectangles(Tk_Display(tkwin), d, bgGC, rects, 1); if (!TkMacOSXSetupDrawingContext(d, NULL, 1, &dc)) { return 0; } ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); TkMacOSXRestoreDrawingContext(&dc); return 1; }
void XmuFillRoundedRectangle(Display *dpy, Drawable draw, GC gc, int x, int y, int w, int h, int ew, int eh) { XArc arcs[4]; XRectangle rects[3]; XGCValues vals; int ew2, eh2; XGetGCValues(dpy, gc, GCArcMode, &vals); if (vals.arc_mode != ArcPieSlice) XSetArcMode(dpy, gc, ArcPieSlice); if ((ew2 = (ew << 1)) > w) ew2 = ew = 0; if ((eh2 = (eh << 1)) > h) eh2 = eh = 0; arcs[0].x = x; arcs[0].y = y; arcs[0].width = ew2; arcs[0].height = eh2; arcs[0].angle1 = 180 * 64; arcs[0].angle2 = -90 * 64; arcs[1].x = x + w - ew2 - 1; arcs[1].y = y; arcs[1].width = ew2; arcs[1].height = eh2; arcs[1].angle1 = 90 * 64; arcs[1].angle2 = -90 * 64; arcs[2].x = x + w - ew2 - 1; arcs[2].y = y + h - eh2 - 1; arcs[2].width = ew2; arcs[2].height = eh2; arcs[2].angle1 = 0; arcs[2].angle2 = -90 * 64; arcs[3].x = x; arcs[3].y = y + h - eh2 - 1; arcs[3].width = ew2; arcs[3].height = eh2; arcs[3].angle1 = 270 * 64; arcs[3].angle2 = -90 * 64; XFillArcs(dpy, draw, gc, arcs, 4); rects[0].x = x + ew; rects[0].y = y; rects[0].width = w - ew2; rects[0].height = h; rects[1].x = x; rects[1].y = y + eh; rects[1].width = ew; rects[1].height = h - eh2; rects[2].x = x + w - ew; rects[2].y = y + eh; rects[2].width = ew; rects[2].height = h - eh2; XFillRectangles(dpy, draw, gc, rects, 3); if (vals.arc_mode != ArcPieSlice) XSetArcMode(dpy, gc, vals.arc_mode); }
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; } }