Revision: 6758
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6758&view=rev
Author:   jeremy_asher
Date:     2008-07-04 10:44:35 -0700 (Fri, 04 Jul 2008)

Log Message:
-----------
Extended Option class to allow custom callbacks on menu option selection to 
permit perspective cam mode to invalidate canvas

Modified Paths:
--------------
    code/stage/trunk/libstage/canvas.cc
    code/stage/trunk/libstage/option.cc
    code/stage/trunk/libstage/option.hh

Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-07-04 17:07:49 UTC (rev 6757)
+++ code/stage/trunk/libstage/canvas.cc 2008-07-04 17:44:35 UTC (rev 6758)
@@ -201,12 +201,11 @@
 
 int StgCanvas::handle(int event) 
 {
-
-  switch(event) 
-    {
-    case FL_MOUSEWHEEL:
-      if( selected_models )
+       switch(event) 
        {
+       case FL_MOUSEWHEEL:
+               if( selected_models )
+               {
          // rotate all selected models
          for( GList* it = selected_models; it; it=it->next )
            {
@@ -214,7 +213,7 @@
              mod->AddToPose( 0,0,0, 0.1*(double)Fl::event_dy() );
            }
          redraw();
-       }
+               }
       else
        {
          if( perspectiveCam == true ) {
@@ -759,6 +758,11 @@
   printf( "Saved %s\n", filename );
 }
 
+void perspectiveCb( Fl_Widget* w, void* p ) 
+{
+       StgCanvas* canvas = static_cast<StgCanvas*>( p );
+       canvas->invalidate();
+}
 
 void StgCanvas::createMenuItems( Fl_Menu_Bar* menu, std::string path )
 {
@@ -773,6 +777,7 @@
   showGrid.createMenuItem( menu, path );
   showStatus.createMenuItem( menu, path );
   perspectiveCam.createMenuItem( menu, path );
+  perspectiveCam.menuCallback( perspectiveCb, this );
   showOccupancy.createMenuItem( menu, path );
   showTrailArrows.createMenuItem( menu, path );
   showTrails.createMenuItem( menu, path );

Modified: code/stage/trunk/libstage/option.cc
===================================================================
--- code/stage/trunk/libstage/option.cc 2008-07-04 17:07:49 UTC (rev 6757)
+++ code/stage/trunk/libstage/option.cc 2008-07-04 17:44:35 UTC (rev 6758)
@@ -9,17 +9,13 @@
 wf_token( tok ), 
 shortcut( key ), 
 menu( NULL ),
-menuIndex( -1 )
+menuCb( NULL )
 { }
 
-Option::Option( const Option& o ) : 
-optName( o.optName ), 
-value( o.value ), 
-wf_token( o.wf_token ), 
-shortcut( o.shortcut ), 
-menu( o.menu ),
-menuIndex( o.menuIndex )
-{ }
+Fl_Menu_Item* getMenuItem( Fl_Menu_* menu, int i ) {
+       const Fl_Menu_Item* mArr = menu->menu();
+       return const_cast<Fl_Menu_Item*>( &mArr[ i ] );
+}
 
 
 void Option::Load( Worldfile* wf, int section )
@@ -32,13 +28,20 @@
   wf->WriteInt(section, wf_token.c_str(), value );
 }
 
-void toggleCb( Fl_Widget* w, void* p ) 
+void Option::toggleCb( Fl_Widget* w, void* p ) 
 {
        //Fl_Menu_* menu = static_cast<Fl_Menu_*>( w );
        Option* opt = static_cast<Option*>( p );
        opt->invert();
+       if ( opt->menuCb )
+               opt->menuCb( NULL, opt->menuCbParam );
 }
 
+void Option::menuCallback( Fl_Callback* cb, void* p ) {
+       menuCb = cb;
+       menuCbParam = p;
+}
+
 void Option::createMenuItem( Fl_Menu_Bar* m, std::string path )
 {
        menu = m;
@@ -47,15 +50,14 @@
        menuIndex = menu->add( path.c_str(), shortcut.c_str(), 
                                 toggleCb, this, 
                                 FL_MENU_TOGGLE | (value ? FL_MENU_VALUE : 0 ) 
);
-}              
+}
 
 void Option::set( bool val )
 {
        value = val;
 
        if( menu ) {
-               const Fl_Menu_Item* mArr = menu->menu();
-               Fl_Menu_Item* item = const_cast<Fl_Menu_Item*>( &mArr[ 
menuIndex ] );
+               Fl_Menu_Item* item = getMenuItem( menu, menuIndex );
                value ? item->set() : item->clear();
        }
 }

Modified: code/stage/trunk/libstage/option.hh
===================================================================
--- code/stage/trunk/libstage/option.hh 2008-07-04 17:07:49 UTC (rev 6757)
+++ code/stage/trunk/libstage/option.hh 2008-07-04 17:44:35 UTC (rev 6758)
@@ -29,10 +29,11 @@
                std::string shortcut;
                Fl_Menu_* menu;
                int menuIndex;
+               Fl_Callback* menuCb;
+               void* menuCbParam;
          
        public:
                Option( std::string n, std::string tok, std::string key, bool v 
);        
-               Option( const Option& o );
 
                const std::string name() const { return optName; }
                inline bool val() const { return value; }
@@ -50,6 +51,8 @@
 
 
                void createMenuItem( Fl_Menu_Bar* menu, std::string path );
+               void menuCallback( Fl_Callback* cb, void* p );
+               static void toggleCb( Fl_Widget* w, void* p );
                void Load( Worldfile* wf, int section );
                void Save( Worldfile* wf, int section );          
        };


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

Reply via email to