From: mfranz Date: Mon, 5 Jun 2006 20:23:56 +0000 (+0000) Subject: make FGFontCache independent of NewGUI and allow early construction in X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=47223b0442fce99d21f80e3ab06af205526ee863;p=flightgear.git make FGFontCache independent of NewGUI and allow early construction in FGGlobals --- diff --git a/src/GUI/new_gui.cxx b/src/GUI/new_gui.cxx index cbccde541..c7790d1d9 100644 --- a/src/GUI/new_gui.cxx +++ b/src/GUI/new_gui.cxx @@ -26,8 +26,7 @@ extern puFont FONT_SANS_12B; NewGUI::NewGUI () - : _fontcache(new FGFontCache), - _menubar(new FGMenuBar), + : _menubar(new FGMenuBar), _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 NewGUI::setupFont (SGPropertyNode *node) { - _font = _fontcache->get(node); + _font = globals->get_fontcache()->get(node); puSetDefaultFonts(*_font, *_font); return; } @@ -403,19 +383,32 @@ FGColor::merge(const FGColor *color) } -// -FGFontCache::FGFontCache() -{ - char *envp = ::getenv("FG_FONTS"); - if (envp != NULL) { - _path.set(envp); - } else { - _path.set(globals->get_fg_root()); - _path.append("Fonts"); - } + +//////////////////////////////////////////////////////////////////////// +// FGFontCache class. +//////////////////////////////////////////////////////////////////////// - for (int i=0; guifonts[i].name; i++) - _fonts[guifonts[i].name] = new fnt(guifonts[i].font); +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 } +}; + + +FGFontCache::FGFontCache() : + _initialized(false) +{ } FGFontCache::~FGFontCache() @@ -426,6 +419,19 @@ FGFontCache::~FGFontCache() puFont * 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; if ((it = _fonts.find(name)) != _fonts.end()) diff --git a/src/GUI/new_gui.hxx b/src/GUI/new_gui.hxx index f00bf72bf..12f44401a 100644 --- a/src/GUI/new_gui.hxx +++ b/src/GUI/new_gui.hxx @@ -186,15 +186,8 @@ public: 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. * @@ -310,6 +303,7 @@ private: map _fonts; typedef map::const_iterator _itt_t; + bool _initialized; public: FGFontCache();