GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 24, 2014 1:33 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Drawing area, how to set it redrawable
PostPosted: Wed Dec 21, 2011 12:34 pm 
Offline
Familiar Face

Joined: Fri Dec 09, 2011 6:25 pm
Posts: 12
I have a gtk_drawing_area. On the expose_event i draw a white rectangle
Code:
drawing_area = gtk_drawing_area_new ();
   gtk_widget_set_size_request (drawing_area, 600, 500);
   gtk_box_pack_start (GTK_BOX (hbox), drawing_area, FALSE, TRUE, 0);
   
   //gtk_widget_queue_draw_area (drawing_area, 0, 0, 600, 500);
   
   g_signal_connect (G_OBJECT (drawing_area), "expose_event",
                       G_CALLBACK (background), NULL);

Code:
void background (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
   cairo_t *cr;

   cr = gdk_cairo_create (widget->window);

   cairo_set_source_rgb (cr, 0, 0, 0);
   cairo_set_line_width (cr, 0);

   cairo_rectangle (cr, 0, 0, 600, 500);
   cairo_stroke_preserve (cr);
   cairo_set_source_rgb (cr, 1, 1, 1);
   cairo_fill (cr);
   cairo_destroy (cr);   
}

But after i have to open a file and draw it on the drawing area.
My new function doesn't run...
Code:
if (gtk_dialog_run (GTK_DIALOG (open_dialog)) == GTK_RESPONSE_ACCEPT) {
      gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (open_dialog));
      image = cairo_image_surface_create_from_png (filename);
    
      g_signal_connect (G_OBJECT (drawing_area), "expose_event",
                          G_CALLBACK (expose_event_callback), NULL);
   }

Code:
gboolean expose_event_callback (GtkWidget *widget,
                        GdkEventExpose *event,
                        gpointer data)
{
   cairo_t *cr;
   
   cr = gdk_cairo_create (widget->window);
   cairo_set_source_surface (cr, image, 0, 0);
   cairo_paint (cr);
   
   cairo_destroy (cr);

   return FALSE;
}

I think the problem is on the expose_event, but i saw that you can handle only "resize", "configure_event" and "expose_event".
Any suggestions? Thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group