option.cc
Go to the documentation of this file.
00001 
00002 #include "stage.hh"
00003 #include "worldfile.hh"
00004 #include "option.hh"
00005 #include "canvas.hh"
00006 using namespace Stg;
00007 
00008 
00009 Option::Option( const std::string& n, 
00010                                          const std::string& tok, 
00011                                          const std::string& key, 
00012                                          bool v, 
00013                                          World* world ) : 
00014   optName( n ), 
00015   value( v ), 
00016   wf_token( tok ), 
00017   shortcut( key ), 
00018   menu( NULL ),
00019   menuCb( NULL ),
00020   _world( world ),
00021   htname( n )
00022 { 
00023   /* do nothing */ 
00024 }
00025 
00026 Fl_Menu_Item* getMenuItem( Fl_Menu_* menu, int i ) 
00027 {
00028   const Fl_Menu_Item* mArr = menu->menu();
00029   return const_cast<Fl_Menu_Item*>( &mArr[ i ] );
00030 }
00031 
00032 
00033 void Option::Load( Worldfile* wf, int section )
00034 {
00035   //printf( "loading wf key %s\n", wf_token.c_str() );
00036   set( (bool)wf->ReadInt( section, wf_token.c_str(), value ));
00037 }
00038 
00039 void Option::Save( Worldfile* wf, int section )
00040 {
00041   wf->WriteInt(section, wf_token.c_str(), value );
00042 }
00043 
00044 void Option::toggleCb( Fl_Widget* w, void* p ) 
00045 {
00046         //Fl_Menu_* menu = static_cast<Fl_Menu_*>( w );
00047         Option* opt = static_cast<Option*>( p );
00048         opt->invert();
00049         if ( opt->menuCb )
00050                 opt->menuCb( opt->menuCbWidget, opt );
00051 }
00052 
00053 void Option::menuCallback( Fl_Callback* cb, Fl_Widget* w ) {
00054         menuCb = cb;
00055         menuCbWidget = w;
00056 }
00057 
00058 void Option::createMenuItem( Fl_Menu_Bar* m, std::string path )
00059 {
00060         menu = m;
00061         path = path + "/" + optName;
00062         // create a menu item and save its index
00063         menuIndex = menu->add( path.c_str(), shortcut.c_str(), 
00064                                  toggleCb, this, 
00065                                  FL_MENU_TOGGLE | (value ? FL_MENU_VALUE : 0 ) );
00066 }
00067 
00068 void Option::set( bool val )
00069 {
00070         value = val;
00071 
00072         if( menu ) {
00073                 Fl_Menu_Item* item = getMenuItem( menu, menuIndex );
00074                 value ? item->set() : item->clear();
00075         }
00076 
00077         if( _world ) {
00078                 WorldGui* wg = dynamic_cast< WorldGui* >( _world );
00079                 if( wg == NULL ) return;
00080                 Canvas* canvas = wg->GetCanvas();
00081                 canvas->invalidate();
00082                 canvas->redraw();
00083         }
00084 }


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Thu Aug 27 2015 15:20:57