From 1b72bcafe84e05a7e5476c3ae8f4ada2beebc1e8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 1 Jul 2011 01:18:47 +0000 Subject: [PATCH] - i think this fixes the y centering for all resolutions, after testing we can remove lots of unused properties and code --- source/glest_game/global/metrics.cpp | 3 +++ source/glest_game/graphics/renderer.cpp | 6 ++++-- source/shared_lib/include/graphics/font.h | 1 + source/shared_lib/include/graphics/gl/font_textFTGL.h | 2 ++ source/shared_lib/sources/graphics/font.cpp | 2 ++ .../shared_lib/sources/graphics/gl/font_textFTGL.cpp | 10 ++++++---- 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/glest_game/global/metrics.cpp b/source/glest_game/global/metrics.cpp index 39b103f3..2384d9f3 100644 --- a/source/glest_game/global/metrics.cpp +++ b/source/glest_game/global/metrics.cpp @@ -67,6 +67,9 @@ int Metrics::toVirtualY(int h) const{ if(screenH == 0) { throw runtime_error("div by 0 screenH == 0"); } + + //printf("h [%d] virtualH [%d] screenH [%d] result = %d\n",h,virtualH,screenH,(h*virtualH/screenH)); + return h*virtualH/screenH; } diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 6308929a..7dc4f342 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1446,9 +1446,11 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i } const Metrics &metrics= Metrics::getInstance(); float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue); - lineHeight=metrics.toVirtualY(lineHeight); + //lineHeight=metrics.toVirtualY(lineHeight); //lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR); - pos.y += (h / 2.f) - (lineHeight / 2.f); + //pos.y += (h / 2.f) - (lineHeight / 2.f); + //pos.y += (h / 2.f) - (lineHeight); + pos.y += (lineHeight / 2.f); // y starts at the middle of the render position, so only move up 1/2 the font height return pos; } diff --git a/source/shared_lib/include/graphics/font.h b/source/shared_lib/include/graphics/font.h index 4fcb7c07..f532d2b4 100644 --- a/source/shared_lib/include/graphics/font.h +++ b/source/shared_lib/include/graphics/font.h @@ -67,6 +67,7 @@ public: static bool fontIsRightToLeft; static float scaleFontValue; static int baseSize; + static int faceResolution; //static int scaleFontYOffset; public: diff --git a/source/shared_lib/include/graphics/gl/font_textFTGL.h b/source/shared_lib/include/graphics/gl/font_textFTGL.h index f6d95fad..ed2b293d 100644 --- a/source/shared_lib/include/graphics/gl/font_textFTGL.h +++ b/source/shared_lib/include/graphics/gl/font_textFTGL.h @@ -28,6 +28,8 @@ class TextFTGL : public Text { public: + static int faceResolution; + TextFTGL(FontTextHandlerType type); virtual ~TextFTGL(); virtual void init(string fontName, int fontSize); diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 3d9ef9c0..38a4177c 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -40,6 +40,7 @@ float FontMetrics::DEFAULT_Y_OFFSET_FACTOR = 2.0f; bool Font::fontIsRightToLeft = false; float Font::scaleFontValue = 1.0; int Font::baseSize = 0; +int Font::faceResolution = 72; //int Font::scaleFontYOffset = 0; // @@ -129,6 +130,7 @@ Font::Font(FontTextHandlerType type) { try { textHandler = NULL; textHandler = new TextFTGL(type); + TextFTGL::faceResolution = faceResolution; metrics.setTextHandler(this->textHandler); } catch(exception &ex) { diff --git a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp index b232b9f7..01625a2e 100644 --- a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp +++ b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp @@ -32,6 +32,8 @@ using namespace Shared::PlatformCommon; namespace Shared { namespace Graphics { namespace Gl { +int TextFTGL::faceResolution = 72; + //==================================================================== TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) { @@ -77,7 +79,7 @@ TextFTGL::TextFTGL(FontTextHandlerType type) : Text(type) { free((void*)fontFile); fontFile = NULL; - ftFont->FaceSize(24); + ftFont->FaceSize(24,TextFTGL::faceResolution); if(ftFont->Error()) { throw runtime_error("FTGL: error setting face size"); } @@ -143,10 +145,10 @@ void TextFTGL::init(string fontName, int fontSize) { fontFile = NULL; if(fontSize > 0) { - ftFont->FaceSize(fontSize); + ftFont->FaceSize(fontSize,TextFTGL::faceResolution); } else { - ftFont->FaceSize(24); + ftFont->FaceSize(24,TextFTGL::faceResolution); } if(ftFont->Error()) { @@ -170,7 +172,7 @@ void TextFTGL::init(string fontName, int fontSize) { } void TextFTGL::SetFaceSize(int value) { - ftFont->FaceSize(value); + ftFont->FaceSize(value,TextFTGL::faceResolution); if(ftFont->Error()) { throw runtime_error("FTGL: error setting face size"); }