/* gcc -o polytest polytest.c -L/usr/X11R6/lib -lX11 MArk. ps. click the mouse button in the window to quit. */ #include #include #include #define SIZE 800 static Display* TheDisplay; static GC fgContext; static GC bgContext; static Visual* TheVisual; static Window TheWindow; static int TheScreenNumber; static char stipple_bits[] = { 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x88, 0x88, 0x88, 0x88, 0x44, 0x44, 0x44, 0x44, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11}; void DoPoly() { XEvent event; int dx, dy; XPoint points[4] = { {100,100}, {400,100}, {400,400}, {100,400} }; XFillPolygon(TheDisplay,TheWindow,fgContext, points,4,Convex,CoordModeOrigin); while(1) { XNextEvent(TheDisplay,&event); if(event.type == ButtonPress) break; else if(event.type == MotionNotify) { XFillPolygon(TheDisplay,TheWindow,bgContext, points,4,Convex,CoordModeOrigin); points[0].x = event.xmotion.x; points[0].y = event.xmotion.y; points[2].x = SIZE - points[0].x; points[2].y = SIZE - points[0].y; points[1].x = points[0].y; points[1].y = points[2].x; points[3].x = points[2].y; points[3].y = points[0].x; } XFillPolygon(TheDisplay,TheWindow,fgContext, points,4,Convex,CoordModeOrigin); } } int main(int argc, char* argv[]) { XGCValues values; unsigned long black, white, color; XColor dummy, actual; Pixmap pix; TheDisplay = XOpenDisplay("\0"); TheScreenNumber = DefaultScreen(TheDisplay); TheVisual = DefaultVisual(TheDisplay,TheScreenNumber); white = XWhitePixel(TheDisplay,TheScreenNumber); black = XBlackPixel(TheDisplay,TheScreenNumber); XAllocNamedColor(TheDisplay, XDefaultColormap(TheDisplay,TheScreenNumber), "blue", &actual, &dummy); color = actual.pixel; TheWindow = XCreateSimpleWindow(TheDisplay, DefaultRootWindow(TheDisplay), 0, 0, SIZE, SIZE, 0, 0, black); pix = XCreateBitmapFromData(TheDisplay,TheWindow,stipple_bits,32,32); XMapWindow(TheDisplay,TheWindow); XSelectInput(TheDisplay,TheWindow,PointerMotionMask|ButtonPressMask| KeyPressMask); XClearWindow(TheDisplay,TheWindow); fgContext = XCreateGC(TheDisplay,TheWindow,0,&values); bgContext = XCreateGC(TheDisplay,TheWindow,0,&values); XSetForeground(TheDisplay,fgContext,white); XSetBackground(TheDisplay,fgContext,color); XSetStipple(TheDisplay,fgContext,pix); XSetFillStyle(TheDisplay,fgContext,FillOpaqueStippled); XSetForeground(TheDisplay,bgContext,black); DoPoly(); XFreePixmap(TheDisplay,pix); BAILOUT: XCloseDisplay(TheDisplay); return 1; }