#include #include #include #include #include #include #include #include #define WINSIZ 500 /* X Stuff */ Display *dpy; int screen; int depth; Window root; Visual *visual; XRenderPictFormat *fmt; /* Window */ Window win; Pixmap background; Picture drawingarea; Picture white_brush; Picture create_brush(int red, int green, int blue, int alpha) { XRenderColor color={.red=red, .green=green, .blue=blue, .alpha=alpha}; Pixmap pm=XCreatePixmap(dpy, win, 1, 1, depth); XRenderPictureAttributes pict_attr; pict_attr.repeat=1; Picture picture=XRenderCreatePicture(dpy, pm, fmt, CPRepeat, &pict_attr); XRenderFillRectangle(dpy, PictOpOver, picture, &color, 0, 0, 1, 1); XFreePixmap(dpy, pm); return picture; } Window initwin(void) { Window win; win = XCreateWindow(dpy, root, 0, 0, WINSIZ, WINSIZ, 0, depth, InputOutput, visual, 0, NULL); background = XCreatePixmap(dpy, win, WINSIZ, WINSIZ, depth); XSelectInput(dpy, win, StructureNotifyMask); XSetWindowBackgroundPixmap(dpy, win, background); XMapWindow(dpy, win); return win; } Picture initdrawingarea(void) { XRenderPictureAttributes pict_attr; Picture drawingarea; pict_attr.poly_edge = PolyEdgeSmooth; pict_attr.poly_mode = PolyModeImprecise; drawingarea = XRenderCreatePicture(dpy, background, fmt, CPPolyEdge|CPPolyMode, &pict_attr); return drawingarea; } void drawarc(Picture src, Picture dst, int cx, int cy, int radius, int angle1, int angle2) { XTriangle *tri; int angle = angle2 - angle1; int a; int i; if (angle < 1 || angle > 360 * 64) errx(1, "could not draw arc"); if ((tri = calloc(angle, sizeof *tri)) == NULL) err(1, "calloc"); a = angle1; for (i = 0; i < angle; i++) { tri[i].p1.x = cx << 16; tri[i].p1.y = cy << 16; tri[i].p2.x = (cx << 16) + (radius << 16) * cos((a * M_PI) / (180 * 64)); tri[i].p2.y = (cy << 16) - (radius << 16) * sin((a * M_PI) / (180 * 64)); a++; tri[i].p3.x = (cx << 16) + (radius << 16) * cos((a * M_PI) / (180 * 64)); tri[i].p3.y = (cy << 16) - (radius << 16) * sin((a * M_PI) / (180 * 64)); } XRenderCompositeTriangles (dpy, PictOpOver, src, dst, 0, 0, 0, tri, angle); free(tri); } int main() { int da, db; /* dummy variables */ XRenderColor black = {0,0,0,0xffff}; if ((dpy = XOpenDisplay(NULL)) == NULL) errx(1, "could not open display"); if (!XRenderQueryExtension(dpy, &da, &db)) errx(1, "RENDER extension missing"); screen = DefaultScreen(dpy); root = DefaultRootWindow(dpy); visual = DefaultVisual(dpy, screen); depth = DefaultDepth(dpy, screen); fmt = XRenderFindVisualFormat(dpy, visual); win = initwin(); drawingarea = initdrawingarea(); white_brush = create_brush(0xffff, 0xffff, 0xffff, 0xffff); while(1) { XFlush(dpy); XRenderFillRectangle(dpy, PictOpOver, drawingarea, &black, 0, 0, 640, 480); drawarc(white_brush, drawingarea, WINSIZ/2, WINSIZ/2, WINSIZ/2, 0, 90 * 64); XClearArea(dpy, win, 0, 0, 640, 480, 0); usleep(20*1000); } return 0; }