- if (props->hasValue("action")) {
- string action = props->getStringValue("action");
- if (action == "update")
- object->setCallback(update_callback);
- else if (action == "close")
- object->setCallback(close_callback);
- else if (action == "apply")
- object->setCallback(apply_callback);
- else if (action == "close-apply")
- object->setCallback(close_apply_callback);
- else
- SG_LOG(SG_GENERAL, SG_ALERT, "Unknown GUI action " + action);
+\f
+////////////////////////////////////////////////////////////////////////
+// FGFontCache class.
+////////////////////////////////////////////////////////////////////////
+
+namespace
+{
+struct GuiFont
+{
+ const char *name;
+ puFont *font;
+ struct Predicate
+ : public std::unary_function<const GuiFont, bool>
+ {
+ Predicate(const char* name_) : name(name_) {}
+ bool operator() (const GuiFont& f1) const
+ {
+ return std::strcmp(f1.name, name) == 0;
+ }
+ const char* name;
+ };
+};
+
+const GuiFont guifonts[] = {
+ { "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 }
+};
+
+const GuiFont* guifontsEnd = &guifonts[sizeof(guifonts)/ sizeof(guifonts[0])];
+}
+
+FGFontCache::FGFontCache() :
+ _initialized(false)
+{
+}
+
+FGFontCache::~FGFontCache()
+{
+ PuFontMap::iterator it, end = _puFonts.end();
+ for (it = _puFonts.begin(); it != end; ++it)
+ delete it->second;
+}
+
+inline bool FGFontCache::FntParamsLess::operator()(const FntParams& f1,
+ const FntParams& f2) const
+{
+ int comp = f1.name.compare(f2.name);
+ if (comp < 0)
+ return true;
+ else if (comp > 0)
+ return false;
+ if (f1.size < f2.size)
+ return true;
+ else if (f1.size > f2.size)
+ return false;
+ return f1.slant < f2.slant;
+}
+
+struct FGFontCache::fnt *
+FGFontCache::getfnt(const char *name, float size, float slant)
+{
+ string fontName(name);
+ FntParams fntParams(fontName, size, slant);
+ PuFontMap::iterator i = _puFonts.find(fntParams);
+ if (i != _puFonts.end())
+ return i->second;
+ // fntTexFont s are all preloaded into the _texFonts map
+ TexFontMap::iterator texi = _texFonts.find(fontName);
+ fntTexFont* texfont = 0;
+ puFont* pufont = 0;
+ if (texi != _texFonts.end()) {
+ texfont = texi->second;
+ } else {
+ const GuiFont* guifont = std::find_if(&guifonts[0], guifontsEnd,
+ GuiFont::Predicate(name));
+ if (guifont != guifontsEnd) {
+ pufont = guifont->font;
+ }
+ }
+ fnt* f = new fnt;
+ if (pufont) {
+ f->pufont = pufont;
+ } else if (texfont) {
+ f->texfont = texfont;
+ f->pufont = new puFont;
+ f->pufont->initialize(static_cast<fntFont *>(f->texfont), size, slant);
+ } else {
+ f->pufont = guifonts[0].font;