]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD_instrument.cxx
Merge branch 'maint2' into next
[flightgear.git] / src / Instrumentation / HUD / HUD_instrument.cxx
index 9f3628b053a70da5a66c5e10587fc354eccedc27..a6769c60945f0b97408c8964a9f6ff91a9206912 100644 (file)
@@ -24,7 +24,6 @@
 #endif
 
 #include <simgear/math/SGLimits.hxx>
-#include <simgear/props/condition.hxx>
 #include "HUD.hxx"
 
 
@@ -39,20 +38,18 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
     if (node)
         _condition = sgReadCondition(globals->get_props(), node);
 
-    _scrn_pos.left = n->getIntValue("x") + x;
-    _scrn_pos.top = n->getIntValue("y") + y;
-    _scrn_pos.right = n->getIntValue("width");
-    _scrn_pos.bottom = n->getIntValue("height");
+    _x = n->getFloatValue("x") + x;
+    _y = n->getFloatValue("y") + y;
+    _w = n->getFloatValue("width");
+    _h = n->getFloatValue("height");
 
     vector<SGPropertyNode_ptr> opt = n->getChildren("option");
     for (unsigned int i = 0; i < opt.size(); i++) {
         const char *o = opt[i]->getStringValue();
-        if (!strcmp(o, "autoticks"))
-            _options |= AUTOTICKS;
-        else if (!strcmp(o, "vertical"))
-            _options |= VERT;
+        if (!strcmp(o, "vertical"))
+            _options |= VERTICAL;
         else if (!strcmp(o, "horizontal"))
-            _options |= HORZ;
+            _options |= HORIZONTAL;
         else if (!strcmp(o, "top"))
             _options |= TOP;
         else if (!strcmp(o, "left"))
@@ -65,10 +62,6 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
             _options |= (LEFT|RIGHT);
         else if (!strcmp(o, "noticks"))
             _options |= NOTICKS;
-        else if (!strcmp(o, "arithtic"))
-            _options |= ARITHTIC;
-        else if (!strcmp(o, "decitics"))
-            _options |= DECITICS;
         else if (!strcmp(o, "notext"))
             _options |= NOTEXT;
         else
@@ -78,14 +71,14 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
     // Set up convenience values for centroid of the box and
     // the span values according to orientation
 
-    if (_options & VERT) {
-        _scr_span = _scrn_pos.bottom;
+    if (_options & VERTICAL) {
+        _scr_span = _h;
     } else {
-        _scr_span = _scrn_pos.right;
+        _scr_span = _w;
     }
 
-    _mid_span.x = _scrn_pos.left + _scrn_pos.right / 2.0;
-    _mid_span.y = _scrn_pos.top + _scrn_pos.bottom / 2.0;
+    _center_x = _x + _w / 2.0;
+    _center_y = _y + _h / 2.0;
 }
 
 
@@ -95,31 +88,32 @@ bool HUD::Item::isEnabled()
 }
 
 
-void HUD::Item::draw_line( float x1, float y1, float x2, float y2)
+void HUD::Item::draw_line(float x1, float y1, float x2, float y2)
 {
     _hud->_line_list.add(LineSegment(x1, y1, x2, y2));
 }
 
 
-void HUD::Item::draw_stipple_line( float x1, float y1, float x2, float y2)
+void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
 {
     _hud->_stipple_line_list.add(LineSegment(x1, y1, x2, y2));
 }
 
 
-void HUD::Item::draw_text( float x, float y, char *msg, int digit)
+void HUD::Item::draw_text(float x, float y, const char *msg, int align, int digit)
 {
-    _hud->_text_list.add(HUDText(x, y, msg, digit));
+    _hud->_text_list.add(x, y, msg, align, digit);
 }
 
 
-void HUD::Item::draw_circle(float x1, float y1, float r) const
+void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
 {
     glBegin(GL_LINE_LOOP);
-    for (int count = 0; count < 25; count++) {
-        float cosine = r * cos(count * 2 * SG_PI / 10.0);
-        float sine =   r * sin(count * 2 * SG_PI / 10.0);
-        glVertex2f(cosine + x1, sine + y1);
+    float step = SG_PI / r;
+    for (float alpha = 0; alpha < SG_PI * 2.0; alpha += step) {
+        float x = r * cos(alpha);
+        float y = r * sin(alpha);
+        glVertex2f(x + xoffs, y + yoffs);
     }
     glEnd();
 }
@@ -139,12 +133,55 @@ void HUD::Item::draw_bullet(float x, float y, float size)
 }
 
 
-float HUD::Item::text_width(char *str) const
+// make sure the format matches '[ -+#]?\d*(\.\d*)?(l?[df]|s)'
+//
+HUD::Item::Format HUD::Item::check_format(const char *f) const
 {
-    assert(_hud->_font_renderer);
-    float r, l;
-    _hud->_font->getBBox(str, _hud->_font_size, 0, &l, &r, 0, 0);
-    return r - l;
+    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;
 }