that gives 2 blank windows:( Re: hello, Mr. Ronald Bultje



Hi, ronald,
I did try as you said, and realized the widget, but always get errors. otherwise, I would not have such a headache and bother you again and again,believe me, it is not so simple to me :(

I made my short program based on your code,
hope you can point out which part is wrong. if you compile and run the codes listed here

#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
int main( int   argc,char *argv[] )
                {
                    GtkWidget *window;
                    GdkPixbuf *pixbuf;
                    GtkWidget *widget;


                    gtk_init (&argc, &argv);

                    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

              	    widget = gtk_drawing_area_new();


                    pixbuf = gdk_pixbuf_new_from_file("rose.jpg");

gtk_widget_set_usize(widget, gdk_pixbuf_get_width(pixbuf),gdk_pixbuf_get_height(pixbuf));
                    gtk_widget_realize(widget);


                    printf("widget realized\n");

                    gdk_pixbuf_render_to_drawable (
pixbuf, widget->window,window->style->fg_gc[GTK_STATE_NORMAL],0, 0,0,0, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), GDK_RGB_DITHER_NORMAL, 0, 0);
                    printf("rendered\n");

                    gtk_container_add(GTK_CONTAINER(window), widget);
                    printf("widget added to window\n");


                    gtk_widget_show(widget);
                    gtk_widget_show(window);
                    gtk_main ();





                }


you will get 2 windows!!! and the errors like:

[gli olympia GTK]$ gcc base3.c `gtk-config --cflags --libs` `gdk-pixbuf-config --cflags --libs`
[gli olympia GTK]$ ./a.out

Gtk-CRITICAL **: file gtkwidget.c: line 3722 (gtk_widget_get_parent_window): assertion `widget->parent != NULL' failed.
widget realized

** CRITICAL **: file gdk-pixbuf-render.c: line 206 (gdk_pixbuf_render_to_drawable): assertion `gc != NULL' failed.
rendered
widget added to window

[3]+  Stopped                 ./a.out
[gli olympia GTK]$


















From: Ronald Bultje <rbultje ronald bitfreak net>
To: guo li <liguo503 hotmail com>
Subject: Re: hello, Mr. Ronald Bultje
Date: 21 Mar 2002 07:54:03 +0100

On Thu, 2002-03-21 at 04:35, guo li wrote:
>   as you can see from the list, others do not think that the codes will
> work, I tried and tried, no good. :(
> can u please send me a copy of a working file?
> thank you very very much.

As they said, just realize the widget:

> >--code for gtk+-1.2 starts here--
> >char *file = "/path/to/file.jpg";
> >/* this can be any widget as long as it has its own
> >  * GdkWindow for example, use a GtkDrawingArea or a
> >  * GtkEventBox */
> >GtkWidget *widget;
> >GdkPixbuf *pixbuf;
> >
> >/* create the widget and the pixbuf */
> >widget = gtk_event_box_new(); /* could be any widget */

make this "widget = gtk_drawing_area_new();"

> >pixbuf = gdk_pixbuf_new_from_file(file);
> >
> >/* resize the widget so that the pixbuf fits */
> >gtk_widget_set_usize(widget, gdk_pixbuf_get_width(pixbuf,
> >   gdk_pixbuf_get_height(pixbuf));

insert "gtk_widget_realize(widget);" here.

> >/* place the image in the widget */
> >gdk_pixbuf_render_to_drawable (pixbuf, widget->window,
> >   widget->style->white_gc, 0, 0, 0, 0,
> >   gdk_pixbuf_get_width(pixbuf),
> >   gdk_pixbuf_get_height(pixbuf),
> >   GDK_RGB_DITHER_NORMAL, 0, 0);
> >
> >/* use general Gtk+-1.2 routines to add the widget to a
> >  * window and show it */
> >[..]
> >gtk_widget_show(widget);
> >--code ends here--

That's all. Just play with it, it's really simple.

Ronald

--
-   .-.
-   /V\    | Ronald Bultje <rbultje ronald bitfreak net>
-  // \\   | Running: Linux 2.4.18-XFS and OpenBSD 3.0
- /(   )\  | http://ronald.bitfreak.net/
-  ^^-^^





_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com




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