Newbie questions: Why this code doesn't show my drawings?



	I'm running a Debian 2.1, gtk 1.2.1. And this code is getting me crazy!,
all I do is: create a window with a drawingarea inside it. Try to draw on
this drawingarea with the function Draw. It enters in the function,
*APPARENTLY* it draws! (because the prints say so), but there ara no
changes in the window!.
	I've used:  while (gtk_events_pending())

gtk_main_iteration();
       as says in the FAQ, but with no results. 


Can someone help me please!

Another question: 
	If I pass to a function a window, how (from this function) can I access
the widgets inside the window? 

Thanks in advance.
Ssebastià.

Here is the code:
#include <gtk/gtk.h>


gint destroyapp (GtkWidget *widget, gpointer
gdata)
{
 gtk_main_quit ();
 return (FALSE);
}



void Draw (gpointer
data)
{
  GtkWidget* drawingarea1 = (GtkWidget *) data;
  GdkDrawable
*pintable;

  pintable= drawingarea1->window;

  g_print("Before painting
the rectangle.\n");
  gdk_draw_rectangle( pintable,
drawingarea1->style->black_gc, TRUE,0,0, drawingarea1->allocation.width-10,
drawingarea1->allocation.height-10);
  g_print("Before painting the
point.\n");
  gdk_draw_point( pintable, drawingarea1->style->white_gc,
10,10);
  g_print("Before painting the line.\n");
  gdk_draw_line(
pintable, drawingarea1->style->white_gc, 10, 10,  110, 110);

g_print("After painting the line.\n");

  gdk_draw_point (	pintable,

drawingarea1->style->white_gc,
			5,

drawingarea1->allocation.height-50);

 gtk_widget_show (drawingarea1);


while (gtk_events_pending())

gtk_main_iteration();

}


GtkWidget*
create_window1 ()
{
  GtkWidget
*window1;

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_object_set_data (GTK_OBJECT (window1), "Finestra 1 ", window1);

gtk_window_set_title (GTK_WINDOW (window1), "Finestra 1");

gtk_window_set_policy (GTK_WINDOW (window1), TRUE, TRUE, FALSE);

  return
window1;
}



int
main (int argc, char *argv[])
{
  GtkWidget *window1;

GtkWidget *drawingarea1;


  gtk_set_locale ();
  gtk_init (&argc,
&argv);

/* Here I create a window with a drawingarea inside of it. */


window1 = create_window1 ();
  drawingarea1 = gtk_drawing_area_new ();

gtk_object_set_data (GTK_OBJECT (window1), "drawingarea1", drawingarea1);

gtk_widget_show (drawingarea1);
  gtk_container_add (GTK_CONTAINER
(window1), drawingarea1);
  gtk_widget_set_usize (drawingarea1, 513,
502);

  /* I connect the signal destroy to the function destroyapp in
order to be
     able to kill the window with the mouse. */

gtk_signal_connect (GTK_OBJECT (window1), "destroy",
  			GTK_SIGNAL_FUNC
(destroyapp), NULL);

  /* Now I connect the signal "entern_notify_event"
with the function that draws
    on the DrawingArea. HERE IS THE PROBLEM!!!
*/
  gtk_signal_connect (GTK_OBJECT (window1), "enter_notify_event",
GTK_SIGNAL_FUNC (Draw), (gpointer) drawingarea1 );

  gtk_widget_show
(window1); /* show the window */

  Draw( (gpointer) drawingarea1); /* I
try to draw myself on the drawing area... not succeed */

  gtk_main ();

return 0;
}


__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com



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