Path: utzoo!attcan!uunet!mcvax!guido From: guido@cwi.nl (Guido van Rossum) Newsgroups: comp.windows.x Subject: inverting areas Message-ID: <324@piring.cwi.nl> Date: 17 May 88 16:25:32 GMT Reply-To: guido@cwi.nl (Guido van Rossum) Organization: The Royal Society for Prevention of Cruelty to Amoebae Lines: 30 I am porting a group of applications that were written for a monochrome window system to X11. Unfortunately they use the notion of 'inverting' areas of the screen (e.g., to indicate a text selection). This should swap the foreground and background colors. Inverting the same area twice should have a null net effect. My problem: how to do this on arbitrary color displays! I've found a trick that works, but I don't know if it is kosher. Please comment! To invert an arbitrary rectangle, use XFillRectangle with function set to GXinvert and plane mask set to the XOR of foreground and background color. This will change all pixels that have fg color to bg color and vice versa (and do semi-random things to pixels in other colors, but since we can assume the picture is monochrome, that's no problem). Code fragment (fill in the obvious declarations): XSetFunction(dpy, gc, GXinvert); XSetPlaneMask(dpy, gc, gc->values.foreground ^ gc->values.background); /* '^' is the not-so-well-known XOR operator in C */ XFillRectangle(dpy, w, gc, x, y, width, height); I've seen similar code in clients/xterm/menu.c. Questions: 1) is it kosher to retrieve the fg and bg pixels using gc->values? (if not, what is in general the recommended way to get a value out of a GC?) 2) is this the recommended way to do "invert" an area? -- Guido van Rossum, Centre for Mathematics and Computer Science (CWI), Amsterdam guido@piring.cwi.nl or mcvax!piring!guido or guido%piring.cwi.nl@uunet.uu.net