IRIX fixes.
Somehow the MIPSpro compiler doesn't like an STL map entry being called using a variable when the reference is an object and not a pointer to an object. Preliminary support for a fontcache is added which prevents fonts from being loaded more than once and takes care of freeing them up again. The fontcache isn't used yet since there seems to be a problem somewhere.
This commit is contained in:
parent
6776103190
commit
0ec8fa64a4
2 changed files with 118 additions and 24 deletions
|
@ -13,8 +13,6 @@
|
|||
#include "menubar.hxx"
|
||||
#include "dialog.hxx"
|
||||
|
||||
SG_USING_STD(map);
|
||||
|
||||
extern puFont FONT_HELVETICA_14;
|
||||
extern puFont FONT_SANS_12B;
|
||||
|
||||
|
@ -183,6 +181,7 @@ NewGUI::clear ()
|
|||
delete _menubar;
|
||||
_menubar = 0;
|
||||
_dialog_props.clear();
|
||||
_colors.clear();
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -269,12 +268,12 @@ NewGUI::setStyle (void)
|
|||
_colors.clear();
|
||||
|
||||
// set up the traditional colors as default
|
||||
_colors["background"] = FGColor(0.8f, 0.8f, 0.9f, 0.85f);
|
||||
_colors["foreground"] = FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
_colors["highlight"] = FGColor(0.7f, 0.7f, 0.7f, 1.0f);
|
||||
_colors["label"] = FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
_colors["legend"] = FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
_colors["misc"] = FGColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
_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);
|
||||
|
||||
//puSetDefaultStyle();
|
||||
|
||||
|
@ -289,11 +288,11 @@ NewGUI::setStyle (void)
|
|||
|
||||
for (int i = 0; i < n->nChildren(); i++) {
|
||||
SGPropertyNode *child = n->getChild(i);
|
||||
_colors[child->getName()] = FGColor(child);
|
||||
_colors[child->getName()] = new FGColor(child);
|
||||
}
|
||||
|
||||
FGColor c = _colors["background"];
|
||||
puSetDefaultColourScheme(c.red(), c.green(), c.blue(), c.alpha());
|
||||
FGColor *c = _colors["background"];
|
||||
puSetDefaultColourScheme(c->red(), c->green(), c->blue(), c->alpha());
|
||||
}
|
||||
|
||||
|
||||
|
@ -394,4 +393,67 @@ FGColor::merge(const FGColor& color)
|
|||
return dirty;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
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++)
|
||||
_fonts[guifonts[i].name] = guifonts[i].font;
|
||||
}
|
||||
|
||||
FGFontCache::~FGFontCache()
|
||||
{
|
||||
_fonts.clear();
|
||||
}
|
||||
|
||||
puFont *
|
||||
FGFontCache::get(const char *name, float size, float slant)
|
||||
{
|
||||
puFont *font;
|
||||
_itt_t it;
|
||||
|
||||
if ((it = _fonts.find(name)) == _fonts.end())
|
||||
{
|
||||
SGPath path(_path);
|
||||
path.append(name);
|
||||
|
||||
fntTexFont tex_font;
|
||||
if (tex_font.load((char *)path.c_str()))
|
||||
{
|
||||
font = new puFont;
|
||||
font->initialize((fntFont *)&tex_font, size, slant);
|
||||
_fonts[name] = font;
|
||||
}
|
||||
else
|
||||
{
|
||||
font = _fonts["default"];
|
||||
// puSetDefaultFonts(font, font);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
font = it->second;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// end of new_gui.cxx
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
#include <simgear/compiler.h> // for SG_USING_STD
|
||||
#include <simgear/props/props.hxx>
|
||||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
||||
#include <vector>
|
||||
SG_USING_STD(vector);
|
||||
|
||||
#include <map>
|
||||
|
||||
SG_USING_STD(vector);
|
||||
SG_USING_STD(map);
|
||||
SG_USING_STD(string);
|
||||
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
|
@ -29,6 +31,7 @@ class FGMenuBar;
|
|||
class FGDialog;
|
||||
class FGBinding;
|
||||
class FGColor;
|
||||
class FGFontCache;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -151,13 +154,27 @@ public:
|
|||
*/
|
||||
virtual FGDialog * getActiveDialog ();
|
||||
|
||||
virtual const FGColor& getColor (const char * which) { return _colors[which]; }
|
||||
virtual const FGColor& getColor (string which) { return _colors[which.c_str()]; }
|
||||
virtual FGColor *getColor (const char * name) const {
|
||||
_itt_t it = _colors.find(name);
|
||||
return it->second;
|
||||
}
|
||||
virtual FGColor *getColor (const string &name) const {
|
||||
_itt_t it = _colors.find(name.c_str());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
virtual puFont *getDefaultFont() { return &_font; }
|
||||
|
||||
|
||||
/**
|
||||
* menu wide font cache, accessible from other classes as well.
|
||||
*/
|
||||
FGFontCache *get_fontcache() { return _fontcache; }
|
||||
|
||||
protected:
|
||||
|
||||
FGFontCache * _fontcache;
|
||||
|
||||
/**
|
||||
* Test if the menubar is visible.
|
||||
*
|
||||
|
@ -178,7 +195,8 @@ protected:
|
|||
private:
|
||||
fntTexFont _tex_font;
|
||||
puFont _font;
|
||||
map<string,FGColor> _colors;
|
||||
map<const char*,FGColor*> _colors;
|
||||
typedef map<const char*,FGColor*>::const_iterator _itt_t;
|
||||
|
||||
// Free all allocated memory.
|
||||
void clear ();
|
||||
|
@ -199,14 +217,7 @@ public:
|
|||
FGColor() { clear(); }
|
||||
FGColor(float r, float g, float b, float a = 1.0f) { set(r, g, b, a); }
|
||||
FGColor(const SGPropertyNode *prop) { set(prop); }
|
||||
|
||||
FGColor& operator=(const FGColor& c) {
|
||||
_red = c._red;
|
||||
_green = c._green;
|
||||
_blue = c._blue;
|
||||
_alpha = c._alpha;
|
||||
return *this;
|
||||
}
|
||||
FGColor(FGColor *c) { set(c->_red, c->_green, c->_blue, c->_alpha); }
|
||||
|
||||
inline void clear() { _red = _green = _blue = _alpha = -1.0f; }
|
||||
// merges in non-negative components from property with children <red> etc.
|
||||
|
@ -245,5 +256,26 @@ private:
|
|||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A small class to keep all fonts available for future use.
|
||||
* This also assures a font isn't resident more than once.
|
||||
*/
|
||||
class FGFontCache {
|
||||
private:
|
||||
SGPath _path;
|
||||
|
||||
map<const char*,puFont*> _fonts;
|
||||
typedef map<const char*,puFont*>::iterator _itt_t;
|
||||
|
||||
public:
|
||||
FGFontCache();
|
||||
~FGFontCache();
|
||||
|
||||
puFont *get(const char *name, float size=15.0, float slant=0.0);
|
||||
puFont *get(SGPropertyNode *node);
|
||||
};
|
||||
|
||||
|
||||
#endif // __NEW_GUI_HXX
|
||||
|
||||
|
|
Loading…
Reference in a new issue