Re: newbie
- From: Owen Taylor <otaylor redhat com>
- To: <khosro iglou com>
- Cc: Gtk+ MList <gtk-list redhat com>
- Subject: Re: newbie
- Date: 25 Sep 1998 10:35:12 -0400
<khosro@iglou.com> writes:
> Hi all,
>
> Newbie with a question: I modified/simplified the example code, provided
> with the gtk-tutorial. My goal is to draw a simple window, in which
> geometric figures are drawn sequentially, not stamped form a backing pixmap.
> Now, the window appears, but the line doesn't! Can someone help me?
>
> TIA,
>
> Khosro
> =================================================================
> here is the code:
> =================================================================
>
>
> /* GTK - The GIMP Toolkit
> * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
> *...
> */
>
> #include <gtk/gtk.h>
>
> static GdkPixmap *pixmap = NULL;
>
> void
> quit ()
> {
> gtk_exit (0);
> }
>
> int
> main (int argc, char *argv[])
> {
> GtkWidget *window;
> GtkWidget *drawing_area;
> GtkWidget *vbox;
> GtkWidget *widget;
> GtkWidget *button;
>
>
> gtk_init (&argc, &argv);
>
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>
> vbox = gtk_vbox_new (FALSE, 0);
> gtk_container_add (GTK_CONTAINER (window), vbox);
>
> gtk_signal_connect (GTK_OBJECT (window), "destroy",
> GTK_SIGNAL_FUNC (quit), NULL);
>
> /* Create the drawing area */
>
> drawing_area = gtk_drawing_area_new ();
> gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 200, 200);
> gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);
>
>
> widget = drawing_area;
>
> pixmap = gdk_pixmap_new(widget->window,
> widget->allocation.width,
> widget->allocation.height,
> -1);
widget->window will be NULL here, since the widget
hasn't been "realized" yet. Your better off doing:
pixmap = gdk_pixmap_new(NULL,
widget->allocation.width,
widget->allocation.height,
gtk_widget_get_visual (widget)->depth);
> gdk_draw_rectangle (pixmap,
> widget->style->white_gc,
> TRUE,
> 0, 0,
> widget->allocation.width,
> widget->allocation.height);
>
> gdk_draw_line (pixmap,
> widget->style->black_gc,
> 100, 50, 50, 100); /** ??? ***/
>
> gdk_draw_pixmap(widget->window,
> widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
> pixmap,
> 0,0,
> 0,0,
> widget->allocation.width,
> widget->allocation.height);
To draw widget->window and have it appear, it must be non-NULL (at
this point the widget still hasn't been realized), the
widget and all its parents must have been shown, and the
X server must have got around to mapping the window on
the screen. Because of the last condition, just showing
a widget and immediately drawing on it doesn't work.
You can use gtk_widget_show_now() which waits for the window
to be mapped, or probably better, just do your drawing
in a "expose_event" handler.
Take a look at the "scribble" section of the tutorial for
a working example of code that draws on a backing pixmap
and then copies that to the screen.
> gtk_widget_show (drawing_area);
>
> gtk_widget_show (vbox);
>
> gtk_widget_show (button);
>
> gtk_widget_show (window);
'gtk_widget_show_all (window)' would be more compact. ;-)
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]