make FGFontCache independent of NewGUI and allow early construction in
FGGlobals
This commit is contained in:
parent
d5fd30249f
commit
47223b0442
2 changed files with 41 additions and 41 deletions
|
@ -26,8 +26,7 @@ extern puFont FONT_SANS_12B;
|
||||||
|
|
||||||
|
|
||||||
NewGUI::NewGUI ()
|
NewGUI::NewGUI ()
|
||||||
: _fontcache(new FGFontCache),
|
: _menubar(new FGMenuBar),
|
||||||
_menubar(new FGMenuBar),
|
|
||||||
_active_dialog(0)
|
_active_dialog(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -334,29 +333,10 @@ NewGUI::setStyle (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const struct {
|
|
||||||
char *name;
|
|
||||||
puFont *font;
|
|
||||||
} 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 },
|
|
||||||
{ 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NewGUI::setupFont (SGPropertyNode *node)
|
NewGUI::setupFont (SGPropertyNode *node)
|
||||||
{
|
{
|
||||||
_font = _fontcache->get(node);
|
_font = globals->get_fontcache()->get(node);
|
||||||
puSetDefaultFonts(*_font, *_font);
|
puSetDefaultFonts(*_font, *_font);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -403,19 +383,32 @@ FGColor::merge(const FGColor *color)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
FGFontCache::FGFontCache()
|
////////////////////////////////////////////////////////////////////////
|
||||||
{
|
// FGFontCache class.
|
||||||
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++)
|
static const struct {
|
||||||
_fonts[guifonts[i].name] = new fnt(guifonts[i].font);
|
char *name;
|
||||||
|
puFont *font;
|
||||||
|
} 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 },
|
||||||
|
{ 0, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
FGFontCache::FGFontCache() :
|
||||||
|
_initialized(false)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
FGFontCache::~FGFontCache()
|
FGFontCache::~FGFontCache()
|
||||||
|
@ -426,6 +419,19 @@ FGFontCache::~FGFontCache()
|
||||||
puFont *
|
puFont *
|
||||||
FGFontCache::get(const char *name, float size, float slant)
|
FGFontCache::get(const char *name, float size, float slant)
|
||||||
{
|
{
|
||||||
|
if (!_initialized) {
|
||||||
|
char *envp = ::getenv("FG_FONTS");
|
||||||
|
if (envp != NULL) {
|
||||||
|
_path.set(envp);
|
||||||
|
} else {
|
||||||
|
_path.set(globals->get_fg_root());
|
||||||
|
_path.append("Fonts");
|
||||||
|
}
|
||||||
|
_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; guifonts[i].name; i++)
|
||||||
|
_fonts[guifonts[i].name] = new fnt(guifonts[i].font);
|
||||||
_itt_t it;
|
_itt_t it;
|
||||||
|
|
||||||
if ((it = _fonts.find(name)) != _fonts.end())
|
if ((it = _fonts.find(name)) != _fonts.end())
|
||||||
|
|
|
@ -186,15 +186,8 @@ public:
|
||||||
virtual puFont *getDefaultFont() { return _font; }
|
virtual puFont *getDefaultFont() { return _font; }
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* menu wide font cache, accessible from other classes as well.
|
|
||||||
*/
|
|
||||||
FGFontCache *get_fontcache() { return _fontcache; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
FGFontCache * _fontcache;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if the menubar is visible.
|
* Test if the menubar is visible.
|
||||||
*
|
*
|
||||||
|
@ -310,6 +303,7 @@ private:
|
||||||
|
|
||||||
map<const string,fnt *> _fonts;
|
map<const string,fnt *> _fonts;
|
||||||
typedef map<const string,fnt *>::const_iterator _itt_t;
|
typedef map<const string,fnt *>::const_iterator _itt_t;
|
||||||
|
bool _initialized;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FGFontCache();
|
FGFontCache();
|
||||||
|
|
Loading…
Add table
Reference in a new issue