Debian Codegraph @

text.cpp

raw symbols SCIP
1 /* ************************************************************************* *
2 SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
3 Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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 (at your option) 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 #define FONT_MENUcxx . . $ `text.cpp:19:9`! 0
20 #define FONT_ANNOUNCE_GOODcxx . . $ `text.cpp:20:9`! 1
21 #define FONT_ANNOUNCE_BADcxx . . $ `text.cpp:21:9`! 2
22 #define FONT_HIGHSCOREcxx . . $ `text.cpp:22:9`! 3
23 #define FONT_MENUHIGHSCOREcxx . . $ `text.cpp:23:9`! 4
24 #define FONT_INTROHIGHSCOREcxx . . $ `text.cpp:24:9`! 5
25 #define FONT_INTRODESCRIPTIONcxx . . $ `text.cpp:25:9`! 6
26 #define FONT_NUMcxx . . $ `text.cpp:26:9`! 7
27
28 struct glCharInfo_structcxx . . $ glCharInfo_struct# {
29 GLfloat Xacxx . . $ glCharInfo_struct#Xa.,Yacxx . . $ glCharInfo_struct#Ya.,Xbcxx . . $ glCharInfo_struct#Xb.,Ybcxx . . $ glCharInfo_struct#Yb., widthcxx . . $ glCharInfo_struct#width.;
30 };
31
32 struct glFontInfo_structcxx . . $ glFontInfo_struct# {
33 GLuint texcxx . . $ glFontInfo_struct#tex.;
34 GLfloat heightcxx . . $ glFontInfo_struct#height.;
35 struct glCharInfo_structcxx . . $ glCharInfo_struct# chcxx . . $ glFontInfo_struct#ch.[255];
36 };
37
38
39 class glTextClasscxx . . $ glTextClass# {
40 private:
41 void genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(stringcxx . . $ std/string# TTFfontName, int fontSize, int font);
42 struct glFontInfo_structcxx . . $ glFontInfo_struct# fontInfocxx . . $ glTextClass#fontInfo.[FONT_NUMcxx . . $ `text.cpp:26:9`!];
43
44 public:
45 GLfloat getHeightcxx . . $ glTextClass#getHeight(5cde91ea12d43f46).(int font);
46 void writecxx . . $ glTextClass#write(e3805d4e487d2eea).(stringcxx . . $ std/string# text, int font, bool center, GLfloat scale, GLfloat x, GLfloat y);
47 glTextClasscxx . . $ glTextClass#glTextClass(49f6e7a06ebc5aa8).();
48 };
49
50 GLfloat glTextClasscxx . . $ glTextClass#::getHeightcxx . . $ glTextClass#getHeight(5cde91ea12d43f46).(int font)
51 {
52 return(fontInfocxx . . $ glTextClass#fontInfo.[font].heightcxx . . $ glFontInfo_struct#height.*2.0);
53 }
54
55 glTextClasscxx . . $ glTextClass#::glTextClasscxx . . $ glTextClass#glTextClass(49f6e7a06ebc5aa8).()
56 {
57 TTF_Init();
58 //Parse font-description file
59 ifstreamcxx . . $ std/ifstream# fcxx . . $ std/basic_ifstream#basic_ifstream(49f6e7a06ebc5aa8).;
60 stringcxx . . $ std/string# linecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).,setcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).,valcxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).,tempNamecxx . . $ std/__cxx11/basic_string#basic_string(925dcc5e17f50391).;
61
62 f.opencxx . . $ std/basic_ifstream#open(b8cd37071ce335df).( useThemecxx . . $ useTheme(24764cae04130674).("/font/fonts.txt"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).,settingcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)..gfxThemecxx . . $ settings#gfxTheme.).datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).() );
63 if(f.is_opencxx . . $ std/basic_ifstream#is_open(c9857a73d68e59ba).())
64 {
65 while(!f.eofcxx . . $ std/basic_ios#eof(50ce9a9e25b4a850).())
66 {
67 getlinecxx . . $ std/getline(4ec722ed0b69c2ab).(f, line);
68 if(line.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('=') != stringcxx . . $ std/string#::nposcxx . . $ std/__cxx11/basic_string#npos.)
69 {
70 set=cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966).line.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(0,line.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('='));
71 val=cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966).line.substrcxx . . $ std/__cxx11/basic_string#substr(149c655009c9bbd2).(line.findcxx . . $ std/__cxx11/basic_string#find(2dda2fc6b78abe68).('=')+1);
72 if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."menufile")
73 {
74 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
75 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."menusize")
76 {
77 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_MENUcxx . . $ `text.cpp:19:9`!);
78 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."announcegoodfile")
79 {
80 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
81 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."announcegoodsize")
82 {
83 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_ANNOUNCE_GOODcxx . . $ `text.cpp:20:9`!);
84
85 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."announcebadfile")
86 {
87 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
88 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."announcebadsize")
89 {
90 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_ANNOUNCE_BADcxx . . $ `text.cpp:21:9`!);
91 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."highscorefile")
92 {
93 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
94 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."highscoresize")
95 {
96 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_HIGHSCOREcxx . . $ `text.cpp:22:9`!);
97 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."menuhighscorefile")
98 {
99 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
100 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."menuhighscoresize")
101 {
102 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_MENUHIGHSCOREcxx . . $ `text.cpp:23:9`!);
103 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."introhighscorefile")
104 {
105 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
106 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."introhighscoresize")
107 {
108 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_INTROHIGHSCOREcxx . . $ `text.cpp:24:9`!);
109 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."introdescriptionfile")
110 {
111 tempName=cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75).val;
112 } else if(set==cxx . . $ std/`operator==`(4b17aa87c9f300c6)."introdescriptionsize")
113 {
114 genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(tempNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)., atoicxx . . $ atoi(f5ecf3191ed0cd93).(val.datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).()), FONT_INTRODESCRIPTIONcxx . . $ `text.cpp:25:9`!);
115 }
116 }
117 }
118 f.closecxx . . $ std/basic_ifstream#close(49f6e7a06ebc5aa8).();
119 } else {
120 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Error: could not open font-description file.";
121 }
122 TTF_Quit();
123 }
124
125 void glTextClasscxx . . $ glTextClass#::genFontTexcxx . . $ glTextClass#genFontTex(6471c7b84fc484b4).(stringcxx . . $ std/string# TTFfontName, int fontSize, int font)
126 {
127 TTF_Font *ttfFont = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
128 SDL_Surface *c, *t;
129 Uint32cxx . . $ Uint32# rmask, gmask, bmask, amask;
130 char tempChar[2] = { 0,0 };
131 int sX=0,sY=0; //Size of the rendered character
132 SDL_Rect src={0,0,0,0},dst={0,0,0,0};
133 SDL_Color white = { 255,255,255 };
134
135 #if SDL_BYTEORDERcxx . . $ `<external>/11920633478002857172/SDL_endian.h:43:9`! == SDL_BIG_ENDIANcxx . . $ `<external>/11920633478002857172/SDL_endian.h:38:9`!
136 rmask = 0xff000000;
137 gmask = 0x00ff0000;
138 bmask = 0x0000ff00;
139 amask = 0x000000ff;
140 #else
141 rmask = 0x000000ff;
142 gmask = 0x0000ff00;
143 bmask = 0x00ff0000;
144 amask = 0xff000000;
145 #endif
146
147 ttfFont = TTF_OpenFont( useThemecxx . . $ useTheme(24764cae04130674).(TTFfontNamecxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).,settingcxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5)..gfxThemecxx . . $ settings#gfxTheme.).datacxx . . $ std/__cxx11/basic_string#data(258ee1c9e0a18a5c).(), fontSize );
148 t = SDL_CreateRGBSurface(0, 512, 512, 32, rmask,gmask,bmask,amask);
149
150 dst.x=1;
151 dst.y=1;
152
153 fontInfocxx . . $ glTextClass#fontInfo.[font].heightcxx . . $ glFontInfo_struct#height.=0.0;
154 for(int i=32; i < 128; i++)
155 {
156 tempChar[0] = (char)i;
157
158 //Render to surface
159 c = TTF_RenderText_Blended(ttfFont, tempChar, white);
160 SDL_SetAlpha(c, 0, 0);
161 TTF_SizeUTF8(ttfFont, tempChar, &sX, &sY);
162
163 src.x=0;
164 src.y=0;
165 src.w=sX;
166 src.h=sY;
167
168
169 if(dst.x + sX > 512)
170 {
171 dst.x=1;
172 dst.y += sY+2;
173 if(dst.y > 512 && font != FONT_HIGHSCOREcxx . . $ `text.cpp:22:9`!) //FONT_HIGHSCORE is always rendered too big for texture
174 {
175 coutcxx . . $ std/cout. <<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7). "Too many chars for tex ("<<cxx . . $ std/basic_ostream#`operator<<`(23b6575433a77e57).i<<cxx . . $ std/`operator<<`(efaf8c13fc75f3c7).")"<<cxx . . $ std/basic_ostream#`operator<<`(f46f7e25851d787a).endlcxx . . $ std/endl(345bf97a19cc83a9).;
176 }
177 }
178
179 fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[i].Xacxx . . $ glCharInfo_struct#Xa. = ( 1.0 / ( 512.0 / (float)dst.x ) );
180 fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[i].Xbcxx . . $ glCharInfo_struct#Xb. = ( 1.0 / ( 512.0 / ((float)dst.x+sX) ) );
181 fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[i].Yacxx . . $ glCharInfo_struct#Ya. = ( 1.0 / ( 512.0 / (float)dst.y ) );
182 fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[i].Ybcxx . . $ glCharInfo_struct#Yb. = ( 1.0 / ( 512.0 / ((float)dst.y+sY) ) );
183 fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[i].widthcxx . . $ glCharInfo_struct#width. = sX/800.0;
184
185 if(sY/800.0 > fontInfocxx . . $ glTextClass#fontInfo.[font].heightcxx . . $ glFontInfo_struct#height.)
186 {
187 fontInfocxx . . $ glTextClass#fontInfo.[font].heightcxx . . $ glFontInfo_struct#height. = sY/800.0;
188 }
189
190 //blit
191 dst.w=sX;
192 dst.h=sY;
193 SDL_BlitSurfacecxx . . $ `<external>/3508485105195885937/SDL_video.h:262:9`!(c,&src,t,&dst);
194
195 dst.x += sX+2; // Waste some space 1 px padding around each char
196
197 SDL_FreeSurface(c); //Free character-surface
198 }
199
200 glGenTextures(1, &fontInfocxx . . $ glTextClass#fontInfo.[font].texcxx . . $ glFontInfo_struct#tex.); //Generate a gltexture for this font
201
202 glBindTexture(GL_TEXTURE_2Dcxx . . $ `<external>/11565930711847777359/gl.h:611:9`!, fontInfocxx . . $ glTextClass#fontInfo.[font].texcxx . . $ glFontInfo_struct#tex.);
203 gluBuild2DMipmaps(GL_TEXTURE_2Dcxx . . $ `<external>/11565930711847777359/gl.h:611:9`!, GL_RGBAcxx . . $ `<external>/11565930711847777359/gl.h:469:9`!, t->w, t->h, GL_RGBAcxx . . $ `<external>/11565930711847777359/gl.h:469:9`!, GL_UNSIGNED_BYTEcxx . . $ `<external>/11565930711847777359/gl.h:144:9`!, t->pixels);
204
205 TTF_CloseFont(ttfFont); //Free the font
206 SDL_FreeSurface(t); //Free text-surface
207 }
208
209 void glTextClasscxx . . $ glTextClass#::writecxx . . $ glTextClass#write(e3805d4e487d2eea).(stringcxx . . $ std/string# text, int font,bool center, GLfloat scale, GLfloat x, GLfloat y)
210 {
211 int c;
212 GLfloat sX,sY,posX=0;
213
214 //We need to find out half of the string width in order to center
215 if(center)
216 {
217 for(unsigned int i=0; i < text.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); i++)
218 {
219 c = (unsigned int)text[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i];
220 sX = fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].widthcxx . . $ glCharInfo_struct#width.*scale;
221 posX += sX;
222 }
223 posX *= -1;
224 }
225 posX += x;
226
227 glEnable( GL_TEXTURE_2Dcxx . . $ `<external>/11565930711847777359/gl.h:611:9`! );
228 glBindTexture(GL_TEXTURE_2Dcxx . . $ `<external>/11565930711847777359/gl.h:611:9`!, fontInfocxx . . $ glTextClass#fontInfo.[font].texcxx . . $ glFontInfo_struct#tex.);
229
230
231 //Draw the quads
232 for(unsigned int i=0; i < text.lengthcxx . . $ std/__cxx11/basic_string#length(6f8bd5c0ea8fb29a).(); i++)
233 {
234 c = (unsigned int)text[cxx . . $ std/__cxx11/basic_string#`operator[]`(7b73c3179b3cb3ad).i];
235 sX = fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].widthcxx . . $ glCharInfo_struct#width.*scale;
236 sY = fontInfocxx . . $ glTextClass#fontInfo.[font].heightcxx . . $ glFontInfo_struct#height.*scale;
237 posX += sX;
238
239 glBegin(GL_QUADScxx . . $ `<external>/11565930711847777359/gl.h:163:9`!);
240 glTexCoord2f( fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Xacxx . . $ glCharInfo_struct#Xa.,fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Yacxx . . $ glCharInfo_struct#Ya. ); glVertex3f(-sX+posX, sY+y,0);
241 glTexCoord2f( fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Xbcxx . . $ glCharInfo_struct#Xb.,fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Yacxx . . $ glCharInfo_struct#Ya. ); glVertex3f( sX+posX, sY+y,0);
242 glTexCoord2f( fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Xbcxx . . $ glCharInfo_struct#Xb.,fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Ybcxx . . $ glCharInfo_struct#Yb. ); glVertex3f( sX+posX,-sY+y,0);
243 glTexCoord2f( fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Xacxx . . $ glCharInfo_struct#Xa.,fontInfocxx . . $ glTextClass#fontInfo.[font].chcxx . . $ glFontInfo_struct#ch.[c].Ybcxx . . $ glCharInfo_struct#Yb. ); glVertex3f(-sX+posX,-sY+y,0);
244 glEnd( );
245 posX += sX;
246 }
247 }