Transparent XPM's]

I am not sure how relevant this answer is going to be for you as I am using
GTK and ADA....

The way I did it goes something like this.

When you load the XPM the function returns a bitmap mask from the image.

         Pixmap      => pixmap_image,
         Window      => gdk_win,
         Colormap    => Gtk.Widget.Get_Default_Colormap,
         Mask        => bitmap_mask,
         transparent => black,
         Filename    => "image.xpm");

If the XPM has transparent parts then those will be drawn black, without
any further operations.
However we can adjust the environment to ensure that it remains truly

This is where things are going to become very Gtk'y...

Whenever something is drawn it is drawn with the properties stored in a
GC variable associated with a window. This is similar to OpenGL where the
object is drawn using the current 'state' (although there is no actual

gdk.GC.Gdk_New (settings, gdk_win);

As part of this variable you can set the clip mask variable to be equal to
that of a bitmap...
... so using the bitmap returned from loading the XPM..

gdk.bitmap.set_clip_mask(settings, bitmap_mask);

Now we have set the clip mask to be the same shape as the XPM image. So
when we draw the image only those pixels within the mask are going to be
changed, and those which were originally transparent will be left unaltered
to produce a transparent image.

The only other thing to bear in mind when drawing the actual image is to
ensure that you are drawing in the same location as the clip_mask :


gdk.drawable.draw_pixmap(frame_buffer, settings, image,

I will be happy to answer any further questions on this matter, or indeed
the translation of these ADA commands into C.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]