1 /* 2 * XPilotNG/SDL, an SDL/OpenGL XPilot client. 3 * 4 * Copyright (C) 2003-2004 Erik Andersson <deity_at_home.se> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 */ 20 21 #ifndef TEXT_H 22 #define TEXT_H 23 24 #include "xpclient_sdl.h" 25 26 #include "sdlpaint.h" 27 28 #define LEFT 0 29 #define DOWN 0 30 #define CENTER 1 31 #define RIGHT 2 32 #define UP 2 33 34 #define NUMCHARS 256 35 36 typedef struct { 37 GLfloat MinX; 38 GLfloat MinY; 39 GLfloat MaxX; 40 GLfloat MaxY; 41 } texcoord_t; 42 43 typedef struct { 44 GLuint textures[NUMCHARS]; /* texture indexes for the characters */ 45 GLuint W[NUMCHARS]; /* holds paint width fr each character */ 46 GLuint list_base; /* start of the texture list for this font */ 47 GLuint h; /* char height */ 48 GLuint linespacing; /* proper line spacing according to FT */ 49 TTF_Font *ttffont; 50 } font_data; 51 52 typedef struct { 53 GLuint texture; 54 texcoord_t texcoords; 55 int width; 56 } tex_t; 57 58 typedef struct { 59 arraylist_t *tex_list; 60 char *text; 61 int width; 62 int height; 63 int font_height; 64 } string_tex_t; 65 66 extern int renderstyle; 67 extern enum rendertype { 68 RENDER_LATIN1, 69 RENDER_UTF8, 70 RENDER_UNICODE 71 } rendertype; 72 73 typedef struct { 74 float width; 75 float height; 76 } fontbounds; 77 78 /* The init function will create a font of 79 * of the height h from the file fname. 80 */ 81 int fontinit(font_data *ft_font, const char * fname, unsigned int size); 82 83 /* Free all the resources assosiated with the font.*/ 84 void fontclean(font_data *ft_font); 85 86 /* loads a SDL surface onto a GL texture */ 87 GLuint SDL_GL_LoadTexture(SDL_Surface *surface, texcoord_t *texcoord); 88 89 /* Calcs the bounding width,height for the text if it were printed 90 * to screen with given font 91 */ 92 fontbounds nprintsize(font_data *ft_font, int length, const char *fmt, ...); 93 fontbounds printsize(font_data *ft_font, const char *fmt, ...); 94 95 /* 96 * NOTE: passing color 0x00000000 causes the painting to *not* set color, 97 * it does *not* mean the text will be drawn with color 0x00000000, you 98 * should check for that before calling this function. 99 */ 100 void HUDnprint(font_data *ft_font, int color, int XALIGN, int YALIGN, int x, int y, int length, const char *fmt, ...); 101 void mapnprint(font_data *ft_font, int color, int XALIGN, int YALIGN, int x, int y, int length, const char *fmt,...); 102 void HUDprint(font_data *ft_font, int color, int XALIGN, int YALIGN, int x, int y, const char *fmt, ...); 103 void mapprint(font_data *ft_font, int color, int XALIGN, int YALIGN, int x, int y, const char *fmt,...); 104 105 bool draw_text(font_data *ft_font, int color, int XALIGN, int YALIGN, int x, int y, const char *text, bool savetex, string_tex_t *string_tex, bool onHUD); 106 bool draw_text_fraq(font_data *ft_font, int color, int XALIGN, int YALIGN, int x, int y, const char *text 107 , float xstart 108 , float xstop 109 , float ystart 110 , float ystop 111 , bool savetex, string_tex_t *string_tex, bool onHUD); 112 bool render_text(font_data *ft_font, const char *text, string_tex_t *string_tex); 113 void disp_text(string_tex_t *string_tex, int color, int XALIGN, int YALIGN, int x, int y, bool onHUD); 114 void disp_text_fraq(string_tex_t *string_tex, int color, int XALIGN, int YALIGN, int x, int y 115 , float xstart 116 , float xstop 117 , float ystart 118 , float ystop 119 , bool onHUD); 120 void free_string_texture(string_tex_t *string_tex); 121 122 extern font_data gamefont; 123 extern font_data mapfont; 124 125 extern int gameFontSize; 126 extern int mapFontSize; 127 128 extern char *gamefontname; 129 130 extern string_tex_t score_object_texs[]; 131 132 /*typedef struct { 133 int id; 134 string_tex_t string_tex; 135 void *next; 136 } name_tex_t; 137 138 name_tex_t *others_name_texs;*/ 139 140 #define MAX_METERS 12 141 extern string_tex_t meter_texs[]; 142 #define MAX_HUD_TEXS 10 143 extern string_tex_t HUD_texs[]; 144 #endif 145