Path: utzoo!attcan!uunet!bloom-beacon!LARRY.MCRCIM.MCGILL.EDU!mouse
From: mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse)
Newsgroups: comp.windows.x
Subject: Re: Problem with GXxor Function???
Message-ID: <8909290716.AA22128@Larry.McRCIM.McGill.EDU>
Date: 29 Sep 89 07:16:38 GMT
Sender: daemon@bloom-beacon.MIT.EDU
Organization: The Internet
Lines: 38

> [ Sample program using GXxor function that sometimes works removed ]
>> What am I forgetting????
> You are forgetting that the server released from MIT is considered a
> "sample" X11 server, and that it is supposedly meant to be an
> illustration of how vendors could go about writing their own.  [It is
> buggy.]

> One of those bugs is that the xor function (and many of the inverting
> functions as well) have the foreground and background colors
> reversed.  On a server that doesn't show the xor'd box, try setting
> the foreground color to white.

While the MIT sample server is doubtless buggy, I don't think this
problem can be laid at MIT's door.  More likely, from the original
posting, is that the programmer made a certain (apparently common)
mistake when using GXxor.

The mistake is to set the GC foreground and background colors to the
foreground and background colors desired, draw with GXxor, and expect
the drawn areas to interchange foreground and background colors.  It
doesn't work this way: drawn areas get XORed with the GC foreground
color and nothing else, in particular, not (GC fg) XOR (GC bg).

In particular, on a one-bit visual (eg, your typical vanilla monochrome
server), the mistaken approach will work if, and only if, the GC
foreground value is 1.  On some servers this may be white, on others it
may be black; this is why the "switch fg and bg and it'll work" tactic
appears to work (because on a one-bit visual, one or the other will).

The solution?  Set the GC's foreground to the XOR of the desired
foreground and background pixel values.

(On a visual with more than one bit per pixel, things get hairier.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu