00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021
00022
00024
00025 #include "Bitmapfont.hpp"
00026 #include "Singletons.hpp"
00027
00029
00030 CBitmapFont::CBitmapFont()
00031 {
00032 }
00033
00034 CBitmapFont::~CBitmapFont()
00035 {
00036 for(std::size_t CurChar = 0; CurChar < m_FontSprites.size(); CurChar++)
00037 {
00038 delete m_FontSprites[CurChar];
00039 }
00040 m_FontSprites.clear();
00041 }
00042
00043 void CBitmapFont::Init()
00044 {
00045 AddChar("data/gfx/BitMapFont/A.png");
00046 AddChar("data/gfx/BitMapFont/B.png");
00047 AddChar("data/gfx/BitMapFont/C.png");
00048 AddChar("data/gfx/BitMapFont/D.png");
00049 AddChar("data/gfx/BitMapFont/E.png");
00050 AddChar("data/gfx/BitMapFont/F.png");
00051 AddChar("data/gfx/BitMapFont/G.png");
00052 AddChar("data/gfx/BitMapFont/H.png");
00053 AddChar("data/gfx/BitMapFont/I.png");
00054 AddChar("data/gfx/BitMapFont/J.png");
00055 AddChar("data/gfx/BitMapFont/K.png");
00056 AddChar("data/gfx/BitMapFont/L.png");
00057 AddChar("data/gfx/BitMapFont/M.png");
00058 AddChar("data/gfx/BitMapFont/N.png");
00059 AddChar("data/gfx/BitMapFont/O.png");
00060 AddChar("data/gfx/BitMapFont/P.png");
00061 AddChar("data/gfx/BitMapFont/Q.png");
00062 AddChar("data/gfx/BitMapFont/R.png");
00063 AddChar("data/gfx/BitMapFont/S.png");
00064 AddChar("data/gfx/BitMapFont/T.png");
00065 AddChar("data/gfx/BitMapFont/U.png");
00066 AddChar("data/gfx/BitMapFont/V.png");
00067 AddChar("data/gfx/BitMapFont/W.png");
00068 AddChar("data/gfx/BitMapFont/X.png");
00069 AddChar("data/gfx/BitMapFont/Y.png");
00070 AddChar("data/gfx/BitMapFont/Z.png");
00071
00072 AddChar("data/gfx/BitMapFont/A_klein.png");
00073 AddChar("data/gfx/BitMapFont/B_klein.png");
00074 AddChar("data/gfx/BitMapFont/C_klein.png");
00075 AddChar("data/gfx/BitMapFont/D_klein.png");
00076 AddChar("data/gfx/BitMapFont/E_klein.png");
00077 AddChar("data/gfx/BitMapFont/F_klein.png");
00078 AddChar("data/gfx/BitMapFont/G_klein.png");
00079 AddChar("data/gfx/BitMapFont/H_klein.png");
00080 AddChar("data/gfx/BitMapFont/I_klein.png");
00081 AddChar("data/gfx/BitMapFont/J_klein.png");
00082 AddChar("data/gfx/BitMapFont/K_klein.png");
00083 AddChar("data/gfx/BitMapFont/L_klein.png");
00084 AddChar("data/gfx/BitMapFont/M_klein.png");
00085 AddChar("data/gfx/BitMapFont/N_klein.png");
00086 AddChar("data/gfx/BitMapFont/O_klein.png");
00087 AddChar("data/gfx/BitMapFont/P_klein.png");
00088 AddChar("data/gfx/BitMapFont/Q_klein.png");
00089 AddChar("data/gfx/BitMapFont/R_klein.png");
00090 AddChar("data/gfx/BitMapFont/S_klein.png");
00091 AddChar("data/gfx/BitMapFont/T_klein.png");
00092 AddChar("data/gfx/BitMapFont/U_klein.png");
00093 AddChar("data/gfx/BitMapFont/V_klein.png");
00094 AddChar("data/gfx/BitMapFont/W_klein.png");
00095 AddChar("data/gfx/BitMapFont/X_klein.png");
00096 AddChar("data/gfx/BitMapFont/Y_klein.png");
00097 AddChar("data/gfx/BitMapFont/Z_klein.png");
00098
00099 AddChar("data/gfx/BitMapFont/0.png");
00100 AddChar("data/gfx/BitMapFont/1.png");
00101 AddChar("data/gfx/BitMapFont/2.png");
00102 AddChar("data/gfx/BitMapFont/3.png");
00103 AddChar("data/gfx/BitMapFont/4.png");
00104 AddChar("data/gfx/BitMapFont/5.png");
00105 AddChar("data/gfx/BitMapFont/6.png");
00106 AddChar("data/gfx/BitMapFont/7.png");
00107 AddChar("data/gfx/BitMapFont/8.png");
00108 AddChar("data/gfx/BitMapFont/9.png");
00109
00110 AddChar("data/gfx/BitMapFont/Doppelpunkt.png");
00111 AddChar("data/gfx/BitMapFont/Punkt.png");
00112 AddChar("data/gfx/BitMapFont/AusrufeZeichen.png");
00113 AddChar("data/gfx/BitMapFont/Komma.png");
00114 AddChar("data/gfx/BitMapFont/Minus.png");
00115 AddChar("data/gfx/BitMapFont/Plus.png");
00116 AddChar("data/gfx/BitMapFont/GrößerAls.png");
00117 AddChar("data/gfx/BitMapFont/KleinerAls.png");
00118 AddChar("data/gfx/BitMapFont/Raute.png");
00119 AddChar("data/gfx/BitMapFont/Sternchen.png");
00120 AddChar("data/gfx/BitMapFont/UnterStrich.png");
00121 AddChar("data/gfx/BitMapFont/Und.png");
00122 AddChar("data/gfx/BitMapFont/KlammerAuf.png");
00123 AddChar("data/gfx/BitMapFont/KlammerZu.png");
00124 AddChar("data/gfx/BitMapFont/Slash.png");
00125 AddChar("data/gfx/BitMapFont/Gleich.png");
00126 AddChar("data/gfx/BitMapFont/FrageZeichen.png");
00127 AddChar("data/gfx/BitMapFont/Apostroph.png");
00128 AddChar("data/gfx/BitMapFont/BackSlash.png");
00129 AddChar("data/gfx/BitMapFont/Grad.png");
00130 AddChar("data/gfx/BitMapFont/Prozent.png");
00131 AddChar("data/gfx/BitMapFont/StrichPunkt.png");
00132
00133 AddChar("data/gfx/BitMapFont/Ä.png");
00134 AddChar("data/gfx/BitMapFont/Ä_klein.png");
00135 AddChar("data/gfx/BitMapFont/Ö.png");
00136 AddChar("data/gfx/BitMapFont/Ö_klein.png");
00137 AddChar("data/gfx/BitMapFont/Ü.png");
00138 AddChar("data/gfx/BitMapFont/Ü_klein.png");
00139
00140 AddChar("data/gfx/BitMapFont/ß.png");
00141 }
00142
00143 void CBitmapFont::AddChar(std::string FileName)
00144 {
00145 sf::Sprite* TempSprite = new sf::Sprite;
00146
00147 TempSprite->SetImage(sgl::get_imagemgr().get_img(FileName));
00148
00149 m_FontSprites.push_back(TempSprite);
00150 }
00151
00152 void CBitmapFont::DrawText(float x, float y, std::string Text, float PixelHeight, float RectXSize,
00153 float RectYSize, int ScrollY, bool* CanScroll, int Alpha, bool CenterdX)
00154 {
00155 float Scale = PixelHeight / m_FontSprites[0]->GetSubRect().GetHeight();
00156
00157 if(Scale == 0.0f)
00158 {
00159 Scale = 1.0f;
00160 }
00161
00162 for(std::size_t CurChar = 0; CurChar < m_FontSprites.size(); CurChar++)
00163 {
00164 m_FontSprites[CurChar]->SetScale(Scale,Scale);
00165 m_FontSprites[CurChar]->SetColor(sf::Color(255,255,255, Alpha));
00166 }
00167
00168 float Offset = 0.0f;
00169 float StandardY = y;
00170 y -= m_FontSprites[0]->GetSubRect().GetHeight() * Scale * ScrollY;
00171 int CurLine = 0;
00172 bool Draw = true;
00173
00174 unsigned i = 0;
00175 int LastWhiteSpace = -1;
00176 int OldLastWhiteSpace = -2;
00177 int TextWidth = 0;
00178 char BreakStr[3];
00179 BreakStr[0] = (char)92;
00180 BreakStr[1] = 'n';
00181 BreakStr[2] = '\0';
00182 std::string SlashString = BreakStr;
00183
00184 if(RectXSize < 10000.0f)
00185 {
00186
00187 for(i = 0; i < Text.size(); i++)
00188 {
00189 if((int)Text[i] == 32)
00190 {
00191 LastWhiteSpace = i;
00192 }
00193
00194 if((int)Text[i] == 92 && (Text[i + 1] == 110 || Text[i + 1] == 78))
00195 {
00196 i += 2;
00197 Offset = 0;
00198 continue;
00199 }
00200
00201 Offset += (m_FontSprites[0]->GetSubRect().GetWidth() - 3.0f) * Scale;
00202
00203 if(Offset >= RectXSize && LastWhiteSpace != -1)
00204 {
00205 if(OldLastWhiteSpace == LastWhiteSpace)
00206 {
00207 break;
00208 }
00209 Text.insert(LastWhiteSpace,SlashString);
00210 i = LastWhiteSpace + 1;
00211 OldLastWhiteSpace = LastWhiteSpace + 2;
00212 Offset = 0;
00213 }
00214 }
00215 Offset = 0.0f;
00216 }
00217
00218 if(CenterdX == true)
00219 {
00220 TextWidth = ((m_FontSprites[0]->GetSubRect().GetWidth() - 3.0f) * Scale) * Text.size();
00221 Offset = -TextWidth/2;
00222 }
00223
00224 for(i = 0; i < Text.size(); i++)
00225 {
00226 if(i < Text.size() - 1)
00227 {
00228
00229 if((int)Text[i] == 92 && (Text[i + 1] == 110 || Text[i + 1] == 78))
00230 {
00231 y += m_FontSprites[0]->GetSubRect().GetHeight() * Scale;
00232
00233 Offset = 0;
00234 if(CenterdX == true)
00235 {
00236 Offset = -TextWidth/2;
00237 }
00238 i++;
00239 CurLine++;
00240 continue;
00241 }
00242 }
00243
00244 if(y - StandardY > RectYSize)
00245 {
00246 if(CanScroll != NULL)
00247 {
00248 *CanScroll = true;
00249 }
00250
00251 break;
00252 }
00253
00254 if(CurLine < ScrollY)
00255 {
00256 Draw = false;
00257 }
00258 else
00259 {
00260 Draw = true;
00261 }
00262
00263
00264 if((int)Text[i] >= 65 && (int)Text[i] <= 90)
00265 {
00266 if(Draw == true)
00267 {
00268 m_FontSprites[(int)Text[i]-65]->SetPosition(x+Offset,y);
00269 sgl::get_window().Draw(*(m_FontSprites[(int)Text[i]-65]));
00270 }
00271 Offset += (m_FontSprites[(int)Text[i]-65]->GetSubRect().GetWidth()-3.0f) * Scale;
00272 }
00273
00274
00275 else if((int)Text[i] >= 97 && (int)Text[i] <= 122)
00276 {
00277 if(Draw == true)
00278 {
00279 m_FontSprites[(int)Text[i]-97+26]->SetPosition(x+Offset,y);
00280 sgl::get_window().Draw(*(m_FontSprites[(int)Text[i]-97+26]));
00281 }
00282 Offset += (m_FontSprites[(int)Text[i]-97+26]->GetSubRect().GetWidth()-3.0f) * Scale;
00283 }
00284
00285
00286 else if((int)Text[i] >= 48 && (int)Text[i] <= 57)
00287 {
00288 if(Draw == true)
00289 {
00290 m_FontSprites[(int)Text[i]-48+52]->SetPosition(x+Offset,y);
00291 sgl::get_window().Draw(*(m_FontSprites[(int)Text[i]-48+52]));
00292 }
00293 Offset += (m_FontSprites[(int)Text[i]-48+52]->GetSubRect().GetWidth()-3.0f) * Scale;
00294 }
00295
00296
00297 else if((int)Text[i] == 32)
00298 {
00299 Offset += (m_FontSprites[0]->GetSubRect().GetWidth()-3.0f) * Scale;
00300 }
00301
00302
00303 else if((int)Text[i] == 33)
00304 {
00305 if(Draw == true)
00306 {
00307 m_FontSprites[64]->SetPosition(x+Offset,y);
00308 sgl::get_window().Draw(*(m_FontSprites[64]));
00309 }
00310 Offset += (m_FontSprites[64]->GetSubRect().GetWidth()-3.0f) * Scale;
00311 }
00312
00313
00314 else if((int)Text[i] == -80)
00315 {
00316 if(Draw == true)
00317 {
00318 m_FontSprites[81]->SetPosition(x+Offset,y);
00319 sgl::get_window().Draw(*(m_FontSprites[81]));
00320 }
00321 Offset += (m_FontSprites[81]->GetSubRect().GetWidth()-3.0f) * Scale;
00322 }
00323
00324
00325 else if((int)Text[i] == 35)
00326 {
00327 if(Draw == true)
00328 {
00329 m_FontSprites[70]->SetPosition(x+Offset,y);
00330 sgl::get_window().Draw(*(m_FontSprites[70]));
00331 }
00332 Offset += (m_FontSprites[70]->GetSubRect().GetWidth()-3.0f) * Scale;
00333 }
00334
00335
00336 else if((int)Text[i] == 38)
00337 {
00338 if(Draw == true)
00339 {
00340 m_FontSprites[73]->SetPosition(x+Offset,y);
00341 sgl::get_window().Draw(*(m_FontSprites[73]));
00342 }
00343 Offset += (m_FontSprites[73]->GetSubRect().GetWidth()-3.0f) * Scale;
00344 }
00345
00346
00347 else if((int)Text[i] == 40)
00348 {
00349 if(Draw == true)
00350 {
00351 m_FontSprites[74]->SetPosition(x+Offset,y);
00352 sgl::get_window().Draw(*(m_FontSprites[74]));
00353 }
00354 Offset += (m_FontSprites[74]->GetSubRect().GetWidth()-3.0f) * Scale;
00355 }
00356
00357
00358 else if((int)Text[i] == 41)
00359 {
00360 if(Draw == true)
00361 {
00362 m_FontSprites[75]->SetPosition(x+Offset,y);
00363 sgl::get_window().Draw(*(m_FontSprites[75]));
00364 }
00365 Offset += (m_FontSprites[75]->GetSubRect().GetWidth()-3.0f) * Scale;
00366 }
00367
00368
00369 else if((int)Text[i] == 42)
00370 {
00371 if(Draw == true)
00372 {
00373 m_FontSprites[71]->SetPosition(x+Offset,y);
00374 sgl::get_window().Draw(*(m_FontSprites[71]));
00375 }
00376 Offset += (m_FontSprites[71]->GetSubRect().GetWidth()-3.0f) * Scale;
00377 }
00378
00379
00380 if((int)Text[i] == 43)
00381 {
00382 if(Draw == true)
00383 {
00384 m_FontSprites[67]->SetPosition(x+Offset,y);
00385 sgl::get_window().Draw(*(m_FontSprites[67]));
00386 }
00387 Offset += (m_FontSprites[67]->GetSubRect().GetWidth()-3.0f) * Scale;
00388 }
00389
00390
00391 if((int)Text[i] == 37)
00392 {
00393 if(Draw == true)
00394 {
00395 m_FontSprites[82]->SetPosition(x+Offset,y);
00396 sgl::get_window().Draw(*(m_FontSprites[82]));
00397 }
00398 Offset += (m_FontSprites[82]->GetSubRect().GetWidth()-3.0f) * Scale;
00399 }
00400
00401
00402 else if((int)Text[i] == 44)
00403 {
00404 if(Draw == true)
00405 {
00406 m_FontSprites[65]->SetPosition(x+Offset,y);
00407 sgl::get_window().Draw(*(m_FontSprites[65]));
00408 }
00409 Offset += (m_FontSprites[65]->GetSubRect().GetWidth()-3.0f) * Scale;
00410 }
00411
00412
00413 else if((int)Text[i] == 45 || (int)Text[i] == 127)
00414 {
00415 if(Draw == true)
00416 {
00417 m_FontSprites[66]->SetPosition(x+Offset,y);
00418 sgl::get_window().Draw(*(m_FontSprites[66]));
00419 }
00420 Offset += (m_FontSprites[66]->GetSubRect().GetWidth()-3.0f) * Scale;
00421 }
00422
00423
00424 else if((int)Text[i] == 46)
00425 {
00426 if(Draw == true)
00427 {
00428 m_FontSprites[63]->SetPosition(x+Offset,y);
00429 sgl::get_window().Draw(*(m_FontSprites[63]));
00430 }
00431 Offset += (m_FontSprites[63]->GetSubRect().GetWidth()-3.0f) * Scale;
00432 }
00433
00434
00435 else if((int)Text[i] == 47)
00436 {
00437 if(Draw == true)
00438 {
00439 m_FontSprites[76]->SetPosition(x+Offset,y);
00440 sgl::get_window().Draw(*(m_FontSprites[76]));
00441 }
00442 Offset += (m_FontSprites[76]->GetSubRect().GetWidth()-3.0f) * Scale;
00443 }
00444
00445
00446 else if((int)Text[i] == 58)
00447 {
00448 if(Draw == true)
00449 {
00450 m_FontSprites[62]->SetPosition(x+Offset,y);
00451 sgl::get_window().Draw(*(m_FontSprites[62]));
00452 }
00453 Offset += (m_FontSprites[62]->GetSubRect().GetWidth()-3.0f) * Scale;
00454 }
00455
00456
00457 else if((int)Text[i] == 60)
00458 {
00459 if(Draw == true)
00460 {
00461 m_FontSprites[69]->SetPosition(x+Offset,y);
00462 sgl::get_window().Draw(*(m_FontSprites[69]));
00463 }
00464 Offset += (m_FontSprites[69]->GetSubRect().GetWidth()-3.0f) * Scale;
00465 }
00466
00467
00468 else if((int)Text[i] == 61)
00469 {
00470 if(Draw == true)
00471 {
00472 m_FontSprites[77]->SetPosition(x+Offset,y);
00473 sgl::get_window().Draw(*(m_FontSprites[77]));
00474 }
00475 Offset += (m_FontSprites[77]->GetSubRect().GetWidth()-3.0f) * Scale;
00476 }
00477
00478
00479 else if((int)Text[i] == 62)
00480 {
00481 if(Draw == true)
00482 {
00483 m_FontSprites[68]->SetPosition(x+Offset,y);
00484 sgl::get_window().Draw(*(m_FontSprites[68]));
00485 }
00486 Offset += (m_FontSprites[68]->GetSubRect().GetWidth()-3.0f) * Scale;
00487 }
00488
00489
00490 else if((int)Text[i] == 63)
00491 {
00492 if(Draw == true)
00493 {
00494 m_FontSprites[78]->SetPosition(x+Offset,y);
00495 sgl::get_window().Draw(*(m_FontSprites[78]));
00496 }
00497 Offset += (m_FontSprites[78]->GetSubRect().GetWidth()-3.0f) * Scale;
00498 }
00499
00500
00501 else if((int)Text[i] == 95)
00502 {
00503 if(Draw == true)
00504 {
00505 m_FontSprites[72]->SetPosition(x+Offset,y);
00506 sgl::get_window().Draw(*(m_FontSprites[72]));
00507 }
00508 Offset += (m_FontSprites[72]->GetSubRect().GetWidth()-3.0f) * Scale;
00509 }
00510
00511
00512 else if((int)Text[i] == 39)
00513 {
00514 if(Draw == true)
00515 {
00516 m_FontSprites[79]->SetPosition(x+Offset,y);
00517 sgl::get_window().Draw(*(m_FontSprites[79]));
00518 }
00519 Offset += (m_FontSprites[79]->GetSubRect().GetWidth()-3.0f) * Scale;
00520 }
00521
00522
00523 else if((int)Text[i] == 92)
00524 {
00525 if(Draw == true)
00526 {
00527 m_FontSprites[80]->SetPosition(x+Offset,y);
00528 sgl::get_window().Draw(*(m_FontSprites[80]));
00529 }
00530 Offset += (m_FontSprites[80]->GetSubRect().GetWidth()-3.0f) * Scale;
00531 }
00532
00533
00534 else if((int)Text[i] == 59)
00535 {
00536 if(Draw == true)
00537 {
00538 m_FontSprites[83]->SetPosition(x+Offset,y);
00539 sgl::get_window().Draw(*(m_FontSprites[83]));
00540 }
00541 Offset += (m_FontSprites[83]->GetSubRect().GetWidth()-3.0f) * Scale;
00542 }
00543
00544
00545 else if((int)Text[i] == -60)
00546 {
00547 if(Draw == true)
00548 {
00549 m_FontSprites[84]->SetPosition(x+Offset,y);
00550 sgl::get_window().Draw(*(m_FontSprites[84]));
00551 }
00552 Offset += (m_FontSprites[84]->GetSubRect().GetWidth()-3.0f) * Scale;
00553 }
00554
00555
00556 else if((int)Text[i] == -28)
00557 {
00558 if(Draw == true)
00559 {
00560 m_FontSprites[85]->SetPosition(x+Offset,y);
00561 sgl::get_window().Draw(*(m_FontSprites[85]));
00562 }
00563 Offset += (m_FontSprites[85]->GetSubRect().GetWidth()-3.0f) * Scale;
00564 }
00565
00566
00567 else if((int)Text[i] == -42)
00568 {
00569 if(Draw == true)
00570 {
00571 m_FontSprites[86]->SetPosition(x+Offset,y);
00572 sgl::get_window().Draw(*(m_FontSprites[86]));
00573 }
00574 Offset += (m_FontSprites[86]->GetSubRect().GetWidth()-3.0f) * Scale;
00575 }
00576
00577
00578 else if((int)Text[i] == -10)
00579 {
00580 if(Draw == true)
00581 {
00582 m_FontSprites[87]->SetPosition(x+Offset,y);
00583 sgl::get_window().Draw(*(m_FontSprites[87]));
00584 }
00585 Offset += (m_FontSprites[87]->GetSubRect().GetWidth()-3.0f) * Scale;
00586 }
00587
00588
00589 else if((int)Text[i] == -36)
00590 {
00591 if(Draw == true)
00592 {
00593 m_FontSprites[88]->SetPosition(x+Offset,y);
00594 sgl::get_window().Draw(*(m_FontSprites[88]));
00595 }
00596 Offset += (m_FontSprites[88]->GetSubRect().GetWidth()-3.0f) * Scale;
00597 }
00598
00599
00600 else if((int)Text[i] == -4)
00601 {
00602 if(Draw == true)
00603 {
00604 m_FontSprites[89]->SetPosition(x+Offset,y);
00605 sgl::get_window().Draw(*(m_FontSprites[89]));
00606 }
00607 Offset += (m_FontSprites[89]->GetSubRect().GetWidth()-3.0f) * Scale;
00608 }
00609
00610 else if((int)Text[i] == -33)
00611 {
00612 if(Draw == true)
00613 {
00614 m_FontSprites[90]->SetPosition(x+Offset,y);
00615 sgl::get_window().Draw(*(m_FontSprites[90]));
00616 }
00617 Offset += (m_FontSprites[90]->GetSubRect().GetWidth()-3.0f) * Scale;
00618 }
00619 }
00620 }