]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud.cxx
Removed ios::binary on file open.
[flightgear.git] / src / Cockpit / hud.cxx
1 // hud.cxx -- hud defines and prototypes
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  - micheleamerica@geocities.com
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23 #include <simgear/compiler.h>
24
25 #ifdef HAVE_CONFIG_H
26 #  include <config.h>
27 #endif
28
29 #ifdef HAVE_WINDOWS_H
30 #  include <windows.h>
31 #endif
32
33 #ifdef __BORLANDC__
34 #  define exception c_exception
35 #endif
36 #include <math.h>
37
38 #include <GL/glut.h>
39 #include <stdlib.h>
40 #include STL_STRING
41 #include STL_FSTREAM
42
43 #include <simgear/constants.h>
44 #include <simgear/debug/logstream.hxx>
45 #include <simgear/misc/props.hxx>
46 //#include <simgear/math/fg_random.h>
47 //#include <simgear/math/polar3d.hxx>
48
49 #include <Aircraft/aircraft.hxx>
50 #include <Autopilot/newauto.hxx>
51 #include <GUI/gui.h>
52 #include <Main/globals.hxx>
53 #include <Main/fg_props.hxx>
54 #ifdef FG_NETWORK_OLK
55 #include <NetworkOLK/network.h>
56 #endif
57 #include <Scenery/scenery.hxx>
58 //#include <Time/fg_timer.hxx>
59
60 #if defined ( __sun__ ) || defined ( __sgi )
61 extern "C" {
62   extern void *memmove(void *, const void *, size_t);
63 }
64 #endif
65
66 #include "hud.hxx"
67
68 static char units[5];
69
70 // The following routines obtain information concerning the aircraft's
71 // current state and return it to calling instrument display routines.
72 // They should eventually be member functions of the aircraft.
73 //
74
75 deque< instr_item * > HUD_deque;
76
77 fgTextList         HUD_TextList;
78 fgLineList         HUD_LineList;
79 fgLineList         HUD_StippleLineList;
80
81 fntRenderer *HUDtext = 0;
82 float  HUD_TextSize = 0;
83 int HUD_style = 0;
84
85 float HUD_matrix[16];
86 static float hud_trans_alpha = 0.67f;
87
88
89 //$$$ begin - added, Neetha, 28 Nov 2k
90
91 static string   name;
92 static int              x;
93 static int              y;
94 static UINT    width;
95 static UINT    height;
96 static float    factor;
97 static float   span_units;
98 static float   division_units;
99 static float   minor_division = 0;
100 static UINT    screen_hole;
101 static UINT    lbl_pos;
102 static bool    working;
103 static string  loadfn;
104 static UINT     options;
105 static float   maxValue;
106 static float   minValue;
107 static float   scaling;
108 static UINT    major_divs;
109 static UINT    minor_divs;
110 static UINT    modulator;
111 static int     dp_showing = 0;
112 static string  label_format;
113 static string  prelabel;
114 static string  postlabel;
115 static int     justi;
116 static int              blinking;
117 static float   maxBankAngle;
118 static float   maxSlipAngle;
119 static UINT    gap_width;
120 static bool     latitude;
121 static bool     longitude;
122 static bool     tick_bottom;
123 static bool     tick_top;
124 static bool     tick_right;
125 static bool     tick_left;
126 static bool     cap_bottom;
127 static bool     cap_top;
128 static bool     cap_right;
129 static bool     cap_left;
130 static float   marker_off;
131 static string  type;
132 static bool    enable_pointer;
133 static string  type_pointer;
134 static bool    frl_spot;
135 static bool     target;
136 static bool    vel_vector;
137 static bool    drift;
138 static bool    alpha;
139 static bool     energy;
140 static bool     climb_dive;
141 static bool     glide;
142 static float    glide_slope_val;
143 static bool     worm_energy;
144 static bool     waypoint;
145
146 static FLTFNPTR load_fn;    
147 static fgLabelJust justification;
148 static const char *pre_label_string  = 0;
149 static const char *post_label_string = 0;
150
151 int readHud( istream &input );
152 int readInstrument ( const SGPropertyNode * node);
153 static instr_item * readLadder ( const SGPropertyNode * node);
154 static instr_item * readCard ( const SGPropertyNode * node);
155 static instr_item * readLabel( const SGPropertyNode * node);
156 static instr_item * readTBI( const SGPropertyNode * node);
157 //$$$ end   - added, Neetha, 28 Nov 2k
158
159 void fgHUDalphaInit( void );
160
161 class locRECT {
162   public:
163     RECT rect;
164
165     locRECT( UINT left, UINT top, UINT right, UINT bottom);
166     RECT get_rect(void) { return rect;}
167 };
168
169 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
170 {
171   rect.left   =  left;
172   rect.top    =  top;
173   rect.right  =  right;
174   rect.bottom =  bottom;
175
176 }
177 // #define DEBUG
178
179 #ifdef OLD_CODE
180 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
181 {
182   glBegin(GL_LINES);
183   glVertex2f(x1, y1);
184   glVertex2f(x2, y2);
185   glEnd();
186 }
187
188 void drawOneLine( RECT &rect)
189 {
190   glBegin(GL_LINES);
191   glVertex2f(rect.left, rect.top);
192   glVertex2f(rect.right, rect.bottom);
193   glEnd();
194 }
195
196 //
197 // The following code deals with painting the "instrument" on the display
198 //
199    /* textString - Bitmap font string */
200
201 void textString( int x, int y, char *msg, void *font ){
202
203     if(*msg)
204     {
205 //      puDrawString (  NULL, msg, x, y );
206         glRasterPos2f(x, y);
207         while (*msg) {
208             glutBitmapCharacter(font, *msg);
209             msg++;
210         }
211     }
212 }
213
214
215 /* strokeString - Stroke font string */
216 void strokeString(int x, int y, char *msg, void *font, float theta)
217 {
218     int xx;
219     int yy;
220     int c;
221     float sintheta,costheta;
222     
223
224     if(*msg)
225     {
226     glPushMatrix();
227     glRotatef(theta * RAD_TO_DEG, 0.0, 0.0, 1.0);
228     sintheta = sin(theta);
229     costheta = cos(theta);
230     xx = (int)(x * costheta + y * sintheta);
231     yy = (int)(y * costheta - x * sintheta);
232     glTranslatef( xx, yy, 0);
233     glScalef(.1, .1, 0.0);
234     while( (c=*msg++) ) {
235         glutStrokeCharacter(font, c);
236     }
237     glPopMatrix();
238     }
239 }
240
241 int getStringWidth ( char *str )
242 {
243     if ( HUDtext && str )
244     {
245         float r, l ;
246         guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
247         return FloatToInt( r - l );
248     }
249     return 0 ;
250 }
251 #endif // OLD_CODE
252
253 //========================= End of Class Implementations===================
254 // fgHUDInit
255 //
256 // Constructs a HUD object and then adds in instruments. At the present
257 // the instruments are hard coded into the routine. Ultimately these need
258 // to be defined by the aircraft's instrumentation records so that the
259 // display for a Piper Cub doesn't show the speed range of a North American
260 // mustange and the engine readouts of a B36!
261 //
262
263 #define INSTRDEFS 21
264
265 //$$$ begin - added, Neetha, 28 Nov 2k
266 static instr_item * 
267 readLadder(const SGPropertyNode * node)
268 {
269
270         instr_item *p;
271
272                                 name                    = node->getStringValue("name");
273                                 x                               = node->getIntValue("x");
274                                 y                               = node->getIntValue("y");
275                                 width                   = node->getIntValue("width");
276                                 height                  = node->getIntValue("height");
277                                 factor                  = node->getFloatValue("compression_factor");
278                                 span_units              = node->getFloatValue("span_units");
279                                 division_units  = node->getFloatValue("division_units");
280                                 screen_hole             = node->getIntValue("screen_hole");
281                                 lbl_pos                 = node->getIntValue("lbl_pos");
282                                 frl_spot                = node->getBoolValue("enable_frl",false);
283                                 target                  = node->getBoolValue("enable_target_spot",false);
284                                 vel_vector              = node->getBoolValue("enable_velocity_vector",false);
285                                 drift                   = node->getBoolValue("enable_drift_marker",false);
286                                 alpha                   = node->getBoolValue("enable_alpha_bracket",false);
287                                 energy                  = node->getBoolValue("enable_energy_marker",false);
288                                 climb_dive              = node->getBoolValue("enable_climb_dive_marker",false);
289                                 glide                   = node->getBoolValue("enable_glide_slope_marker",false);
290                                 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
291                                 worm_energy             = node->getBoolValue("enable_energy_marker",false);
292                                 waypoint                = node->getBoolValue("enable_waypoint_marker",false);
293                                 working                 = node->getBoolValue("working");
294
295                                 FG_LOG(FG_INPUT, FG_INFO, "Done reading instrument " << name);
296         
297                                 
298                                 p = (instr_item *) new HudLadder( name, x, y,
299                                         width, height, factor,
300                                                                                 get_roll, get_pitch,
301                                                                                 span_units, division_units, minor_division,
302                                                                                 screen_hole, lbl_pos, frl_spot, target, vel_vector, 
303                                                                                 drift, alpha, energy, climb_dive, 
304                                                                                 glide, glide_slope_val, worm_energy, 
305                                                                                 waypoint, working);
306                                 
307                                 return p;
308                 
309 } //end readLadder
310
311 static instr_item * 
312 readCard(const SGPropertyNode * node)
313 {
314
315         instr_item *p;
316
317                                 name                    = node->getStringValue("name");
318                                 x                               = node->getIntValue("x");
319                                 y                               = node->getIntValue("y");
320                                 width                   = node->getIntValue("width");
321                                 height                  = node->getIntValue("height");
322                                 loadfn                  = node->getStringValue("loadfn");
323                                 options                 = node->getIntValue("options");
324                                 maxValue                = node->getFloatValue("maxValue");
325                                 minValue                = node->getFloatValue("minValue");
326                                 scaling                 = node->getFloatValue("disp_scaling");
327                                 major_divs              = node->getIntValue("major_divs");
328                                 minor_divs              = node->getIntValue("minor_divs");
329                                 modulator               = node->getIntValue("modulator");
330                                 span_units              = node->getFloatValue("value_span");
331                                 type                    = node->getStringValue("type");
332                                 tick_bottom         = node->getBoolValue("tick_bottom",false);
333                                 tick_top                = node->getBoolValue("tick_top",false);
334                                 tick_right              = node->getBoolValue("tick_right",false);
335                                 tick_left               = node->getBoolValue("tick_left",false);
336                                 cap_bottom              = node->getBoolValue("cap_bottom",false);
337                                 cap_top                 = node->getBoolValue("cap_top",false);
338                                 cap_right               = node->getBoolValue("cap_right",false);
339                                 cap_left                = node->getBoolValue("cap_left",false);
340                                 marker_off              = node->getFloatValue("marker_offset",0.0);
341                                 enable_pointer  = node->getBoolValue("enable_pointer",true);
342                                 type_pointer    = node->getStringValue("pointer_type");
343                                 working                 = node->getBoolValue("working");
344
345
346                                 FG_LOG(FG_INPUT, FG_INFO, "Done reading instrument " << name);
347
348
349                                 if(type=="guage")
350                                         span_units = maxValue - minValue;
351
352                                 if(loadfn=="anzg")
353                                         load_fn = get_anzg;
354                                 else                            
355                                 if(loadfn=="heading")
356                                         load_fn = get_heading;
357                                 else
358                                 if(loadfn=="aoa")
359                                         load_fn = get_aoa;
360                                 else
361                                 if(loadfn=="climb")
362                                         load_fn = get_climb_rate;
363                                 else
364                                 if(loadfn=="altitude")
365                                         load_fn = get_altitude;
366                                 else
367                                 if(loadfn=="agl")
368                                         load_fn = get_agl;
369                                 else
370                                 if(loadfn=="speed")
371                                         load_fn = get_speed;
372                                 else
373                                 if(loadfn=="view_direction")
374                                         load_fn = get_view_direction;
375                                 else
376                                 if(loadfn=="aileronval")
377                                         load_fn = get_aileronval;
378                                 else
379                                 if(loadfn=="elevatorval")
380                                         load_fn = get_elevatorval;
381                                 else
382                                 if(loadfn=="rudderval")
383                                         load_fn = get_rudderval;
384                                 else
385                                 if(loadfn=="throttleval")
386                                         load_fn = get_throttleval;
387
388
389                                 p = (instr_item *) new hud_card(        x,
390                                                                                                                 y,  
391                                                                                                                 width,
392                                                                                                                 height,
393                                                                             load_fn,
394                                                                                                                 options,
395                                                                                                                 maxValue, minValue,
396                                                                                                                 scaling,
397                                                                                                                 major_divs, minor_divs,
398                                                                                                                 modulator,
399                                                                                                                 dp_showing,
400                                                                                                                 span_units,
401                                                                                                                 type,
402                                                                                                                 tick_bottom,
403                                                                                                                 tick_top,
404                                                                                                                 tick_right,
405                                                                                                                 tick_left,
406                                                                                                                 cap_bottom,
407                                                                                                                 cap_top,
408                                                                                                                 cap_right,
409                                                                                                                 cap_left,
410                                                                                                                 marker_off,
411                                                                                                                 enable_pointer,
412                                                                                                                 type_pointer,
413                                                                                                                 working);
414                                         return p;
415 }// end readCard
416
417 static instr_item *
418 readLabel(const SGPropertyNode * node)
419 {
420         instr_item *p;
421
422         int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? LARGE : SMALL;
423
424                                 name                            = node->getStringValue("name");
425                                 x                   = node->getIntValue("x");
426                                 y                   = node->getIntValue("y");
427                                 width               = node->getIntValue("width");
428                                 height                          = node->getIntValue("height");
429                                 loadfn                          = node->getStringValue("data_source");
430                                 label_format            = node->getStringValue("label_format");
431                                 prelabel                        = node->getStringValue("pre_label_string");
432                                 postlabel                       = node->getStringValue("post_label_string");
433                                 scaling                         = node->getFloatValue("scale_data");
434                                 options                         = node->getIntValue("options");
435                                 justi                           = node->getIntValue("justification");
436                                 blinking            = node->getIntValue("blinking");
437                                 latitude                        = node->getBoolValue("latitude",false);
438                                 longitude                       = node->getBoolValue("longitude",false);
439                                 working             = node->getBoolValue("working");
440
441
442                                 FG_LOG(FG_INPUT, FG_INFO, "Done reading instrument " << name);
443
444
445                                 if(justi==0)
446                                         justification = LEFT_JUST;
447                                 else
448                                 if(justi==1)
449                                         justification = CENTER_JUST;
450                                 else
451                                 if(justi==2)
452                                         justification = RIGHT_JUST;
453
454
455                                 if(prelabel=="NULL")
456                                         pre_label_string = NULL;
457                                 else
458                                 if(prelabel=="blank")
459                                         pre_label_string = " ";
460                                 else
461                                         pre_label_string = prelabel.c_str();
462
463
464                                 if(postlabel=="blank")
465                                         post_label_string = " ";
466                                 else
467                                 if(postlabel=="NULL")
468                                         post_label_string = NULL;
469                                 else
470                                 if(postlabel=="units")
471                                         post_label_string = units;
472                                 else
473                                         post_label_string = postlabel.c_str();
474  
475
476                                 if(loadfn=="aux16")
477                                         load_fn = get_aux16;
478                                 else
479                                 if(loadfn=="aux17")
480                                         load_fn = get_aux17;
481                                 else
482                                 if(loadfn=="aux9")
483                                         load_fn = get_aux9;
484                                 else
485                                 if(loadfn=="aux11")
486                                         load_fn = get_aux11;
487                                 else
488                                 if(loadfn=="aux12")
489                                         load_fn = get_aux12;
490                                 else
491                                 if(loadfn=="aux10")
492                                         load_fn = get_aux10;
493                                 else
494                                 if(loadfn=="aux13")
495                                         load_fn = get_aux13;
496                                 else
497                                 if(loadfn=="aux14")
498                                         load_fn = get_aux14;
499                                 else
500                                 if(loadfn=="aux15")
501                                         load_fn = get_aux15;
502                                 else
503                                 if(loadfn=="aux8")
504                                         load_fn = get_aux8;
505                                 else
506                                 if(loadfn=="ax")
507                                         load_fn = get_Ax;
508                                 else
509                                 if(loadfn=="speed")
510                                         load_fn = get_speed;
511                                 else
512                                 if(loadfn=="mach")
513                                         load_fn = get_mach;
514                                 else
515                                 if(loadfn=="altitude")
516                                         load_fn = get_altitude;
517                                 else
518                                 if(loadfn=="agl")
519                                         load_fn = get_agl;
520                                 else
521                                 if(loadfn=="framerate")
522                                         load_fn = get_frame_rate;
523                                 else
524                                 if(loadfn=="heading")
525                                         load_fn = get_heading;
526                                 else
527                                 if(loadfn=="fov")
528                                         load_fn = get_fov;
529                                 else
530                                 if(loadfn=="vfc_tris_culled")
531                                         load_fn = get_vfc_tris_culled;
532                                 else
533                                 if(loadfn=="vfc_tris_drawn")
534                                         load_fn = get_vfc_tris_drawn;
535                                 else
536                                 if(loadfn=="aoa")
537                                         load_fn = get_aoa;
538                                 else
539                                 if(loadfn=="latitude")
540                                         load_fn  = get_latitude;
541                                 else
542                                 if(loadfn=="longitude")
543                                         load_fn   = get_longitude;
544
545
546                                 p = (instr_item *) new instr_label ( x,
547                                                  y,
548                                                  width,
549                                                  height,
550                                                  load_fn,
551                                                                                              label_format.c_str(),
552                                                  pre_label_string,
553                                                                                                  post_label_string,
554                                                  scaling,
555                                                  options,
556                                                  justification,
557                                                                                                  font_size,
558                                                  blinking,
559                                                                                                  latitude,
560                                                  longitude,
561                                                                                                  working);
562
563                                 return p;
564
565 } // end readLabel
566
567 static instr_item * 
568 readTBI(const SGPropertyNode * node)
569 {
570
571         instr_item *p;
572
573                                 name           = node->getStringValue("name");
574                                 x              = node->getIntValue("x");
575                                 y              = node->getIntValue("y");
576                                 width          = node->getIntValue("width");
577                                 height         = node->getIntValue("height");
578                                 maxBankAngle   = node->getFloatValue("maxBankAngle");
579                                 maxSlipAngle   = node->getFloatValue("maxSlipAngle");
580                                 gap_width      = node->getIntValue("gap_width");
581                                 working        = node->getBoolValue("working");
582
583                                 FG_LOG(FG_INPUT, FG_INFO, "Done reading instrument " << name);
584
585
586                                 p = (instr_item *) new fgTBI_instr(     x,
587                                                                                                                 y,  
588                                                                                                                 width,
589                                                                                                                 height,
590                                                                                                                 get_roll,
591                                                                                                                 get_sideslip,
592                                                                                                                 maxBankAngle, 
593                                                                                                                 maxSlipAngle,
594                                                                                                                 gap_width,
595                                                                                                                 working);
596
597                                 return p;
598 } //end readTBI
599
600
601 int readInstrument(const SGPropertyNode * node)
602 {
603
604         instr_item *HIptr;
605     
606     if ( fgGetString("/sim/startup/units") == "feet" ) {
607     strcpy(units, " ft");
608     } else {
609     strcpy(units, " m");
610     }
611
612                         const SGPropertyNode * ladder_group = node->getNode("ladders");
613
614                         if (ladder_group != 0) {
615                                 int nLadders = ladder_group->nChildren();
616                                 for (int j = 0; j < nLadders; j++) {
617
618                                         HIptr = readLadder(ladder_group->getChild(j));
619                                         HUD_deque.insert( HUD_deque.begin(), HIptr);
620                                         
621                                 }// for - ladders
622                         }
623
624                         const SGPropertyNode * card_group = node->getNode("cards");
625                         if (card_group != 0) {
626                                 int nCards = card_group->nChildren();
627                                 for (int j = 0; j < nCards; j++) {
628
629                                         HIptr = readCard(card_group->getChild(j));
630                                         HUD_deque.insert( HUD_deque.begin(), HIptr);
631
632                                 }//for - cards
633                         }
634
635                         const SGPropertyNode * label_group = node->getNode("labels");
636                         if (label_group != 0) {
637                                 int nLabels = label_group->nChildren();
638                                 for (int j = 0; j < nLabels; j++) {
639
640                                         HIptr = readLabel(label_group->getChild(j));
641                                         HUD_deque.insert( HUD_deque.begin(), HIptr);
642
643                                 }//for - labels
644                         }
645
646                         const SGPropertyNode * tbi_group = node->getNode("tbis");
647                         if (tbi_group != 0) {
648                                 int nTbis = tbi_group->nChildren();
649                                 for (int j = 0; j < nTbis; j++) {
650
651                                         HIptr = readTBI(tbi_group->getChild(j));
652                                         HUD_deque.insert( HUD_deque.begin(), HIptr);
653
654                                 }//for - tbis
655                         }
656  return 0;
657 }//end readinstrument
658
659 int readHud( istream &input ) 
660 {
661
662         SGPropertyNode root;
663
664
665         if (!readProperties(input, &root)) {
666                 FG_LOG(FG_INPUT, FG_ALERT, "Malformed property list for hud.");
667                 return 0;
668         }
669   
670         
671         FG_LOG(FG_INPUT, FG_INFO, "Read properties for  " <<
672                 root.getStringValue("name"));
673
674
675         HUD_deque.erase( HUD_deque.begin(), HUD_deque.end());  // empty the HUD deque
676
677
678         FG_LOG(FG_INPUT, FG_INFO, "Reading Hud instruments");
679
680         const SGPropertyNode * instrument_group = root.getChild("instruments");
681         int nInstruments = instrument_group->nChildren();
682
683         for (int i = 0; i < nInstruments; i++) {
684                 
685                 const SGPropertyNode * node = instrument_group->getChild(i);
686
687                 FGPath path( globals->get_fg_root() );
688                 path.append(node->getStringValue("path"));
689
690                 FG_LOG(FG_INPUT, FG_INFO, "Reading Instrument "
691                 << node->getName()
692                 << " from "
693                 << path.str());
694
695
696                 SGPropertyNode root2;
697                 if (readProperties(path.str(), &root2)) {
698
699                         readInstrument(&root2);
700
701                 }//if
702         }//for loop(i)
703  return 0;
704 }
705
706
707 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
708 {
709
710
711         HUD_style = 1;
712
713         FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
714
715     string hud_path =
716         fgGetString("/sim/hud/path", "Huds/Default/default.xml");
717         FGPath path(globals->get_fg_root());
718         path.append(hud_path);
719         
720         ifstream input(path.c_str());
721         if (!input.good()) 
722                 {
723                         FG_LOG(FG_INPUT, FG_ALERT,
724                         "Cannot read Hud configuration from " << path.str());
725                 } 
726         else 
727                 {
728                         readHud(input);
729                         input.close();
730                 }
731
732         fgHUDalphaInit();
733         fgHUDReshape();
734
735   return 0;  // For now. Later we may use this for an error code.
736
737 }
738
739 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
740 {
741
742     HUD_style = 2;
743
744     FG_LOG( FG_COCKPIT, FG_INFO, "Initializing current aircraft HUD" );
745
746         FGPath path(globals->get_fg_root());
747         path.append("Huds/Minimal/default.xml");
748
749
750         ifstream input(path.c_str());
751         if (!input.good()) {
752                 FG_LOG(FG_INPUT, FG_ALERT,
753                         "Cannot read Hud configuration from " << path.str());
754         } 
755         else {
756                 readHud(input);
757                 input.close();
758         }
759
760     return 0;  // For now. Later we may use this for an error code.
761
762 }
763 //$$$ End - added, Neetha, 28 Nov 2k  
764
765 static int global_day_night_switch = DAY;
766
767 void HUD_masterswitch( bool incr )
768 {
769     if ( fgGetBool("/sim/hud/visibility") ) {
770         if ( global_day_night_switch == DAY ) {
771             global_day_night_switch = NIGHT;
772         } else {
773             fgSetBool("/sim/hud/visibility", false);
774         }
775     } else {
776         fgSetBool("/sim/hud/visibility", true);
777         global_day_night_switch = DAY;
778     }   
779 }
780
781 void HUD_brightkey( bool incr_bright )
782 {
783     instr_item *pHUDInstr = HUD_deque[0];
784     int brightness        = pHUDInstr->get_brightness();
785
786     if( fgGetBool("/sim/hud/visibility") ) {
787         if( incr_bright ) {
788             switch (brightness)
789                 {
790                 case BRT_LIGHT:
791                     brightness = BRT_BLACK;
792                     break;
793
794                 case BRT_MEDIUM:
795                     brightness = BRT_LIGHT;
796                     break;
797
798                 case BRT_DARK:
799                     brightness = BRT_MEDIUM;
800                     break;
801
802                 case BRT_BLACK:
803                     brightness = BRT_DARK;
804                     break;
805
806                 default:
807                     brightness = BRT_BLACK;
808                 }
809         } else {
810             switch (brightness)
811                 {
812                 case BRT_LIGHT:
813                     brightness = BRT_MEDIUM;
814                     break;
815
816                 case BRT_MEDIUM:
817                     brightness = BRT_DARK;
818                     break;
819
820                 case BRT_DARK:
821                     brightness = BRT_BLACK;
822                     break;
823
824                 case BRT_BLACK:
825                     brightness = BRT_LIGHT;
826                     break;
827
828                 default:
829                     fgSetBool("/sim/hud/visibility", false);
830                 }
831         }
832     } else {
833         fgSetBool("/sim/hud/visibility", true);
834     }
835
836     pHUDInstr->SetBrightness( brightness );
837 }
838
839
840 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
841
842 static puDialogBox *HUDalphaDialog;
843 static puText      *HUDalphaText;
844 static puSlider    *HUDalphaHS0;
845 //static puText      *HUDtextText;
846 //static puSlider    *HUDalphaHS1;
847 static char         SliderText[2][ 8 ];
848
849 static void alpha_adj( puObject *hs ) {
850         float val ;
851
852         hs-> getValue ( &val ) ;
853         fgAP_CLAMP ( val, 0.1, 1.0 ) ;
854         //    printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
855         hud_trans_alpha = val;
856         sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
857         HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
858 }
859
860 void fgHUDalphaAdjust( puObject * ) {
861         fgSetBool("/sim/hud/antialiased", true);
862         FG_PUSH_PUI_DIALOG( HUDalphaDialog );
863 }
864
865 static void goAwayHUDalphaAdjust (puObject *)
866 {
867         FG_POP_PUI_DIALOG( HUDalphaDialog );
868 }
869
870 static void cancelHUDalphaAdjust (puObject *)
871 {
872         fgSetBool("/sim/hud/antialiased", false);
873         FG_POP_PUI_DIALOG( HUDalphaDialog );
874 }
875
876 // Done once at system initialization
877 void fgHUDalphaInit( void ) {
878
879         //      printf("fgHUDalphaInit\n");
880 #define HORIZONTAL  FALSE
881
882         int DialogX = 40;
883         int DialogY = 100;
884         int DialogWidth = 240;
885
886         char Label[] =  "HUD Adjuster";
887         char *s;
888
889         int labelX = (DialogWidth / 2) -
890                                  (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
891         
892         int nSliders = 1;
893         int slider_x = 10;
894         int slider_y = 55;
895         int slider_width = 220;
896         int slider_title_x = 15;
897         int slider_value_x = 160;
898         float slider_delta = 0.05f;
899
900         puFont HUDalphaLegendFont;
901         puFont HUDalphaLabelFont;
902         puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
903         
904         HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
905                 int horiz_slider_height = puGetStringHeight (HUDalphaLabelFont) +
906                                                                   puGetStringDescender (HUDalphaLabelFont) +
907                                                                   PUSTR_TGAP + PUSTR_BGAP + 5;
908
909                 puFrame *
910                 HUDalphaFrame = new puFrame ( 0, 0,
911                                                                           DialogWidth,
912                                                                           85 + nSliders * horiz_slider_height );
913                 
914                 puText *
915                 HUDalphaDialogMessage = new puText ( labelX,
916                                                                                          52 + nSliders
917                                                                                          * horiz_slider_height );
918                 HUDalphaDialogMessage -> setDefaultValue ( Label );
919                 HUDalphaDialogMessage -> getDefaultValue ( &s );
920                 HUDalphaDialogMessage -> setLabel        ( s );
921
922                 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
923                                                                          slider_width, HORIZONTAL ) ;
924                 HUDalphaHS0->     setDelta ( slider_delta ) ;
925                 HUDalphaHS0->     setValue ( hud_trans_alpha ) ;
926                 HUDalphaHS0->    setCBMode ( PUSLIDER_DELTA ) ;
927                 HUDalphaHS0->  setCallback ( alpha_adj ) ;
928
929                 puText *
930                 HUDalphaTitle =      new puText ( slider_title_x, slider_y ) ;
931                 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
932                 HUDalphaTitle-> getDefaultValue ( &s ) ;
933                 HUDalphaTitle->        setLabel ( s ) ;
934                 
935                 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
936                 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
937                 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
938
939
940                 puOneShot *
941                 HUDalphaOkButton =     new puOneShot ( 10, 10, 60, 45 );
942                 HUDalphaOkButton->         setLegend ( gui_msg_OK );
943                 HUDalphaOkButton-> makeReturnDefault ( TRUE );
944                 HUDalphaOkButton->       setCallback ( goAwayHUDalphaAdjust );
945                 
946                 puOneShot *
947                 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
948                 HUDalphaNoButton->     setLegend ( gui_msg_CANCEL );
949                 HUDalphaNoButton->   setCallback ( cancelHUDalphaAdjust );
950         }
951         FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
952
953 #undef HORIZONTAL
954 }
955
956 void fgHUDReshape(void) {
957         if ( HUDtext )
958                 delete HUDtext;
959
960         HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
961         HUD_TextSize = 10;
962         HUDtext = new fntRenderer();
963         HUDtext -> setFont      ( guiFntHandle ) ;
964         HUDtext -> setPointSize ( HUD_TextSize ) ;
965         HUD_TextList.setFont( HUDtext );
966 }
967
968
969 static void set_hud_color(float r, float g, float b) {
970         fgGetBool("/sim/hud/antialiased") ?
971                         glColor4f(r,g,b,hud_trans_alpha) :
972                         glColor3f(r,g,b);
973 }
974
975 // fgUpdateHUD
976 //
977 // Performs a once around the list of calls to instruments installed in
978 // the HUD object with requests for redraw. Kinda. It will when this is
979 // all C++.
980 //
981 void fgUpdateHUD( void ) {
982   int brightness;
983 //  int day_night_sw = current_aircraft.controls->day_night_switch;
984   int day_night_sw = global_day_night_switch;
985   int hud_displays = HUD_deque.size();
986   instr_item *pHUDInstr;
987   float line_width;
988
989   if( !hud_displays ) {  // Trust everyone, but ALWAYS cut the cards!
990     return;
991     }
992
993   HUD_TextList.erase();
994   HUD_LineList.erase();
995 //  HUD_StippleLineList.erase();
996   
997   pHUDInstr = HUD_deque[0];
998   brightness = pHUDInstr->get_brightness();
999 //  brightness = HUD_deque.at(0)->get_brightness();
1000
1001   glMatrixMode(GL_PROJECTION);
1002   glPushMatrix();
1003
1004   glLoadIdentity();
1005   gluOrtho2D(0, 640, 0, 480);
1006   glMatrixMode(GL_MODELVIEW);
1007   glPushMatrix();
1008   glLoadIdentity();
1009
1010   glDisable(GL_DEPTH_TEST);
1011   glDisable(GL_LIGHTING);
1012
1013   if( fgGetBool("/sim/hud/antialiased") ) {
1014           glEnable(GL_LINE_SMOOTH);
1015 //        glEnable(GL_BLEND);
1016           glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1017           glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1018           glLineWidth(1.5);
1019   } else {
1020           glLineWidth(1.0);
1021   }
1022
1023   if( day_night_sw == DAY) {
1024       switch (brightness)
1025           {
1026           case BRT_LIGHT:
1027               set_hud_color (0.1f, 0.9f, 0.1f);
1028               break;
1029
1030           case BRT_MEDIUM:
1031               set_hud_color (0.1f, 0.7f, 0.0f);
1032               break;
1033
1034           case BRT_DARK:
1035               set_hud_color (0.0f, 0.6f, 0.0f);
1036               break;
1037
1038           case BRT_BLACK:
1039               set_hud_color( 0.0f, 0.0f, 0.0f);
1040               break;
1041
1042           default:
1043               set_hud_color (0.1f, 0.9f, 0.1f);
1044           }
1045   } else {
1046       if( day_night_sw == NIGHT) {
1047           switch (brightness)
1048               {
1049               case BRT_LIGHT:
1050                   set_hud_color (0.9f, 0.1f, 0.1f);
1051                   break;
1052
1053               case BRT_MEDIUM:
1054                   set_hud_color (0.7f, 0.0f, 0.1f);
1055                   break;
1056
1057               case BRT_DARK:
1058                   set_hud_color (0.6f, 0.0f, 0.0f);
1059                   break;
1060
1061               case BRT_BLACK:
1062                   set_hud_color( 0.0f, 0.0f, 0.0f);
1063                   break;
1064
1065               default:
1066                   set_hud_color (0.6f, 0.0f, 0.0f);
1067               }
1068       } else {     // Just in case default
1069           set_hud_color (0.1f, 0.9f, 0.1f);
1070       }
1071   }
1072
1073   deque < instr_item * > :: iterator current = HUD_deque.begin();
1074   deque < instr_item * > :: iterator last = HUD_deque.end();
1075
1076   for ( ; current != last; ++current ) {
1077           pHUDInstr = *current;
1078
1079           if( pHUDInstr->enabled()) {
1080                   //  fgPrintf( FG_COCKPIT, FG_DEBUG, "HUD Code %d  Status %d\n",
1081                   //            hud->code, hud->status );
1082                   pHUDInstr->draw();
1083                   
1084           }
1085   }
1086
1087   char *gmt_str = get_formated_gmt_time();
1088   HUD_TextList.add( fgText(40, 10, gmt_str) );
1089
1090 #ifdef FG_NETWORK_OLK
1091   if ( net_hud_display ) {
1092       net_hud_update();
1093   }
1094 #endif
1095
1096
1097   // temporary
1098   // extern bool fgAPAltitudeEnabled( void );
1099   // extern bool fgAPHeadingEnabled( void );
1100   // extern bool fgAPWayPointEnabled( void );
1101   // extern char *fgAPget_TargetDistanceStr( void );
1102   // extern char *fgAPget_TargetHeadingStr( void );
1103   // extern char *fgAPget_TargetAltitudeStr( void );
1104   // extern char *fgAPget_TargetLatLonStr( void );
1105
1106   int apY = 480 - 80;
1107 //  char scratch[128];
1108 //  HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1109 //  apY -= 15;
1110   if( current_autopilot->get_HeadingEnabled() ) {
1111       HUD_TextList.add( fgText( 40, apY, 
1112                                 current_autopilot->get_TargetHeadingStr()) );
1113       apY -= 15;
1114   }
1115   if( current_autopilot->get_AltitudeEnabled() ) {
1116       HUD_TextList.add( fgText( 40, apY, 
1117                                 current_autopilot->get_TargetAltitudeStr()) );
1118       apY -= 15;
1119   }
1120   if( current_autopilot->get_HeadingMode() == 
1121       FGAutopilot::FG_HEADING_WAYPOINT )
1122   {
1123       char *wpstr;
1124       wpstr = current_autopilot->get_TargetWP1Str();
1125       if ( strlen( wpstr ) ) {
1126           HUD_TextList.add( fgText( 40, apY, wpstr ) );
1127           apY -= 15;
1128       }
1129       wpstr = current_autopilot->get_TargetWP2Str();
1130       if ( strlen( wpstr ) ) {
1131           HUD_TextList.add( fgText( 40, apY, wpstr ) );
1132           apY -= 15;
1133       }
1134       wpstr = current_autopilot->get_TargetWP3Str();
1135       if ( strlen( wpstr ) ) {
1136           HUD_TextList.add( fgText( 40, apY, wpstr ) );
1137           apY -= 15;
1138       }
1139   }
1140   
1141   HUD_TextList.draw();
1142
1143   HUD_LineList.draw();
1144
1145 //  glEnable(GL_LINE_STIPPLE);
1146 //  glLineStipple( 1, 0x00FF );
1147 //  HUD_StippleLineList.draw();
1148 //  glDisable(GL_LINE_STIPPLE);
1149
1150   if( fgGetBool("/sim/hud/antialiased") ) {
1151 //        glDisable(GL_BLEND);
1152           glDisable(GL_LINE_SMOOTH);
1153           glLineWidth(1.0);
1154   }
1155
1156   glEnable(GL_DEPTH_TEST);
1157   glEnable(GL_LIGHTING);
1158   glMatrixMode(GL_PROJECTION);
1159   glPopMatrix();
1160   glMatrixMode(GL_MODELVIEW);
1161   glPopMatrix();
1162 }
1163