Drawing the drawingarea whith another thread...



Hi all:
       My env. is GTK+2.0 with Glade-2.
       I'm trying to draw a drawingarea with a background gthread...I have connected the signal expose and configure with the correspond event handler in callbacks.c
       My main.c looks like...
....
  1 /*
  2  * Initial main.c file generated by Glade. Edit as required.
  3  * Glade will not overwrite this file.
  4  */
  5
  6 #ifdef HAVE_CONFIG_H
  7 #  include < config.h>
  8 #endif
  9
 10 #include <gtk/gtk.h>
 11
 12 #include <glib.h>
 13
 14 #include "interface.h"
 15 #include "support.h"
 16 #include " callbacks.h "
 17 #include "my_draw.h"
 18
 19 gpointer drawing_thread(gpointer data);
 20
 21 int
 22 main (int argc, char *argv[])
 23 {
 24   GtkWidget *window1;
 25   GtkWidget *aboutdialog1;
 26
 27   gtk_set_locale ();
 28
 29   if(!g_thread_supported()) g_thread_init(NULL);
 30         gdk_threads_init();
 31
 32 GtkWidget *drawingarea1 = lookup_widget(window1,"drawingarea1");
 33
 34   gtk_init (&argc, &argv);
 35
 36   add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
 37
 38   /*
 39    * The following code was added by Glade to create one of each component
 40    * (except popup menus), just so that you see something after building
 41    * the project. Delete any components that you don't want shown initially.
 42    */
 43   window1 = create_window1 ();
 44   gtk_widget_show (window1);
 45   aboutdialog1 = create_aboutdialog1 ();
 46   gtk_widget_show (aboutdialog1);
 47
 48 g_signal_connect(G_OBJECT(drawingarea1), "expose-event",G_CALLBACK(on_drawingarea1_expose_event), NULL);
 49 g_signal_connect(G_OBJECT(drawingarea1), "configure-event",G_CALLBACK(on_drawingarea1_configure_event), NULL);
 50
 51 //  drawing_thread
 52 g_thread_create(drawing_thread, window1 , TRUE, NULL);
 53
 54 gdk_threads_enter();
 55   gtk_main ();
 56 gdk_threads_leave();
 57   return 0;
 58 }
 59


and in the callbacks.c
 92 gboolean
 93 on_drawingarea1_expose_event           (GtkWidget       *widget,
 94                                         GdkEventExpose  *event,
 95                                         gpointer         user_data)
 96 {
 97
 98    gdk_draw_drawable(widget->window,
 99                     widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
100                     draw_code_cache_pixmap,
101                     event->area.x, event->area.y,
102                     event->area.x, event->area.y,
103                     event->area.width , event->area.height);
104   return FALSE;
105 }
106

140 gboolean
141 on_drawingarea1_configure_event        (GtkWidget       *widget,
142                                         GdkEventConfigure *event,
143                                         gpointer         user_data)
144 {
145  if(draw_code_cache_pixmap)
146         g_object_unref(draw_code_cache_pixmap);
147
148   draw_code_cache_pixmap = gdk_pixmap_new(widget->window,
149                           widget->allocation.width,
150                           widget->allocation.height,
151                           -1);
152
153   return FALSE;
154 }

and my draeing thread is
  6 gpointer drawing_thread(gpointer data){
  7         gint x_aix;
  8         gint y_aix;
  9         gint trace_len=0;
 10         GtkWidget* sim_drawing_area = (GtkWidget*)data;
 11
 12         for(;;){
 13         if(trace_len >= 50)
 14                 trace_len = 0;
 15
 16         gdk_threads_enter();
 17
 18         //gdk_draw_rectangle(_sim_drawing_data->sim_drawing_area->window,
 19         gdk_draw_rectangle(draw_code_cache_pixmap,
 20                            sim_drawing_area->style->fg_gc[GTK_WIDGET_STATE (sim_drawing_area)],
 21                            TRUE,
 22                            0,
 23                            0,
 24                            trace_len,
 25                            20);
 26         gdk_flush();
 27         gdk_threads_leave();
 28
 29         trace_len++;
 30         }
 31 }

I'm created a pixmap in the on_drawingarea1_configure_event function, and connect this envnt handler with the corresponded signal.
But, as I execute the program, I got the following error msg...

(gui2:27742): Gdk-CRITICAL **: gdk_draw_rectangle: assertion `GDK_IS_DRAWABLE (drawable)' failed

(gui2:27742): Gdk-CRITICAL **: gdk_draw_rectangle: assertion `GDK_IS_DRAWABLE (drawable)' failed

(gui2:27742): Gdk-CRITICAL **: gdk_draw_rectangle: assertion `GDK_IS_DRAWABLE (drawable)' failed


Does any idea?

ThankX!!!!

Dave.



--
System  on Chip Design  Lab.
Dept. of Computer Science and Information Engineering,
National Chung Cheng University
E-mail : s88 tw acm org

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