void GLUI_RadioGroup::set_selected( int int_val ) { GLUI_RadioButton *button; this->int_val = int_val; button = (GLUI_RadioButton*) first_child(); while( button != NULL ) { if ( int_val == -1 ) { /*** All buttons in group are deselected ***/ button->set_int_val(0); } else if ( int_val == button->user_id ) { /*** This is selected button ***/ button->set_int_val(1); } else { /*** This is NOT selected button ***/ button->set_int_val(0); } button = (GLUI_RadioButton*) button->next(); } glutPostRedisplay(); }
GLUI_RadioButton *GLUI::add_radiobutton_to_group( GLUI_RadioGroup *group, char *name ) { GLUI_RadioButton *control; if ( group->type != GLUI_CONTROL_RADIOGROUP ) { /*fprintf( stderr, "ERROR: Trying to add radiobutton to non-radiogroup\n" ); */ /*fflush( stderr ); */ return NULL; } control = new GLUI_RadioButton; if ( control ) { control->set_int_val( 0 ); /*int_val = 0; */ /** A radio button's user id is always its ordinal number (zero-indexed) within the group */ control->user_id = group->num_buttons; group->num_buttons++; /* Increments radiogroup's button count */ control->set_name( name ); control->group = group; add_control( group, control ); /*** Now update button states ***/ group->set_int_val( group->int_val ); /* This tells the group to reset itself to its current value, thereby updating all its buttons */ return control; } else { return NULL; } }