Re: Drawing images ( with transparency ) one on another



Hi,
    I need do this too but have not succeeded yet. I try to use gdk_draw_pixbuf and gdk_pixbuf_composite in expose event handler, but it still doesn't work. I really need help to make my test code work.
   
Laowb

#include <gtk/gtk.h>
#define STD_WIDTH    680
#define STD_HEIGHT  480

static GdkPixbuf * s_basePix;
static GdkPixbuf * s_homeMenuPix;

gboolean on_expose(GtkWidget * widget,
                   GdkEventExpose * ps,
                   gpointer data)
{
    gdk_pixbuf_composite(s_homeMenuPix,
                         s_basePix, 0, 0, STD_WIDTH, STD_HEIGHT, 0, 0, 0, 0,
                         GDK_INTERP_NEAREST, 0);

    gdk_draw_pixbuf(widget->window, widget->style->bg_gc[GTK_STATE_NORMAL],
                    s_homeMenuPix, 0, 0, 0, 0,
                    STD_WIDTH,
                    STD_HEIGHT,
                    GDK_RGB_DITHER_NORMAL,
                    0, 0);
    return FALSE;
}


int main(int argc, char * argv[])
{
    GtkWidget * mainWnd        = NULL;
    GdkDrawable *    pixMap    = NULL;
    GtkWidget * img            = NULL;
    GtkWidget * box            = NULL;
    GtkWidget * button        = NULL;
    GtkAdjustment * vadj    = NULL;
    GtkAdjustment * hadj    = NULL;
    GdkBitmap      * msk        = NULL;
    GdkBitmap * homeMenu    = NULL;

    gtk_init(&argc, &argv);

    mainWnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   
    gtk_window_set_title(GTK_WINDOW(mainWnd), "test draw...\n");   
   
    gtk_signal_connect(GTK_OBJECT(mainWnd), "destroy", gtk_main_quit, NULL);

    img = gtk_image_new();
    gtk_container_add(GTK_CONTAINER(mainWnd), img);
    gtk_signal_connect(GTK_OBJECT(img),
                       "expose-event",
                       GTK_SIGNAL_FUNC(on_expose),
                       NULL);

    gtk_container_set_border_width(GTK_CONTAINER(mainWnd), 5);

    gtk_widget_show_all(mainWnd);

    homeMenu = gdk_pixmap_create_from_xpm(mainWnd->window,
                                          &msk,
                                          &mainWnd->style->bg[GTK_STATE_NORMAL],
                                          "f:/homemenu.bmp"); /* alpha channel bitmap*/
    s_homeMenuPix =
    gdk_pixbuf_get_from_drawable(s_homeMenuPix,
                                 homeMenu,
                                 gdk_colormap_get_system(),
                                 0, 0, 0, 0,
                                 STD_WIDTH,
                                 STD_HEIGHT);

    pixMap = gdk_pixmap_create_from_xpm(mainWnd->window,
                                        &msk,
                                        &mainWnd->style->bg[GTK_STATE_NORMAL],
                                        "f:/Sunset.bmp"); /* no alpha channel bitmap*/
    s_basePix =
    gdk_pixbuf_get_from_drawable(s_basePix,
                                 pixMap,
                                 gdk_colormap_get_system(),
                                 0, 0, 0, 0,
                                 STD_WIDTH,
                                 STD_HEIGHT);

    gtk_main();

    return 0;
}

2006/6/19, David Nečas (Yeti) <yeti physics muni cz>:
On Mon, Jun 19, 2006 at 11:35:09AM +0200, hm wrote:
>
>   I`ve got a problem. I`ve got two separate images. One is background for  the secondone. Secondone is partially transparent. There is also table. Question is : how to draw in one of the table`s cells the backgraound, and on this background ( as a second layer ) second image (transparent) ?  I know ( of course ) how to create images, tables.

Either use gdk_draw_pixbuf() if the correct order (first
base, then the one with alpha channel) in expose event
handler, or use gdk_pixbuf_composite() and draw the final
image.

Yeti


--
Anonyms eat their boogers.
_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list



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