From: raney@teal.csn.org (Scott Raney)
Newsgroups: fj.mail-lists.x-window
Subject: Re: Non-rectangular bitmaps/setting pixmap background...
Date: 22 Jul 92 03:41:27 GMT
Distribution: fj
Organization: Colorado SuperNet, Inc.

Date: Sat, 18 Jul 1992 21:17:27 GMT
Message-Id: <raney.711494247@teal>
Newsgroups: comp.windows.x

mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:

>In article <1992Jul13.194934.5605@news.cs.brandeis.edu>, slanka@chaos.cs.brandeis.edu (Ishantha Lokuge) writes:

>> I am trying to create a non-rectangular bitmap...

>This is not possible.  You'll have to get the effect you want some
>other way.

I say it *is* possible, but the process is nontrivial.  First, you
need a mask of the shape you will be drawing, and a pixmap of the size
of your control to draw into.  Your source image should have 0's
everywhere the mask does.  Then do the following:

XCopyArea the destination screen area to the pixmap
XCopyPlane with function GXandInverted from your mask to the pixmap
  (this sets values the pixels you want to draw in to 0)
XPutImage (or XCopyPlane) with function GXor into the pixmap
  (set the pixels you want to draw in to the new value, leaving
   the rest of them unchanged)
XCopyArea the pixmap back to the screen

You can skip steps 1 and 4 if you don't mind the screen flashing.
Using this technique, our product MetaCard supports opaque moving and
sizing of UI controls *underneath* bitmaps.  If you haven't seen this,
you can anonymously FTP a save-disabled distribution from
ftp.metacard.com (directory MetaCard) or world.std.com (directory
pub/MetaCard) and try it yourself.  It's pretty impressive (if I do
say so myself).

>> This means that the pixmap will appear to be irregular (or just the
>> shape of the foreground)....

>You will have to go about your ends some other way.  There are various
>possibilities.  One is to create a bitmap that is 1 where you want to
>change things when copying and 0 when not, then set this as the
>clip-mask in your GC, and then do an XFillRectangle (if the drawings
>are all one color) or an XCopyArea/XCopyPlane (if you want the opaque
>area to include more than one color).  In the former case, you can also
>set the bitmap as the stipple in the GC and set the fill-style to
>FillStippled.

Unfortunately, the X server designers chose to implement clip masks by
converting them to rectangle lists instead of developing a three
element logic op.  The result?  Setting a full screen clip mask on a
386 takes several seconds.  Clipping a wide polyline to the mask can
take several *minutes*.  If it had been implemented as a mask, the
results would be about 50% slower than regular operations.  As it is,
X clipmasks are essentially useless.

>If the shape decomposes easily into relatively few rectangles, you can
>also take advantage of that and draw each rectangle separately.

>					der Mouse

>			    mouse@larry.mcrcim.mcgill.edu
-- 
***********************************************************************
* Scott Raney  303-447-3936            Remember: the better you look, *
* raney@metacard.com                   the more you'll see -- Lidia   *
***********************************************************************