2002-11-07 16:27:47 +00:00
|
|
|
|
// new_gui.cxx: implementation of XML-configurable GUI support.
|
2010-09-30 17:58:01 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "new_gui.hxx"
|
|
|
|
|
|
2008-06-06 19:02:17 +00:00
|
|
|
|
#include <algorithm>
|
2008-06-02 21:07:35 +00:00
|
|
|
|
#include <iostream>
|
2008-06-06 19:02:17 +00:00
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <sys/types.h>
|
2002-11-07 16:27:47 +00:00
|
|
|
|
|
|
|
|
|
#include <plib/pu.h>
|
|
|
|
|
|
2003-04-13 21:25:46 +00:00
|
|
|
|
#include <simgear/compiler.h>
|
2003-09-24 17:20:55 +00:00
|
|
|
|
#include <simgear/structure/exception.hxx>
|
2008-07-31 12:04:32 +00:00
|
|
|
|
#include <simgear/props/props_io.hxx>
|
2010-10-24 00:09:06 +00:00
|
|
|
|
#include <simgear/misc/sg_dir.hxx>
|
2003-09-24 17:20:55 +00:00
|
|
|
|
|
2010-02-10 19:28:35 +00:00
|
|
|
|
#include <boost/algorithm/string/case_conv.hpp>
|
|
|
|
|
|
2002-11-07 16:27:47 +00:00
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
|
2011-10-01 09:05:01 +00:00
|
|
|
|
#if defined(SG_UNIX) && !defined(SG_MAC)
|
2011-10-01 07:50:34 +00:00
|
|
|
|
#include "GL/glx.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-11-19 22:04:35 +00:00
|
|
|
|
#include "FGPUIMenuBar.hxx"
|
2011-11-20 13:23:52 +00:00
|
|
|
|
|
|
|
|
|
#if defined(SG_MAC)
|
|
|
|
|
#include "FGCocoaMenuBar.hxx"
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-11-19 20:46:17 +00:00
|
|
|
|
#include "FGPUIDialog.hxx"
|
2011-11-19 20:25:51 +00:00
|
|
|
|
#include "FGFontCache.hxx"
|
|
|
|
|
#include "FGColor.hxx"
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
2011-10-17 16:41:59 +00:00
|
|
|
|
using std::map;
|
|
|
|
|
using std::string;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
2002-11-08 15:24:14 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of NewGUI.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
2011-11-20 13:23:52 +00:00
|
|
|
|
NewGUI::NewGUI () :
|
|
|
|
|
_active_dialog(0)
|
2002-11-08 15:24:14 +00:00
|
|
|
|
{
|
2011-11-20 13:23:52 +00:00
|
|
|
|
#if defined(SG_MAC)
|
|
|
|
|
_menubar.reset(new FGCocoaMenuBar);
|
|
|
|
|
#else
|
|
|
|
|
_menubar.reset(new FGPUIMenuBar);
|
|
|
|
|
#endif
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NewGUI::~NewGUI ()
|
|
|
|
|
{
|
2005-11-09 17:16:59 +00:00
|
|
|
|
_dialog_props.clear();
|
2007-10-20 08:36:21 +00:00
|
|
|
|
for (_itt_t it = _colors.begin(); it != _colors.end(); ++it)
|
|
|
|
|
delete it->second;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::init ()
|
|
|
|
|
{
|
2005-07-13 10:16:42 +00:00
|
|
|
|
setStyle();
|
2010-10-24 00:09:06 +00:00
|
|
|
|
SGPath p(globals->get_fg_root(), "gui/dialogs");
|
|
|
|
|
readDir(p);
|
2003-01-16 18:06:27 +00:00
|
|
|
|
_menubar->init();
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-21 02:09:27 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::reinit ()
|
2005-11-09 17:16:59 +00:00
|
|
|
|
{
|
|
|
|
|
reset(true);
|
2007-04-02 12:12:23 +00:00
|
|
|
|
fgSetBool("/sim/signals/reinit-gui", true);
|
2005-11-09 17:16:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::redraw ()
|
|
|
|
|
{
|
|
|
|
|
reset(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::reset (bool reload)
|
2003-01-21 02:09:27 +00:00
|
|
|
|
{
|
2005-07-07 21:28:15 +00:00
|
|
|
|
map<string,FGDialog *>::iterator iter;
|
2011-11-19 20:46:17 +00:00
|
|
|
|
std::vector<string> dlg;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
// close all open dialogs and remember them ...
|
2005-11-08 18:18:55 +00:00
|
|
|
|
for (iter = _active_dialogs.begin(); iter != _active_dialogs.end(); ++iter)
|
2005-07-07 21:28:15 +00:00
|
|
|
|
dlg.push_back(iter->first);
|
2005-11-08 18:18:55 +00:00
|
|
|
|
|
|
|
|
|
unsigned int i;
|
|
|
|
|
for (i = 0; i < dlg.size(); i++)
|
|
|
|
|
closeDialog(dlg[i]);
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
|
|
|
|
setStyle();
|
2005-11-09 17:16:59 +00:00
|
|
|
|
|
|
|
|
|
unbind();
|
2011-11-20 16:33:22 +00:00
|
|
|
|
#if !defined(SG_MAC)
|
2011-11-19 22:04:35 +00:00
|
|
|
|
_menubar.reset(new FGPUIMenuBar);
|
2011-11-20 13:23:52 +00:00
|
|
|
|
#endif
|
2005-11-09 17:16:59 +00:00
|
|
|
|
|
|
|
|
|
if (reload) {
|
|
|
|
|
_dialog_props.clear();
|
|
|
|
|
init();
|
|
|
|
|
} else {
|
|
|
|
|
_menubar->init();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-21 02:09:27 +00:00
|
|
|
|
bind();
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
2005-11-09 17:16:59 +00:00
|
|
|
|
// open dialogs again
|
2005-11-08 18:18:55 +00:00
|
|
|
|
for (i = 0; i < dlg.size(); i++)
|
|
|
|
|
showDialog(dlg[i]);
|
2003-01-21 02:09:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2004-05-14 17:16:35 +00:00
|
|
|
|
map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
|
|
|
|
|
for(/**/; iter != _active_dialogs.end(); iter++)
|
|
|
|
|
iter->second->update();
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2003-12-08 02:05:10 +00:00
|
|
|
|
if(!_active_dialogs[name])
|
2011-11-19 20:46:17 +00:00
|
|
|
|
_active_dialogs[name] = new FGPUIDialog(_dialog_props[name]);
|
2003-01-20 16:03:09 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NewGUI::closeActiveDialog ()
|
|
|
|
|
{
|
2003-12-08 02:05:10 +00:00
|
|
|
|
if (_active_dialog == 0)
|
2003-01-20 16:03:09 +00:00
|
|
|
|
return false;
|
2003-12-08 02:05:10 +00:00
|
|
|
|
|
|
|
|
|
// Kill any entries in _active_dialogs... Is there an STL
|
|
|
|
|
// algorithm to do (delete map entries by value, not key)? I hate
|
|
|
|
|
// the STL :) -Andy
|
|
|
|
|
map<string,FGDialog *>::iterator iter = _active_dialogs.begin();
|
2004-04-05 11:29:12 +00:00
|
|
|
|
for(/**/; iter != _active_dialogs.end(); iter++) {
|
|
|
|
|
if(iter->second == _active_dialog) {
|
2003-12-08 02:05:10 +00:00
|
|
|
|
_active_dialogs.erase(iter);
|
2004-04-05 11:29:12 +00:00
|
|
|
|
// iter is no longer valid
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-08 02:05:10 +00:00
|
|
|
|
|
|
|
|
|
delete _active_dialog;
|
|
|
|
|
_active_dialog = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
NewGUI::closeDialog (const string& name)
|
|
|
|
|
{
|
|
|
|
|
if(_active_dialogs.find(name) != _active_dialogs.end()) {
|
|
|
|
|
if(_active_dialog == _active_dialogs[name])
|
|
|
|
|
_active_dialog = 0;
|
|
|
|
|
delete _active_dialogs[name];
|
|
|
|
|
_active_dialogs.erase(name);
|
2003-01-20 16:03:09 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-12-08 02:05:10 +00:00
|
|
|
|
return false; // dialog wasn't open...
|
2002-12-22 19:52:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-20 11:15:00 +00:00
|
|
|
|
SGPropertyNode_ptr
|
2006-04-28 09:59:31 +00:00
|
|
|
|
NewGUI::getDialogProperties (const string &name)
|
2005-10-20 11:15:00 +00:00
|
|
|
|
{
|
|
|
|
|
if(_dialog_props.find(name) != _dialog_props.end())
|
|
|
|
|
return _dialog_props[name];
|
2005-10-22 16:51:27 +00:00
|
|
|
|
|
2006-04-28 10:27:54 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_DEBUG, "dialog '" << name << "' missing");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGDialog *
|
|
|
|
|
NewGUI::getDialog (const string &name)
|
|
|
|
|
{
|
|
|
|
|
if(_active_dialogs.find(name) != _active_dialogs.end())
|
|
|
|
|
return _active_dialogs[name];
|
|
|
|
|
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_DEBUG, "dialog '" << name << "' missing");
|
2005-10-22 16:51:27 +00:00
|
|
|
|
return 0;
|
2005-10-20 11:15:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
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 ()
|
|
|
|
|
{
|
2011-11-19 22:04:35 +00:00
|
|
|
|
return _menubar.get();
|
2003-01-16 18:06:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-12-08 02:05:10 +00:00
|
|
|
|
void
|
|
|
|
|
NewGUI::newDialog (SGPropertyNode* props)
|
|
|
|
|
{
|
|
|
|
|
const char* cname = props->getStringValue("name");
|
|
|
|
|
if(!cname) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "New dialog has no <name> property");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2005-03-29 08:35:13 +00:00
|
|
|
|
string name = cname;
|
2005-11-08 11:05:50 +00:00
|
|
|
|
if(_active_dialogs.find(name) == _active_dialogs.end())
|
2005-03-29 08:35:13 +00:00
|
|
|
|
_dialog_props[name] = props;
|
2003-12-08 02:05:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-08 15:24:14 +00:00
|
|
|
|
void
|
2010-10-24 00:09:06 +00:00
|
|
|
|
NewGUI::readDir (const SGPath& path)
|
2002-11-08 15:24:14 +00:00
|
|
|
|
{
|
2010-10-24 00:09:06 +00:00
|
|
|
|
simgear::Dir dir(path);
|
|
|
|
|
simgear::PathList xmls = dir.children(simgear::Dir::TYPE_FILE, ".xml");
|
|
|
|
|
|
|
|
|
|
for (unsigned int i=0; i<xmls.size(); ++i) {
|
|
|
|
|
SGPropertyNode * props = new SGPropertyNode;
|
|
|
|
|
try {
|
|
|
|
|
readProperties(xmls[i].str(), props);
|
|
|
|
|
} catch (const sg_exception &) {
|
|
|
|
|
SG_LOG(SG_INPUT, SG_ALERT, "Error parsing dialog "
|
|
|
|
|
<< xmls[i].str());
|
|
|
|
|
delete props;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
SGPropertyNode *nameprop = props->getNode("name");
|
|
|
|
|
if (!nameprop) {
|
|
|
|
|
SG_LOG(SG_INPUT, SG_WARN, "dialog " << xmls[i].str()
|
|
|
|
|
<< " has no name; skipping.");
|
|
|
|
|
delete props;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
string name = nameprop->getStringValue();
|
|
|
|
|
_dialog_props[name] = props;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Style handling.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::setStyle (void)
|
|
|
|
|
{
|
2005-10-14 16:25:14 +00:00
|
|
|
|
_itt_t it;
|
|
|
|
|
for (it = _colors.begin(); it != _colors.end(); ++it)
|
|
|
|
|
delete it->second;
|
2005-07-13 10:16:42 +00:00
|
|
|
|
_colors.clear();
|
|
|
|
|
|
|
|
|
|
// set up the traditional colors as default
|
2005-07-18 09:18:24 +00:00
|
|
|
|
_colors["background"] = new FGColor(0.8f, 0.8f, 0.9f, 0.85f);
|
|
|
|
|
_colors["foreground"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
_colors["highlight"] = new FGColor(0.7f, 0.7f, 0.7f, 1.0f);
|
|
|
|
|
_colors["label"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
_colors["legend"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
|
_colors["misc"] = new FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
2005-11-09 17:16:59 +00:00
|
|
|
|
_colors["inputfield"] = new FGColor(0.8f, 0.7f, 0.7f, 1.0f);
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
|
|
|
|
//puSetDefaultStyle();
|
|
|
|
|
|
2006-03-09 23:04:41 +00:00
|
|
|
|
int which = fgGetInt("/sim/gui/current-style", 0);
|
2006-03-19 07:10:10 +00:00
|
|
|
|
SGPropertyNode *sim = globals->get_props()->getNode("sim/gui", true);
|
2006-03-09 23:04:41 +00:00
|
|
|
|
SGPropertyNode *n = sim->getChild("style", which);
|
2005-07-13 10:57:27 +00:00
|
|
|
|
if (!n)
|
2006-03-09 23:04:41 +00:00
|
|
|
|
n = sim->getChild("style", 0, true);
|
2005-07-13 10:57:27 +00:00
|
|
|
|
|
2006-02-04 13:06:47 +00:00
|
|
|
|
setupFont(n->getNode("fonts/gui", true));
|
2005-07-13 10:57:27 +00:00
|
|
|
|
n = n->getNode("colors", true);
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n->nChildren(); i++) {
|
|
|
|
|
SGPropertyNode *child = n->getChild(i);
|
2005-07-18 09:18:24 +00:00
|
|
|
|
_colors[child->getName()] = new FGColor(child);
|
2005-07-07 21:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-18 09:18:24 +00:00
|
|
|
|
FGColor *c = _colors["background"];
|
|
|
|
|
puSetDefaultColourScheme(c->red(), c->green(), c->blue(), c->alpha());
|
2005-07-07 21:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-07-13 10:16:42 +00:00
|
|
|
|
NewGUI::setupFont (SGPropertyNode *node)
|
2005-07-07 21:28:15 +00:00
|
|
|
|
{
|
2006-06-05 20:23:56 +00:00
|
|
|
|
_font = globals->get_fontcache()->get(node);
|
2006-01-26 21:40:37 +00:00
|
|
|
|
puSetDefaultFonts(*_font, *_font);
|
|
|
|
|
return;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-07 16:27:47 +00:00
|
|
|
|
// end of new_gui.cxx
|