PGE Engine
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
font_manager.h
1 /*
2  * Platformer Game Engine by Wohlstand, a free platform for game making
3  * Copyright (c) 2015 Vitaly Novichkov <admin@wohlnet.ru>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef FONT_MANAGER_H
20 #define FONT_MANAGER_H
21 
22 //#include <SDL2/SDL_ttf.h>
23 #include <SDL2/SDL_opengl.h>
24 #include <QString>
25 #include <QFont>
26 #include <QSize>
27 #include <QMap>
28 #include <QRgb>
29 #include <QRegExp>
30 
31 
32 #include <common_features/pge_texture.h>
33 #include <common_features/rect.h>
35 {
36 public:
37  RasterFont();
38  RasterFont(const RasterFont &rf);
39  ~RasterFont();
40  void loadFont(QString font_ini);
41  void loadFontMap(QString fontmap_ini);
42  PGE_Size textSize(QString &text, int max_line_lenght=0, bool cut=false);
43  void printText(QString text, int x, int y, float Red=1.f, float Green=1.f, float Blue=1.f, float Alpha=1.f);
44  bool isLoaded();
45  QString getFontName();
46 private:
47  bool isReady;
48  bool ttf_borders;
49  int letter_width;
50  int letter_height;
51  int interletter_space;
52  int space_width;
53  int newline_offset;
54 
55  int matrix_width;
56  int matrix_height;
57  QString fontName;
58 
59  struct RasChar
60  {
61  RasChar() {valid=false;}
62  bool valid;
63  GLuint tx;
64  int padding_left;
65  int padding_right;
66  float l;
67  float t;
68  float b;
69  float r;
70  };
71  QHash<QChar, RasChar > fontMap;
72  QRegExp first_line_only;
73 
74  //Font textures cache
75  QList<PGE_Texture > textures;
76 };
77 
78 
79 
81 {
82 public:
83  static void init();
84  static void quit();
85  //static TTF_Font *buildFont(QString _fontPath, GLint size);
86  //static TTF_Font *buildFont_RW(QString _fontPath, GLint size);
87 
88  static PGE_Size textSize(QString &text, int fontID, int max_line_lenght=0, bool cut=false);
89  static int getFontID(QString fontName);
90 
91  static GLuint getChar1(QChar _x);
92  static GLuint getChar2(QChar _x);
93 
94  static QFont font();
95  enum DefaultFont
96  {
97  DefaultTTF_Font=-1,
98  DefaultRaster=0
99  };
100  static void printText(QString text, int x, int y, int font=DefaultRaster,
101  float Red=1.0, float Green=1.0, float Blue=1.0, float Alpha=1.0, int ttf_FontSize=14);
102  static void printTextTTF(QString text, int x, int y, int pointSize, QRgb color=qRgba(255,255,255,255));
103 
104 
105  static QList<RasterFont> rasterFonts;
106  static RasterFont *rFont;
107 
108  static void optimizeText(QString &text, int max_line_lenght, int *numLines=0, int *numCols=0);
109  static QString cropText(QString text, int max_symbols);
110 
111  /****Deprecated functions*******/
112  static void SDL_string_texture_create(QFont &font, QRgb color, QString &text, GLuint *texture, bool borders=false);
113  static void SDL_string_texture_create(QFont &font, PGE_Rect limitRect, int fontFlags, QRgb color,
114  QString &text, GLuint *texture, bool borders=false);
115 
116  static void SDL_string_render2D(GLuint x, GLuint y, GLuint *texture);
117  static GLuint TextToTexture(QString text, PGE_Rect rectangle, int alignFlags, bool borders=false);
118 
119 private:
120  static bool isInit;
121  //static TTF_Font * defaultFont;
122  static GLuint textTexture;
123  static QHash<QChar, GLuint> fontTable_1;
124  static QHash<QChar, GLuint> fontTable_2;
125  static QHash<QString, int> fonts;
126  static int fontID;
127  static bool double_pixled;
128 
129  static QFont *defaultFont;
130 };
131 
132 #endif // FONT_MANAGER_H
Definition: rect.h:26
Definition: size.h:23
Definition: font_manager.h:80
PGE_Size textSize(QString &text, int max_line_lenght=0, bool cut=false)
Definition: font_manager.cpp:219
static RasterFont * rFont
Default raster font.
Definition: font_manager.h:106
static QList< RasterFont > rasterFonts
Complete array of raster fonts.
Definition: font_manager.h:105
Definition: font_manager.h:34