#include "menubar.hxx"
#include "dialog.hxx"
-SG_USING_STD(map);
-
extern puFont FONT_HELVETICA_14;
extern puFont FONT_SANS_12B;
delete _menubar;
_menubar = 0;
_dialog_props.clear();
+ _colors.clear();
}
static bool
_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();
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());
}
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
#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>
class FGDialog;
class FGBinding;
class FGColor;
+class FGFontCache;
/**
*/
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.
*
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 ();
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.
};
+
+/**
+ * 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