2002-11-07 16:27:47 +00:00
|
|
|
|
// new_gui.cxx: implementation of XML-configurable GUI support.
|
|
|
|
|
|
|
|
|
|
#include "new_gui.hxx"
|
|
|
|
|
|
|
|
|
|
#include <plib/pu.h>
|
2002-11-08 02:03:56 +00:00
|
|
|
|
#include <plib/ul.h>
|
2002-11-07 16:27:47 +00:00
|
|
|
|
|
2003-04-13 21:25:46 +00:00
|
|
|
|
#include <simgear/compiler.h>
|
2002-11-07 16:27:47 +00:00
|
|
|
|
#include <simgear/misc/exception.hxx>
|
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
|
2003-01-16 18:06:27 +00:00
|
|
|
|
#include "menubar.hxx"
|
2003-01-18 15:16:34 +00:00
|
|
|
|
#include "dialog.hxx"
|
2002-11-07 22:59:46 +00:00
|
|
|
|
|
2003-04-13 21:25:46 +00:00
|
|
|
|
SG_USING_STD(map);
|
2002-11-08 15:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of NewGUI.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NewGUI::NewGUI ()
|
2003-01-16 18:06:27 +00:00
|
|
|
|
: _menubar(new FGMenuBar),
|
2003-01-20 16:03:09 +00:00
|
|
|
|
_active_dialog(0)
|
2002-11-08 15:24:14 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NewGUI::~NewGUI ()
|
|
|
|
|
{
|
2003-01-21 15:44:21 +00:00
|
|
|
|
clear();
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::init ()
|
|
|
|
|
{
|
2003-01-16 18:06:27 +00:00
|
|
|
|
char path1[1024];
|
|
|
|
|
char path2[1024];
|
2003-01-19 12:54:26 +00:00
|
|
|
|
ulMakePath(path1, globals->get_fg_root().c_str(), "gui");
|
2003-01-16 18:06:27 +00:00
|
|
|
|
ulMakePath(path2, path1, "dialogs");
|
|
|
|
|
readDir(path2);
|
|
|
|
|
_menubar->init();
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-21 02:09:27 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::reinit ()
|
|
|
|
|
{
|
|
|
|
|
unbind();
|
2003-01-21 15:44:21 +00:00
|
|
|
|
clear();
|
2003-01-21 02:09:27 +00:00
|
|
|
|
_menubar = new FGMenuBar;
|
|
|
|
|
init();
|
|
|
|
|
bind();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 21:11:51 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::bind ()
|
|
|
|
|
{
|
|
|
|
|
fgTie("/sim/menubar/visibility", this,
|
|
|
|
|
&NewGUI::getMenuBarVisible, &NewGUI::setMenuBarVisible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::unbind ()
|
|
|
|
|
{
|
|
|
|
|
fgUntie("/sim/menubar/visibility");
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-08 15:24:14 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::update (double delta_time_sec)
|
|
|
|
|
{
|
|
|
|
|
// NO OP
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 16:03:09 +00:00
|
|
|
|
bool
|
|
|
|
|
NewGUI::showDialog (const string &name)
|
2002-11-08 15:24:14 +00:00
|
|
|
|
{
|
2003-01-20 16:03:09 +00:00
|
|
|
|
if (_dialog_props.find(name) == _dialog_props.end()) {
|
2002-11-08 15:24:14 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Dialog " << name << " not defined");
|
2003-01-20 16:03:09 +00:00
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
new FGDialog(_dialog_props[name]); // it will be deleted by a callback
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NewGUI::closeActiveDialog ()
|
|
|
|
|
{
|
|
|
|
|
if (_active_dialog == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
delete _active_dialog;
|
|
|
|
|
_active_dialog = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2002-12-22 19:52:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2003-01-20 16:03:09 +00:00
|
|
|
|
NewGUI::setActiveDialog (FGDialog * dialog)
|
2002-12-22 19:52:26 +00:00
|
|
|
|
{
|
2003-01-20 16:03:09 +00:00
|
|
|
|
_active_dialog = dialog;
|
2002-12-22 19:52:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 15:16:34 +00:00
|
|
|
|
FGDialog *
|
2003-01-20 16:03:09 +00:00
|
|
|
|
NewGUI::getActiveDialog ()
|
2002-12-22 19:52:26 +00:00
|
|
|
|
{
|
2003-01-20 16:03:09 +00:00
|
|
|
|
return _active_dialog;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-16 18:06:27 +00:00
|
|
|
|
FGMenuBar *
|
|
|
|
|
NewGUI::getMenuBar ()
|
|
|
|
|
{
|
|
|
|
|
return _menubar;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-18 21:11:51 +00:00
|
|
|
|
bool
|
|
|
|
|
NewGUI::getMenuBarVisible () const
|
|
|
|
|
{
|
|
|
|
|
return _menubar->isVisible();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::setMenuBarVisible (bool visible)
|
|
|
|
|
{
|
|
|
|
|
if (visible)
|
|
|
|
|
_menubar->show();
|
|
|
|
|
else
|
|
|
|
|
_menubar->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-21 15:44:21 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::clear ()
|
|
|
|
|
{
|
|
|
|
|
delete _menubar;
|
|
|
|
|
_menubar = 0;
|
|
|
|
|
|
|
|
|
|
map<string,SGPropertyNode *>::iterator it;
|
|
|
|
|
for (it = _dialog_props.begin(); it != _dialog_props.end(); it++)
|
|
|
|
|
delete it->second;
|
|
|
|
|
_dialog_props.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-24 02:43:52 +00:00
|
|
|
|
static bool
|
|
|
|
|
test_extension (const char * path, const char * ext)
|
|
|
|
|
{
|
|
|
|
|
int pathlen = strlen(path);
|
|
|
|
|
int extlen = strlen(ext);
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= pathlen && i <= extlen; i++) {
|
|
|
|
|
if (path[pathlen-i] != ext[extlen-i])
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-08 15:24:14 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::readDir (const char * path)
|
|
|
|
|
{
|
|
|
|
|
ulDir * dir = ulOpenDir(path);
|
|
|
|
|
|
|
|
|
|
if (dir == 0) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Failed to read GUI files from "
|
|
|
|
|
<< path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-21 15:44:21 +00:00
|
|
|
|
for (ulDirEnt * dirEnt = ulReadDir(dir);
|
|
|
|
|
dirEnt != 0;
|
|
|
|
|
dirEnt = ulReadDir(dir)) {
|
|
|
|
|
|
2002-11-08 15:24:14 +00:00
|
|
|
|
char subpath[1024];
|
|
|
|
|
|
|
|
|
|
ulMakePath(subpath, path, dirEnt->d_name);
|
|
|
|
|
|
2003-01-24 02:43:52 +00:00
|
|
|
|
if (!dirEnt->d_isdir && test_extension(subpath, ".xml")) {
|
2003-01-21 15:44:21 +00:00
|
|
|
|
SGPropertyNode * props = new SGPropertyNode;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
try {
|
|
|
|
|
readProperties(subpath, props);
|
|
|
|
|
} catch (const sg_exception &ex) {
|
2003-01-21 15:44:21 +00:00
|
|
|
|
SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
|
2002-11-08 15:24:14 +00:00
|
|
|
|
<< subpath);
|
2003-01-21 15:44:21 +00:00
|
|
|
|
delete props;
|
|
|
|
|
continue;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
if (!props->hasValue("name")) {
|
2003-01-21 15:44:21 +00:00
|
|
|
|
SG_LOG(SG_INPUT, SG_WARN, "dialog " << subpath
|
2002-11-08 15:24:14 +00:00
|
|
|
|
<< " has no name; skipping.");
|
2003-01-21 15:44:21 +00:00
|
|
|
|
delete props;
|
|
|
|
|
continue;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
2003-01-21 15:44:21 +00:00
|
|
|
|
string name = props->getStringValue("name");
|
|
|
|
|
SG_LOG(SG_INPUT, SG_BULK, "Saving dialog " << name);
|
|
|
|
|
if (_dialog_props[name] != 0)
|
|
|
|
|
delete _dialog_props[name];
|
|
|
|
|
_dialog_props[name] = props;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ulCloseDir(dir);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-07 16:27:47 +00:00
|
|
|
|
// end of new_gui.cxx
|