On Fri, 2007-02-02 at 18:01 -0700, Rob Barnes wrote: > It seems to work fine without using g_idle and just using > gdk_threads_enter()/gdk_threads_leave(). What do I gain from using g_idle?
Well you gain simplicity, and you can avoid the gdk locking stuff. Also on some platforms, particularly win32, you just cannot call gdk or gtk functions from a thread, even with the locking primitives due to the way the win32 message events work. The theoretically correct way to interact with the gui is either with g_idle_add (thread-safe), or with some kind of IPC mechanism where other threads can queue up events that you feed into the main loop. Michael > > Thanks. > > -RobB > > Michael > > > > > > > Some code snippets: > > > > > > GtkWidget *drawing_area; > > > .... > > > //Inside main: > > > drawing_area = gtk_drawing_area_new (); > > > g_signal_connect (G_OBJECT (drawing_area), "expose_event", G_CALLBACK > > > (expose_event), NULL); > > > gtk_widget_set_events(drawing_area,GDK_ALL_EVENTS_MASK); > > > .... > > > > > > gboolean expose_event( GtkWidget *widget, > > > GdkEventExpose *event ) > > > { > > > printf("expose\n"); > > > //draw_player(players[0]); > > > gdk_draw_drawable (widget->window, > > > widget->style->fg_gc[GTK_WIDGET_STATE (widget)], > > > pixmap, > > > event->area.x, event->area.y, > > > event->area.x, event->area.y, > > > event->area.width, event->area.height); > > > > > > return FALSE; > > > } > > > > > > //Inside a asynchronous function > > > //marker is an ADT > > > gdk_draw_polygon (pixmap,marker.kontext,TRUE,marker->poly,4); > > > .... > > > gdk_widget_queue_draw(drawing_area); > > > .... > > > > > > Thanks. > > > -RobB > > > > > > > > > On 2/2/07, Michael Ekstrand <[EMAIL PROTECTED]> wrote: > > > > > > > > On Fri, 2007-02-02 at 12:20 -0700, Rob Barnes wrote: > > > > > I'm trying to write a simple program that draws a moving polygon on > > the > > > > > screen. I started with the scribble-simple example and modified to > > draw > > > > the > > > > > moving shape by redrawing the shape in the background color in the > > > > previous > > > > > position first then drawing it in the foreground color in the > > current > > > > > position. It works fine, except it only refreshes when something > > happens > > > > > > > > > such as mouse movement, click, expose, window adjustment. So to keep > > > > things > > > > > moving I have to keep moving the mouse around, but it stops if the > > mouse > > > > > stops, even though the polygon is being redrawn contently. > > > > > > > > Make sure you request a redraw every time the underlying state changes > > - > > > > check out gtk_widget_queue_draw. > > > > > > > > -- > > > > Michael Ekstrand > > > > Research Assistant, Scalable Computing Laboratory > > > > Goanna, compute cluster and InfiniBand network monitor tool: > > > > http://www.scl.ameslab.gov/Projects/Monitor/ > > > > > > > > > > > _______________________________________________ > > > gtk-app-devel-list mailing list > > > gtk-app-devel-list@gnome.org > > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > > > > > > _______________________________________________ > > gtk-app-devel-list mailing list > > gtk-app-devel-list@gnome.org > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list