From ebc130f5269cb76594d62174a8ef57d1562b0c0e Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 3 Oct 2011 04:49:52 +0000 Subject: [PATCH] - added a few new chinese fonts and changed default to a new font - fixed location of player title in menus - added better ftgl error checking --- .../menu/menu_state_connected_game.cpp | 2 +- .../menu/menu_state_custom_game.cpp | 2 +- .../sources/graphics/gl/font_textFTGL.cpp | 66 ++++++++++++++++--- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index d8f69a409..a028046c3 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -330,7 +330,7 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM labelPlayerStatus[i].init(10, setupPos-30-i*rowHeight, 60); labelPlayers[i].registerGraphicComponent(containerName,"labelPlayers" + intToStr(i)); - labelPlayers[i].init(xoffset+0, setupPos-30-i*rowHeight); + labelPlayers[i].init(xoffset-20, setupPos-30-i*rowHeight); labelPlayers[i].setEditable(false); labelPlayerNames[i].registerGraphicComponent(containerName,"labelPlayerNames" + intToStr(i)); diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index ec00b8ce4..1d28bb8b5 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -427,7 +427,7 @@ MenuStateCustomGame::MenuStateCustomGame(Program *program, MainMenu *mainMenu, labelPlayerStatus[i].init(10, setupPos-30-i*rowHeight, 60); labelPlayers[i].registerGraphicComponent(containerName,"labelPlayers" + intToStr(i)); - labelPlayers[i].init(xoffset+0, setupPos-30-i*rowHeight); + labelPlayers[i].init(xoffset-20, setupPos-30-i*rowHeight); labelPlayerNames[i].registerGraphicComponent(containerName,"labelPlayerNames" + intToStr(i)); labelPlayerNames[i].init(xoffset+50,setupPos-30-i*rowHeight); diff --git a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp index a604b8b61..7e0ec83d1 100644 --- a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp +++ b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp @@ -82,7 +82,9 @@ TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) { ftFont->FaceSize(24,TextFTGL::faceResolution); if(ftFont->Error()) { - throw runtime_error("FTGL: error setting face size"); + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error setting face size, #%d",ftFont->Error()); + throw runtime_error(szBuf); } //ftFont->UseDisplayList(false); //ftFont->CharMap(ft_encoding_gb2312); @@ -92,7 +94,9 @@ TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) { } if(ftFont->Error()) { - throw runtime_error("FTGL: error setting encoding"); + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error setting encoding, #%d",ftFont->Error()); + throw runtime_error(szBuf); } } @@ -153,7 +157,9 @@ void TextFTGL::init(string fontName, int fontSize) { } if(ftFont->Error()) { - throw runtime_error("FTGL: error setting face size"); + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error setting face size, #%d",ftFont->Error()); + throw runtime_error(szBuf); } //ftFont->UseDisplayList(false); @@ -163,21 +169,32 @@ void TextFTGL::init(string fontName, int fontSize) { throw runtime_error("FTGL: error setting encoding"); } if(ftFont->Error()) { - throw runtime_error("FTGL: error setting encoding"); + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error setting encoding, #%d",ftFont->Error()); + throw runtime_error(szBuf); } // Create a string containing common characters // and preload the chars without rendering them. string preloadText = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890-=!@#$%^&*()_+:\"{}[]/?.,<>\\';"; ftFont->Advance(preloadText.c_str()); + + if(ftFont->Error()) { + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error advancing(a), #%d",ftFont->Error()); + throw runtime_error(szBuf); + } } void TextFTGL::SetFaceSize(int value) { ftFont->FaceSize(value,TextFTGL::faceResolution); if(ftFont->Error()) { - throw runtime_error("FTGL: error setting face size"); + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error setting face size, #%d",ftFont->Error()); + throw runtime_error(szBuf); } } + int TextFTGL::GetFaceSize() { return ftFont->FaceSize(); } @@ -192,13 +209,21 @@ void TextFTGL::Render(const char* str, const int len) { ftFont->Render(str, len); if(ftFont->Error()) { - throw runtime_error("FTGL: error trying to render"); + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error trying to render, #%d",ftFont->Error()); + throw runtime_error(szBuf); } } } float TextFTGL::Advance(const char* str, const int len) { - return ftFont->Advance(str, len); + float result = ftFont->Advance(str, len); + if(ftFont->Error()) { + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error trying to advance(b), #%d",ftFont->Error()); + throw runtime_error(szBuf); + } + return result; //FTBBox box = ftFont->BBox(str); //float urx = box.Upper().X(); @@ -242,6 +267,12 @@ float TextFTGL::LineHeight(const char* str, const int len) { } //printf("ftFont->BBox(''yW'')%f\n",result); } + if(ftFont->Error()) { + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error trying to get lineheight, #%d",ftFont->Error()); + throw runtime_error(szBuf); + } + return result; // printf("For str [%s] LineHeight = %f, result = %f\n",str, ftFont->LineHeight(),result); // return result; @@ -281,6 +312,12 @@ float TextFTGL::LineHeight(const wchar_t* str, const int len) { } //printf("ftFont->BBox(''yW'')%f\n",result); } + if(ftFont->Error()) { + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error trying to get lineheight, #%d",ftFont->Error()); + throw runtime_error(szBuf); + } + return result; } @@ -291,11 +328,24 @@ void TextFTGL::Render(const wchar_t* str, const int len) { */ if(len != 0) { ftFont->Render(str, len); + + if(ftFont->Error()) { + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error trying to render, #%d",ftFont->Error()); + throw runtime_error(szBuf); + } } } float TextFTGL::Advance(const wchar_t* str, const int len) { - return ftFont->Advance(str, len); + float result = ftFont->Advance(str, len); + if(ftFont->Error()) { + char szBuf[1024]=""; + sprintf(szBuf,"FTGL: error trying to advance(c), #%d",ftFont->Error()); + throw runtime_error(szBuf); + } + + return result; } const char* TextFTGL::findFont(const char *firstFontToTry) {