Go to the documentation of this file.00001 #include "options_dlg.hh"
00002 #include <FL/Fl.H>
00003
00004 namespace Stg {
00005
00006 OptionsDlg::OptionsDlg( int x, int y, int w, int h ) :
00007 Fl_Window( x,y, w,h, "Visualize" ),
00008 changedItem( NULL ),
00009 showAll( NULL ),
00010 status( NO_EVENT ),
00011 hm( w/6 )
00012 {
00013 set_non_modal();
00014
00015 showAllCheck = new Fl_Check_Button( 0,0, w,boxH );
00016 showAllCheck->callback( checkChanged, this );
00017 showAllCheck->box( FL_UP_FRAME );
00018
00019 scroll = new Fl_Scroll( 0,boxH+vm, w,h-boxH-3*vm );
00020 resizable( scroll );
00021 scroll->type( Fl_Scroll::VERTICAL );
00022 scroll->end();
00023
00024 this->end();
00025 }
00026
00027 OptionsDlg::~OptionsDlg() {
00028 delete scroll;
00029 delete showAllCheck;
00030 }
00031
00032
00033 void OptionsDlg::checkChanged( Fl_Widget* w, void* p ) {
00034 Fl_Check_Button* check = static_cast<Fl_Check_Button*>( w );
00035 OptionsDlg* oDlg = static_cast<OptionsDlg*>( p );
00036
00037 if ( check == oDlg->showAllCheck && oDlg->showAll )
00038 {
00039 oDlg->status = CHANGE_ALL;
00040 oDlg->showAll->set( check->value() );
00041 oDlg->do_callback();
00042 oDlg->status = NO_EVENT;
00043 }
00044 else
00045 {
00046 int item = oDlg->scroll->find( check );
00047 oDlg->options[ item ]->set( check->value() );
00048 oDlg->changedItem = oDlg->options[ item ];
00049 oDlg->status = CHANGE;
00050 oDlg->do_callback();
00051 oDlg->changedItem = NULL;
00052 oDlg->status = NO_EVENT;
00053 }
00054 }
00055
00056 void OptionsDlg::updateChecks() {
00057 if (scroll->children())
00058 scroll->clear();
00059 scroll->begin();
00060 Fl_Check_Button* check;
00061 for ( unsigned int i=0; i<options.size(); i++ ) {
00062 check = new Fl_Check_Button( 0,boxH*(i+1)+vm, scroll->w(), boxH, options[ i ]->name().c_str() );
00063 if ( options[ i ]->val() )
00064 check->set();
00065 check->callback( checkChanged, this );
00066 }
00067 scroll->end();
00068 this->redraw();
00069 }
00070
00071 void OptionsDlg::setOptions( const std::set<Option*>& opts ) {
00072 options.clear();
00073 options.assign( opts.begin(), opts.end() );
00074 updateChecks();
00075 }
00076
00077
00078 void OptionsDlg::showAllOpt( Option* opt ) {
00079 showAll = opt;
00080 showAllCheck->label( opt->name().c_str() );
00081 showAllCheck->value( opt->val() );
00082 }
00083
00084 }