From 9799f05bb7aa7a1bcaa3654489c3387405022acb Mon Sep 17 00:00:00 2001 From: mfranz Date: Tue, 25 Jul 2006 20:05:52 +0000 Subject: [PATCH] finally fix the text-in-box alignment (= Rocket Science[TM]!) (This will be moved to HUD_instrument.cxx, where it will be available to all draw_text() users.) --- src/Instrumentation/HUD/HUD_label.cxx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Instrumentation/HUD/HUD_label.cxx b/src/Instrumentation/HUD/HUD_label.cxx index bed53a63e..17fc2798d 100644 --- a/src/Instrumentation/HUD/HUD_label.cxx +++ b/src/Instrumentation/HUD/HUD_label.cxx @@ -73,9 +73,9 @@ HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) : _mode = NONE; } - float top; - _hud->_font->getBBox("0", _hud->_font_size, 0.0, 0, 0, 0, &top); - _text_y = _y + (_h - top) / 2.0; + float top, bot; + _hud->_font->getBBox("0", _hud->_font_size, 0.0, 0, 0, &bot, &top); + _text_y = _y + (_h - top + bot) / 2.0 - bot; blink(); } @@ -158,7 +158,9 @@ void HUD::Label::draw(void) snprintf(buf, BUFSIZE, _format.c_str(), double(_input.getFloatValue())); float posincr; - float lenstr = text_width(buf); + float L, R, B, T; + _hud->_font->getBBox(buf, _hud->_font_size, 0.0, &L, &R, &B, &T); + float lenstr = R - L; if (_halign == RIGHT_ALIGN) posincr = _w - lenstr; @@ -167,6 +169,8 @@ void HUD::Label::draw(void) else // LEFT_ALIGN posincr = 0; + posincr += _hud->_font->getGap() / 2.0 - L; + if (_fontsize == FONT_SMALL) draw_text(_x + posincr, _text_y, buf, get_digits()); else if (_fontsize == FONT_LARGE) -- 2.39.5