C/GTK - Packing GtkImage inside GtkEventBox loses reference



Hi all, I'm newbie in C / GTK and trying to build a simple game. I got
this callback function:

#########################################################################
static GtkWidget *cria_quadrante(int tipo)
{
GtkWidget *image;
GtkWidget *event_box;

g_print("%d",tipo);

if(tipo==0) image = gtk_image_new_from_file ("img/n.png");
else if(tipo==1) image = gtk_image_new_from_file ("img/o.png");
else image = gtk_image_new_from_file ("img/x.png");

event_box = gtk_event_box_new ();

//g_object_ref(image);

gtk_container_add (GTK_CONTAINER (event_box), image);

g_signal_connect (G_OBJECT (event_box), 
                      "button_press_event",
                      G_CALLBACK (movimento_do_jogador),
                      image);
return event_box;
}
#########################################################################


The callback function movimento_do_jogador() is connected to
"button_press_event" of GtkEventBox, look at it:


#########################################################################
static void movimento_do_jogador(GtkWidget *widget, GtkWidget *image)
{
const gchar *posicao = gtk_widget_get_name(widget);

gtk_image_set_from_file(GTK_IMAGE (image), "img/o.png");

g_print("Voce clicou no quadrante %c-%c n", posicao[2], posicao[4]);
}
#########################################################################

That's it, the code above gives me a SEGFAULT in
gtk_image_set_from_file(). The objective is when user clicks on images
the image changes to another trough the function. I'm really messy with
child widgets access...

Thanks in advance.

Marcus Reis
marcus lanhelp com br


        

        
                
_______________________________________________________ 
Yahoo! Acesso Grátis: Internet rápida e grátis. 
Instale o discador agora!
http://br.acesso.yahoo.com/




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