]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD_instrument.cxx
httpd: better handling of first-time notifications
[flightgear.git] / src / Instrumentation / HUD / HUD_instrument.cxx
index d98db887649dabd120fb8daf19c80aacb7bf855d..69fb3309cbf817b97ddd8b8e5d6a3a33f65fe994 100644 (file)
 
 #include <simgear/math/SGLimits.hxx>
 #include <simgear/props/condition.hxx>
+
 #include "HUD.hxx"
+#include "HUD_private.hxx"
+
+#include <Main/globals.hxx>
 
+using std::vector;
 
 HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
     _hud(hud),
@@ -39,10 +44,10 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
     if (node)
         _condition = sgReadCondition(globals->get_props(), node);
 
-    _x = n->getIntValue("x") + x;
-    _y = n->getIntValue("y") + y;
-    _w = n->getIntValue("width");
-    _h = 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++) {
@@ -101,7 +106,7 @@ void HUD::Item::draw_stipple_line(float x1, float y1, float x2, float y2)
 }
 
 
-void HUD::Item::draw_text(float x, float y, char *msg, int align, int digit)
+void HUD::Item::draw_text(float x, float y, const char *msg, int align, int digit)
 {
     _hud->_text_list.add(x, y, msg, align, digit);
 }
@@ -119,6 +124,20 @@ void HUD::Item::draw_circle(float xoffs, float yoffs, float r) const
     glEnd();
 }
 
+void HUD::Item::draw_arc(float xoffs, float yoffs, float t0, float t1, float r) const
+{
+    glBegin(GL_LINE_STRIP);
+    float step = SG_PI / r;
+    t0 = t0 * SG_DEGREES_TO_RADIANS;
+    t1 = t1 * SG_DEGREES_TO_RADIANS;
+
+    for (float alpha = t0; alpha < t1; alpha += step) {
+        float x = r * cos(alpha);
+        float y = r * sin(alpha);
+        glVertex2f(x + xoffs, y + yoffs);
+    }
+    glEnd();
+}
 
 void HUD::Item::draw_bullet(float x, float y, float size)
 {
@@ -134,12 +153,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;
 }