]> git.mxchange.org Git - flightgear.git/blob - utils/fgpanel/FGFontCache.hxx
Add property controls for cloud impostors and LoD hierarchy radii.
[flightgear.git] / utils / fgpanel / FGFontCache.hxx
1 //  This program is free software; you can redistribute it and/or
2 //  modify it under the terms of the GNU General Public License as
3 //  published by the Free Software Foundation; either version 2 of the
4 //  License, or (at your option) any later version.
5 // 
6 //  This program is distributed in the hope that it will be useful, but
7 //  WITHOUT ANY WARRANTY; without even the implied warranty of
8 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
9 //  General Public License for more details.
10 //
11 //  You should have received a copy of the GNU General Public License
12 //  along with this program; if not, write to the Free Software
13 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
14 //
15 #ifndef __FGFONTCACHE_HXX
16 #define __FGFONTCACHE_HXX
17
18 #include <simgear/math/SGMath.hxx>
19 #include <simgear/misc/sg_path.hxx>
20 #include <simgear/props/props.hxx>
21
22
23 // forward declare only!
24 class puFont;
25 class fntTexFont;
26
27 /**
28  * A class to keep all fonts available for future use.
29  * This also assures a font isn't resident more than once.
30  */
31 class FGFontCache {
32 private:
33     // The parameters of a request to the cache.
34     struct FntParams
35     {
36         const std::string name;
37         const float size;
38         const float slant;
39         FntParams() : size(0.0f), slant(0.0f) {}
40         FntParams(const FntParams& rhs)
41             : name(rhs.name), size(rhs.size), slant(rhs.slant)
42         {
43         }
44         FntParams(const std::string& name_, float size_, float slant_)
45             : name(name_), size(size_), slant(slant_)
46         {
47         }
48     };
49     struct FntParamsLess
50         : public std::binary_function<const FntParams, const FntParams, bool>
51     {
52         bool operator() (const FntParams& f1, const FntParams& f2) const;
53     };
54     struct fnt {
55         fnt(puFont *pu = 0) : pufont(pu), texfont(0) {}
56         ~fnt();
57         // Font used by plib GUI code
58         puFont *pufont;
59         // TXF font
60         fntTexFont *texfont;
61     };
62     // Path to the font directory
63     SGPath _path;
64
65     typedef std::map<const std::string, fntTexFont*> TexFontMap;
66     typedef std::map<const FntParams, fnt*, FntParamsLess> PuFontMap;
67     TexFontMap _texFonts;
68     PuFontMap _puFonts;
69
70     bool _initialized;
71     struct fnt *getfnt(const char *name, float size, float slant);
72     void init();
73
74 public:
75     FGFontCache();
76     ~FGFontCache();
77
78     puFont *get(const char *name, float size=15.0, float slant=0.0);
79     puFont *get(SGPropertyNode *node);
80
81     fntTexFont *getTexFont(const char *name, float size=15.0, float slant=0.0);
82
83     SGPath getfntpath(const char *name);
84     /**
85      * Preload all the fonts in the FlightGear font directory. It is
86      * important to load the font textures early, with the proper
87      * graphics context current, so that no plib (or our own) code
88      * tries to load a font from disk when there's no current graphics
89      * context.
90      */
91     bool initializeFonts();
92 };
93 #endif