newbie




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);
  
  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);
      


  /* .. And a quit button */
  button = gtk_button_new_with_label ("Quit");
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
			     GTK_SIGNAL_FUNC (gtk_widget_destroy),
			     GTK_OBJECT (window));

  
  gtk_widget_show (drawing_area);

  gtk_widget_show (vbox);

  gtk_widget_show (button);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}




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