gtk option menu problems



Greetings,
I have a little program that creates a menu, however, it's not setting the 
global varible race_bonus when you activate the menu item like it should. 
Can anyone explain to me why it does not seem to be doing this ? I know how 
to do it the long way, but I'd perfer to do it this way (using the 
add_to_menu() function) if possible. Thanks.

Sincerely,
Randy

#############################################################

gdouble race_bonus;

void
set_race( GtkObject *race, gdouble *bonus )
{
	race_bonus = *bonus;
	// this prints out garbage //
	g_print( "race is now %f\n", *bonus );
}

void
add_to_menu( GtkWidget *menu, gchar *label, gdouble bonus )
{
	GtkWidget *race;
	// prints out right data  which makes me think that gtk_signal_connect is 	
	//  messing it up in the set_race()  function.
	g_print( "bonus is %f\n", bonus );
	race = gtk_menu_item_new_with_label( label );
	gtk_menu_append( GTK_MENU(menu), race );
	gtk_signal_connect( GTK_OBJECT(race), "activate", GTK_SIGNAL_FUNC(set_race), 
&bonus );
}

void
create_science_calculator( GtkWidget *science_table )
{
	GtkWidget *hbox;
	GtkWidget *label;
	GtkWidget *menu;
	GtkWidget *option_menu;

	hbox = gtk_hbox_new( FALSE, 0 );

	label = gtk_label_new( "Race:" );
        gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 2 );

        option_menu = gtk_option_menu_new();
        menu = gtk_menu_new();
	add_to_menu( menu, "Avian", 1.0 );
	add_to_menu( menu, "Dwarf", 1.0 );
	add_to_menu( menu, "Elf", 1.0  );
	add_to_menu( menu, "Faery", 1.0 );
	add_to_menu( menu, "Halfling",  1.0 );
	add_to_menu( menu, "Human", 1.15 );
	add_to_menu( menu, "Orc", 1.0 );
	add_to_menu( menu, "Undead",  0.80);
	
        gtk_option_menu_set_menu( GTK_OPTION_MENU(option_menu), menu );
        gtk_box_pack_start( GTK_BOX(hbox), option_menu, FALSE, TRUE, 2 );
	gtk_table_attach( GTK_TABLE(science_table), hbox, 0, 1, 0, 1, GTK_FILL, 
GTK_FILL, 1, 1 );

}



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