| Previous | Next
The Bitmap Image TypeThe my $b = $mw->Bitmap(-file => 'circle.xbm', -foreground => 'black', -background => 'white', ); my $l = $mw->Label(-image => $b, -background => 'gray')->pack; Since the Label shrink-wraps around the image, all we see is the picture shown in Figure 17-5. Notice also that we've omitted any mask file. Figure 17-5. A bitmap of a circle without a maskSuppose we copy the original bitmap and invert it (that is, toggle all the bits so ones become zeros and zeros become ones) and save the result as a mask file. This statement reconfigures the Bitmap image and adds a $b->configure(-maskfile => 'images/circle.msk'); Notice the bitmap's background color appears wherever the mask has an on bit and the original source bit is off. Figure 17-6. Mask that's an inverted version of bitmap makes the bitmap's foreground transparentFigure 17-7 shows a similar mask that has some bits set where the original source bits are also set, allowing the source foreground to show through. Figure 17-7. Mask bits set over on source bits show the foreground colorThe Cool Tricks with an Empty BitmapWe can make the cursor totally invisible by assigning it an empty, or transparent, bitmap such as this:
a mask such as this:
and a - my $c = $mw->Canvas->grid; $c->configure(-cursor => ['@trans_cur.xbm', 'trans_cur.msk', 'black', 'white']); How can this possibly be useful? Just wait and see. An invisible cursorThe tiny mote that represents the display's cursor is an X11 bitmap. For some applications (mostly games), the built-in cursors are not sufficient. Playing Doom with an X pointer just won't work! But if we use a transparent bitmap, the cursor is completely invisible when it's over the Canvas, although it's possible to track it programmatically with a simple
Filling a transparent Canvas itemAn interesting problem cropped up on the pTk mailing list. The task at hand was to create a series of transparent Canvas items that also responded to bound events. Creating a transparent item such as an oval, polygon, or rectangle is simple enough: just don't give it a -
If we give the oval a - my $o2 = $c->createOval(155, 25, 225, 100, -outline => 'red', -fill => 'blue', -stipple => '@trans_cur.xbm', ); $c->bind($o2, '<Motion>' => $cb); This oval has a red outline just like the first but is transparently filled such that it generates events anywhere, yet allows us to see through it. This feature was deemed important enough that a new built-in bitmap named |