]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud.cxx
new FSF address
[flightgear.git] / src / Cockpit / hud.cxx
index d9654f231e2341b00bb74c5a0ca6be6ad967c2a0..8ddf3bb711086af532bfd2f96a4984ca56da3ff0 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 #include <simgear/compiler.h>
-#include <simgear/misc/exception.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include STL_STRING
 #include STL_FSTREAM
 
 #include <math.h>
 
-#include <GL/glut.h>
 #include <stdlib.h>
 #include <stdio.h>             // char related functions
 #include <string.h>            // strcmp()
 
+#include SG_GLU_H
+
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/props.hxx>
+#include <simgear/props/props.hxx>
 #include <simgear/misc/sg_path.hxx>
-//#include <simgear/math/fg_random.h>
-//#include <simgear/math/polar3d.hxx>
 
 #include <Aircraft/aircraft.hxx>
-#include <Autopilot/newauto.hxx>
-#include <GUI/gui.h>
+#include <Autopilot/xmlauto.hxx>
+#include <GUI/new_gui.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-#ifdef FG_NETWORK_OLK
-#include <NetworkOLK/network.h>
-#endif
 #include <Scenery/scenery.hxx>
-//#include <Time/fg_timer.hxx>
 
-#if defined ( __sun__ ) || defined ( __sgi )
+#if defined (__sun) || defined ( __sgi )
 extern "C" {
     extern void *memmove(void *, const void *, size_t);
 }
@@ -89,7 +84,6 @@ float  HUD_TextSize = 0;
 int HUD_style = 0;
 
 float HUD_matrix[16];
-static float hud_trans_alpha = 0.67f;
 
 
 //$$$ begin - added, Neetha, 28 Nov 2k
@@ -178,8 +172,6 @@ static instr_item * readTBI( const SGPropertyNode * node);
 static void drawHUD();
 static void fgUpdateHUDVirtual();
 
-void fgHUDalphaInit( void );
-
 class locRECT {
 public:
     RECT rect;
@@ -245,11 +237,13 @@ readLadder(const SGPropertyNode * node)
     // The factor assumes a base of 55 degrees per 640 pixels.
     // Invert to convert the "compression" factor to a
     // pixels-per-degree number.
-    if( HUD_style == 1)
+    if(fgGetBool("/sim/hud/enable3d", true))
     {
-//        if(factor == 0)
+        if (HUD_style == 1)
+        {
             factor = 1;
-        factor = (640./55.) / factor;
+            factor = (640./55.) / factor;
+        }
     }
 
     SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
@@ -458,6 +452,7 @@ readLabel(const SGPropertyNode * node)
         }
     }
 
+#ifdef ENABLE_SP_FMDS
     if ( loadfn== "aux1" ) {
         load_fn = get_aux1;
     } else if ( loadfn == "aux2" ) {
@@ -494,7 +489,9 @@ readLabel(const SGPropertyNode * node)
         load_fn = get_aux17;
     } else if ( loadfn == "aux18" ) {
         load_fn = get_aux18;
-    } else if ( loadfn == "ax" ) {
+    } else
+#endif
+      if ( loadfn == "ax" ) {
         load_fn = get_Ax;
     } else if ( loadfn == "speed" ) {
         load_fn = get_speed;
@@ -585,6 +582,29 @@ readTBI(const SGPropertyNode * node)
     return p;
 } //end readTBI
 
+static instr_item * 
+readRunway(const SGPropertyNode * node) {
+       name    = node->getStringValue("name");
+       x       = node->getIntValue("x");
+       y       = node->getIntValue("y");
+       width = node->getIntValue("width");
+       height = node->getIntValue("height");
+       scaling = node->getDoubleValue("scale");
+       working = node->getBoolValue("working",true);
+       runway_instr *ri = new runway_instr(x,y,width,height,scaling,working);
+       double scale = node->getDoubleValue("arrow_scale",1.0); 
+       ri->setDrawArrow((scale>0)?true:false);
+       ri->setDrawArrowAlways((scale>0)?node->getBoolValue("arrow_always"):false);
+       ri->setStippleOutline(node->getIntValue("outer_stipple",0xFFFF));
+       ri->setStippleCenterline(node->getIntValue("center_stipple",0xFFFF));
+       ri->setArrowRotationRadius(node->getDoubleValue("arrow_radius"));
+       ri->setArrowScale(scale);
+       ri->setLineScale(node->getDoubleValue("line_scale",1.0));
+       ri->setScaleDist(node->getDoubleValue("scale_dist_nm"));
+       SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
+       return (instr_item *) ri;
+}
+
 
 int readInstrument(const SGPropertyNode * node)
 {
@@ -643,6 +663,18 @@ int readInstrument(const SGPropertyNode * node)
 
         }//for - tbis
     }
+    
+    const SGPropertyNode * rwy_group = node->getNode("runways");
+    if (rwy_group != 0) {
+        int nRwy = rwy_group->nChildren();
+        for (int j = 0; j < nRwy; j++) {
+            SG_LOG( SG_COCKPIT, SG_DEBUG,
+                    "**************  Reading runway properties" );
+            HIptr = readRunway(rwy_group->getChild(j));
+            HUD_deque.insert( HUD_deque.begin(), HIptr);
+
+        }//for - runways
+    }    
     return 0;
 }//end readinstrument
 
@@ -719,7 +751,6 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
         input.close();
     }
 
-    fgHUDalphaInit();
     fgHUDReshape();
 
     if ( HUDtext ) {
@@ -843,122 +874,6 @@ void HUD_brightkey( bool incr_bright )
 }
 
 
-#define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
-
-static puDialogBox *HUDalphaDialog;
-static puText      *HUDalphaText;
-static puSlider    *HUDalphaHS0;
-//static puText      *HUDtextText;
-//static puSlider    *HUDalphaHS1;
-static char         SliderText[2][ 8 ];
-
-static void alpha_adj( puObject *hs ) {
-    float val ;
-
-    hs-> getValue ( &val ) ;
-    fgAP_CLAMP ( val, 0.1, 1.0 ) ;
-    // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
-    hud_trans_alpha = val;
-    sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
-    HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
-}
-
-void fgHUDalphaAdjust( puObject * ) {
-    fgSetBool("/sim/hud/antialiased", true);
-    FG_PUSH_PUI_DIALOG( HUDalphaDialog );
-}
-
-static void goAwayHUDalphaAdjust (puObject *)
-{
-    FG_POP_PUI_DIALOG( HUDalphaDialog );
-}
-
-static void cancelHUDalphaAdjust (puObject *)
-{
-    fgSetBool("/sim/hud/antialiased", false);
-    FG_POP_PUI_DIALOG( HUDalphaDialog );
-}
-
-// Done once at system initialization
-void fgHUDalphaInit( void ) {
-
-    // printf("fgHUDalphaInit\n");
-#define HORIZONTAL  FALSE
-
-    int DialogX = 40;
-    int DialogY = 100;
-    int DialogWidth = 240;
-
-    char Label[] =  "HUD Adjuster";
-    char *s;
-
-    int labelX = (DialogWidth / 2) -
-        ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
-       
-    int nSliders = 1;
-    int slider_x = 10;
-    int slider_y = 55;
-    int slider_width = 220;
-    int slider_title_x = 15;
-    int slider_value_x = 160;
-    float slider_delta = 0.05f;
-
-    puFont HUDalphaLegendFont;
-    puFont HUDalphaLabelFont;
-    puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
-       
-    HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
-        int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
-            HUDalphaLabelFont.getStringDescender() +
-            PUSTR_TGAP + PUSTR_BGAP + 5;
-
-        /* puFrame *
-           HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
-           85 + nSliders
-           * horiz_slider_height ); */
-
-        puText *
-            HUDalphaDialogMessage = new puText ( labelX,
-                                                 52 + nSliders
-                                                 * horiz_slider_height );
-        HUDalphaDialogMessage -> setDefaultValue ( Label );
-        HUDalphaDialogMessage -> getDefaultValue ( &s );
-        HUDalphaDialogMessage -> setLabel        ( s );
-
-        HUDalphaHS0 = new puSlider ( slider_x, slider_y,
-                                     slider_width, HORIZONTAL ) ;
-        HUDalphaHS0->     setDelta ( slider_delta ) ;
-        HUDalphaHS0->     setValue ( hud_trans_alpha ) ;
-        HUDalphaHS0->    setCBMode ( PUSLIDER_DELTA ) ;
-        HUDalphaHS0->  setCallback ( alpha_adj ) ;
-
-        puText *
-            HUDalphaTitle =      new puText ( slider_title_x, slider_y ) ;
-        HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
-        HUDalphaTitle-> getDefaultValue ( &s ) ;
-        HUDalphaTitle->        setLabel ( s ) ;
-               
-        HUDalphaText = new puText ( slider_value_x, slider_y ) ;
-        sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
-        HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
-
-        puOneShot *
-            HUDalphaOkButton =     new puOneShot ( 10, 10, 60, 45 );
-        HUDalphaOkButton->         setLegend ( gui_msg_OK );
-        HUDalphaOkButton-> makeReturnDefault ( TRUE );
-        HUDalphaOkButton->       setCallback ( goAwayHUDalphaAdjust );
-
-        puOneShot *
-            HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
-        HUDalphaNoButton->     setLegend ( gui_msg_CANCEL );
-        HUDalphaNoButton->   setCallback ( cancelHUDalphaAdjust );
-    }
-    FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
-
-#undef HORIZONTAL
-}
-
-
 void fgHUDReshape(void) {
 #if 0
     if ( HUDtext ) {
@@ -982,9 +897,13 @@ void fgHUDReshape(void) {
 
 
 static void set_hud_color(float r, float g, float b) {
-    fgGetBool("/sim/hud/antialiased") ?
-        glColor4f(r,g,b,hud_trans_alpha) :
-        glColor3f(r,g,b);
+    static SGPropertyNode_ptr alias = fgGetNode("/sim/hud/antialiased", true);
+    static SGPropertyNode_ptr alpha = fgGetNode("/sim/hud/alpha", true);
+
+    if (alias->getBoolValue())
+        glColor4f(r, g, b, alpha->getFloatValue());
+    else
+        glColor3f(r, g, b);
 }
 
 
@@ -996,7 +915,8 @@ static void set_hud_color(float r, float g, float b) {
 //
 void fgUpdateHUD( void ) {
        
-    if( HUD_style == 1)
+    static const SGPropertyNode *enable3d_node = fgGetNode("/sim/hud/enable3d");
+    if( HUD_style == 1 && enable3d_node->getBoolValue() )
     {
         fgUpdateHUDVirtual();
         return;
@@ -1099,8 +1019,18 @@ void drawHUD()
     glDisable(GL_DEPTH_TEST);
     glDisable(GL_LIGHTING);
 
-    static const SGPropertyNode * antialiased_node
-        = fgGetNode("/sim/hud/antialiased");
+    static const SGPropertyNode *antialiased_node
+        = fgGetNode("/sim/hud/antialiased", true);
+    static const SGPropertyNode *heading_enabled
+        = fgGetNode("/autopilot/locks/heading", true);
+    static const SGPropertyNode *altitude_enabled
+        = fgGetNode("/autopilot/locks/altitude", true);
+
+    static char hud_hdg_text[256];
+    static char hud_wp0_text[256];
+    static char hud_wp1_text[256];
+    static char hud_wp2_text[256];
+    static char hud_alt_text[256];
 
     if( antialiased_node->getBoolValue() ) {
         glEnable(GL_LINE_SMOOTH);
@@ -1166,43 +1096,59 @@ void drawHUD()
 
     HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
 
-#ifdef FG_NETWORK_OLK
-    if ( net_hud_display ) {
-        net_hud_update();
-    }
-#endif
-
 
     int apY = 480 - 80;
-    // char scratch[128];
-    // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
-    // apY -= 15;
-    FGAutopilot *AP = globals->get_autopilot();
     
-    if( AP->get_HeadingEnabled() ) {
-        HUD_TextList.add( fgText( 40, apY, AP->get_TargetHeadingStr()) );
+    
+    if (strcmp( heading_enabled->getStringValue(), "dg-heading-hold") == 0 ) {
+        snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
+                  fgGetDouble("/autopilot/settings/heading-bug-deg") );
+        HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
         apY -= 15;
-    }
-    if( AP->get_AltitudeEnabled() ) {
-        HUD_TextList.add( fgText( 40, apY, AP->get_TargetAltitudeStr()) );
+    } else if ( strcmp(heading_enabled->getStringValue(), "true-heading-hold") == 0 ) {
+        snprintf( hud_hdg_text, 256, "hdg = %.1f\n",
+                  fgGetDouble("/autopilot/settings/true-heading-deg") );
+        HUD_TextList.add( fgText( 40, apY, hud_hdg_text ) );
         apY -= 15;
-    }
-    if( AP->get_HeadingMode() == FGAutopilot::FG_HEADING_WAYPOINT )
-    {
-        if ( strlen( AP->get_TargetWP1Str() ) ) {
-            HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP1Str() ) );
+
+        string wp0_id = fgGetString( "/autopilot/route-manager/wp[0]/id" );
+        if ( wp0_id.length() > 0 ) {
+            snprintf( hud_wp0_text, 256, "%5s %6.1fnm %s", wp0_id.c_str(), 
+                      fgGetDouble( "/autopilot/route-manager/wp[0]/dist" ),
+                      fgGetString( "/autopilot/route-manager/wp[0]/eta" ) );
+            HUD_TextList.add( fgText( 40, apY, hud_wp0_text ) );
             apY -= 15;
         }
-        if ( strlen( AP->get_TargetWP2Str() ) ) {
-            HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP2Str() ) );
+        string wp1_id = fgGetString( "/autopilot/route-manager/wp[1]/id" );
+        if ( wp1_id.length() > 0 ) {
+            snprintf( hud_wp1_text, 256, "%5s %6.1fnm %s", wp1_id.c_str(), 
+                      fgGetDouble( "/autopilot/route-manager/wp[1]/dist" ),
+                      fgGetString( "/autopilot/route-manager/wp[1]/eta" ) );
+            HUD_TextList.add( fgText( 40, apY, hud_wp1_text ) );
             apY -= 15;
         }
-        if ( strlen( AP->get_TargetWP3Str() ) ) {
-            HUD_TextList.add( fgText( 40, apY, AP->get_TargetWP3Str() ) );
-                apY -= 15;
+        string wp2_id = fgGetString( "/autopilot/route-manager/wp-last/id" );
+        if ( wp2_id.length() > 0 ) {
+            snprintf( hud_wp2_text, 256, "%5s %6.1fnm %s", wp2_id.c_str(), 
+                      fgGetDouble( "/autopilot/route-manager/wp-last/dist" ),
+                      fgGetString( "/autopilot/route-manager/wp-last/eta" ) );
+            HUD_TextList.add( fgText( 40, apY, hud_wp2_text ) );
+            apY -= 15;
         }
     }
   
+    if ( strcmp( altitude_enabled->getStringValue(), "altitude-hold" ) == 0 ) {
+        snprintf( hud_alt_text, 256, "alt = %.0f\n",
+                  fgGetDouble("/autopilot/settings/target-altitude-ft") );
+        HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
+        apY -= 15;
+    } else if ( strcmp( altitude_enabled->getStringValue(), "agl-hold" ) == 0 ){
+        snprintf( hud_alt_text, 256, "agl = %.0f\n",
+                  fgGetDouble("/autopilot/settings/target-agl-ft") );
+        HUD_TextList.add( fgText( 40, apY, hud_alt_text ) );
+        apY -= 15;
+    }
+
     HUD_TextList.draw();
 
     HUD_LineList.draw();