Revision: 6697
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6697&view=rev
Author:   jeremy_asher
Date:     2008-06-26 15:40:34 -0700 (Thu, 26 Jun 2008)

Log Message:
-----------
More Option/OptionDlg updates

Modified Paths:
--------------
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/option.hh
    code/stage/trunk/libstage/options_dlg.cc
    code/stage/trunk/libstage/options_dlg.hh
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/libstage/worldgui.cc

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2008-06-26 21:04:18 UTC (rev 6696)
+++ code/stage/trunk/libstage/model.cc  2008-06-26 22:40:34 UTC (rev 6697)
@@ -162,7 +162,6 @@
   
   this->parent = parent;
   this->world = world;  
-  this->debug = false;
   this->type = type;
   this->id = StgModel::count++; // assign a unique ID and increment
                                                                                
  // the global model counter
@@ -1003,7 +1002,7 @@
        if( gui_grid && (flags & STG_SHOW_GRID) )
                DrawGrid();
 
-       if( ShowFlags ) 
+       if( flag_list && ShowFlags ) 
                DrawFlagList();
 
        if( ShowBlinken )

Modified: code/stage/trunk/libstage/option.hh
===================================================================
--- code/stage/trunk/libstage/option.hh 2008-06-26 21:04:18 UTC (rev 6696)
+++ code/stage/trunk/libstage/option.hh 2008-06-26 22:40:34 UTC (rev 6697)
@@ -10,11 +10,10 @@
                std::string optName;
                bool value;
        public:
-               Option() { }
                Option( std::string n, bool v ) : optName( n ), value( v ) { }
                Option( const Option& o ) : optName( o.optName ), value( 
o.value ) { }
                const std::string name() const { return optName; }
-               inline const bool val() const { return value; }
+               inline bool val() const { return value; }
                inline operator bool() { return val(); }
                inline bool operator<( const Option& rhs ) const
                        { return optName<rhs.optName; } 

Modified: code/stage/trunk/libstage/options_dlg.cc
===================================================================
--- code/stage/trunk/libstage/options_dlg.cc    2008-06-26 21:04:18 UTC (rev 
6696)
+++ code/stage/trunk/libstage/options_dlg.cc    2008-06-26 22:40:34 UTC (rev 
6697)
@@ -4,22 +4,29 @@
 namespace Stg {
 
        OptionsDlg::OptionsDlg( int x, int y, int w, int h ) :
-       Fl_Window( /*x,y,*/w, h, "Model Options" ),
+       Fl_Window( x,y, w,h, "Model Options" ),
        changedItem( NULL ),
+       showAll( NULL ),
        status( NO_EVENT ),
        hm( w/6 ) {
-               scroll = new Fl_Scroll( 0, 0, w, h-btnH-2*vm );
+               showAllCheck = new Fl_Check_Button( 0,0, w,boxH );
+               showAllCheck->callback( checkChanged, this );
+               showAllCheck->deactivate();
+               
+               scroll = new Fl_Scroll( 0,boxH+vm, w,h-boxH-btnH-3*vm );
                scroll->type( Fl_Scroll::VERTICAL );
                scroll->end();
+
                
-               button = new Fl_Button( hm, h-btnH-vm, w-2*hm, btnH, "Apply to 
all" );
-               button->callback( applyAllPress, this );
+               button = new Fl_Button( hm, h-btnH-vm, w-2*hm, btnH, "&Close" );
+               button->callback( closePress, this );
                this->end();
        }
 
        OptionsDlg::~OptionsDlg() {
                delete button;
                delete scroll; // deletes members
+               delete showAllCheck;
        }
 
 
@@ -27,19 +34,27 @@
                Fl_Check_Button* check = static_cast<Fl_Check_Button*>( w );
                OptionsDlg* oDlg = static_cast<OptionsDlg*>( p );
                
-               int item = oDlg->scroll->find( check );
-               oDlg->options[ item ]->set( check->value() );
-               oDlg->changedItem = oDlg->options[ item ];
-               oDlg->status = CHANGE;
-               oDlg->do_callback();
-               oDlg->changedItem = NULL;
-               oDlg->status = NO_EVENT;
+               if ( check == oDlg->showAllCheck && oDlg->showAll ) {
+                       oDlg->status = CHANGE_ALL;
+                       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->changedItem = oDlg->options[ item ];
+                       oDlg->status = CHANGE;
+                       oDlg->do_callback();
+                       oDlg->changedItem = NULL;
+                       oDlg->status = NO_EVENT;
+               }
        }
 
-       void OptionsDlg::applyAllPress( Fl_Widget* w, void* p ) {
+       void OptionsDlg::closePress( Fl_Widget* w, void* p ) {
                OptionsDlg* oDlg = static_cast<OptionsDlg*>( p );
                
-               oDlg->status = CHANGE_ALL;
+               oDlg->status = CLOSE;
                oDlg->do_callback();
                oDlg->status = NO_EVENT;
        }
@@ -77,5 +92,11 @@
                options.insert( options.begin(), opts.begin(), opts.end() );
                updateChecks();
        }
+       
+       void OptionsDlg::showAllOpt( Option* opt ) {
+               showAll = opt;
+               showAllCheck->label( opt->name().c_str() );
+               showAllCheck->value( opt->val() );
+       }
 
 } // namespace Stg 
\ No newline at end of file

Modified: code/stage/trunk/libstage/options_dlg.hh
===================================================================
--- code/stage/trunk/libstage/options_dlg.hh    2008-06-26 21:04:18 UTC (rev 
6696)
+++ code/stage/trunk/libstage/options_dlg.hh    2008-06-26 22:40:34 UTC (rev 
6697)
@@ -16,22 +16,24 @@
 
        class OptionsDlg : protected Fl_Window {
        public:
-               enum event_t { NO_EVENT, CHANGE, CHANGE_ALL };
+               enum event_t { NO_EVENT, CHANGE, CHANGE_ALL, CLOSE };
                
        private:
                std::vector<Option*> options;
                Option* changedItem;
+               Option* showAll;
                event_t status;
                Fl_Scroll* scroll;
                Fl_Button* button;
+               Fl_Check_Button* showAllCheck;
                void updateChecks();
                
                virtual int handle( int event );
                static void checkChanged( Fl_Widget* w, void* p );
-               static void applyAllPress( Fl_Widget* w, void* p );
+               static void closePress( Fl_Widget* w, void* p );
                
                // constants
-               static const int vm = 2;
+               static const int vm = 4;
                const int hm;
                static const int btnH = 25;
                static const int boxH = 30;
@@ -46,6 +48,7 @@
                void setOptions( const std::vector<Option*>& opts );
                void setOptions( const std::set<Option*, optComp>& opts );
                void clearOptions() { options.clear(); }
+               void showAllOpt( Option* opt );
                const event_t event() const { return status; }
                Option* changed() { return changedItem; }
        };

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-26 21:04:18 UTC (rev 6696)
+++ code/stage/trunk/libstage/stage.hh  2008-06-26 22:40:34 UTC (rev 6697)
@@ -870,7 +870,7 @@
   //GHashTable* child_types;
   
 
-  char* token;
+       char* token;
        bool debug;
 
        public:
@@ -2015,6 +2015,8 @@
   
   stg_usec_t real_time_of_last_update;
   stg_usec_t interval_real;   ///< real-time interval between updates - set 
this to zero for 'as fast as possible
+       
+  Option ShowAll;
 
 public:
   static const stg_msec_t DEFAULT_INTERVAL_REAL = 100; ///< real time between 
updates

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2008-06-26 21:04:18 UTC (rev 6696)
+++ code/stage/trunk/libstage/world.cc  2008-06-26 22:40:34 UTC (rev 6697)
@@ -113,9 +113,9 @@
        this->ray_list = NULL;
        this->quit_time = 0;
 
-       assert(token);
-       this->token = (char*)g_malloc(Stg::TOKEN_MAX);
-       snprintf( this->token, Stg::TOKEN_MAX, "%s", token );//this->id );
+       //assert(token);
+       //this->token = (char*)g_malloc(Stg::TOKEN_MAX);
+       //snprintf( this->token, Stg::TOKEN_MAX, "%s", token );//this->id );
 
        this->quit = false;
        this->updates = 0;
@@ -333,9 +333,7 @@
        g_hash_table_foreach( superregions, (GHFunc)destroy_sregion, NULL );
        g_hash_table_remove_all( superregions );
 
-       g_free( token );
-       this->token = (char*)g_malloc(Stg::TOKEN_MAX);  // necessary?
-       
+       token = NULL;
 }
 
 stg_usec_t StgWorld::RealTimeNow()

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2008-06-26 21:04:18 UTC (rev 
6696)
+++ code/stage/trunk/libstage/worldgui.cc       2008-06-26 22:40:34 UTC (rev 
6697)
@@ -132,7 +132,8 @@
 
 
 
-StgWorldGui::StgWorldGui(int W,int H,const char* L) : Fl_Window(W,H,L)
+StgWorldGui::StgWorldGui(int W,int H,const char* L) : Fl_Window(W,H,L),
+ShowAll( "Visualize all models", true )
 {
        //size_range( 100,100 ); // set minimum window size
        oDlg = NULL;
@@ -550,7 +551,6 @@
 void StgWorldGui::viewOptionsCb( Fl_Widget* w, void* p ) {
        StgWorldGui* worldGui = static_cast<StgWorldGui*>( p );
        
-//     std::set<Option*, bool(*)(const Option*,const Option*)> options( 
compare );
        std::set<Option*, optComp> options;
        std::vector<Option*> modOpts;
        for( GList* it=worldGui->update_list; it; it=it->next ) {
@@ -558,17 +558,12 @@
                options.insert( modOpts.begin(), modOpts.end() );       
        }
 
-//     std::vector<Option> options;
-//     std::set<Option*>::iterator it;
-//     for( it=optSet.begin(); it!=optSet.end(); it++ ) {
-//             options.push_back( **it );
-//     }
-       
        if ( !worldGui->oDlg ) {
-               OptionsDlg* oDlg = new OptionsDlg( 0, 0, 180, 250 );
-               // TODO - move initial coords to right edge of window
-               //printf("width: %d\n", worldGui->w());
+               int x = worldGui->w()+worldGui->x() + 10;
+               int y = worldGui->y();
+               OptionsDlg* oDlg = new OptionsDlg( x,y, 180,250 );
                oDlg->callback( optionsDlgCb, worldGui );
+               oDlg->showAllOpt( &worldGui->ShowAll );
                oDlg->setOptions( options );
                oDlg->show();
 
@@ -583,32 +578,39 @@
        OptionsDlg* oDlg = static_cast<OptionsDlg*>( w );
        StgWorldGui* worldGui = static_cast<StgWorldGui*>( p );
 
+       // get event from dialog
+       OptionsDlg::event_t event;
+       event = oDlg->event();
+       
+       // Check FLTK events first
        switch ( Fl::event() ) {
                case FL_SHORTCUT:
                        if ( Fl::event_key() != FL_Escape ) 
-                               break;
+                               break; //return
                        // otherwise, ESC pressed-> do as below
                case FL_CLOSE: // clicked close button
+                       // override event to close
+                       event = OptionsDlg::CLOSE;
+                       break;
+       }
+       
+       switch ( event ) {
+               case OptionsDlg::CHANGE: 
+               {
+                       //Option* o = oDlg->changed();
+                       //printf( "\"%s\" changed to %d!\n", o->name().c_str(), 
o->val() );                     
+                       break;
+               }                       
+               case OptionsDlg::CLOSE:
                        // invalidate the oDlg pointer from the WorldGui
                        //   instance before the dialog is destroyed
                        worldGui->oDlg = NULL; 
                        oDlg->hide();
                        Fl::delete_widget( oDlg );
-                       return;
-               default:
-                       switch ( oDlg->event() ) {
-                               case OptionsDlg::CHANGE: 
-                               {
-                                       //Option* o = oDlg->changed();
-                                       //printf( "\"%s\" changed to %d!\n", 
o->name().c_str(), o->val() );                     
-                                       break;
-                               }
-                               case OptionsDlg::CHANGE_ALL:
-                                       break;
-                               case OptionsDlg::NO_EVENT:
-                                       break;
-                       }
-
+                       return; 
+               case OptionsDlg::NO_EVENT:
+               case OptionsDlg::CHANGE_ALL:
+                       break;
        }
 }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
Playerstage-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to