]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud.cxx
remove obsolete constants
[flightgear.git] / src / Cockpit / hud.cxx
index 268bb943a257295ea486606ffda2b2453887e0dc..5ff98efa4853d20aee75fee0862b17e1cc740d76 100644 (file)
@@ -16,7 +16,7 @@
 //
 // 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 <Aircraft/aircraft.hxx>
 #include <Autopilot/xmlauto.hxx>
-#include <GUI/gui.h>
+#include <GUI/new_gui.hxx>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <Scenery/scenery.hxx>
 
-#if defined ( __sun__ ) || defined ( __sgi )
+#if defined (__sun) || defined ( __sgi )
 extern "C" {
     extern void *memmove(void *, const void *, size_t);
 }
@@ -66,6 +66,9 @@ extern "C" {
 
 #include "hud.hxx"
 
+
+static HUD_Properties *HUD;
+
 static char units[5];
 
 // The following routines obtain information concerning the aircraft's
@@ -80,11 +83,11 @@ fgLineList         HUD_LineList;
 fgLineList         HUD_StippleLineList;
 
 fntRenderer *HUDtext = 0;
-float  HUD_TextSize = 0;
+fntTexFont *HUD_Font = 0;
+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
@@ -173,8 +176,6 @@ static instr_item * readTBI( const SGPropertyNode * node);
 static void drawHUD();
 static void fgUpdateHUDVirtual();
 
-void fgHUDalphaInit( void );
-
 class locRECT {
 public:
     RECT rect;
@@ -585,6 +586,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 +667,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 +755,6 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
         input.close();
     }
 
-    fgHUDalphaInit();
     fgHUDReshape();
 
     if ( HUDtext ) {
@@ -732,13 +767,19 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
         delete tmp;
     }
 
-//    HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
-    HUD_TextSize = 10;
+    FGFontCache *fc = globals->get_fontcache();
+    HUD_Font = fc->getTexFont(fgGetString("/sim/hud/font/name", "Helvetica.txf"));
+    if (!HUD_Font)
+        throw sg_throwable(string("/sim/hud/font/name is not a texture font"));
+
+    HUD_TextSize = fgGetFloat("/sim/hud/font/size", 10);
+
     HUDtext = new fntRenderer();
-    HUDtext -> setFont      ( guiFntHandle ) ;
-    HUDtext -> setPointSize ( HUD_TextSize ) ;
+    HUDtext->setFont(HUD_Font);
+    HUDtext->setPointSize(HUD_TextSize);
     HUD_TextList.setFont( HUDtext );
-    
+
+    HUD = new HUD_Properties;
     return 0;  // For now. Later we may use this for an error code.
 
 }
@@ -768,196 +809,6 @@ int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
 }
 //$$$ End - added, Neetha, 28 Nov 2k  
 
-static int global_day_night_switch = HUD_DAY;
-
-void HUD_masterswitch( bool incr )
-{
-    if ( fgGetBool("/sim/hud/visibility") ) {
-       if ( global_day_night_switch == HUD_DAY ) {
-           global_day_night_switch = HUD_NIGHT;
-       } else {
-           fgSetBool("/sim/hud/visibility", false);
-       }
-    } else {
-        fgSetBool("/sim/hud/visibility", true);
-       global_day_night_switch = HUD_DAY;
-    }  
-}
-
-void HUD_brightkey( bool incr_bright )
-{
-    instr_item *pHUDInstr = HUD_deque[0];
-    int brightness        = pHUDInstr->get_brightness();
-
-    if( fgGetBool("/sim/hud/visibility") ) {
-       if( incr_bright ) {
-           switch (brightness)
-               {
-               case HUD_BRT_LIGHT:
-                   brightness = HUD_BRT_BLACK;
-                   break;
-
-               case HUD_BRT_MEDIUM:
-                   brightness = HUD_BRT_LIGHT;
-                   break;
-
-               case HUD_BRT_DARK:
-                   brightness = HUD_BRT_MEDIUM;
-                   break;
-
-               case HUD_BRT_BLACK:
-                   brightness = HUD_BRT_DARK;
-                   break;
-
-               default:
-                   brightness = HUD_BRT_BLACK;
-               }
-       } else {
-           switch (brightness)
-               {
-               case HUD_BRT_LIGHT:
-                   brightness = HUD_BRT_MEDIUM;
-                   break;
-
-               case HUD_BRT_MEDIUM:
-                   brightness = HUD_BRT_DARK;
-                   break;
-
-               case HUD_BRT_DARK:
-                   brightness = HUD_BRT_BLACK;
-                   break;
-
-               case HUD_BRT_BLACK:
-                   brightness = HUD_BRT_LIGHT;
-                   break;
-
-               default:
-                   fgSetBool("/sim/hud/visibility", false);
-               }
-       }
-    } else {
-       fgSetBool("/sim/hud/visibility", true);
-    }
-
-    pHUDInstr->SetBrightness( brightness );
-}
-
-
-#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
@@ -981,13 +832,6 @@ 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);
-}
-
-
 // fgUpdateHUD
 //
 // Performs a once around the list of calls to instruments installed in
@@ -1100,8 +944,6 @@ void drawHUD()
     glDisable(GL_DEPTH_TEST);
     glDisable(GL_LIGHTING);
 
-    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
@@ -1113,7 +955,7 @@ void drawHUD()
     static char hud_wp2_text[256];
     static char hud_alt_text[256];
 
-    if( antialiased_node->getBoolValue() ) {
+    if (HUD->isAntialiased()) {
         glEnable(GL_LINE_SMOOTH);
         //       glEnable(GL_BLEND);
         glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -1123,56 +965,7 @@ void drawHUD()
         glLineWidth(1.0);
     }
 
-    if( global_day_night_switch == HUD_DAY) {
-        switch (HUD_deque[0]->get_brightness())
-            {
-            case HUD_BRT_LIGHT:
-                set_hud_color (0.1f, 0.9f, 0.1f);
-                break;
-
-            case HUD_BRT_MEDIUM:
-                set_hud_color (0.1f, 0.7f, 0.0f);
-                break;
-
-            case HUD_BRT_DARK:
-                set_hud_color (0.0f, 0.6f, 0.0f);
-                break;
-
-            case HUD_BRT_BLACK:
-                set_hud_color( 0.0f, 0.0f, 0.0f);
-                break;
-
-            default:
-                set_hud_color (0.1f, 0.9f, 0.1f);
-            }
-    } else {
-        if( global_day_night_switch == HUD_NIGHT) {
-            switch (HUD_deque[0]->get_brightness())
-                {
-                case HUD_BRT_LIGHT:
-                    set_hud_color (0.9f, 0.1f, 0.1f);
-                    break;
-
-                case HUD_BRT_MEDIUM:
-                    set_hud_color (0.7f, 0.0f, 0.1f);
-                    break;
-
-                case HUD_BRT_DARK:
-                    set_hud_color (0.6f, 0.0f, 0.0f);
-                    break;
-
-                case HUD_BRT_BLACK:
-                    set_hud_color( 0.0f, 0.0f, 0.0f);
-                    break;
-
-                default:
-                    set_hud_color (0.6f, 0.0f, 0.0f);
-                }
-        } else {     // Just in case default
-            set_hud_color (0.1f, 0.9f, 0.1f);
-        }
-    }
-
+    HUD->setColor();
     for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
 
     HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
@@ -1239,7 +1032,7 @@ void drawHUD()
     // HUD_StippleLineList.draw();
     // glDisable(GL_LINE_STIPPLE);
 
-    if( antialiased_node->getBoolValue() ) {
+    if (HUD->isAntialiased()) {
         // glDisable(GL_BLEND);
         glDisable(GL_LINE_SMOOTH);
         glLineWidth(1.0);
@@ -1249,3 +1042,51 @@ void drawHUD()
     glEnable(GL_LIGHTING);
 }
 
+
+
+
+
+// HUD property listener class
+//
+HUD_Properties::HUD_Properties()
+{
+    _colors = fgGetNode("/sim/hud/colors", true)->getChildren("color");
+    _which = fgGetNode("/sim/hud/current-color", true);
+    _brightness = fgGetNode("/sim/hud/brightness", true);
+    _alpha = fgGetNode("/sim/hud/alpha", true);
+    _visibility = fgGetNode("/sim/hud/visibility", true);
+    _antialiasing = fgGetNode("/sim/hud/antialiased", true);
+
+    _which->addChangeListener(this);
+    _brightness->addChangeListener(this);
+    _alpha->addChangeListener(this);
+    _visibility->addChangeListener(this);
+    _antialiasing->addChangeListener(this, true);
+}
+
+
+void HUD_Properties::valueChanged(SGPropertyNode *n)
+{
+    _visible = _visibility->getBoolValue();
+    _antialiased = _antialiasing->getBoolValue();
+    float brt = _brightness->getFloatValue();
+    int w = _which->getIntValue();
+    if (w < 0 || w >= int(_colors.size()))
+        _visible = false;
+    else {
+        _r = clamp(brt * _colors[w]->getFloatValue("red", 1.0));
+        _g = clamp(brt * _colors[w]->getFloatValue("green", 1.0));
+        _b = clamp(brt * _colors[w]->getFloatValue("blue", 1.0));
+    }
+    _a = _alpha->getFloatValue();
+}
+
+
+void HUD_Properties::setColor() const
+{
+    if (_antialiased)
+        glColor4f(_r, _g, _b, _a);
+    else
+        glColor3f(_r, _g, _b);
+}
+