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>
|
2003-09-24 17:20:55 +00:00
|
|
|
|
#include <simgear/structure/exception.hxx>
|
|
|
|
|
|
2002-11-07 16:27:47 +00:00
|
|
|
|
#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
|
|
|
|
|
2005-07-07 21:28:15 +00:00
|
|
|
|
extern puFont FONT_HELVETICA_14;
|
2005-07-08 13:28:40 +00:00
|
|
|
|
extern puFont FONT_SANS_12B;
|
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
|
|
|
|
|
2002-11-08 15:24:14 +00:00
|
|
|
|
NewGUI::NewGUI ()
|
2006-01-26 21:40:37 +00:00
|
|
|
|
: _fontcache(new FGFontCache),
|
2005-07-07 21:28:15 +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 ()
|
|
|
|
|
{
|
2005-11-09 17:16:59 +00:00
|
|
|
|
delete _menubar;
|
|
|
|
|
_dialog_props.clear();
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NewGUI::init ()
|
|
|
|
|
{
|
2005-07-13 10:16:42 +00:00
|
|
|
|
setStyle();
|
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 ()
|
2005-11-09 17:16:59 +00:00
|
|
|
|
{
|
|
|
|
|
reset(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
vector<string> dlg;
|
|
|
|
|
// 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();
|
2005-11-08 18:18:55 +00:00
|
|
|
|
delete _menubar;
|
2003-01-21 02:09:27 +00:00
|
|
|
|
_menubar = new FGMenuBar;
|
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])
|
|
|
|
|
_active_dialogs[name] = new FGDialog(_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
|
|
|
|
|
NewGUI::getDialog (const string &name)
|
|
|
|
|
{
|
|
|
|
|
if(_dialog_props.find(name) != _dialog_props.end())
|
|
|
|
|
return _dialog_props[name];
|
2005-10-22 16:51:27 +00:00
|
|
|
|
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "dialog '" << name << "' missing");
|
|
|
|
|
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 ()
|
|
|
|
|
{
|
|
|
|
|
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-24 02:43:52 +00:00
|
|
|
|
static bool
|
|
|
|
|
test_extension (const char * path, const char * ext)
|
|
|
|
|
{
|
|
|
|
|
int pathlen = strlen(path);
|
|
|
|
|
int extlen = strlen(ext);
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
2003-01-24 02:43:52 +00:00
|
|
|
|
for (int i = 1; i <= pathlen && i <= extlen; i++) {
|
|
|
|
|
if (path[pathlen-i] != ext[extlen-i])
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
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);
|
2004-04-05 11:29:12 +00:00
|
|
|
|
} catch (const sg_exception &) {
|
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
|
|
|
|
}
|
2005-03-29 08:35:13 +00:00
|
|
|
|
SGPropertyNode *nameprop = props->getNode("name");
|
|
|
|
|
if (!nameprop) {
|
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
|
|
|
|
}
|
2005-03-29 08:35:13 +00:00
|
|
|
|
string name = nameprop->getStringValue();
|
|
|
|
|
if (_dialog_props[name])
|
|
|
|
|
delete (SGPropertyNode *)_dialog_props[name];
|
|
|
|
|
|
|
|
|
|
_dialog_props[name] = props;
|
2002-11-08 15:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ulCloseDir(dir);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
SGPropertyNode *sim = globals->get_props()->getNode("sim/gui");
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
|
char *name;
|
2005-07-08 11:15:17 +00:00
|
|
|
|
puFont *font;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
} guifonts[] = {
|
2005-07-13 11:43:00 +00:00
|
|
|
|
{ "default", &FONT_HELVETICA_14 },
|
|
|
|
|
{ "FIXED_8x13", &PUFONT_8_BY_13 },
|
|
|
|
|
{ "FIXED_9x15", &PUFONT_9_BY_15 },
|
|
|
|
|
{ "TIMES_10", &PUFONT_TIMES_ROMAN_10 },
|
|
|
|
|
{ "TIMES_24", &PUFONT_TIMES_ROMAN_24 },
|
|
|
|
|
{ "HELVETICA_10", &PUFONT_HELVETICA_10 },
|
|
|
|
|
{ "HELVETICA_12", &PUFONT_HELVETICA_12 },
|
|
|
|
|
{ "HELVETICA_14", &FONT_HELVETICA_14 },
|
|
|
|
|
{ "HELVETICA_18", &PUFONT_HELVETICA_18 },
|
|
|
|
|
{ "SANS_12B", &FONT_SANS_12B },
|
|
|
|
|
{ 0, 0 }
|
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-01-26 21:40:37 +00:00
|
|
|
|
_font = _fontcache->get(node);
|
|
|
|
|
puSetDefaultFonts(*_font, *_font);
|
|
|
|
|
return;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// FGColor class.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2005-07-11 08:01:28 +00:00
|
|
|
|
bool
|
2005-07-07 21:28:15 +00:00
|
|
|
|
FGColor::merge(const SGPropertyNode *node)
|
|
|
|
|
{
|
|
|
|
|
if (!node)
|
2005-07-11 08:01:28 +00:00
|
|
|
|
return false;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
|
2005-07-11 08:01:28 +00:00
|
|
|
|
bool dirty = false;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
const SGPropertyNode * n;
|
|
|
|
|
if ((n = node->getNode("red")))
|
2005-07-11 08:01:28 +00:00
|
|
|
|
_red = n->getFloatValue(), dirty = true;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
if ((n = node->getNode("green")))
|
2005-07-11 08:01:28 +00:00
|
|
|
|
_green = n->getFloatValue(), dirty = true;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
if ((n = node->getNode("blue")))
|
2005-07-11 08:01:28 +00:00
|
|
|
|
_blue = n->getFloatValue(), dirty = true;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
if ((n = node->getNode("alpha")))
|
2005-07-11 08:01:28 +00:00
|
|
|
|
_alpha = n->getFloatValue(), dirty = true;
|
|
|
|
|
return dirty;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 08:01:28 +00:00
|
|
|
|
bool
|
2005-07-18 10:00:02 +00:00
|
|
|
|
FGColor::merge(const FGColor *color)
|
2005-07-07 21:28:15 +00:00
|
|
|
|
{
|
2005-07-11 08:01:28 +00:00
|
|
|
|
bool dirty = false;
|
2005-07-18 10:00:02 +00:00
|
|
|
|
if (color && color->_red >= 0.0)
|
|
|
|
|
_red = color->_red, dirty = true;
|
|
|
|
|
if (color && color->_green >= 0.0)
|
|
|
|
|
_green = color->_green, dirty = true;
|
|
|
|
|
if (color && color->_blue >= 0.0)
|
|
|
|
|
_blue = color->_blue, dirty = true;
|
|
|
|
|
if (color && color->_alpha >= 0.0)
|
|
|
|
|
_alpha = color->_alpha, dirty = true;
|
2005-07-11 08:01:28 +00:00
|
|
|
|
return dirty;
|
2005-07-07 21:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-18 09:18:24 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
FGFontCache::FGFontCache()
|
|
|
|
|
{
|
|
|
|
|
char *envp = ::getenv("FG_FONTS");
|
|
|
|
|
if (envp != NULL) {
|
|
|
|
|
_path.set(envp);
|
|
|
|
|
} else {
|
|
|
|
|
_path.set(globals->get_fg_root());
|
|
|
|
|
_path.append("Fonts");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i=0; guifonts[i].name; i++)
|
2006-01-26 21:40:37 +00:00
|
|
|
|
_fonts[guifonts[i].name] = new fnt(guifonts[i].font);
|
2005-07-18 09:18:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGFontCache::~FGFontCache()
|
|
|
|
|
{
|
|
|
|
|
_fonts.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puFont *
|
|
|
|
|
FGFontCache::get(const char *name, float size, float slant)
|
|
|
|
|
{
|
|
|
|
|
_itt_t it;
|
|
|
|
|
|
2006-01-26 22:22:37 +00:00
|
|
|
|
if ((it = _fonts.find(name)) != _fonts.end())
|
2006-01-26 21:40:37 +00:00
|
|
|
|
return it->second->pufont;
|
2006-01-26 22:22:37 +00:00
|
|
|
|
|
|
|
|
|
SGPath path(_path);
|
|
|
|
|
path.append(name);
|
|
|
|
|
|
|
|
|
|
fnt *f = new fnt();
|
|
|
|
|
f->texfont = new fntTexFont;
|
|
|
|
|
|
|
|
|
|
if (f->texfont->load((char *)path.c_str())) {
|
|
|
|
|
f->pufont = new puFont;
|
|
|
|
|
f->pufont->initialize(static_cast<fntFont *>(f->texfont), size, slant);
|
|
|
|
|
_fonts[name] = f;
|
|
|
|
|
return f->pufont;
|
2006-01-26 21:40:37 +00:00
|
|
|
|
}
|
2006-01-26 22:22:37 +00:00
|
|
|
|
|
|
|
|
|
delete f;
|
|
|
|
|
return _fonts["default"]->pufont;
|
2005-07-18 09:18:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
puFont *
|
|
|
|
|
FGFontCache::get(SGPropertyNode *node)
|
|
|
|
|
{
|
|
|
|
|
const char *name = node->getStringValue("name", "Helvetica.txf");
|
|
|
|
|
float size = node->getFloatValue("size", 15.0);
|
|
|
|
|
float slant = node->getFloatValue("slant", 0.0);
|
|
|
|
|
|
|
|
|
|
return get(name, size, slant);
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-07 16:27:47 +00:00
|
|
|
|
// end of new_gui.cxx
|