MFMv2.0.10
Movable Feast Machine Simulator 2.0.10
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Fonts.h
Go to the documentation of this file.
1 /* -*- mode:C++ -*-
2  Fonts.h SDL_Font loading / caching toolkit
3  Copyright (C) 2014 The Regents of the University of New Mexico. All rights reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
27 #ifndef FONTS_H
28 #define FONTS_H
29 
30 #include "itype.h"
31 #include "SDL.h"
32 #include "SDL_ttf.h"
33 #include "Drawing.h"
34 
35 namespace MFM
36 {
40  class Fonts
41  {
42  private:
43 
44  bool m_initted;
45 
46  static const u32 CACHE_SIZE = 10;
47  struct Cache {
48  const char * path;
49  u32 size;
50  TTF_Font * font;
51  } m_fontCache[CACHE_SIZE];
52 
53  public:
54  static const char * DEFAULT_FONT;
55  static const u32 DEFAULT_FONT_SIZE;
56 
57  Fonts() : m_initted(false) { }
58 
59  void Init();
60 
61  TTF_Font * GetFont(const char * resourcePath, u32 size) ;
62 
63  TTF_Font * GetDefaultFont(u32 size = DEFAULT_FONT_SIZE) {
64  return GetFont(DEFAULT_FONT, size);
65  }
66 
67  };
68 }
69 
70 #endif /* FONTS_H */
Definition: Fonts.h:40