From bd9ec88355d20ee0f92d1ec2da708a5945ad193f Mon Sep 17 00:00:00 2001 From: mfranz Date: Mon, 24 Jul 2006 16:00:18 +0000 Subject: [PATCH] - don't use 10 pt font size for width calculations, when in fact we use a 8 pt font (set 8 pt in preferences.xml, too) - fix vertical alignment of digits in label and ladder (temporary solution -- the whole font handling needs to be reviewd and fixed) - simplify nadir and zenith (they always want to be horizontally centered on the ladder lines, no?) - simplify and abstract label box drawing (no need for stippled side lines) - align text (more) correctly in label boxes --- src/Instrumentation/HUD/HUD.cxx | 2 +- src/Instrumentation/HUD/HUD.hxx | 13 +-- src/Instrumentation/HUD/HUD_dial.cxx | 10 +- src/Instrumentation/HUD/HUD_instrument.cxx | 2 +- src/Instrumentation/HUD/HUD_label.cxx | 37 +++----- src/Instrumentation/HUD/HUD_ladder.cxx | 104 ++++++++++----------- src/Instrumentation/HUD/HUD_tape.cxx | 12 ++- 7 files changed, 82 insertions(+), 98 deletions(-) diff --git a/src/Instrumentation/HUD/HUD.cxx b/src/Instrumentation/HUD/HUD.cxx index 743e07488..a8128ff8f 100644 --- a/src/Instrumentation/HUD/HUD.cxx +++ b/src/Instrumentation/HUD/HUD.cxx @@ -129,7 +129,7 @@ void HUD::init() if (!_font) throw sg_throwable(string("/sim/hud/font/name is not a texture font")); - _font_size = fgGetFloat("/sim/hud/font/size", 10); + _font_size = fgGetFloat("/sim/hud/font/size", 8); _font_renderer->setFont(_font); _font_renderer->setPointSize(_font_size); _text_list.setFont(_font_renderer); diff --git a/src/Instrumentation/HUD/HUD.hxx b/src/Instrumentation/HUD/HUD.hxx index 61bc05d64..b43f1c5e1 100644 --- a/src/Instrumentation/HUD/HUD.hxx +++ b/src/Instrumentation/HUD/HUD.hxx @@ -100,13 +100,9 @@ public: // is shown as 10ooo. void draw(fntRenderer *fnt) { - float orig_size = fnt->getPointSize(); if (!_digits) { // show all digits in same size - fnt->setPointSize(orig_size * 0.8); fnt->start2f(_x, _y); fnt->puts(_msg); - - fnt->setPointSize(orig_size); return; } @@ -126,6 +122,8 @@ public: c++; i++; } + + float orig_size = fnt->getPointSize(); if (c > p) { fnt->setPointSize(orig_size * 0.8); int p1 = c - 3; @@ -440,6 +438,7 @@ private: int _fontsize; int _blink; bool _box; + float _text_y; SGCondition *_blink_condition; double _blink_interval; @@ -506,6 +505,8 @@ private: float _marker_offset; bool _pointer; int _zoom; + float _0_ht; + enum PointerType { FIXED, MOVING } _pointer_type; enum TickType { LINE, CIRCLE } _tick_type; enum TickLength { VARIABLE, CONSTANT } _tick_length; @@ -547,8 +548,8 @@ public: virtual void draw(); private: - void draw_zenith(float, float, float); - void draw_nadir(float, float, float); + void draw_zenith(float, float); + void draw_nadir(float, float); void draw_text(float x, float y, char *s) { _locTextList.add(HUDText(x, y, s)); diff --git a/src/Instrumentation/HUD/HUD_dial.cxx b/src/Instrumentation/HUD/HUD_dial.cxx index af917eeff..d641dca9b 100644 --- a/src/Instrumentation/HUD/HUD_dial.cxx +++ b/src/Instrumentation/HUD/HUD_dial.cxx @@ -56,16 +56,16 @@ void HUD::Dial::draw(void) float offset = 90.0 * SGD_DEGREES_TO_RADIANS; - float r1 = 10.0; //size of carrot + const float R = 10.0; //size of carrot float theta = _input.getFloatValue(); float theta1 = -theta * SGD_DEGREES_TO_RADIANS + offset; float x1 = _x + _radius * cos(theta1); float y1 = _y + _radius * sin(theta1); - float x2 = x1 - r1 * cos(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS); - float y2 = y1 - r1 * sin(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS); - float x3 = x1 - r1 * cos(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS); - float y3 = y1 - r1 * sin(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS); + float x2 = x1 - R * cos(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS); + float y2 = y1 - R * sin(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS); + float x3 = x1 - R * cos(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS); + float y3 = y1 - R * sin(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS); // draw carrot draw_line(x1, y1, x2, y2); diff --git a/src/Instrumentation/HUD/HUD_instrument.cxx b/src/Instrumentation/HUD/HUD_instrument.cxx index d7d1f7747..7f3b9ce0d 100644 --- a/src/Instrumentation/HUD/HUD_instrument.cxx +++ b/src/Instrumentation/HUD/HUD_instrument.cxx @@ -145,7 +145,7 @@ float HUD::Item::text_width(char *str) const assert(_hud->_font_renderer); float r, l; _hud->_font->getBBox(str, _hud->_font_size, 0, &l, &r, 0, 0); - return r + l; + return r - l; } diff --git a/src/Instrumentation/HUD/HUD_label.cxx b/src/Instrumentation/HUD/HUD_label.cxx index 5a2d215af..6a00c05da 100644 --- a/src/Instrumentation/HUD/HUD_label.cxx +++ b/src/Instrumentation/HUD/HUD_label.cxx @@ -55,10 +55,12 @@ HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) : if (pre) _format = pre; + if (fmt) _format += fmt; else _format += "%s"; + if (post) _format += post; @@ -69,6 +71,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; blink(); } @@ -79,30 +84,10 @@ void HUD::Label::draw(void) return; if (_box) { - float h = _hud->_font_size; // FIXME - - glPushMatrix(); - glLoadIdentity(); - - glBegin(GL_LINES); - glVertex2f(_x - 2.0, _y - 2.0); - glVertex2f(_x + _w + 2.0, _y - 2.0); - glVertex2f(_x + _w + 2.0, _y + h + 2.0); - glVertex2f(_x - 2.0, _y + h + 2.0); - glEnd(); - - glEnable(GL_LINE_STIPPLE); - glLineStipple(1, 0xAAAA); - - glBegin(GL_LINES); - glVertex2f(_x + _w + 2.0, _y - 2.0); - glVertex2f(_x + _w + 2.0, _y + h + 2.0); - glVertex2f(_x - 2.0, _y + h + 2.0); - glVertex2f(_x - 2.0, _y - 2.0); - glEnd(); - - glDisable(GL_LINE_STIPPLE); - glPopMatrix(); + draw_line(_x, _y, _x + _w, _y); + draw_line(_x + _w, _y, _x + _w, _y + _h); + draw_line(_x + _w, _y + _h, _x, _y + _h); + draw_line(_x, _y + _h, _x, _y); } const int BUFSIZE = 256; @@ -131,9 +116,9 @@ void HUD::Label::draw(void) posincr = 0; if (_fontsize == FONT_SMALL) - draw_text(_x + posincr, _y, buf, get_digits()); + draw_text(_x + posincr, _text_y, buf, get_digits()); else if (_fontsize == FONT_LARGE) - draw_text(_x + posincr, _y, buf, get_digits()); + draw_text(_x + posincr, _text_y, buf, get_digits()); } diff --git a/src/Instrumentation/HUD/HUD_ladder.cxx b/src/Instrumentation/HUD/HUD_ladder.cxx index 847770a05..9a763d868 100644 --- a/src/Instrumentation/HUD/HUD_ladder.cxx +++ b/src/Instrumentation/HUD/HUD_ladder.cxx @@ -479,13 +479,13 @@ void HUD::Ladder::draw(void) draw_line(x_ini, y, x_end, y); if (i == 90 && _zenith) - draw_zenith(x_ini, x_end, y); + draw_zenith(0.0, y); } else { // Below zero draw dashed lines. draw_stipple_line(x_ini, y, x_end, y); if (i == -90 && _nadir) - draw_nadir(x_ini, x_end, y); + draw_nadir(0.0, y); } // Calculate the position of the left text and write it. @@ -536,7 +536,7 @@ void HUD::Ladder::draw(void) draw_line(x_ini2, y, x_end2, y); if (i == 90 && _zenith) - draw_zenith(x_ini2, x_end, y); + draw_zenith(0.0, y); } else { // i < 0 // draw dive bar vertical lines @@ -550,7 +550,7 @@ void HUD::Ladder::draw(void) draw_stipple_line(x_ini2, y, x_end2, y); if (i == -90 && _nadir) - draw_nadir(x_ini2, x_end, y); + draw_nadir(0.0, y); } // Now calculate the location of the left side label using @@ -649,13 +649,14 @@ void HUD::Ladder::draw(void) if (fabs(brg - psi) < 12.0) { if (!_hat) { glBegin(GL_LINE_LOOP); - glVertex2f(((brg - psi) * 60 / 25) + 320, 240.0); - glVertex2f(((brg - psi) * 60 / 25) + 326, 240.0 - 4); - glVertex2f(((brg - psi) * 60 / 25) + 323, 240.0 - 4); - glVertex2f(((brg - psi) * 60 / 25) + 323, 240.0 - 8); - glVertex2f(((brg - psi) * 60 / 25) + 317, 240.0 - 8); - glVertex2f(((brg - psi) * 60 / 25) + 317, 240.0 - 4); - glVertex2f(((brg - psi) * 60 / 25) + 314, 240.0 - 4); + GLfloat x = (brg - psi) * 60 / 25; + glVertex2f(x + 320, 240.0); + glVertex2f(x + 326, 240.0 - 4); + glVertex2f(x + 323, 240.0 - 4); + glVertex2f(x + 323, 240.0 - 8); + glVertex2f(x + 317, 240.0 - 8); + glVertex2f(x + 317, 240.0 - 4); + glVertex2f(x + 314, 240.0 - 4); glEnd(); } else { // if (_hat) @@ -684,77 +685,72 @@ void HUD::Ladder::draw(void) /******************************************************************/ -// draws the zenith symbol for highest possible climb angle (i.e. 90 degree climb angle) +// draws the zenith symbol (highest possible climb angle i.e. 90 degree climb angle) // -void HUD::Ladder::draw_zenith(float xfirst, float xlast, float yvalue) +void HUD::Ladder::draw_zenith(float x, float y) { - float xcentre = (xfirst + xlast) / 2.0; - float ycentre = yvalue; + draw_line(x - 9.0, y, x - 3.0, y + 1.3); + draw_line(x - 9.0, y, x - 3.0, y - 1.3); - draw_line(xcentre - 9.0, ycentre, xcentre - 3.0, ycentre + 1.3); - draw_line(xcentre - 9.0, ycentre, xcentre - 3.0, ycentre - 1.3); + draw_line(x + 9.0, y, x + 3.0, y + 1.3); + draw_line(x + 9.0, y, x + 3.0, y - 1.3); - draw_line(xcentre + 9.0, ycentre, xcentre + 3.0, ycentre + 1.3); - draw_line(xcentre + 9.0, ycentre, xcentre + 3.0, ycentre - 1.3); + draw_line(x, y + 9.0, x - 1.3, y + 3.0); + draw_line(x, y + 9.0, x + 1.3, y + 3.0); - draw_line(xcentre, ycentre + 9.0, xcentre - 1.3, ycentre + 3.0); - draw_line(xcentre, ycentre + 9.0, xcentre + 1.3, ycentre + 3.0); + draw_line(x - 3.9, y + 3.9, x - 3.0, y + 1.3); + draw_line(x - 3.9, y + 3.9, x - 1.3, y + 3.0); - draw_line(xcentre - 3.9, ycentre + 3.9, xcentre - 3.0, ycentre + 1.3); - draw_line(xcentre - 3.9, ycentre + 3.9, xcentre - 1.3, ycentre + 3.0); + draw_line(x + 3.9, y + 3.9, x + 1.3, y + 3.0); + draw_line(x + 3.9, y + 3.9, x + 3.0, y + 1.3); - draw_line(xcentre + 3.9, ycentre + 3.9, xcentre + 1.3, ycentre+3.0); - draw_line(xcentre + 3.9, ycentre + 3.9, xcentre + 3.0, ycentre+1.3); + draw_line(x - 3.9, y - 3.9, x - 3.0, y - 1.3); + draw_line(x - 3.9, y - 3.9, x - 1.3, y - 2.6); - draw_line(xcentre - 3.9, ycentre - 3.9, xcentre - 3.0, ycentre-1.3); - draw_line(xcentre - 3.9, ycentre - 3.9, xcentre - 1.3, ycentre-2.6); + draw_line(x + 3.9, y - 3.9, x + 3.0, y - 1.3); + draw_line(x + 3.9, y - 3.9, x + 1.3, y - 2.6); - draw_line(xcentre + 3.9, ycentre - 3.9, xcentre + 3.0, ycentre-1.3); - draw_line(xcentre + 3.9, ycentre - 3.9, xcentre + 1.3, ycentre-2.6); - - draw_line(xcentre - 1.3, ycentre - 2.6, xcentre, ycentre - 27.0); - draw_line(xcentre + 1.3, ycentre - 2.6, xcentre, ycentre - 27.0); + draw_line(x - 1.3, y - 2.6, x, y - 27.0); + draw_line(x + 1.3, y - 2.6, x, y - 27.0); } // draws the nadir symbol (lowest possible dive angle i.e. 90 degree dive angle)) // -void HUD::Ladder::draw_nadir(float xfirst, float xlast, float yvalue) +void HUD::Ladder::draw_nadir(float x, float y) { - float xcentre = (xfirst + xlast) / 2.0; - float ycentre = yvalue; const float R = 7.5; - draw_circle(xcentre, ycentre, R); - draw_line(xcentre, ycentre + R, xcentre, ycentre + 22.5); // line above the circle - draw_line(xcentre - R, ycentre, xcentre + R, ycentre); // line at middle of circle + draw_circle(x, y, R); + draw_line(x, y + R, x, y + 22.5); // line above the circle + draw_line(x - R, y, x + R, y); // line at middle of circle float theta = asin(2.5 / R); float theta1 = asin(5.0 / R); float x1, y1, x2, y2; - x1 = xcentre + R * cos(theta); - y1 = ycentre + 2.5; - x2 = xcentre + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta); - y2 = ycentre + 2.5; + x1 = x + R * cos(theta); + y1 = y + 2.5; + x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta); + y2 = y + 2.5; draw_line(x1, y1, x2, y2); - x1 = xcentre + R * cos(theta1); - y1 = ycentre + 5.0; - x2 = xcentre + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1); - y2 = ycentre + 5.0; + x1 = x + R * cos(theta1); + y1 = y + 5.0; + x2 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) - theta1); + y2 = y + 5.0; draw_line(x1, y1, x2, y2); - x1 = xcentre + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta); - y1 = ycentre - 2.5; - x2 = xcentre + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta); - y2 = ycentre - 2.5; + x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta); + y1 = y - 2.5; + x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta); + y2 = y - 2.5; draw_line(x1, y1, x2, y2); - x1 = xcentre + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1); - y1 = ycentre - 5.0; - x2 = xcentre + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1); - y2 = ycentre - 5.0; + x1 = x + R * cos((180.0 * SGD_DEGREES_TO_RADIANS) + theta1); + y1 = y - 5.0; + x2 = x + R * cos((360.0 * SGD_DEGREES_TO_RADIANS) - theta1); + y2 = y - 5.0; draw_line(x1, y1, x2, y2); } diff --git a/src/Instrumentation/HUD/HUD_tape.cxx b/src/Instrumentation/HUD/HUD_tape.cxx index 8decc7bcc..6d6b089a3 100644 --- a/src/Instrumentation/HUD/HUD_tape.cxx +++ b/src/Instrumentation/HUD/HUD_tape.cxx @@ -47,6 +47,10 @@ HUD::Tape::Tape(HUD *hud, const SGPropertyNode *n, float x, float y) : s = n->getStringValue("tick-length"); // "variable", "constant" _tick_length = strcmp(s, "constant") ? VARIABLE : CONSTANT; + + float top; + _hud->_font->getBBox("0", _hud->_font_size, 0.0, 0, 0, 0, &top); + _0_ht = top / 2.0; // half 0 height } @@ -334,7 +338,6 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale) snprintf(buf, BUFSIZE, "%d", display_value); float strwd = text_width(buf); - float strht = _hud->_font_size; if (option_both()) { // draw_line(_x, y, marker_xs, y); @@ -351,7 +354,7 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale) } if (!option_notext()) - draw_text(marker_xs + 2, y, buf, 0); + draw_text(marker_xs + 2, y - _0_ht, buf, 0); } else { if (_tick_type == LINE) @@ -361,9 +364,9 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale) if (!option_notext()) { if (option_left()) - draw_text(marker_xs - strwd, y - 4, buf, 0); + draw_text(marker_xs - strwd, y - _0_ht, buf, 0); else - draw_text(marker_xe + strwd / 2, y - 4, buf, 0); + draw_text(marker_xe + strwd / 2, y - _0_ht, buf, 0); } } // End if huds-both } @@ -531,7 +534,6 @@ void HUD::Tape::draw(void) // (HUD_scale * pscale) snprintf(buf, BUFSIZE, "%d", display_value); float strwd = text_width(buf); - float strht = _hud->_font_size; // Draw major ticks and text only if far enough from the edge. // FIXME if (x < _x + 10 || x + 10 > _x + _w)