diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 9253b70a5..df1c32e79 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -2896,7 +2896,7 @@ void Game::render2d(){ if(renderer.getShowDebugUI() == true) { const Metrics &metrics= Metrics::getInstance(); //int mx= metrics.getMinimapX(); - //int my= metrics.getMinimapY(); + int my= metrics.getMinimapY(); //int mw= metrics.getMinimapW(); int mh= metrics.getMinimapH(); const Vec4f fontColor=getGui()->getDisplay()->getColor(); @@ -2910,6 +2910,14 @@ void Game::render2d(){ fontColor, 10, metrics.getVirtualH() - mh - 60, false); } + vector lineTokens; + Tokenize(str,lineTokens,"\n"); + int fontHeightNormal = (Renderer::renderText3DEnabled == true ? coreData.getMenuFontNormal3D()->getMetrics()->getHeight("W") : coreData.getMenuFontNormal()->getMetrics()->getHeight("W")); + int fontHeightBig = (Renderer::renderText3DEnabled == true ? coreData.getMenuFontBig3D()->getMetrics()->getHeight("W") : coreData.getMenuFontBig()->getMetrics()->getHeight("W")); + int playerPosY = lineTokens.size() * fontHeightNormal; + + //printf("lineTokens.size() = %d\n",lineTokens.size()); + for(int i = 0; i < world.getFactionCount(); ++i) { string factionInfo = factionDebugInfo[i]; Vec3f playerColor = world.getFaction(i)->getTexture()->getPixmapConst()->getPixel3f(0, 0); @@ -2917,12 +2925,18 @@ void Game::render2d(){ if(Renderer::renderText3DEnabled == true) { renderer.renderText3D(factionInfo, coreData.getMenuFontBig3D(), Vec4f(playerColor.x,playerColor.y,playerColor.z,1.0), - 10, metrics.getVirtualH() - mh - 90 - 280 - (i * 16), false); + 10, + //metrics.getVirtualH() - mh - 90 - 280 - (i * 16), + metrics.getVirtualH() - mh - 60 - playerPosY - (fontHeightBig * i), + false); } else { renderer.renderText(factionInfo, coreData.getMenuFontBig(), Vec4f(playerColor.x,playerColor.y,playerColor.z,1.0), - 10, metrics.getVirtualH() - mh - 90 - 280 - (i * 16), false); + 10, + //metrics.getVirtualH() - mh - 90 - 280 - (i * 16), + metrics.getVirtualH() - mh - 60 - playerPosY - (fontHeightBig * i), + false); } } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 21b6dc295..37b6525f0 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1845,7 +1845,7 @@ Vec2i computeCenteredPos(const string &text, Font2D *font, int x, int y) { } int virtualX = (fontMetrics->getTextWidth(text) > 0 ? static_cast(fontMetrics->getTextWidth(text)/2.f) : 5); - int virtualY = (fontMetrics->getHeight() > 0 ? static_cast(fontMetrics->getHeight()/2.f) : 5); + int virtualY = (fontMetrics->getHeight(text) > 0 ? static_cast(fontMetrics->getHeight(text)/2.f) : 5); Vec2i textPos( x-metrics.toVirtualX(virtualX), @@ -1868,7 +1868,7 @@ Vec2i computeCenteredPos(const string &text, Font3D *font, int x, int y) { } int virtualX = (fontMetrics->getTextWidth(text) > 0 ? static_cast(fontMetrics->getTextWidth(text) / 2.f) : 5); - int virtualY = (fontMetrics->getHeight() > 0 ? static_cast(fontMetrics->getHeight() / 2.f) : 5); + int virtualY = (fontMetrics->getHeight(text) > 0 ? static_cast(fontMetrics->getHeight(text) / 2.f) : 5); Vec2i textPos( x-metrics.toVirtualX(virtualX), @@ -7356,7 +7356,7 @@ void Renderer::renderPopupMenu(PopupMenu *menu) { int renderX = (menu->getX() + (menu->getW() / 2)); //int renderY = (menu->getY() + (menu->getH() / 2)); FontMetrics *fontMetrics= menu->getFont()->getMetrics(); - int renderY = menu->getY() + menu->getH() - fontMetrics->getHeight(); + int renderY = menu->getY() + menu->getH() - fontMetrics->getHeight(menu->getHeader()); renderTextShadow( menu->getHeader(), menu->getFont(),fontColor, renderX, renderY, diff --git a/source/glest_game/main/intro.cpp b/source/glest_game/main/intro.cpp index e7318106f..cf7bf0cbb 100644 --- a/source/glest_game/main/intro.cpp +++ b/source/glest_game/main/intro.cpp @@ -704,7 +704,7 @@ void Intro::render() { if(renderY < 0) { const Metrics &metrics= Metrics::getInstance(); int h= metrics.getVirtualH(); - renderY = (h / 2) + (text->getFont3D()->getMetrics()->getHeight() / 2); + renderY = (h / 2) + (text->getFont3D()->getMetrics()->getHeight(text->getText()) / 2); } renderer.renderText3D( diff --git a/source/shared_lib/include/graphics/font.h b/source/shared_lib/include/graphics/font.h index 67b97f732..102d784d9 100644 --- a/source/shared_lib/include/graphics/font.h +++ b/source/shared_lib/include/graphics/font.h @@ -51,7 +51,7 @@ public: void setHeight(float height) {this->height= height;} float getTextWidth(const string &str); - float getHeight() const; + float getHeight(const string &str) const; }; // ===================================================== diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index a5f0b8e17..ee6389504 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -141,10 +141,11 @@ float FontMetrics::getTextWidth(const string &str) { } } -float FontMetrics::getHeight() const { +float FontMetrics::getHeight(const string &str) const { if(textHandler != NULL) { //printf("(textHandler->LineHeight(" ") = %f Font::scaleFontValue = %f\n",textHandler->LineHeight(" "),Font::scaleFontValue); - return (textHandler->LineHeight(" ") * Font::scaleFontValue); + //return (textHandler->LineHeight(str.c_str()) * Font::scaleFontValue); + return (textHandler->LineHeight(str.c_str())); } else { return height; diff --git a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp index 0edd6babd..86d77a218 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -88,7 +88,7 @@ void TextRenderer2DGl::render(const string &text, float x, float y, bool centere metrics= font->getMetrics(); if(centered) { rasterPos.x= x-metrics->getTextWidth(renderText)/2.f; - rasterPos.y= y+metrics->getHeight()/2.f; + rasterPos.y= y + metrics->getHeight(renderText)/2.f; } else { rasterPos= Vec2f(static_cast(x), static_cast(y)); @@ -328,7 +328,7 @@ void TextRenderer2DGl::render(const string &text, float x, float y, bool centere break; case '\n': line++; - rasterPos= Vec2f(static_cast(x), y-(metrics->getHeight()*2.f)*line); + rasterPos= Vec2f(static_cast(x), y-(metrics->getHeight("W")*2.f)*line); glRasterPos2f(rasterPos.x, rasterPos.y); break; default: @@ -511,7 +511,7 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo if(centered) { //glTranslatef(x-scale*metrics->getTextWidth(text)/2.f, y-scale*metrics->getHeight()/2.f, 0); translatePos.x = x-scale*metrics->getTextWidth(renderText)/2.f; - translatePos.y = y-scale*metrics->getHeight()/2.f; + translatePos.y = y-scale*metrics->getHeight(renderText)/2.f; translatePos.z = 0; } else {