]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud.hxx
In the process of changing, adding and removing files the last few years
[flightgear.git] / src / Cockpit / hud.hxx
index 8d6871a9f9283ecd63733a4cce8f0417804fd69d..50365f35aaff4f5c54ca1e10d05f7865f060c08f 100644 (file)
@@ -38,7 +38,6 @@
 #  include <windows.h>
 #endif
 
-#include <GL/glut.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -46,6 +45,7 @@
 //#  include <values.h>  // for MAXINT
 //#endif
 
+#include <algorithm>    // for_each()
 #include <vector>       // STL vector
 #include <deque>        // STL double ended queue
 #include STL_FSTREAM
 
 #include <Include/fg_typedefs.h>
 #include <Aircraft/aircraft.hxx>
+#include <Aircraft/controls.hxx>
 #include <FDM/flight.hxx>
-#include <Controls/controls.hxx>
 #include <GUI/gui.h>
 #include <Main/globals.hxx>
 #include <Main/viewmgr.hxx>
+#include <Airports/runways.hxx>
 
 #include "hud_opts.hxx"
+#include <plib/sg.h>
 
 SG_USING_STD(deque);
 SG_USING_STD(vector);
@@ -70,13 +72,13 @@ SG_USING_NAMESPACE(std);
 // some of Norman's crazy optimizations. :-)
 
 #ifndef WIN32
-  typedef struct {
-      int x, y;
-  } POINT;
+typedef struct {
+    int x, y;
+} POINT;
  
-  typedef struct {
-      int top, bottom, left, right;
-  } RECT;
+typedef struct {
+    int top, bottom, left, right;
+} RECT;
 #endif
 
 // View mode definitions
@@ -87,44 +89,19 @@ enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
 // controls can be used to set intensity and appropriate color. This will
 // be moved.
 // Hud general constants
-#define DAY                1
-#define NIGHT              2
-#define BRT_BLACK          3
-#define BRT_DARK           4
-#define BRT_MEDIUM         5
-#define BRT_LIGHT          6
-#define SIZE_SMALL         7
-#define SIZE_LARGE         8
+#define HUD_DAY                1
+#define HUD_NIGHT              2
+#define HUD_BRT_BLACK          3
+#define HUD_BRT_DARK           4
+#define HUD_BRT_MEDIUM         5
+#define HUD_BRT_LIGHT          6
 
 // Label constants
-#define SMALL              1
-#define LARGE              2
-
-#define BLINK              3
-#define NOBLINK            4
+#define HUD_FONT_SMALL     1
+#define HUD_FONT_LARGE     2
 
 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
 
-// Ladder constants
-#define NONE               1
-#define UPPER_LEFT         2
-#define UPPER_CENTER       3
-#define UPPER_RIGHT        4
-#define CENTER_RIGHT       5
-#define LOWER_RIGHT        6
-#define LOWER_CENTER       7
-#define LOWER_LEFT         8
-#define CENTER_LEFT        9
-#define SOLID_LINES       10
-#define DASHED_LINES      11
-#define DASHED_NEG_LINES  12
-
-
-#define HORIZON_FIXED   1
-#define HORIZON_MOVING  2
-#define LABEL_COUNTER   1
-#define LABEL_WARNING   2
-
 #define HUDS_AUTOTICKS           0x0001
 #define HUDS_VERT                0x0002
 #define HUDS_HORZ                0x0000
@@ -172,6 +149,7 @@ extern float get_elev_trimval( void );
 extern float get_rudderval   ( void );
 extern float get_speed       ( void );
 extern float get_aoa         ( void );
+extern float get_nlf         ( void );
 extern float get_roll        ( void );
 extern float get_pitch       ( void );
 extern float get_heading     ( void );
@@ -239,16 +217,16 @@ extern char *get_formated_gmt_time( void );
 extern void fgHUDReshape(void);
 
 enum  hudinstype{ HUDno_instr,
-              HUDscale,
-              HUDlabel,
-              HUDladder,
-              HUDcirc_ladder,
-              HUDhorizon,
-              HUDgauge,
-              HUDdual_inst,
-              HUDmoving_scale,
-              HUDtbi
-              };
+                  HUDscale,
+                  HUDlabel,
+                  HUDladder,
+                  HUDcirc_ladder,
+                  HUDhorizon,
+                  HUDgauge,
+                  HUDdual_inst,
+                  HUDmoving_scale,
+                  HUDtbi
+};
 
 typedef struct gltagRGBTRIPLE { // rgbt
     GLfloat Blue;
@@ -273,13 +251,21 @@ public:
 
     ~fgLineSeg2D() {}
     
-    void draw()
+    void draw() const
     {
         glVertex2f(x0, y0);
         glVertex2f(x1, y1);
     }
 };
 
+class DrawLineSeg2D {
+    public:
+        void operator() (const fgLineSeg2D& elem) const {
+            elem.draw();
+        }
+};
+
+
 #define USE_HUD_TextList
 extern float              HUD_TextSize;
 extern fntRenderer       *HUDtext;
@@ -309,8 +295,7 @@ public:
 
     int getStringWidth ( char *str )
     {
-        if ( HUDtext && str )
-        {
+        if ( HUDtext && str ) {
             float r, l ;
             guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
             return FloatToInt( r - l );
@@ -320,8 +305,7 @@ public:
     
     int StringWidth (void )
     {
-        if ( HUDtext && strlen( msg ))
-        {
+        if ( HUDtext && strlen( msg )) {
             float r, l ;
             guiFntHandle->getBBox ( msg, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
             return FloatToInt( r - l );
@@ -339,9 +323,9 @@ public:
             char *t=msg;
             int p=4;
 
-            if(t[0]=='-') //if negative value then increase the c and p values for '-' sign.
-            {
-                c++;
+            if(t[0]=='-') {
+                //if negative value then increase the c and p values
+                //for '-' sign.  c++;
                 p++;
             }
             char *tmp=msg;
@@ -360,7 +344,7 @@ public:
                 fnt->puts(tmp1);
 
                 fnt->setPointSize(12);
-                char tmp2[p1+1];
+                char tmp2[64];
                 strncpy(tmp2,msg,p1);
                 tmp2[p1]='\0';
                         
@@ -382,7 +366,7 @@ public:
 
     void Draw()
     {
-        puDrawString ( guiFnt, msg, FloatToInt(x), FloatToInt(y) );
+        guiFnt.drawString( msg, FloatToInt(x), FloatToInt(y) );
     }
 };
 
@@ -391,30 +375,13 @@ class fgLineList {
 public:
     fgLineList( void ) {}
     ~fgLineList( void ) {}
-    void add( fgLineSeg2D seg ) { List.push_back(seg); }
+    void add( const fgLineSeg2D& seg ) { List.push_back(seg); }
     void erase( void ) { List.erase( List.begin(), List.end() ); }
-       void draw( void ) {
-               vector < fgLineSeg2D > :: iterator curSeg;
-               vector < fgLineSeg2D > :: iterator lastSeg;
-               curSeg  = List.begin();
-               lastSeg = List.end();
-               glBegin(GL_LINES);
-               for ( ; curSeg != lastSeg; curSeg++ ) {
-                       curSeg->draw();
-               }
-               glEnd();
-       }
-/*    void draw( void ) {
-        vector < fgLineSeg2D > :: iterator curSeg;
-        vector < fgLineSeg2D > :: iterator lastSeg;
-       curSeg  = List.begin();
-        lastSeg = List.end();
+    void draw( void ) {
         glBegin(GL_LINES);
-        for ( ; curSeg != lastSeg; curSeg++ ) {
-            curSeg->draw();
-        }
+        for_each( List.begin(), List.end(), DrawLineSeg2D());
         glEnd();
-    } */
+    }
 };
 
 class fgTextList {
@@ -425,15 +392,15 @@ public:
     ~fgTextList( void ) {}
     
     void setFont( fntRenderer *Renderer ) { Font = Renderer; }
-    void add( fgText String ) { List.push_back(String); }
+    void add( const fgText& String ) { List.push_back(String); }
     void erase( void ) { List.erase( List.begin(), List.end() ); }
     
     void draw( void ) {
-        vector < fgText > :: iterator curString;
-        vector < fgText > :: iterator lastString;
-        if( Font == 0 ) return;
-        curString  = List.begin();
-        lastString = List.end();
+        if( Font == 0 )
+            return;
+        vector < fgText > :: iterator curString = List.begin();
+        vector < fgText > :: iterator lastString = List.end();
+
         glPushAttrib( GL_COLOR_BUFFER_BIT );
         glEnable    ( GL_ALPHA_TEST   ) ;
         glEnable    ( GL_BLEND        ) ;
@@ -457,7 +424,7 @@ inline void Text( fgTextList &List, float x, float y, char *s)
     List.add( fgText( x, y, s) );
 }
 
-inline void Text( fgTextList &List, fgText &me)
+inline void Text( fgTextList &List, const fgText &me)
 {
     List.add(me);
 }
@@ -475,14 +442,14 @@ extern fgLineList         HUD_StippleLineList;
 
 
 class instr_item {  // An Abstract Base Class (ABC)
-  private:
+private:
     static UINT        instances;     // More than 64K instruments? Nah!
     static int         brightness;
     static glRGBTRIPLE color;
 
     UINT               handle;
     RECT               scrn_pos;      // Framing - affects scale dimensions
-                                    // and orientation. Vert vs Horz, etc.
+                                      // and orientation. Vert vs Horz, etc.
     FLTFNPTR           load_value_fn;
     float              disp_factor;   // Multiply by to get numbers shown on scale.
     UINT               opts;
@@ -492,7 +459,7 @@ class instr_item {  // An Abstract Base Class (ABC)
     POINT              mid_span;      //
     int                       digits;        //suma
   
-  public:
+public:
     instr_item( int            x,
                 int            y,
                 UINT           height,
@@ -503,7 +470,6 @@ class instr_item {  // An Abstract Base Class (ABC)
                 bool           working  = true,
                 int           digit = 0); //suma
 
-
     instr_item( const instr_item & image );
 
     instr_item & operator = ( const instr_item & rhs );
@@ -524,7 +490,9 @@ class instr_item {  // An Abstract Base Class (ABC)
     UINT    huds_vert     (UINT options) { return( options  & HUDS_VERT ); }
     UINT    huds_left     (UINT options) { return( options  & HUDS_LEFT ); }
     UINT    huds_right    (UINT options) { return( options  & HUDS_RIGHT ); }
-    UINT    huds_both     (UINT options) { return( (options & HUDS_BOTH) == HUDS_BOTH ); }
+    UINT    huds_both     (UINT options) {
+        return( (options & HUDS_BOTH) == HUDS_BOTH );
+    }
     UINT    huds_noticks  (UINT options) { return( options  & HUDS_NOTICKS ); }
     UINT    huds_notext   (UINT options) { return( options  & HUDS_NOTEXT ); }
     UINT    huds_top      (UINT options) { return( options  & HUDS_TOP ); }
@@ -553,8 +521,7 @@ class instr_item {  // An Abstract Base Class (ABC)
     }
     int getStringWidth ( char *str )
     {
-        if ( HUDtext && str )
-        {
+        if ( HUDtext && str ) {
             float r, l ;
             guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
             return FloatToInt( r - l );
@@ -567,8 +534,8 @@ class instr_item {  // An Abstract Base Class (ABC)
     {
         glBegin(GL_LINE_LOOP);  // Use polygon to approximate a circle 
         for(int count=0; count<25; count++) {             
-            float cosine = r * cos(count * 2 * M_PI/10.0); 
-            float sine =   r * sin(count * 2 * M_PI/10.0); 
+            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);
         }     
         glEnd(); 
@@ -577,6 +544,15 @@ class instr_item {  // An Abstract Base Class (ABC)
 };
 
 typedef instr_item *HIptr;
+
+class HUDdraw {
+    public:
+        void operator() (HIptr elem) const {
+            if( elem->enabled())
+                elem->draw();
+        }
+};
+
 //typedef deque <  instr_item * > hud_deque_type;
 //typedef hud_deque_type::iterator hud_deque_iterator;
 //typedef hud_deque_type::const_iterator hud_deque_const_iterator;
@@ -591,7 +567,7 @@ extern int HUD_style;
 
 
 class instr_label : public instr_item {
-  private:
+private:
     const char *pformat;
     const char *pre_str;
     const char *post_str;
@@ -603,7 +579,7 @@ class instr_label : public instr_item {
     bool               lon;
     bool               lbox;
 
-  public:
+public:
     instr_label( int          x,
                  int          y,
                  UINT         width,
@@ -634,7 +610,7 @@ typedef instr_label * pInstlabel;
 
 
 class lat_label : public instr_item {
-  private:
+private:
     const char *pformat;
     const char *pre_str;
     const char *post_str;
@@ -643,7 +619,7 @@ class lat_label : public instr_item {
     int         blink;
     char format_buffer[80];
 
-  public:
+public:
     lat_label( int          x,
                int          y,
                UINT         width,
@@ -670,7 +646,7 @@ class lat_label : public instr_item {
 typedef lat_label * pLatlabel;
 
 class lon_label : public instr_item {
-  private:
+private:
     const char *pformat;
     const char *pre_str;
     const char *post_str;
@@ -679,7 +655,7 @@ class lon_label : public instr_item {
     int         blink;
     char format_buffer[80];
 
-  public:
+public:
     lon_label( int          x,
                int          y,
                UINT         width,
@@ -706,6 +682,50 @@ class lon_label : public instr_item {
 
 typedef lon_label * pLonlabel;
 
+//
+// fgRunway_instr      This class is responsible for rendering the active runway
+//                     in the hud (if visible).
+class runway_instr : public instr_item 
+{
+private:       
+       void boundPoint(const sgdVec3& v, sgdVec3& m);
+       bool boundOutsidePoints(sgdVec3& v, sgdVec3& m);
+       bool drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3& p1, const sgdVec3& p2);
+       void drawArrow();
+       bool get_active_runway(FGRunway& rwy);
+       void get_rwy_points(sgdVec3 *points);
+       void setLineWidth(void);
+
+       sgdVec3 points3d[6],points2d[6];
+       double mm[16],pm[16], arrowScale, arrowRad, lnScale, scaleDist, default_pitch, default_heading;
+       GLint view[4];
+       FGRunway runway;
+       FGViewer* cockpit_view; 
+       unsigned short stippleOut,stippleCen;
+       bool drawIA,drawIAAlways;
+       RECT location;
+       POINT center; 
+       
+public:
+    runway_instr( int    x,
+                  int    y,                    
+                                 int    width,
+                                 int    height,
+                         float  scale_data,
+                         bool   working = true);
+
+    virtual void draw( void );       // Required method in base class
+       void setArrowRotationRadius(double radius);
+       void setArrowScale(double scale); // Scales the runway indication arrow
+       void setDrawArrow(bool draw);    // Draws arrow when runway is not visible in HUD if draw=true
+       void setDrawArrowAlways(bool draw); //Always draws arrow if draw=true;
+       void setLineScale(double scale); //Sets the maximum line scale
+       void setScaleDist(double dist_nm); //Sets the distance where to start scaling the lines
+       void setStippleOutline(unsigned short stipple); //Sets the stipple pattern of the outline of the runway
+       void setStippleCenterline(unsigned short stipple); //Sets the stipple patter of the center line of the runway
+};
+
+
 //
 // instr_scale           This class is an abstract base class for both moving
 //                       scale and moving needle (fixed scale) indicators. It
@@ -713,7 +733,7 @@ typedef lon_label * pLonlabel;
 //
 
 class instr_scale : public instr_item {
-  private:
+private:
     float range_shown;   // Width Units.
     float Maximum_value; //                ceiling.
     float Minimum_value; // Representation floor.
@@ -723,7 +743,7 @@ class instr_scale : public instr_item {
     UINT   Modulo;        // Roll over point
     int    signif_digits; // digits to show to the right.
 
-  public:
+public:
     instr_scale( int          x,
                  int          y,
                  UINT         width,
@@ -760,7 +780,7 @@ class instr_scale : public instr_item {
 // line.
 
 class hud_card : public instr_scale {
-  private:
+private:
     float val_span;
     string type;
     float half_width_units;
@@ -786,7 +806,7 @@ class hud_card : public instr_scale {
     UINT       Min_div; //suma
        
     
-  public:
+public:
     hud_card( int      x,
               int      y,
               UINT     width,
@@ -818,13 +838,14 @@ class hud_card : public instr_scale {
               bool     working,
               float    radius, //suma
               int      divisions, //suma
-              int         zoom); //suma
+              int       zoom //suma
+            );
 
 
     ~hud_card();
     hud_card( const hud_card & image);
     hud_card & operator = (const hud_card & rhs );
-//    virtual void display_enable( bool setting );
+    //    virtual void display_enable( bool setting );
     virtual void draw( void );       // Required method in base class
     void circles(float,float,float); // suma
     void fixed(float,float,float,float,float,float); //suma
@@ -834,7 +855,7 @@ class hud_card : public instr_scale {
 typedef hud_card * pCardScale;
 
 class gauge_instr : public instr_scale {
-  public:
+public:
     gauge_instr( int       x,
                  int       y,
                  UINT      width,
@@ -862,10 +883,10 @@ typedef gauge_instr * pGaugeInst;
 //                         for both panel and HUD Turn Bank Indicators.
 
 class dual_instr_item : public instr_item {
-  private:
+private:
     FLTFNPTR alt_data_source;
 
-  public:
+public:
     dual_instr_item ( int       x,
                       int       y,
                       UINT      width,
@@ -886,14 +907,14 @@ class dual_instr_item : public instr_item {
 
 class fgTBI_instr : public dual_instr_item 
 {
-  private:
+private:
     UINT BankLimit;
     UINT SlewLimit;
     UINT scr_hole;
     bool tsi;  //suma
     float rad; //suma
 
-  public:
+public:
     fgTBI_instr( int       x,
                  int       y,
                  UINT      width,
@@ -921,7 +942,7 @@ class fgTBI_instr : public dual_instr_item
 typedef fgTBI_instr * pTBI;
 
 class HudLadder : public dual_instr_item {
-  private:
+private:
     UINT   width_units;
     int    div_units;
     UINT   minor_div;
@@ -947,12 +968,13 @@ class HudLadder : public dual_instr_item {
     int                hat; //suma
     
 
+    // The Ladder has it's own temporary display lists
     fgTextList         TextList;
     fgLineList         LineList;
     fgLineList         StippleLineList;
 
-  public:
-    HudLadder( string    name,
+public:
+    HudLadder( const string&    name,
               int       x,
                int       y,
                UINT      width,
@@ -979,7 +1001,8 @@ class HudLadder : public dual_instr_item {
                bool  working,
                int   zenith, //suma
                int   nadir, //suma
-               int   hat); //suma
+               int      hat
+             ); //suma
 
 
     ~HudLadder();
@@ -1018,23 +1041,6 @@ extern void fgUpdateHUD( void );
 extern void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
                          GLfloat x_end, GLfloat y_end );
 
-extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
-extern void drawOneLine ( RECT &rect);
-extern void textString  ( int x,
-                          int y,
-                          char *msg,
-                          void *font = GLUT_BITMAP_9_BY_15,int digit=0); //suma
-extern void strokeString( int x,
-                          int y,
-                          char *msg,
-                          void *font = GLUT_STROKE_ROMAN,
-                          float theta = 0);
-
-//extern void strokeString(float xx,
-//                       float yy,
-//                       char *msg,
-//                       void *font = GLUT_STROKE_ROMAN)
-
 /*
 bool AddHUDInstrument( instr_item *pBlackBox );
 void DrawHUD ( void );