]> git.mxchange.org Git - flightgear.git/blob - src/GUI/FGFontCache.hxx
MouseInput changes to support hover.
[flightgear.git] / src / GUI / 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/misc/sg_path.hxx>
19
20 #include <map>
21 #include <algorithm>
22
23 // forward decls
24 class SGPropertyNode;
25 class puFont;
26 class fntTexFont;
27
28 /**
29  * A class to keep all fonts available for future use.
30  * This also assures a font isn't resident more than once.
31  */
32 class FGFontCache {
33 private:
34     // The parameters of a request to the cache.
35     struct FntParams
36     {
37         const std::string name;
38         const float size;
39         const float slant;
40         FntParams() : size(0.0f), slant(0.0f) {}
41         FntParams(const FntParams& rhs)
42             : name(rhs.name), size(rhs.size), slant(rhs.slant)
43         {
44         }
45         FntParams(const std::string& name_, float size_, float slant_)
46             : name(name_), size(size_), slant(slant_)
47         {
48         }
49     };
50     struct FntParamsLess
51         : public std::binary_function<const FntParams, const FntParams, bool>
52     {
53         bool operator() (const FntParams& f1, const FntParams& f2) const;
54     };
55     struct fnt {
56         fnt(puFont *pu = 0) : pufont(pu), texfont(0) {}
57         ~fnt();
58         
59         // Font used by plib GUI code
60         puFont *pufont;
61         // TXF font
62         fntTexFont *texfont;
63     };
64     // Path to the font directory
65     SGPath _path;
66
67     typedef std::map<const std::string, fntTexFont*> TexFontMap;
68     typedef std::map<const FntParams, fnt*, FntParamsLess> PuFontMap;
69     TexFontMap _texFonts;
70     PuFontMap _puFonts;
71
72     bool _initialized;
73     struct fnt *getfnt(const char *name, float size, float slant);
74     void init();
75
76 public:
77     FGFontCache();
78     ~FGFontCache();
79
80     puFont *get(const char *name, float size=15.0, float slant=0.0);
81     puFont *get(SGPropertyNode *node);
82
83     fntTexFont *getTexFont(const char *name, float size=15.0, float slant=0.0);
84
85     SGPath getfntpath(const char *name);
86     /**
87      * Preload all the fonts in the FlightGear font directory. It is
88      * important to load the font textures early, with the proper
89      * graphics context current, so that no plib (or our own) code
90      * tries to load a font from disk when there's no current graphics
91      * context.
92      */
93     bool initializeFonts();
94 };
95 #endif