Re: [gtk-list] Transparent pixmaps?



On Fri, 6 Mar 1998, Johannes Keukelaar wrote:

> Hello all,
> 
> I tried to post this earlier, but suspect that it didn't get through. I seem to 
> get kicked off the mailing list every couple of days or so. *sigh* Anyway, if 
> it didn't get through:

I CC this directly to you just in case you get thrown off again.
 
> I'm working on an application that will visualize certain expensive-to-draw 
> objects; these objects are nonrectangular, have a position and size and may 
> overlap. Even worse (I would think) is that the objects may even have holes in 
> them; just drawing a filled polygon and then filling in the holes again with 
> the background color would not always work for overlapping objects.
> 
> For this reason and to speed up rendering, I've been looking at using partially 
> transparent pixmaps. However, there doesn't seem to be a way to properly draw 
> these on the screen. Given, e.g. a pixmap and a bitmap mask, how would I go 
> about drawing those on the screen so that the transparency mask works? I've 
> been unable to figure out a better way than to do this in a loop with 
> GetPixel/PutPixel (or some such). Any hints?

The trick is to set the clip mask of the GC you use for drawing the
pixmap. The following snippet should do the trick.

GdkPixmap *pixmap;
GdkBitmap *mask;
GdkGC *gc;
...
/* The window has to exist before we create the pixmap */
/* Passing any drawable ought to be fine though(?) */
gtk_widget_show(main_win);
pixmap = gdk_pixmap_create_from_xpm(main_win->window,  
				    &mask,  
				    NULL,
                                "/usr/X11/include/X11/pixmaps/mail.xpm");  

gc = gdk_gc_new(main_win->window);
gdk_gc_set_clip_mask(gc, mask); 
gdk_gc_set_clip_origin(gc, 50, 50);

gdk_draw_pixmap(main_win->window, gc, pixmap, 0, 0, 50, 50, -1, -1);
...

Hope this helps.

-----------------------------------------------------------------------
Per Lewau (perle@lysator.liu.se)Student of Computer Science at the 
				University of Linkoping, 
				Sweden. 
"Why waste time learning, when ignorance is instantaneous?"
						- Hobbes




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