hx3d  1
2D/3D Simple Game Framework
font.hpp
1 /*
2  Font.
3  Copyright (C) 2015 Denis BOURGE
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 Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_GRAPHICS_FONT
22 #define HX3D_GRAPHICS_FONT
23 
24 #include <freetype-gl/freetype-gl.h>
25 #include <string>
26 #include <map>
27 
28 #include "hx3d/graphics/shader.hpp"
29 #include "hx3d/utils/resource.hpp"
30 #include "hx3d/utils/ptr.hpp"
31 #include "hx3d/utils/file.hpp"
32 
33 namespace hx3d {
34 namespace graphics {
35 
39 class Font: public Resource {
40 public:
41 
45  struct Data {
47  texture_font_t* font;
49  texture_atlas_t* atlas;
50  };
51 
58  Font(std::string fontPath, int characterSize);
59  ~Font();
60 
66  void createFontSize(int size);
67 
77  Data& getFontData(int size);
78 
84  unsigned int getDefaultSize() const;
85 
91  const Ptr<Shader>& getShader();
92 
93 private:
95  Ptr<Shader> shader;
97  Ptr<File> file;
98 
100  std::map<int, Data> data;
101 
103  unsigned int defaultSize;
104 };
105 
106 } /* graphics */
107 } /* hx3d */
108 
109 #endif
unsigned int getDefaultSize() const
Get the default font size.
Definition: font.cpp:69
Data & getFontData(int size)
Get internal font data from a size.
Definition: font.cpp:61
texture_font_t * font
Internal font.
Definition: font.hpp:47
hx3d framework namespace
Definition: audio.hpp:26
Font management.
Definition: font.hpp:39
Internal font data.
Definition: font.hpp:45
texture_atlas_t * atlas
Internal atlas.
Definition: font.hpp:49
Resource type: to use in an asset manager.
Definition: resource.hpp:29
const Ptr< Shader > & getShader()
Get the font shader.
Definition: font.cpp:73
Font(std::string fontPath, int characterSize)
Build a font from a path and a character size.
Definition: font.cpp:36
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34
void createFontSize(int size)
Generate a font in cache.
Definition: font.cpp:48