Re: [gtk-list] Newbie questions: Why this code doesn't show my drawings?



Regarding your draw questions:

The prototype for an enter_notify_event handler is

"enter-notify-event"
            gboolean    user_function      (GtkWidget *widget,
                                            GdkEventCrossing *event,
                                            gpointer user_data);

(from the RDP), so your Draw() has the wrong parameter list.
The drawing area is passed as the third parameter, not the
first, so you are actually drawing into window1 (window1
is the first parameter passed to Draw() since you attached
the enter-notify-handler to window1).  So, you definitely need
to change your prototype on Draw(). (The gboolean return
code is used to indicate whether you have successfully handled
this event, so you need to return TRUE as well.)

  You didn't see anything when you tried to force a Draw() yourself
in the main program because the drawing area wasn't visible yet....
even though you asked for it to be shown, it's not visible on the
screen immediately. (An expose event is generated when a window
has appeared, and is safe for drawing into).  So your Draw() in your
main() may well be drawing, but since this is happening before the drawing
area shows up, you lose the picture.

HTH,
Donna

----- Original Message -----
From: Sebastià Matas Riera <ssebastia@yahoo.com>
To: <gtk-list@redhat.com>
Sent: Friday, January 14, 2000 9:30 AM
Subject: [gtk-list] 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

--
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null





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