]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/HUD/HUD.hxx
better use unset() for unsetting ...
[flightgear.git] / src / Instrumentation / HUD / HUD.hxx
index 8456fd98502021ab569589b5a35964dc632aa601..ba0b4d4b1f04f72c665167b7c03912fda96a1842 100644 (file)
@@ -23,6 +23,7 @@
 #define _HUD_HXX
 
 #include <simgear/compiler.h>
+#include <simgear/props/condition.hxx>
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 
 #include <vector>
 #include <deque>
-#include STL_FSTREAM
+#include <fstream>
 
-SG_USING_STD(deque);
-SG_USING_STD(vector);
-SG_USING_NAMESPACE(std);
+using std::deque;
+using std::vector;
+
+#include <osg/State>
 
 #include <plib/sg.h>
 
@@ -50,7 +52,26 @@ SG_USING_NAMESPACE(std);
 
 
 class FGViewer;
-class SGCondition;
+
+
+class ClipBox {
+public:
+    ClipBox(const SGPropertyNode *, float xoffset = 0, float yoffset = 0);
+    void set();
+    void unset();
+
+private:
+    bool _active;
+    float _xoffs, _yoffs;
+    SGConstPropertyNode_ptr _top_node;
+    SGConstPropertyNode_ptr _bot_node;
+    SGConstPropertyNode_ptr _left_node;
+    SGConstPropertyNode_ptr _right_node;
+    GLdouble _top[4];
+    GLdouble _bot[4];
+    GLdouble _left[4];
+    GLdouble _right[4];
+};
 
 
 
@@ -91,64 +112,11 @@ private:
 
 class HUDText {
 public:
-    HUDText(float x, float y, char *s, int d = 0) : _x(x), _y(y), _digits(d) {
-        strncpy(_msg, s, BUFSIZE);
-    }
-
-    // this code is changed to display Numbers with big/small digits
-    // according to MIL Standards for example Altitude above 10000 ft
-    // is shown as 10ooo.
-
-    void draw(fntRenderer *fnt) {
-        if (!_digits) { // show all digits in same size
-            fnt->start2f(_x, _y);
-            fnt->puts(_msg);
-            return;
-        }
-
-        int c = 0, i = 0;
-        char *t = _msg;
-        int p = 4;
-
-        if (t[0] == '-') {
-            //if negative value then increase the c and p values
-            //for '-' sign.
-            c++; // was moved to the comment. Unintentionally?   TODO
-            p++;
-        }
-        char *tmp = _msg;
-        while (tmp[i] != '\0') {
-            if ((tmp[i] >= '0') && (tmp[i] <= '9'))
-                c++;
-            i++;
-        }
-
-        float orig_size = fnt->getPointSize();
-        if (c > p) {
-            fnt->setPointSize(orig_size * 0.8);
-            int p1 = c - 3;
-            char *tmp1 = _msg + p1;
-            int p2 = p1 * 8;
-
-            fnt->start2f(_x + p2, _y);
-            fnt->puts(tmp1);
-
-            fnt->setPointSize(orig_size * 1.2);
-            char tmp2[BUFSIZE];
-            strncpy(tmp2, _msg, p1);
-            tmp2[p1] = '\0';
-
-            fnt->start2f(_x, _y);
-            fnt->puts(tmp2);
-        } else {
-            fnt->setPointSize(orig_size * 1.2);
-            fnt->start2f(_x, _y);
-            fnt->puts(tmp);
-        }
-        fnt->setPointSize(orig_size);
-    }
+    HUDText(fntRenderer *f, float x, float y, const char *s, int align = 0, int digits = 0);
+    void draw();
 
 private:
+    fntRenderer *_fnt;
     float _x, _y;
     int _digits;
     static const int BUFSIZE = 64;
@@ -162,24 +130,13 @@ public:
     TextList() { _font = 0; }
 
     void setFont(fntRenderer *Renderer) { _font = Renderer; }
-    void add(const HUDText& String) { _list.push_back(String); }
-    void erase() { _list.erase(_list.begin(), _list.end()); }
-    void draw() {
-        assert(_font);
-
-        // FIXME
-        glPushAttrib(GL_COLOR_BUFFER_BIT);
-        glEnable(GL_BLEND);
-
-        _font->begin();
-        vector<HUDText>::iterator it, end = _list.end();
-        for (it = _list.begin(); it != end; ++it)
-            it->draw(_font);
-        _font->end();
-
-        glDisable(GL_TEXTURE_2D);
-        glPopAttrib();
+    void add(float x, float y, const char *s, int align = 0, int digit = 0) {
+        _list.push_back(HUDText(_font, x, y, s, align, digit));
     }
+    void erase() { _list.erase(_list.begin(), _list.end()); }
+    void align(const char *s, int align, float *x, float *y,
+            float *l, float *r, float *b, float *t) const;
+    void draw();
 
 private:
     fntRenderer *_font;
@@ -199,7 +156,7 @@ public:
     void update(double);
 
     // called from Main/renderer.cxx to draw 2D and 3D HUD
-    void draw();
+    void draw(osg::State&);
 
     // listener callback to read various HUD related properties
     void valueChanged(SGPropertyNode *);
@@ -211,35 +168,33 @@ public:
     inline bool is3D() const { return _3Denabled; }
     inline float alphaClamp() const { return _cl; }
     inline double timer() const { return _timer; }
+    static void textAlign(fntRenderer *rend, const char *s, int align, float *x, float *y,
+            float *l, float *r, float *b, float *t);
 
     enum Units { FEET, METER };
     Units getUnits() const { return _units; }
 
     enum {
-        HORZ      = 0x0000,  // keep that at zero?
-        AUTOTICKS = 0x0001,
-        VERT      = 0x0002,
-        TOP       = 0x0004,
-        BOTTOM    = 0x0008,
-        LEFT      = 0x0010,
-        RIGHT     = 0x0020,
-        BOTH      = (LEFT|RIGHT),
-        NOTICKS   = 0x0040,
-        ARITHTIC  = 0x0080,
-        DECITICS  = 0x0100,
-        NOTEXT    = 0x0200,
-    };
-
-    enum Adjust {
-        LEFT_ALIGN,
-        CENTER_ALIGN,
-        RIGHT_ALIGN
+        HORIZONTAL = 0x0000,  // keep that at zero?
+        VERTICAL   = 0x0001,
+        TOP        = 0x0002,
+        BOTTOM     = 0x0004,
+        LEFT       = 0x0008,
+        RIGHT      = 0x0010,
+        NOTICKS    = 0x0020,
+        NOTEXT     = 0x0040,
+        BOTH       = (LEFT|RIGHT),
+
+        // for alignment (with LEFT, RIGHT, TOP, BOTTOM)
+        HCENTER    = 0x0080,
+        VCENTER    = 0x0100,
+        CENTER     = (HCENTER|VCENTER),
     };
 
 protected:
     void common_draw();
     int load(const char *, float x = 320.0f, float y = 240.0f,
-            int level = 0, const string& indent = "");
+            int level = 0, const std::string& indent = "");
 
 private:
     void draw3D();
@@ -258,6 +213,7 @@ private:
     class AimingReticle;
 
     deque<Item *> _items;
+    deque<Item *> _ladders;
 
     SGPropertyNode_ptr _current;
     SGPropertyNode_ptr _visibility;
@@ -285,6 +241,7 @@ private:
     float _font_size;
     int _style;
 
+    ClipBox *_clip_box;
     TextList _text_list;
     LineList _line_list;
     LineList _stipple_line_list;
@@ -373,10 +330,21 @@ public:
     virtual bool isEnabled();
 
 protected:
+    enum Format {
+        INVALID,
+        NONE,
+        INT,
+        LONG,
+        FLOAT,
+        DOUBLE,
+        STRING,
+    };
+
+    Format  check_format(const char *) const;
     inline float get_span()       const { return _scr_span; }
     inline int   get_digits()     const { return _digits; }
 
-    inline bool option_vert()    const { return (_options & VERT) == VERT; }
+    inline bool option_vert()    const { return (_options & VERTICAL) == VERTICAL; }
     inline bool option_left()    const { return (_options & LEFT) == LEFT; }
     inline bool option_right()   const { return (_options & RIGHT) == RIGHT; }
     inline bool option_both()    const { return (_options & BOTH) == BOTH; }
@@ -385,21 +353,20 @@ protected:
     inline bool option_top()     const { return (_options & TOP) == TOP; }
     inline bool option_bottom()  const { return (_options & BOTTOM) == BOTTOM; }
 
-    void draw_line( float x1, float y1, float x2, float y2);
-    void draw_stipple_line( float x1, float y1, float x2, float y2);
-    void draw_text( float x, float y, char *msg, int digit);
-    float text_width(char *str) const;
+    void draw_line(float x1, float y1, float x2, float y2);
+    void draw_stipple_line(float x1, float y1, float x2, float y2);
+    void draw_text(float x, float y, const char *msg, int align = 0, int digit = 0);
     void draw_circle(float x1, float y1, float r) const;
     void draw_bullet(float, float, float);
 
     HUD         *_hud;
-    string      _name;
+    std::string      _name;
     int         _options;
     float       _x, _y, _w, _h;
     float       _center_x, _center_y;
 
 private:
-    SGCondition *_condition;
+    SGSharedPtr<SGCondition> _condition;
     float       _disp_factor;   // Multiply by to get numbers shown on scale.
     float       _scr_span;      // Working values for draw;
     int         _digits;
@@ -413,30 +380,19 @@ public:
     virtual void draw();
 
 private:
-    enum Format {
-        INVALID,
-        NONE,
-        INT,
-        LONG,
-        FLOAT,
-        DOUBLE,
-        STRING,
-    };
-
-    Format  check_format(const char *) const;
     bool    blink();
 
     Input   _input;
     Format  _mode;
-    string  _format;
-    Adjust  _halign;
+    std::string  _format;
+    int     _halign;    // HUDText alignment
     int     _blink;
     bool    _box;
     float   _text_y;
     float   _pointer_width;
     float   _pointer_length;
 
-    SGCondition *_blink_condition;
+    SGSharedPtr<SGCondition> _blink_condition;
     double  _blink_interval;
     double  _blink_target;  // time for next blink state change
     bool    _blink_state;
@@ -484,8 +440,10 @@ public:
     virtual void draw();
 
 protected:
-    void fixed(float, float, float, float, float, float);
-    void zoomed_scale(int, int);
+    void draw_vertical(float);
+    void draw_horizontal(float);
+    void draw_fixed_pointer(float, float, float, float, float, float);
+    char *format_value(float);
 
 private:
     float  _val_span;
@@ -499,9 +457,15 @@ private:
     bool   _draw_cap_right;
     bool   _draw_cap_left;
     float  _marker_offset;
+    float  _label_gap;
     bool   _pointer;
-    int    _zoom;
-    float  _0_ht;
+    Format _label_fmt;
+    std::string _format;
+    int    _div_ratio;          // _major_divs/_minor_divs
+    bool   _odd_type;           // whether to put numbers at 0/2/4 or 1/3/5
+
+    enum { BUFSIZE = 64 };
+    char   _buf[BUFSIZE];
 
     enum PointerType { FIXED, MOVING } _pointer_type;
     enum TickType { LINE, CIRCLE } _tick_type;
@@ -545,22 +509,22 @@ private:
 class HUD::Ladder : public Item {
 public:
     Ladder(HUD *parent, const SGPropertyNode *, float x, float y);
+    ~Ladder();
     virtual void draw();
 
 private:
     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));
+    void draw_text(float x, float y, const char *s, int align = 0) {
+        _locTextList.add(x, y, s, align, 0);
     }
 
-    void draw_line(float x1, float y1, float x2, float y2) {
-        _locLineList.add(LineSegment(x1, y1, x2, y2));
-    }
-
-    void draw_stipple_line(float x1, float y1, float x2, float y2) {
-        _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
+    void draw_line(float x1, float y1, float x2, float y2, bool stipple = false) {
+        if (stipple)
+            _locStippleLineList.add(LineSegment(x1, y1, x2, y2));
+        else
+            _locLineList.add(LineSegment(x1, y1, x2, y2));
     }
 
     enum   Type { PITCH, CLIMB_DIVE } _type;
@@ -568,12 +532,14 @@ private:
     Input  _roll;
     float  _width_units;
     int    _div_units;
-    unsigned int _scr_hole;
+    float  _scr_hole;
+    float  _zero_bar_overlength;
+    bool   _dive_bar_angle;
+    float  _tick_length;
     float  _vmax;
     float  _vmin;
     float  _compression;
     bool   _dynamic_origin;
-    bool   _clip_plane;
     bool   _frl;               // fuselage reference line
     bool   _target_spot;
     bool   _target_markers;
@@ -590,6 +556,7 @@ private:
     bool   _nadir;
     bool   _hat;
 
+    ClipBox *_clip_box;
     // The Ladder has its own temporary display lists
     TextList _locTextList;
     LineList _locLineList;
@@ -641,12 +608,11 @@ public:
     virtual void draw();
 
 private:
-    SGCondition *_active_condition;  // stadiametric (true) or standby (false)
+    SGSharedPtr<SGCondition> _active_condition;  // stadiametric (true) or standby (false)
     Input   _diameter;               // inner/outer radius relation
     float   _bullet_size;
     float   _inner_radius;
 };
 
 
-
 #endif // _HUD_HXX