Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!apple!snorkelwacker!bloom-beacon!LARRY.MCRCIM.MCGILL.EDU!mouse From: mouse@LARRY.MCRCIM.MCGILL.EDU Newsgroups: comp.windows.x Subject: Re: Stupid question about Xor'ing a Pixmap Message-ID: <9010050724.AA09737@Larry.McRCIM.McGill.EDU> Date: 5 Oct 90 07:24:47 GMT Sender: root@athena.mit.edu (Wizard A. Root) Organization: The Internet Lines: 62 > I have a colour machine and want to plot a small cursor in an > application. The (bits that are set in the) cursor should be > coloured - not just black. I want to use a pixmap or bitmap as the > cursor. The cursor has to be able to move around and so I need to be > able to remove it and put it somewhere else. The background is not > necessarily blank so I need to put back what was there before. > Sooo.. my question is what combination of Pixmap/Bitmap and GC should > I use. I've tried using XCopyPlane of a bitmap with an Xor GC, > removing the old cursor by plotting it again in the same place, but I > seem to come unstuck if the background colour is not 0. One possibility is to make the "cursor" a small window of its own and use the SHAPE extension to give it the shape you want. Restoring the stuff underneath it when you move it amounts to just handling exposures, which you must be doing anyway (either by handling Expose events or by arranging for the server to do it for you, such as by setting background pixmaps). Obviously, this way can't work unless your server supports the SHAPE extension. If you really want to do it by drawing graphics on the window...you want to overlay a shape in some color on top of a drawing involving many colors, right? Then what I would suggest is that when allocating the colormap cells you use XAllocColorPlanes to allocate an "overlay" plane in the colormap. (If the cursor requires more than one bit of overlay, ask for more than one plane when allocating.) Then set up the colormap so that for some setting of the "overlay" bits (all zero, probably) the colors are appropriate for your graphics. Then for each color you want in the cursor, choose some combination of the overlay planes and load the desired color into all N of the cells having that combination of overlay bits (N being the number of colors your underlying graphics need). Then just fiddle with the plane-mask in the GC to draw in only the underlying graphics bits or only in the overlay bits, or just draw with GXxor and be careful. (Using GXxor on multi-plane displays requires care. There is a strong temptation to put the foreground pixel value into the GC's foreground; this works properly only when the background pixel value happens to be zero. What you want to put into the GC's foreground is the XOR of the foreground and background pixel values.) All of the above are designed to avoid having to deal with repairing the underlying graphics any more than necessary. However, presumably you can repair the graphics; if nothing else, exposures can happen. You could draw the cursor by blitting a Pixmap onto the window, then remove it by repairing the drawing, as if an Expose event had happened. As for specifically how to draw the cursor, I'd suggest forming a bitmap describing the shape and then either setting that as the clip-mask of the GC and filling (for a solid cursor) or copying (for a colorful cursor) or setting it as the stipple and doing a fill with a fill-style of FillStippled. (The latter method works only when only one color is to be overlaid.) What's best depends on tradeoffs like how many colors the underlying drawing needs and how many colors the cursor needs. If you'd care to drop me a line describing your needs and your server's capabilities in a little more detail I'd be glad to try to pick a method more specifically suited to your situation. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu