Revision: 6750
http://playerstage.svn.sourceforge.net/playerstage/?rev=6750&view=rev
Author: jeremy_asher
Date: 2008-07-03 14:09:25 -0700 (Thu, 03 Jul 2008)
Log Message:
-----------
Fixed Option loading not updating menu
Modified Paths:
--------------
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/option.cc
code/stage/trunk/libstage/option.hh
code/stage/trunk/libstage/options_dlg.cc
code/stage/trunk/libstage/stage.hh
code/stage/trunk/libstage/worldgui.cc
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-07-03 20:22:14 UTC (rev 6749)
+++ code/stage/trunk/libstage/canvas.cc 2008-07-03 21:09:25 UTC (rev 6750)
@@ -760,25 +760,25 @@
}
-void StgCanvas::CreateMenuItems( Fl_Menu_Bar* menu, std::string path )
+void StgCanvas::createMenuItems( Fl_Menu_Bar* menu, std::string path )
{
- showData.CreateMenuItem( menu, path );
-// visualizeAll.CreateMenuItem( menu, path );
- showBlocks.CreateMenuItem( menu, path );
- showFlags.CreateMenuItem( menu, path );
- showClock.CreateMenuItem( menu, path );
- showFlags.CreateMenuItem( menu, path );
- showFollow.CreateMenuItem( menu, path );
- showFootprints.CreateMenuItem( menu, path );
- showGrid.CreateMenuItem( menu, path );
- showStatus.CreateMenuItem( menu, path );
- perspectiveCam.CreateMenuItem( menu, path );
- showOccupancy.CreateMenuItem( menu, path );
- showTrailArrows.CreateMenuItem( menu, path );
- showTrails.CreateMenuItem( menu, path );
- showTrailRise.CreateMenuItem( menu, path );
- showTree.CreateMenuItem( menu, path );
- showScreenshots.CreateMenuItem( menu, path );
+ showData.createMenuItem( menu, path );
+// visualizeAll.createMenuItem( menu, path );
+ showBlocks.createMenuItem( menu, path );
+ showFlags.createMenuItem( menu, path );
+ showClock.createMenuItem( menu, path );
+ showFlags.createMenuItem( menu, path );
+ showFollow.createMenuItem( menu, path );
+ showFootprints.createMenuItem( menu, path );
+ showGrid.createMenuItem( menu, path );
+ showStatus.createMenuItem( menu, path );
+ perspectiveCam.createMenuItem( menu, path );
+ showOccupancy.createMenuItem( menu, path );
+ showTrailArrows.createMenuItem( menu, path );
+ showTrails.createMenuItem( menu, path );
+ showTrailRise.createMenuItem( menu, path );
+ showTree.createMenuItem( menu, path );
+ showScreenshots.createMenuItem( menu, path );
}
Modified: code/stage/trunk/libstage/option.cc
===================================================================
--- code/stage/trunk/libstage/option.cc 2008-07-03 20:22:14 UTC (rev 6749)
+++ code/stage/trunk/libstage/option.cc 2008-07-03 21:09:25 UTC (rev 6750)
@@ -8,7 +8,8 @@
value( v ),
wf_token( tok ),
shortcut( key ),
-menu_item( NULL )
+menu( NULL ),
+menuIndex( -1 )
{ }
Option::Option( const Option& o ) :
@@ -16,13 +17,14 @@
value( o.value ),
wf_token( o.wf_token ),
shortcut( o.shortcut ),
-menu_item( o.menu_item )
+menu( o.menu ),
+menuIndex( o.menuIndex )
{ }
void Option::Load( Worldfile* wf, int section )
{
- Set( (bool)wf->ReadInt(section, wf_token.c_str(), value ));
+ set( (bool)wf->ReadInt( section, wf_token.c_str(), value ));
}
void Option::Save( Worldfile* wf, int section )
@@ -30,32 +32,30 @@
wf->WriteInt(section, wf_token.c_str(), value );
}
-void Option::CreateMenuItem( Fl_Menu_Bar* menu, std::string path )
+void toggleCb( Fl_Widget* w, void* p )
{
- path = path + "/" + optName;
- menu->add( path.c_str(), shortcut.c_str(),
- (Fl_Callback*)ToggleCb, this,
- FL_MENU_TOGGLE | (value ? FL_MENU_VALUE : 0 )
);
-
- // find the menu item we just created and store it for later access
- menu_item = (Fl_Menu_Item*)menu->find_item( path.c_str() );
-}
-
-void Option::ToggleCb( Fl_Menu_Bar* menubar, Option* opt )
-{
- opt->Invert();
+ //Fl_Menu_* menu = static_cast<Fl_Menu_*>( w );
+ Option* opt = static_cast<Option*>( p );
+ opt->invert();
}
-
-void Option::Invert()
+void Option::createMenuItem( Fl_Menu_Bar* m, std::string path )
{
- Set( !value );
-}
+ menu = m;
+ path = path + "/" + optName;
+ // create a menu item and save its index
+ menuIndex = menu->add( path.c_str(), shortcut.c_str(),
+ toggleCb, this,
+ FL_MENU_TOGGLE | (value ? FL_MENU_VALUE : 0 )
);
+}
-void Option::Set( bool val )
+void Option::set( bool val )
{
- value = val;
+ value = val;
- if( menu_item )
- value ? menu_item->set() : menu_item->clear();
+ if( menu ) {
+ const Fl_Menu_Item* mArr = menu->menu();
+ Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>( &mArr[
menuIndex ] );
+ value ? item->set() : item->clear();
+ }
}
Modified: code/stage/trunk/libstage/option.hh
===================================================================
--- code/stage/trunk/libstage/option.hh 2008-07-03 20:22:14 UTC (rev 6749)
+++ code/stage/trunk/libstage/option.hh 2008-07-03 21:09:25 UTC (rev 6750)
@@ -20,38 +20,38 @@
class Option {
private:
- friend bool compare( const Option* lhs, const Option* rhs );
+ friend bool compare( const Option* lhs, const Option* rhs );
- std::string optName;
- bool value;
- /** worldfile entry string for loading and saving this value */
- std::string wf_token;
- std::string shortcut;
- Fl_Menu_Item* menu_item;
+ std::string optName;
+ bool value;
+ /** worldfile entry string for loading and saving this value */
+ std::string wf_token;
+ std::string shortcut;
+ Fl_Menu_* menu;
+ int menuIndex;
public:
Option( std::string n, std::string tok, std::string key, bool v
);
Option( const Option& o );
- const std::string name() const { return optName; }
+ const std::string name() const { return optName; }
inline bool val() const { return value; }
inline operator bool() { return val(); }
inline bool operator<( const Option& rhs ) const
{ return optName<rhs.optName; }
- void Set( bool val );
- void Invert();
+ void set( bool val );
+ void invert() { set( !value ); }
- // Comparator to dereference Option pointers and compare their strings
- struct optComp {
- inline bool operator()( const Option* lhs, const Option* rhs )
const
- { return lhs->operator<(*rhs); }
- };
-
- static void ToggleCb( Fl_Menu_Bar* menubar, Option* opt );
+ // Comparator to dereference Option pointers and compare their
strings
+ struct optComp {
+ inline bool operator()( const Option* lhs, const
Option* rhs ) const
+ { return lhs->operator<(*rhs); }
+ };
- void Load( Worldfile* wf, int section );
- void Save( Worldfile* wf, int section );
- void CreateMenuItem( Fl_Menu_Bar* menu, std::string path );
+
+ void createMenuItem( Fl_Menu_Bar* menu, std::string path );
+ void Load( Worldfile* wf, int section );
+ void Save( Worldfile* wf, int section );
};
}
Modified: code/stage/trunk/libstage/options_dlg.cc
===================================================================
--- code/stage/trunk/libstage/options_dlg.cc 2008-07-03 20:22:14 UTC (rev
6749)
+++ code/stage/trunk/libstage/options_dlg.cc 2008-07-03 21:09:25 UTC (rev
6750)
@@ -36,13 +36,13 @@
if ( check == oDlg->showAllCheck && oDlg->showAll ) {
oDlg->status = CHANGE_ALL;
- oDlg->showAll->Set( check->value() );
+ oDlg->showAll->set( check->value() );
oDlg->do_callback();
oDlg->status = NO_EVENT;
}
else {
int item = oDlg->scroll->find( check );
- oDlg->options[ item ]->Set( check->value() );
+ oDlg->options[ item ]->set( check->value() );
oDlg->changedItem = oDlg->options[ item ];
oDlg->status = CHANGE;
oDlg->do_callback();
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-07-03 20:22:14 UTC (rev 6749)
+++ code/stage/trunk/libstage/stage.hh 2008-07-03 21:09:25 UTC (rev 6750)
@@ -1961,7 +1961,7 @@
void Screenshot();
- void CreateMenuItems( Fl_Menu_Bar* menu, std::string path );
+ void createMenuItems( Fl_Menu_Bar* menu, std::string path );
void FixViewport(int W,int H);
void DrawFloor(); //simpler floor compared to grid
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-07-03 20:22:14 UTC (rev
6749)
+++ code/stage/trunk/libstage/worldgui.cc 2008-07-03 21:09:25 UTC (rev
6750)
@@ -147,7 +147,7 @@
mbar->add( "&View", 0, 0, 0, FL_SUBMENU );
mbar->add( "View/Filter data...", FL_SHIFT + 'd',
StgWorldGui::viewOptionsCb, this );
- canvas->CreateMenuItems( mbar, "View" );
+ canvas->createMenuItems( mbar, "View" );
mbar->add( "&Help", 0, 0, 0, FL_SUBMENU );
mbar->add( "Help/&About Stage...", 0, StgWorldGui::helpAboutCb, this );
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit