How to plot scaled transparent images?



I'm writing a panel applet in which I want to load sets of transparent
images as GdkPixbufs and plot them scaled to fit the destination widget.
It's for ROX as well as Gnome, so I want it to be able to work without
gnome-canvas.

The transparency makes it a bit tricky because I think I need to somehow
get the widget's "blank" background (which may actually be part of the
Gnome panel's backround image) into a GdkPixbuf first then use
gdk_pixbuf_composite() with my source image. If I instead simply use
gdk_pixbuf_scale_simple() the interpolation of pixels on the edge of
transparent areas in the source may be against an incorrect background
colour.

I'm also not sure of how to make sure the background is cleared to its
default before I plot one of my images on it - the images need to be
updated and replaced every so often. Does a widget's background get
cleared just before I receive an expose event? My current prototype uses
a GtkPixmap (OK, I should now use GtkImage, but I think they both work
along the same lines) and I was getting garbage in the transparent
parts. Perhaps my problem was simply failing to call
gtk_widget_queue_draw()?

I've looked at how Gnome panel plots its icons, which solves almost the
exact problem I want to, and gdk_pixbuf_scale_simple() works for that.
But I'm sure it must be missing out on 100% perfection because of
gdk_pixbuf_scale_simple() having to interpolate edges of transparent
areas against an arbitrary background colour instead of the actual
background of the widget/panel.

So I was wondering, to do it "properly", should I:

During expose events get the widget's GdkDrawable and call
gdk_pixbuf_get_from_drawable() to get a background image for
gdk_pixbuf_composite()? If so, should I use the drawable from the widget
I'm plotting into (eg a GtkDrawingArea) or from the applet's top-level
widget? If the latter can I use a GtkImage instead of a GtkDrawingArea
and get my image drawn automatically for me? 

-- 
TH * http://www.realh.co.uk



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