]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD_label.cxx
Quiet some log output.
[flightgear.git] / src / Instrumentation / HUD / HUD_label.cxx
index b8906640580100f62462d9fdf416d2bbeebaf551..5414cf02fdd05a307858087ecd187c8cda7a246d 100644 (file)
 #  include <config.h>
 #endif
 
-#include <simgear/props/condition.hxx>
 #include "HUD.hxx"
+#include "HUD_private.hxx"
 
+#include <Main/globals.hxx>
 
 HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) :
     Item(hud, n, x, y),
@@ -44,13 +45,13 @@ HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) :
 
     const char *halign = n->getStringValue("halign", "center");
     if (!strcmp(halign, "left"))
-        _halign = HUDText::LEFT;
+        _halign = LEFT;
     else if (!strcmp(halign, "right"))
-        _halign = HUDText::RIGHT;
+        _halign = RIGHT;
     else
-        _halign = HUDText::HCENTER;
+        _halign = HCENTER;
 
-    _halign |= HUDText::VCENTER;
+    _halign |= VCENTER;
 
     const char *pre = n->getStringValue("prefix", 0);
     const char *post = n->getStringValue("postfix", 0);
@@ -69,7 +70,8 @@ HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) :
 
     _mode = check_format(_format.c_str());
     if (_mode == INVALID) {
-        SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid format '" << _format.c_str() << '\'');
+        SG_LOG(SG_INPUT, SG_ALERT, "HUD: invalid format '" << _format.c_str()
+                << "' in <label> '" << _name << '\'');
         _format = "INVALID";
         _mode = NONE;
     }
@@ -80,7 +82,7 @@ HUD::Label::Label(HUD *hud, const SGPropertyNode *n, float x, float y) :
 
 void HUD::Label::draw(void)
 {
-    if (!(_mode == NONE || _input.isValid() && blink()))
+    if (!((_mode == NONE || _input.isValid()) && blink()))
         return;
 
     if (_box) {
@@ -89,7 +91,7 @@ void HUD::Label::draw(void)
 
         l = _center_x - pw;
         r = _center_x + pw;
-        bool draw_parallel = fabsf(_pointer_width - _w) > 2.0; // draw lines left and right of arrow?
+        bool draw_parallel = fabs(_pointer_width - _w) > 2.0; // draw lines left and right of arrow?
 
         if (option_bottom()) {
             if (draw_parallel) {
@@ -115,7 +117,7 @@ void HUD::Label::draw(void)
 
         l = _center_y - pw;
         r = _center_y + pw;
-        draw_parallel = fabsf(_pointer_width - _h) > 2.0;
+        draw_parallel = fabs(_pointer_width - _h) > 2.0;
 
         if (option_left()) {
             if (draw_parallel) {
@@ -141,9 +143,10 @@ void HUD::Label::draw(void)
     }
 
     const int BUFSIZE = 256;
-    char buf[BUFSIZE];
+    char buf[BUFSIZE+1];
+       buf[ BUFSIZE] = '\0';  // Be sure to terminate properly
     if (_mode == NONE)
-        snprintf(buf, BUFSIZE, _format.c_str());
+        snprintf(buf, BUFSIZE, _format.c_str(), 0);
     else if (_mode == STRING)
         snprintf(buf, BUFSIZE, _format.c_str(), _input.getStringValue());
     else if (_mode == INT)
@@ -155,67 +158,15 @@ void HUD::Label::draw(void)
     else if (_mode == DOUBLE) // not really supported yet
         snprintf(buf, BUFSIZE, _format.c_str(), double(_input.getFloatValue()));
 
-    if (_halign & HUDText::HCENTER)
+    if (_halign & HCENTER)
         draw_text(_center_x, _center_y, buf, _halign, get_digits());
-    else if (_halign & HUDText::LEFT)
+    else if (_halign & LEFT)
         draw_text(_x, _center_y, buf, _halign, get_digits());
-    else // if (_halign & HUDText::RIGHT)
+    else // if (_halign & RIGHT)
         draw_text(_x + _w, _center_y, buf, _halign, get_digits());
 }
 
 
-// make sure the format matches '[ -+#]?\d*(\.\d*)?(l?[df]|s)'
-//
-HUD::Label::Format HUD::Label::check_format(const char *f) const
-{
-    bool l = false;
-    Format fmt = STRING;
-
-    for (; *f; f++) {
-        if (*f == '%') {
-            if (f[1] == '%')
-                f++;
-            else
-                break;
-        }
-    }
-    if (*f++ != '%')
-        return NONE;
-    if (*f == ' ' || *f == '+' || *f == '-' || *f == '#')
-        f++;
-    while (*f && isdigit(*f))
-        f++;
-    if (*f == '.') {
-        f++;
-        while (*f && isdigit(*f))
-            f++;
-    }
-    if (*f == 'l')
-        l = true, f++;
-
-    if (*f == 'd')
-        fmt = l ? LONG : INT;
-    else if (*f == 'f')
-        fmt = l ? DOUBLE : FLOAT;
-    else if (*f == 's') {
-        if (l)
-            return INVALID;
-        fmt = STRING;
-    } else
-        return INVALID;
-
-    for (++f; *f; f++) {
-        if (*f == '%') {
-            if (f[1] == '%')
-                f++;
-            else
-                return INVALID;
-        }
-    }
-    return fmt;
-}
-
-
 bool HUD::Label::blink()
 {
     if (_blink_interval < 0.0f)