Re: that gives 2 blank windows:( Re: hello, Mr. Ronald Bultje
- From: Hing-Wah Wan <50191914 ee cityu edu hk>
- To: guo li <liguo503 hotmail com>
- Cc: gtk-list gnome org
- Subject: Re: that gives 2 blank windows:( Re: hello, Mr. Ronald Bultje
- Date: Fri, 22 Mar 2002 11:28:39 +0800
On Thu, Mar 21, 2002 at 04:57:29PM +0000, guo li wrote:
> 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
>
gdk-pixbuf is included in gtk+2.0 so you no need have `gdk-pixbuf-config --cflags --libs`
also gdk_pix_buf_new_from_file("rose.jpg",NULL) instead of
gdk_pix_buf_new_from_file("rose.jpg");
you should have all drawing in the expose event,the following will work:
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <stdio.h>
void expose(GtkWidget* widget,GdkEvent *expose,GdkPixbuf *pixbuf)
{
gdk_pixbuf_render_to_drawable (
pixbuf,
widget->window,widget->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);
}
int main( int argc,char *argv[] )
{
GtkWidget *window;
GtkWidget *widget;
GdkPixbuf *pixbuf;
gtk_init (&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
widget=gtk_drawing_area_new();
pixbuf = gdk_pixbuf_new_from_file("rose.jpg",NULL);
gtk_widget_set_usize(widget,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf));
g_signal_connect(widget,"expose_event",(GCallback)expose,pixbuf);
gtk_container_add(GTK_CONTAINER(window),widget);
gtk_widget_show(widget);
gtk_widget_show(window);
gtk_main ();
return 0;
}
however,u can save all the trouble by GtkImage :
#include <gtk/gtk.h>
int main( int argc,char *argv[] )
{
GtkWidget *window;
GtkWidget *w;
gtk_init (&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
widget=gtk_image_new_from_file("rose.jpg");
gtk_container_add(GTK_CONTAINER(window),widget);
gtk_widget_show(widget);
gtk_widget_show(window);
gtk_main ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]