Revision: 8028
          http://playerstage.svn.sourceforge.net/playerstage/?rev=8028&view=rev
Author:   rtv
Date:     2009-07-16 01:10:16 +0000 (Thu, 16 Jul 2009)

Log Message:
-----------
fixed color bug in flags, and more STLing

Modified Paths:
--------------
    code/stage/trunk/examples/ctrl/source.cc
    code/stage/trunk/libstage/model.cc
    code/stage/trunk/libstage/model_draw.cc
    code/stage/trunk/libstage/resource.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/worldgui.cc

Modified: code/stage/trunk/examples/ctrl/source.cc
===================================================================
--- code/stage/trunk/examples/ctrl/source.cc    2009-07-15 21:10:48 UTC (rev 
8027)
+++ code/stage/trunk/examples/ctrl/source.cc    2009-07-16 01:10:16 UTC (rev 
8028)
@@ -18,7 +18,7 @@
 int Update( Model* mod, void* dummy )
 {
   if( mod->GetWorld()->GetUpdateCount() % INTERVAL  == 0 )
-       mod->PushFlag( new Flag( Color( 1,1,0,0), FLAGSZ ) );
+               mod->PushFlag( new Flag( Color( 1,1,0 ), FLAGSZ ) );
 
   return 0; // run again
 }

Modified: code/stage/trunk/libstage/model.cc
===================================================================
--- code/stage/trunk/libstage/model.cc  2009-07-15 21:10:48 UTC (rev 8027)
+++ code/stage/trunk/libstage/model.cc  2009-07-16 01:10:16 UTC (rev 8028)
@@ -201,8 +201,8 @@
     color( 1,0,0 ), // red
     data_fresh(false),
     disabled(false),
-       custom_visual_list( NULL ),
-    flag_list(NULL),
+        custom_visual_list( NULL ),
+    flag_list(),
     geom(),
     has_default_block( true ),
     id( Model::count++ ),
@@ -335,7 +335,7 @@
 {
   if( flag )
         {
-               flag_list = g_list_append( this->flag_list, flag );             
+               flag_list.push_back( flag );            
                CallCallbacks( &hooks.flag_incr );              
         }
 }
@@ -344,7 +344,8 @@
 {
   if( flag )
         {
-               flag_list = g_list_remove( this->flag_list, flag );
+               flag_list.erase( remove( flag_list.begin(), flag_list.end(), 
flag ));
+
                CallCallbacks( &hooks.flag_decr );
         }
 }
@@ -353,18 +354,18 @@
 {
   if( flag )
         {
-               flag_list = g_list_prepend( flag_list, flag);
+               flag_list.push_front( flag);
                CallCallbacks( &hooks.flag_incr );
         }
 }
 
 Flag* Model::PopFlag()
 {
-  if( flag_list == NULL )
+  if( flag_list.size() == 0 )
     return NULL;
 
-  Flag* flag = (Flag*)flag_list->data;
-  flag_list = g_list_remove( flag_list, flag );
+  Flag* flag = flag_list.front();
+  flag_list.pop_front();
 
   CallCallbacks( &hooks.flag_decr );
 

Modified: code/stage/trunk/libstage/model_draw.cc
===================================================================
--- code/stage/trunk/libstage/model_draw.cc     2009-07-15 21:10:48 UTC (rev 
8027)
+++ code/stage/trunk/libstage/model_draw.cc     2009-07-16 01:10:16 UTC (rev 
8028)
@@ -438,7 +438,7 @@
 
 void Model::DrawFlagList( void )
 {      
-  if( flag_list  == NULL )
+  if( flag_list.size() < 1 )
     return;
   
   PushLocalCoords();
@@ -450,43 +450,20 @@
   Pose gpose = GetGlobalPose();
   glRotatef( 180 + rtod(-gpose.a),0,0,1 );
   
-
-  GList* list = g_list_copy( flag_list );
-  list = g_list_reverse(list);
   
-  for( GList* item = list; item; item = item->next )
-    {
-               
-      Flag* flag = (Flag*)item->data;
-               
-      glTranslatef( 0, 0, flag->size/2.0 );
-                               
-      PushColor( flag->color );
-               
+  for( std::list<Flag*>::reverse_iterator it( flag_list.rbegin()); 
+                it != flag_list.rend(); 
+                it++ )
+    {          
+      Flag* flag = *it;
 
-      glEnable(GL_POLYGON_OFFSET_FILL);
-      glPolygonOffset(1.0, 1.0);
-      gluQuadricDrawStyle( quadric, GLU_FILL );
-      gluSphere( quadric, flag->size/2.0, 4,2  );
-               glDisable(GL_POLYGON_OFFSET_FILL);
-
-      // draw the edges darker version of the same color
-               Color c = flag->color;
-               c.r /= 2.0;
-               c.g /= 2.0;
-               c.b /= 2.0;
-               PushColor( c );
+               glTranslatef( 0, 0, flag->size/2.0 );
                
-      gluQuadricDrawStyle( quadric, GLU_LINE );
-      gluSphere( quadric, flag->size/2.0, 4,2 );
-               
-      PopColor();
-      PopColor();
-               
+               flag->Draw( quadric );
+
       glTranslatef( 0, 0, flag->size/2.0 );
     }
   
-  g_list_free( list );
   
   gluDeleteQuadric( quadric );
   
@@ -514,10 +491,10 @@
       PushColor( b->color );
 
       if( b->enabled )
-       gluQuadricDrawStyle( quadric, GLU_FILL );
+                 gluQuadricDrawStyle( quadric, GLU_FILL );
       else
-       gluQuadricDrawStyle( quadric, GLU_LINE );
-
+                 gluQuadricDrawStyle( quadric, GLU_LINE );
+               
       gluSphere( quadric, b->size/2.0, 8,8  );
 
       PopColor();

Modified: code/stage/trunk/libstage/resource.cc
===================================================================
--- code/stage/trunk/libstage/resource.cc       2009-07-15 21:10:48 UTC (rev 
8027)
+++ code/stage/trunk/libstage/resource.cc       2009-07-16 01:10:16 UTC (rev 
8028)
@@ -20,3 +20,21 @@
 
        return piece;
 }
+
+
+void Flag::Draw(  GLUquadric* quadric )
+{
+  glColor4f( color.r, color.g, color.b, color.a );
+    
+  glEnable(GL_POLYGON_OFFSET_FILL);
+  glPolygonOffset(1.0, 1.0);
+  gluQuadricDrawStyle( quadric, GLU_FILL );
+  gluSphere( quadric, size/2.0, 4,2  );
+  glDisable(GL_POLYGON_OFFSET_FILL);
+  
+  // draw the edges darker version of the same color
+  glColor4f( color.r/2.0, color.g/2.0, color.b/2.0, color.a/2.0 );
+    
+  gluQuadricDrawStyle( quadric, GLU_LINE );
+  gluSphere( quadric, size/2.0, 4,2 );
+}

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2009-07-15 21:10:48 UTC (rev 8027)
+++ code/stage/trunk/libstage/stage.hh  2009-07-16 01:10:16 UTC (rev 8028)
@@ -559,6 +559,10 @@
 
     Flag( Color color, double size );
     Flag* Nibble( double portion );
+
+        /** Draw the flag in OpenGl. Takes a quadric parameter to save
+                 creating the quadric for each flag */
+        void Draw(  GLUquadric* quadric );
   };
   
   /** Abstract class for adding visualizations to models. DataVisualize must 
be overloaded, and is then called in the models local coord system */
@@ -896,10 +900,11 @@
        unsigned int steps; ///< When paused, stage updates while steps >
                                                ///0, decrementing steps with 
each update.
 
-    void Start(){ paused = false; };
-    void Stop(){ paused = true; };
-    void TogglePause(){ paused = !paused; };
-       bool Paused(){ return( paused ); };
+    virtual void Start(){ paused = false; };
+    virtual void Stop(){ paused = true; };
+    virtual void TogglePause(){ paused ? Start() : Stop(); };
+
+        bool Paused(){ return( paused ); };
        
         PointIntVec rt_cells;
         PointIntVec rt_candidate_cells;
@@ -1471,6 +1476,9 @@
     virtual bool IsGUI() { return true; }      
        virtual Model* RecentlySelectedModel();
 
+    virtual void Start();
+    virtual void Stop();
+        
     void DrawBoundingBoxTree();
        
     Canvas* GetCanvas( void ) { return canvas; }
@@ -1713,7 +1721,7 @@
         bool data_fresh;
         stg_bool_t disabled; ///< if non-zero, the model is disabled  
         GList* custom_visual_list;
-        GList* flag_list;
+        std::list<Flag*> flag_list;
         Geom geom;
         Pose global_pose;
         bool gpose_dirty; ///< set this to indicate that global pose may have 
changed  
@@ -2040,7 +2048,7 @@
         void PushFlag( Flag* flag );
         Flag* PopFlag();
        
-        int GetFlagCount() const { return g_list_length( flag_list ); }
+        int GetFlagCount() const { return flag_list.size(); }
   
         /** Add a pointer to a blinkenlight to the model. */
         void AddBlinkenlight( stg_blinkenlight_t* b )

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2009-07-15 21:10:48 UTC (rev 
8027)
+++ code/stage/trunk/libstage/worldgui.cc       2009-07-16 01:10:16 UTC (rev 
8028)
@@ -334,14 +334,16 @@
          TogglePause();
          pause_time = true;
   }
-
-  bool val = World::Update(); 
   
   // if we're paused and counting down, we need to redraw the window
   // because it's not drawn on a timer when paused.
-  if( steps )   
-        canvas->redraw(); // in case something happened that will never be
-                        
+  bool need_redraw = paused && (steps > 0);
+  
+  bool val = World::Update(); 
+  
+  if( need_redraw )
+        canvas->redraw();
+        
   stg_usec_t interval;
   stg_usec_t timenow;
   
@@ -599,24 +601,30 @@
   wg->interval_real = 0;
 }
 
-void WorldGui::pauseCb( Fl_Widget* w, WorldGui* worldGui )
+void WorldGui::Start()
 {
-  worldGui->TogglePause();
+  World::Start();
+  
+  // start the timer that causes regular redraws
+  Fl::add_timeout( ((double)canvas->interval/1000), 
+                                                
(Fl_Timeout_Handler)Canvas::TimerCallback, 
+                                                canvas );
+}
 
-  if( ! worldGui->paused )
-        {
-               // // start the timer that causes regular redraws
-               Fl::add_timeout( ((double)worldGui->canvas->interval/1000), 
-                                                         
(Fl_Timeout_Handler)Canvas::TimerCallback, 
-                                                         worldGui->canvas );
-        }
-  else
-        { // remove the timeout
-               Fl::remove_timeout( (Fl_Timeout_Handler)Canvas::TimerCallback );
-        }
+void WorldGui::Stop()
+{
+  World::Stop();
   
-  worldGui->canvas->redraw(); // in case something happened that will never be
+  // remove the redraw timeout
+  Fl::remove_timeout( (Fl_Timeout_Handler)Canvas::TimerCallback );     
+
   // drawn 'cos we cancelled the timeout
+  canvas->redraw(); // in case something happened that will never be
+}  
+
+void WorldGui::pauseCb( Fl_Widget* w, WorldGui* worldGui )
+{
+  worldGui->TogglePause();
 }
 
 void WorldGui::onceCb( Fl_Widget* w, WorldGui* worldGui )


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

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to