El vie, 19-03-2010 a las 13:34 +0800, Tolic Ma escribió:
> Hi,everyone!
> 
> I want to draw something on GtkDrawingArea when I click a GtkButton,but I
> don't know how to do this...
> 
> this is my code(it doesn't work...):
> 
> *void click_button(void){
> 
> 
> gdk_draw_line(drawing_area,drawing_area->style->white_gc,x,y,width+x,height+y);
> 
> }

You shouldn't draw directly in your callback for the button. Instead,
you should call gtk_widget_queue_draw() to tell GTK+ to schedule a paint
of the widget.

How will the widget be painted? GTK+ will tell your code that the widget
needs to be painted by emitting the GtkWidget::expose-event signal.
Then, you should connect to that signal and paint in your callback.

Last but no least, don't forget to paint to the GdkWindow of the drawing
area, since that's the drawable.

More or less (untested code, just for clarity):

*void
click_button(GtkButton *button, gpointer data)
{
   button_clicked = TRUE;
   gtk_widget_queue_draw (drawing_area);
   ...
}

gboolean
expose_drawing_area (GtkWidget *area, 
                     GdkExposureEvent *event,
                     gpointer data)
{
   ...
   if (button_clicked) {
      gdk_draw_line(drawing_area->window,
                    drawing_area->style->white_gc,x,y,width+x,height+y);
   }
   ...
}

int main(int argc,char *argv[]){
   ...
   g_signal_connect(button,"clicked",G_CALLBACK(click_button),NULL);
   
g_signal_connect(drawing_area,"expose-event",G_CALLBACK(expose_drawing_area),NULL);
   ...
}


Claudio

-- 
Claudio Saavedra <csaave...@gnome.org>

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to