Revision: 6668
http://playerstage.svn.sourceforge.net/playerstage/?rev=6668&view=rev
Author: jeremy_asher
Date: 2008-06-23 15:18:02 -0700 (Mon, 23 Jun 2008)
Log Message:
-----------
Options dialog progress, fixed leaks in dialog callbacks, FileManager and
OptionsDlg header reorg
Modified Paths:
--------------
code/stage/trunk/libstage/CMakeLists.txt
code/stage/trunk/libstage/canvas.cc
code/stage/trunk/libstage/main.cc
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/CMakeLists.txt
===================================================================
--- code/stage/trunk/libstage/CMakeLists.txt 2008-06-23 21:17:23 UTC (rev
6667)
+++ code/stage/trunk/libstage/CMakeLists.txt 2008-06-23 22:18:02 UTC (rev
6668)
@@ -27,6 +27,7 @@
model_ranger.cc
resource.cc
texture_manager.cc
+ option.hh
options_dlg.cc
options_dlg.hh
)
@@ -68,5 +69,5 @@
LIBRARY DESTINATION lib
)
-INSTALL(FILES stage.hh file_manager.hh options_dlg.hh
+INSTALL(FILES stage.hh option.hh
DESTINATION include/${PROJECT_NAME}-${V_MAJOR}.${V_MINOR})
Modified: code/stage/trunk/libstage/canvas.cc
===================================================================
--- code/stage/trunk/libstage/canvas.cc 2008-06-23 21:17:23 UTC (rev 6667)
+++ code/stage/trunk/libstage/canvas.cc 2008-06-23 22:18:02 UTC (rev 6668)
@@ -11,6 +11,9 @@
#include <string>
#include <png.h>
+#include "file_manager.hh"
+#include "options_dlg.hh"
+
using namespace Stg;
static const int checkImageWidth = 2;
@@ -159,7 +162,6 @@
// remove it from the selected list
selected_models =
g_list_remove_link( selected_models, link );
-
mod->Disable();
}
else
@@ -701,7 +703,7 @@
//TODO find a better home for loading textures
if( loaded_texture == false ) {
std::string fullpath;
- fullpath = world->fileMan.fullPath( "stall.png" );
+ fullpath = world->fileMan->fullPath( "stall.png" );
if ( fullpath == "" ) {
PRINT_DEBUG( "Unable to load texture.\n" );
}
@@ -730,7 +732,7 @@
//glEnableClientState( GL_COLOR_ARRAY );
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
+
if( ! canvas_init_done ) // do a bit of texture setup
{
canvas_init_done = true;
Modified: code/stage/trunk/libstage/main.cc
===================================================================
--- code/stage/trunk/libstage/main.cc 2008-06-23 21:17:23 UTC (rev 6667)
+++ code/stage/trunk/libstage/main.cc 2008-06-23 22:18:02 UTC (rev 6668)
@@ -63,8 +63,8 @@
}
if( loaded_world_file == false ) {
- // replace this with a loading dialog/window
- StgWorldGui* world = new StgWorldGui( 400, 300 );
+ // TODO: special window/loading dialog for this case
+ new StgWorldGui( 400, 300 );
}
Modified: code/stage/trunk/libstage/options_dlg.cc
===================================================================
--- code/stage/trunk/libstage/options_dlg.cc 2008-06-23 21:17:23 UTC (rev
6667)
+++ code/stage/trunk/libstage/options_dlg.cc 2008-06-23 22:18:02 UTC (rev
6668)
@@ -1,68 +1,69 @@
#include "options_dlg.hh"
#include <FL/Fl.H>
+namespace Stg {
-OptionsDlg::OptionsDlg( const std::vector<Option>& opts, int w, int h ) :
-Fl_Window( w, h, "Model Options" ),
-options( opts ) {
- const int hm = w/6;
- const int vm = 2;
- const int btnH = 25;
-
- scroll = new Fl_Scroll( 0, 0, w, h-btnH-2*vm );
- scroll->type( Fl_Scroll::VERTICAL );
-
- Fl_Check_Button* check;
- for ( unsigned int i=0; i<options.size(); i++ ) {
- check = new Fl_Check_Button( 0,30*i, w, 30, options[ i
].name().c_str() );
- if ( options[ i ].val() )
- check->set();
- check->callback( checkChanged, this );
+ OptionsDlg::OptionsDlg( int x, int y, int w, int h ) :
+ Fl_Window( /*x,y,*/w, h, "Model Options" ),
+ hm( w/6 ) {
+ scroll = new Fl_Scroll( 0, 0, w, h-btnH-2*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 );
+ this->end();
}
- scroll->end();
-
- button = new Fl_Button( hm, h-btnH-vm, w-2*hm, btnH, "Apply to all" );
- button->callback( applyAllPress, this );
- this->end();
-}
-OptionsDlg::~OptionsDlg() {
- delete button;
- delete scroll; // deletes members
-}
+ OptionsDlg::~OptionsDlg() {
+ delete button;
+ delete scroll; // deletes members
+ }
-void OptionsDlg::display() {
- Fl_Window::show();
- while ( shown() )
- Fl::wait();
-}
-void OptionsDlg::checkChanged( Fl_Widget* w, void* p ) {
- 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->do_callback();
-}
+ void OptionsDlg::checkChanged( Fl_Widget* w, void* p ) {
+ 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->do_callback();
+ }
-void OptionsDlg::applyAllPress( Fl_Widget* w, void* p ) {
- OptionsDlg* oDlg = static_cast<OptionsDlg*>( p );
-
- oDlg->changedItem = Option( -1, "", false );
- oDlg->do_callback();
-}
+ void OptionsDlg::applyAllPress( Fl_Widget* w, void* p ) {
+ OptionsDlg* oDlg = static_cast<OptionsDlg*>( p );
+
+ oDlg->changedItem = Option( -1, "", false );
+ oDlg->do_callback();
+ }
-int OptionsDlg::handle( int event ) {
- switch ( event ) {
- case FL_SHORTCUT:
- if ( Fl::event_key() == FL_Escape ) {
- hide();
- return 1;
- }
- break;
+ int OptionsDlg::handle( int event ) {
+ // switch ( event ) {
+ //
+ // }
+
+ return Fl_Window::handle( event );
}
-
- return Fl_Window::handle( event );
-}
\ No newline at end of file
+
+
+ void OptionsDlg::updateChecks() {
+ scroll->clear();
+ scroll->begin();
+ Fl_Check_Button* check;
+ for ( unsigned int i=0; i<options.size(); i++ ) {
+ check = new Fl_Check_Button( 0,boxH*i, scroll->w(),
boxH, options[ i ].name().c_str() );
+ if ( options[ i ].val() )
+ check->set();
+ check->callback( checkChanged, this );
+ }
+ scroll->end();
+ }
+
+ void OptionsDlg::setOptions( const std::vector<Option>& opts ) {
+ options.clear();
+ options.insert( options.begin(), opts.begin(), opts.end() );
+ updateChecks();
+ }
+
+} // 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-23 21:17:23 UTC (rev
6667)
+++ code/stage/trunk/libstage/options_dlg.hh 2008-06-23 22:18:02 UTC (rev
6668)
@@ -9,40 +9,42 @@
#include <string>
#include <vector>
+#include "option.hh"
-class Option {
-private:
- int index;
- std::string optName;
- bool value;
-public:
- Option() { }
- Option( int i, std::string n, bool v ) : index( i ), optName( n ),
value( v ) { }
- Option( const Option& o ) : index( o.index ), optName( o.optName ),
value( o.value ) { }
- const std::string name() const { return optName; }
- const int id() const { return index; }
- const bool val() const { return value; }
- void set( bool val ) { value = val; }
-};
+namespace Stg {
+ class OptionsDlg : protected Fl_Window {
+ private:
+ std::vector<Option> options;
+ Option changedItem;
+ Fl_Scroll* scroll;
+ Fl_Button* button;
+ void updateChecks();
+
+ virtual int handle( int event );
+ static void checkChanged( Fl_Widget* w, void* p );
+ static void applyAllPress( Fl_Widget* w, void* p );
-class OptionsDlg : protected Fl_Window {
-private:
- std::vector<Option> options;
- Fl_Scroll* scroll;
- Fl_Button* button;
- virtual int handle( int event );
- static void checkChanged( Fl_Widget* w, void* p );
- static void applyAllPress( Fl_Widget* w, void* p );
- Option changedItem;
-public:
- OptionsDlg( const std::vector<Option>& opts, int w, int h );
- virtual ~OptionsDlg();
- void display();
- void callback( Fl_Callback* cb, void* p ) { Fl_Window::callback( cb, p
); }
- //void setChangeCb( Fl_Callback* cb, void* p );
- const Option changed() const { return changedItem; }
- void hide() { Fl_Window::hide(); }
-};
+ public:
+ OptionsDlg( int x, int y, int w, int h );
+ virtual ~OptionsDlg();
+ void callback( Fl_Callback* cb, void* p ) {
Fl_Window::callback( cb, p ); }
+ void show() { Fl_Window::show(); }
+ void hide() { Fl_Window::hide(); }
+
+ void setOptions( const std::vector<Option>& opts );
+ void clearOptions() { options.clear(); }
+ const Option changed() const { return changedItem; }
+
+ private:
+ // constants
+ static const int vm = 2;
+ const int hm;
+ static const int btnH = 25;
+ static const int boxH = 30;
+ };
+}
+
#endif
+
Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh 2008-06-23 21:17:23 UTC (rev 6667)
+++ code/stage/trunk/libstage/stage.hh 2008-06-23 22:18:02 UTC (rev 6668)
@@ -54,6 +54,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <iostream>
+#include <vector>
// we use GLib's data structures extensively. Perhaps we'll move to
// C++ STL types to lose this dependency one day.
@@ -75,8 +76,7 @@
#include <GL/glu.h>
#endif
-#include "file_manager.hh"
-#include "options_dlg.hh"
+#include "option.hh"
/** The Stage library uses its own namespace */
namespace Stg
@@ -87,6 +87,8 @@
class StgWorld;
class StgWorldGui;
class StgModel;
+ class FileManager;
+ class OptionsDlg;
/** Initialize the Stage library */
void Init( int* argc, char** argv[] );
@@ -1090,7 +1092,7 @@
virtual ~StgWorld();
- FileManager fileMan;
+ FileManager* fileMan;
stg_usec_t SimTimeNow(void){ return sim_time;} ;
stg_usec_t RealTimeNow(void);
@@ -1164,7 +1166,6 @@
static uint32_t count;
static GHashTable* modelsbyid;
-
public:
/** Look up a model pointer by a unique model ID */
@@ -1234,7 +1235,8 @@
int gui_grid;
int gui_outline;
int gui_mask;
-
+
+
StgModel* parent; //< the model that owns this one, possibly NULL
/** GData datalist can contain arbitrary named data items. Can be used
@@ -1399,7 +1401,7 @@
stg_model_type_t type;
- public:
+public:
static const char* typestr;
@@ -1440,7 +1442,7 @@
StgFlag* PopFlag();
int GetFlagCount(){ return g_list_length( flag_list ); }
-
+
void DrawFlagList();
void AddBlinkenlight( stg_blinkenlight_t* b )
@@ -1999,6 +2001,7 @@
//int wf_section;
StgCanvas* canvas;
Fl_Menu_Bar* mbar;
+ OptionsDlg* oDlg;
stg_usec_t interval_log[INTERVAL_LOG_LEN];
stg_usec_t real_time_of_last_update;
Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc 2008-06-23 21:17:23 UTC (rev 6667)
+++ code/stage/trunk/libstage/world.cc 2008-06-23 22:18:02 UTC (rev 6668)
@@ -52,6 +52,7 @@
#include "stage_internal.hh"
#include "region.hh"
+#include "file_manager.hh"
// static data members
@@ -147,6 +148,8 @@
bzero( &this->extent, sizeof(this->extent));
this->real_time_now = 0;
+
+ fileMan = new FileManager();
}
StgWorld::~StgWorld( void )
@@ -162,6 +165,8 @@
g_free( token );
world_list = g_list_remove( world_list, this );
+
+ delete fileMan;
}
Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc 2008-06-23 21:17:23 UTC (rev
6667)
+++ code/stage/trunk/libstage/worldgui.cc 2008-06-23 22:18:02 UTC (rev
6668)
@@ -105,7 +105,10 @@
#include <FL/Fl_Text_Display.H>
#include <FL/Fl_File_Chooser.H>
+#include "file_manager.hh"
+#include "options_dlg.hh"
+
static const char* MITEM_VIEW_DATA = "&View/&Data";
static const char* MITEM_VIEW_BLOCKS = "&View/&Blocks";
static const char* MITEM_VIEW_GRID = "&View/&Grid";
@@ -147,6 +150,8 @@
canvas = new StgCanvas( this,0,30,W,H-30 );
resizable(canvas);
end();
+
+ oDlg = NULL;
mbar->add( "&File", 0, 0, 0, FL_SUBMENU );
mbar->add( "File/&Load World...", FL_CTRL + 'l', (Fl_Callback
*)LoadCallback, this, FL_MENU_DIVIDER );
@@ -198,6 +203,8 @@
StgWorldGui::~StgWorldGui()
{
delete mbar;
+ if ( oDlg )
+ delete oDlg;
delete canvas;
}
@@ -254,7 +261,7 @@
{
PRINT_DEBUG1( "%s.Load()", token );
- fileMan.newWorld( filename );
+ fileMan->newWorld( filename );
StgWorld::Load( filename );
@@ -351,7 +358,7 @@
//bool success;
const char* pattern = "World Files (*.world)";
- worldsPath = world->fileMan.worldsRoot().c_str();
+ worldsPath = world->fileMan->worldsRoot().c_str();
Fl_File_Chooser fc( worldsPath, pattern, Fl_File_Chooser::CREATE, "Load
World File..." );
fc.ok_label( "Load" );
@@ -362,7 +369,7 @@
filename = fc.value();
if (filename != NULL) { // chose something
- if ( world->fileMan.readable( filename ) ) {
+ if ( world->fileMan->readable( filename ) ) {
// file is readable, clear and load
// if (initialized) {
@@ -513,19 +520,35 @@
options.push_back( o );
}
- OptionsDlg oDlg( options, 180, 250 );
- oDlg.callback( optionsDlgCb, worldGui );
- oDlg.display();
-
- printf("Dialog callback ended\n");
+ 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());
+ oDlg->callback( optionsDlgCb, worldGui );
+ oDlg->setOptions( options );
+ oDlg->show();
+
+ worldGui->oDlg = oDlg;
+ }
+ else {
+ worldGui->oDlg->show(); // bring it to front
+ }
}
void StgWorldGui::optionsDlgCb( Fl_Widget* w, void* p ) {
OptionsDlg* oDlg = static_cast<OptionsDlg*>( w );
StgWorldGui* worldGui = static_cast<StgWorldGui*>( p );
switch ( Fl::event() ) {
+ case FL_SHORTCUT:
+ if ( Fl::event_key() != FL_Escape )
+ break;
+ // otherwise, ESC pressed-> do as below
case FL_CLOSE: // clicked close button
+ // invalidate the oDlg pointer from the WorldGui
+ // instance before the dialog is destroyed
+ worldGui->oDlg = NULL;
oDlg->hide();
+ Fl::delete_widget( oDlg );
return;
default:
Option o = oDlg->changed();
@@ -534,6 +557,18 @@
}
}
+void AboutCloseCb( Fl_Widget* w, void* p ) {
+ Fl_Window* win;
+ win = static_cast<Fl_Window*>( w );
+ Fl_Text_Display* textDisplay;
+ textDisplay = static_cast<Fl_Text_Display*>( p );
+
+ Fl_Text_Buffer* tbuf = textDisplay->buffer();
+ textDisplay->buffer( NULL );
+ delete tbuf;
+ Fl::delete_widget( win );
+}
+
void StgWorldGui::About_cb( Fl_Widget*, StgWorldGui* world )
{
fl_register_images();
@@ -546,22 +581,23 @@
const int pngH = 82;
//const int pngW = 264;
- Fl_Window win( Width, Height ); // make a window
+ Fl_Window* win = new Fl_Window( Width, Height ); // make a window
- Fl_Box box( Spc, Spc,
+ Fl_Box* box = new Fl_Box( Spc, Spc,
Width-2*Spc, pngH ); // widget that will contain
image
std::string fullpath;
- fullpath = world->fileMan.fullPath( "stagelogo.png" );
- Fl_PNG_Image png( fullpath.c_str() ); // load image into ram
- box.image(png); // attach image to box
+ fullpath = world->fileMan->fullPath( "stagelogo.png" );
+ Fl_PNG_Image* png = new Fl_PNG_Image( fullpath.c_str() ); // load image
into ram
+ box->image( png ); // attach image to box
Fl_Text_Display* textDisplay;
textDisplay = new Fl_Text_Display( Spc, pngH+2*Spc,
Width-2*Spc,
Height-pngH-ButtonH-4*Spc );
textDisplay->box( FL_NO_BOX );
- textDisplay->color(win.color());
+ textDisplay->color( win->color() );
+ win->callback( AboutCloseCb, textDisplay );
const char* AboutText =
"\n"
@@ -574,17 +610,13 @@
tbuf->append( AboutText );
textDisplay->buffer( tbuf );
- Fl_Return_Button button( (Width - ButtonW)/2, Height-Spc-ButtonH,
+ Fl_Return_Button* button;
+ button = new Fl_Return_Button( (Width - ButtonW)/2, Height-Spc-ButtonH,
ButtonW, ButtonH,
"&OK" );
- button.callback( (Fl_Callback*)HelpAboutCallback );
+ button->callback( (Fl_Callback*)HelpAboutCallback );
- win.show();
- while (win.shown())
- Fl::wait();
-
- delete textDisplay;
- delete tbuf;
+ win->show();
}
void StgWorldGui::HelpAboutCallback( Fl_Widget* wid ) {
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit