]> git.mxchange.org Git - flightgear.git/blob - src/GUI/SafeTexFont.cxx
Merge branch 'jmt/gps' into next
[flightgear.git] / src / GUI / SafeTexFont.cxx
1 // Copyright (C) 2008  Tim Moore
2 //
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License as
5 // published by the Free Software Foundation; either version 2 of the
6 // License, or (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but
9 // WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <errno.h>
20
21 #include "SafeTexFont.hxx"
22
23 using namespace flightgear;
24
25 int SafeTexFont::load(const char *fname, GLenum mag, GLenum min)
26 {
27     struct stat buf;
28     if (stat(fname, &buf) == -1) {
29         _status = e_ERROR;
30         return FNT_FALSE;
31     }
32     _name = fname;
33     _mag = mag;
34     _min = min;
35     return FNT_TRUE;
36 }
37
38 bool SafeTexFont::ensureTextureLoaded()
39 {
40     if (_status != e_ERROR) {
41         if (_status == e_LOADED) {
42             return true;
43         } else {
44             int loadStatus = fntTexFont::load(_name.c_str(), _mag, _min);
45             if (loadStatus == FNT_TRUE) {
46                 _status = e_LOADED;
47                 return true;
48             } else {
49                 _status = e_ERROR;
50                 _error = ulGetError();
51                 return false;
52             }    
53         }
54     } else {
55         return false;
56     }
57 }
58
59 void SafeTexFont::begin()
60 {
61     if (ensureTextureLoaded())
62         fntTexFont::begin();
63 }
64
65 void SafeTexFont::putch(sgVec3 curpos, float pointsize, float italic, char c)
66 {
67     if (ensureTextureLoaded())
68         fntTexFont::putch(curpos, pointsize, italic, c);
69 }
70
71 void SafeTexFont::puts(sgVec3 curpos, float pointsize, float italic,
72                        const char *s)
73 {
74     if (ensureTextureLoaded())
75         fntTexFont::puts(curpos, pointsize, italic, s);
76 }