Path: utzoo!attcan!uunet!husc6!purdue!decwrl!decwin.dec.com!fisher From: fisher@decwin.dec.com (Burns Fisher ZK3-4/W23 381-1466) Newsgroups: comp.windows.x Subject: re: inverting areas Message-ID: <8805191603.AA00500@decwrl.dec.com> Date: 19 May 88 16:03:30 GMT Organization: Digital Equipment Corporation Lines: 44 Subject: inverting areas >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?) I don't believe it is Kosher to use gx->* for anything. You can't guarantee that some other client did not modify the GC. What I would do is to set the plane mask to the XOR right away when you create the GC (and you know what the fg and bg are). It won't hurt any writing you plan to do using the GC, as long as you make sure that the window background attribute is set to be one of the two values that you XORed. (This forces the window to be initialized correctly with the bits which you can't write using the plane mask). You have a bonus that you are guaranteed to be using colors that you "own" (unless you use one of the less-common writing modes like AND or OR. >2) is this the recommended way to do "invert" an area? > It is the way that I recommend. Burns fisher@decwin.dec.com ======================================================================== Received: by decwrl.dec.com (5.54.4/4.7.34) id AA00459; Thu, 19 May 88 09:01:16 PDT