1 // hud.cxx -- hud defines and prototypes
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - micheleamerica@geocities.com
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.
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.
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.
23 #include <simgear/compiler.h>
24 #include <simgear/misc/exception.hxx>
35 # define exception c_exception
44 #include <simgear/constants.h>
45 #include <simgear/debug/logstream.hxx>
46 #include <simgear/misc/props.hxx>
47 //#include <simgear/math/fg_random.h>
48 //#include <simgear/math/polar3d.hxx>
50 #include <Aircraft/aircraft.hxx>
51 #include <Autopilot/newauto.hxx>
53 #include <Main/globals.hxx>
54 #include <Main/fg_props.hxx>
56 #include <NetworkOLK/network.h>
58 #include <Scenery/scenery.hxx>
59 //#include <Time/fg_timer.hxx>
61 #if defined ( __sun__ ) || defined ( __sgi )
63 extern void *memmove(void *, const void *, size_t);
71 // The following routines obtain information concerning the aircraft's
72 // current state and return it to calling instrument display routines.
73 // They should eventually be member functions of the aircraft.
76 deque< instr_item * > HUD_deque;
78 fgTextList HUD_TextList;
79 fgLineList HUD_LineList;
80 fgLineList HUD_StippleLineList;
82 fntRenderer *HUDtext = 0;
83 float HUD_TextSize = 0;
87 static float hud_trans_alpha = 0.67f;
90 //$$$ begin - added, Neetha, 28 Nov 2k
98 static float span_units;
99 static float division_units;
100 static float minor_division = 0;
101 static UINT screen_hole;
104 static string loadfn;
106 static float maxValue;
107 static float minValue;
108 static float scaling;
109 static UINT major_divs;
110 static UINT minor_divs;
111 static UINT modulator;
112 static int dp_showing = 0;
113 static string label_format;
114 static string prelabel;
115 static string postlabel;
118 static float maxBankAngle;
119 static float maxSlipAngle;
120 static UINT gap_width;
121 static bool latitude;
122 static bool longitude;
123 static bool tick_bottom;
124 static bool tick_top;
125 static bool tick_right;
126 static bool tick_left;
127 static bool cap_bottom;
129 static bool cap_right;
130 static bool cap_left;
131 static float marker_off;
133 static bool enable_pointer;
134 static string type_pointer;
135 static bool frl_spot;
137 static bool vel_vector;
141 static bool climb_dive;
143 static float glide_slope_val;
144 static bool worm_energy;
145 static bool waypoint;
146 static string type_tick;//hud
147 static string length_tick;//hud
148 static bool label_box;//hud
149 static int digits; //suma
150 static float radius; //suma
151 static int divisions; //suma
152 static int zoom; //suma
153 static int zenith; //suma
154 static int nadir ; //suma
155 static int hat; //suma
156 static bool tsi; //suma
157 static float rad; //suma
160 static FLTFNPTR load_fn;
161 static fgLabelJust justification;
162 static const char *pre_label_string = 0;
163 static const char *post_label_string = 0;
165 int readHud( istream &input );
166 int readInstrument ( const SGPropertyNode * node);
167 static instr_item * readLadder ( const SGPropertyNode * node);
168 static instr_item * readCard ( const SGPropertyNode * node);
169 static instr_item * readLabel( const SGPropertyNode * node);
170 static instr_item * readTBI( const SGPropertyNode * node);
171 //$$$ end - added, Neetha, 28 Nov 2k
173 void fgHUDalphaInit( void );
179 locRECT( UINT left, UINT top, UINT right, UINT bottom);
180 RECT get_rect(void) { return rect;}
183 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
188 rect.bottom = bottom;
194 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
202 void drawOneLine( RECT &rect)
205 glVertex2f(rect.left, rect.top);
206 glVertex2f(rect.right, rect.bottom);
211 // The following code deals with painting the "instrument" on the display
213 /* textString - Bitmap font string */
215 void textString( int x, int y, char *msg, void *font,int digit) //suma
220 // puDrawString ( NULL, msg, x, y );
223 glutBitmapCharacter(font, *msg);
230 /* strokeString - Stroke font string */
231 void strokeString(int x, int y, char *msg, void *font, float theta)
236 float sintheta,costheta;
242 glRotatef(theta * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
243 sintheta = sin(theta);
244 costheta = cos(theta);
245 xx = (int)(x * costheta + y * sintheta);
246 yy = (int)(y * costheta - x * sintheta);
247 glTranslatef( xx, yy, 0);
248 glScalef(.1, .1, 0.0);
249 while( (c=*msg++) ) {
250 glutStrokeCharacter(font, c);
256 int getStringWidth ( char *str )
258 if ( HUDtext && str )
261 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
262 return FloatToInt( r - l );
268 //========================= End of Class Implementations===================
271 // Constructs a HUD object and then adds in instruments. At the present
272 // the instruments are hard coded into the routine. Ultimately these need
273 // to be defined by the aircraft's instrumentation records so that the
274 // display for a Piper Cub doesn't show the speed range of a North American
275 // mustange and the engine readouts of a B36!
280 //$$$ begin - added, Neetha, 28 Nov 2k
282 readLadder(const SGPropertyNode * node)
287 name = node->getStringValue("name");
288 x = node->getIntValue("x");
289 y = node->getIntValue("y");
290 width = node->getIntValue("width");
291 height = node->getIntValue("height");
292 factor = node->getFloatValue("compression_factor");
293 span_units = node->getFloatValue("span_units");
294 division_units = node->getFloatValue("division_units");
295 screen_hole = node->getIntValue("screen_hole");
296 lbl_pos = node->getIntValue("lbl_pos");
297 frl_spot = node->getBoolValue("enable_frl",false);
298 target = node->getBoolValue("enable_target_spot",false);
299 vel_vector = node->getBoolValue("enable_velocity_vector",false);
300 drift = node->getBoolValue("enable_drift_marker",false);
301 alpha = node->getBoolValue("enable_alpha_bracket",false);
302 energy = node->getBoolValue("enable_energy_marker",false);
303 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
304 glide = node->getBoolValue("enable_glide_slope_marker",false);
305 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
306 worm_energy = node->getBoolValue("enable_energy_marker",false);
307 waypoint = node->getBoolValue("enable_waypoint_marker",false);
308 working = node->getBoolValue("working");
309 zenith = node->getIntValue("zenith"); //suma
310 nadir = node->getIntValue("nadir"); //suma
311 hat = node->getIntValue("hat");
314 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
317 p = (instr_item *) new HudLadder( name, x, y,
318 width, height, factor,
320 span_units, division_units, minor_division,
321 screen_hole, lbl_pos, frl_spot, target, vel_vector,
322 drift, alpha, energy, climb_dive,
323 glide, glide_slope_val, worm_energy,
324 waypoint, working, zenith, nadir, hat);
331 readCard(const SGPropertyNode * node)
336 name = node->getStringValue("name");
337 x = node->getIntValue("x");
338 y = node->getIntValue("y");
339 width = node->getIntValue("width");
340 height = node->getIntValue("height");
341 loadfn = node->getStringValue("loadfn");
342 options = node->getIntValue("options");
343 maxValue = node->getFloatValue("maxValue");
344 minValue = node->getFloatValue("minValue");
345 scaling = node->getFloatValue("disp_scaling");
346 major_divs = node->getIntValue("major_divs");
347 minor_divs = node->getIntValue("minor_divs");
348 modulator = node->getIntValue("modulator");
349 span_units = node->getFloatValue("value_span");
350 type = node->getStringValue("type");
351 tick_bottom = node->getBoolValue("tick_bottom",false);
352 tick_top = node->getBoolValue("tick_top",false);
353 tick_right = node->getBoolValue("tick_right",false);
354 tick_left = node->getBoolValue("tick_left",false);
355 cap_bottom = node->getBoolValue("cap_bottom",false);
356 cap_top = node->getBoolValue("cap_top",false);
357 cap_right = node->getBoolValue("cap_right",false);
358 cap_left = node->getBoolValue("cap_left",false);
359 marker_off = node->getFloatValue("marker_offset",0.0);
360 enable_pointer = node->getBoolValue("enable_pointer",true);
361 type_pointer = node->getStringValue("pointer_type");
362 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
363 length_tick = node->getStringValue("tick_length");//hud For variable length
364 working = node->getBoolValue("working");
365 radius = node->getFloatValue("radius"); //suma
366 divisions = node->getIntValue("divisions"); //suma
367 zoom = node->getIntValue("zoom"); //suma
369 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
373 span_units = maxValue - minValue;
378 if(loadfn=="heading")
379 load_fn = get_heading;
385 load_fn = get_climb_rate;
387 if(loadfn=="altitude")
388 load_fn = get_altitude;
396 if(loadfn=="view_direction")
397 load_fn = get_view_direction;
399 if(loadfn=="aileronval")
400 load_fn = get_aileronval;
402 if(loadfn=="elevatorval")
403 load_fn = get_elevatorval;
405 if(loadfn=="rudderval")
406 load_fn = get_rudderval;
408 if(loadfn=="throttleval")
409 load_fn = get_throttleval;
412 if ( (type == "dial") | (type == "tape") ) {
413 p = (instr_item *) new hud_card( x,
421 major_divs, minor_divs,
445 p = (instr_item *) new gauge_instr( x, // x
449 load_fn, // data source
453 major_divs, minor_divs,
463 readLabel(const SGPropertyNode * node)
467 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? LARGE : SMALL;
469 name = node->getStringValue("name");
470 x = node->getIntValue("x");
471 y = node->getIntValue("y");
472 width = node->getIntValue("width");
473 height = node->getIntValue("height");
474 loadfn = node->getStringValue("data_source");
475 label_format = node->getStringValue("label_format");
476 prelabel = node->getStringValue("pre_label_string");
477 postlabel = node->getStringValue("post_label_string");
478 scaling = node->getFloatValue("scale_data");
479 options = node->getIntValue("options");
480 justi = node->getIntValue("justification");
481 blinking = node->getIntValue("blinking");
482 latitude = node->getBoolValue("latitude",false);
483 longitude = node->getBoolValue("longitude",false);
484 label_box = node->getBoolValue("label_box",false);//hud
485 working = node->getBoolValue("working");
486 digits = node->getIntValue("digits"); //suma
489 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
493 justification = LEFT_JUST;
496 justification = CENTER_JUST;
499 justification = RIGHT_JUST;
504 if ( prelabel == "NULL" ) {
505 pre_label_string = NULL;
507 if ( prelabel == "blank" ) {
508 pre_label_string = " ";
510 pre_label_string = prelabel.c_str();
514 if ( postlabel == "blank" ) {
515 post_label_string = " ";
517 if ( postlabel == "NULL" ) {
518 post_label_string = NULL;
520 if ( postlabel == "units" ) {
521 post_label_string = units;
523 post_label_string = postlabel.c_str();
528 if ( loadfn== "aux1" ) {
530 } else if ( loadfn == "aux2" ) {
532 } else if ( loadfn == "aux3" ) {
534 } else if ( loadfn == "aux4" ) {
536 } else if ( loadfn == "aux5" ) {
538 } else if ( loadfn == "aux6" ) {
540 } else if ( loadfn == "aux7" ) {
542 } else if ( loadfn == "aux8" ) {
544 } else if ( loadfn == "aux9" ) {
546 } else if ( loadfn == "aux10" ) {
548 } else if ( loadfn == "aux11" ) {
550 } else if ( loadfn == "aux12" ) {
552 } else if ( loadfn == "aux13" ) {
554 } else if ( loadfn == "aux14" ) {
556 } else if ( loadfn == "aux15" ) {
558 } else if ( loadfn == "aux16" ) {
560 } else if ( loadfn == "aux17" ) {
562 } else if ( loadfn == "aux18" ) {
564 } else if ( loadfn == "ax" ) {
566 } else if ( loadfn == "speed" ) {
568 } else if ( loadfn == "mach" ) {
570 } else if ( loadfn == "altitude" ) {
571 load_fn = get_altitude;
572 } else if ( loadfn == "agl" ) {
574 } else if ( loadfn == "framerate" ) {
575 load_fn = get_frame_rate;
576 } else if ( loadfn == "heading" ) {
577 load_fn = get_heading;
578 } else if ( loadfn == "fov" ) {
580 } else if ( loadfn == "vfc_tris_culled" ) {
581 load_fn = get_vfc_tris_culled;
582 } else if ( loadfn == "vfc_tris_drawn" ) {
583 load_fn = get_vfc_tris_drawn;
584 } else if ( loadfn == "aoa" ) {
586 } else if ( loadfn == "latitude" ) {
587 load_fn = get_latitude;
588 } else if ( loadfn == "anzg" ) {
590 } else if ( loadfn == "longitude" ) {
591 load_fn = get_longitude;
592 } else if (loadfn=="throttleval") {
593 load_fn = get_throttleval;
596 p = (instr_item *) new instr_label ( x,
601 label_format.c_str(),
619 readTBI(const SGPropertyNode * node)
624 name = node->getStringValue("name");
625 x = node->getIntValue("x");
626 y = node->getIntValue("y");
627 width = node->getIntValue("width");
628 height = node->getIntValue("height");
629 maxBankAngle = node->getFloatValue("maxBankAngle");
630 maxSlipAngle = node->getFloatValue("maxSlipAngle");
631 gap_width = node->getIntValue("gap_width");
632 working = node->getBoolValue("working");
633 tsi = node->getBoolValue("tsi"); //suma
634 rad = node->getFloatValue("rad"); //suma
636 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
639 p = (instr_item *) new fgTBI_instr( x,
656 int readInstrument(const SGPropertyNode * node)
661 if ( fgGetString("/sim/startup/units") == "feet" ) {
662 strcpy(units, " ft");
667 const SGPropertyNode * ladder_group = node->getNode("ladders");
669 if (ladder_group != 0) {
670 int nLadders = ladder_group->nChildren();
671 for (int j = 0; j < nLadders; j++) {
673 HIptr = readLadder(ladder_group->getChild(j));
674 HUD_deque.insert( HUD_deque.begin(), HIptr);
679 const SGPropertyNode * card_group = node->getNode("cards");
680 if (card_group != 0) {
681 int nCards = card_group->nChildren();
682 for (int j = 0; j < nCards; j++) {
684 HIptr = readCard(card_group->getChild(j));
685 HUD_deque.insert( HUD_deque.begin(), HIptr);
690 const SGPropertyNode * label_group = node->getNode("labels");
691 if (label_group != 0) {
692 int nLabels = label_group->nChildren();
693 for (int j = 0; j < nLabels; j++) {
695 HIptr = readLabel(label_group->getChild(j));
696 HUD_deque.insert( HUD_deque.begin(), HIptr);
701 const SGPropertyNode * tbi_group = node->getNode("tbis");
702 if (tbi_group != 0) {
703 int nTbis = tbi_group->nChildren();
704 for (int j = 0; j < nTbis; j++) {
706 HIptr = readTBI(tbi_group->getChild(j));
707 HUD_deque.insert( HUD_deque.begin(), HIptr);
712 }//end readinstrument
715 int readHud( istream &input )
721 readProperties(input, &root);
722 } catch (const sg_exception &e) {
723 guiErrorMessage("Error reading HUD: ", e);
728 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
729 root.getStringValue("name"));
732 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
735 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
737 const SGPropertyNode * instrument_group = root.getChild("instruments");
738 int nInstruments = instrument_group->nChildren();
740 for (int i = 0; i < nInstruments; i++) {
742 const SGPropertyNode * node = instrument_group->getChild(i);
744 SGPath path( globals->get_fg_root() );
745 path.append(node->getStringValue("path"));
747 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
753 SGPropertyNode root2;
755 readProperties(path.str(), &root2);
756 } catch (const sg_exception &e) {
757 guiErrorMessage("Error reading HUD instrument: ", e);
760 readInstrument(&root2);
767 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
773 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
776 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
777 SGPath path(globals->get_fg_root());
778 path.append(hud_path);
780 ifstream input(path.c_str());
783 SG_LOG(SG_INPUT, SG_ALERT,
784 "Cannot read Hud configuration from " << path.str());
795 return 0; // For now. Later we may use this for an error code.
799 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
804 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
806 SGPath path(globals->get_fg_root());
807 path.append("Huds/Minimal/default.xml");
810 ifstream input(path.c_str());
812 SG_LOG(SG_INPUT, SG_ALERT,
813 "Cannot read Hud configuration from " << path.str());
820 return 0; // For now. Later we may use this for an error code.
823 //$$$ End - added, Neetha, 28 Nov 2k
825 static int global_day_night_switch = DAY;
827 void HUD_masterswitch( bool incr )
829 if ( fgGetBool("/sim/hud/visibility") ) {
830 if ( global_day_night_switch == DAY ) {
831 global_day_night_switch = NIGHT;
833 fgSetBool("/sim/hud/visibility", false);
836 fgSetBool("/sim/hud/visibility", true);
837 global_day_night_switch = DAY;
841 void HUD_brightkey( bool incr_bright )
843 instr_item *pHUDInstr = HUD_deque[0];
844 int brightness = pHUDInstr->get_brightness();
846 if( fgGetBool("/sim/hud/visibility") ) {
851 brightness = BRT_BLACK;
855 brightness = BRT_LIGHT;
859 brightness = BRT_MEDIUM;
863 brightness = BRT_DARK;
867 brightness = BRT_BLACK;
873 brightness = BRT_MEDIUM;
877 brightness = BRT_DARK;
881 brightness = BRT_BLACK;
885 brightness = BRT_LIGHT;
889 fgSetBool("/sim/hud/visibility", false);
893 fgSetBool("/sim/hud/visibility", true);
896 pHUDInstr->SetBrightness( brightness );
900 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
902 static puDialogBox *HUDalphaDialog;
903 static puText *HUDalphaText;
904 static puSlider *HUDalphaHS0;
905 //static puText *HUDtextText;
906 //static puSlider *HUDalphaHS1;
907 static char SliderText[2][ 8 ];
909 static void alpha_adj( puObject *hs ) {
912 hs-> getValue ( &val ) ;
913 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
914 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
915 hud_trans_alpha = val;
916 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
917 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
920 void fgHUDalphaAdjust( puObject * ) {
921 fgSetBool("/sim/hud/antialiased", true);
922 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
925 static void goAwayHUDalphaAdjust (puObject *)
927 FG_POP_PUI_DIALOG( HUDalphaDialog );
930 static void cancelHUDalphaAdjust (puObject *)
932 fgSetBool("/sim/hud/antialiased", false);
933 FG_POP_PUI_DIALOG( HUDalphaDialog );
936 // Done once at system initialization
937 void fgHUDalphaInit( void ) {
939 // printf("fgHUDalphaInit\n");
940 #define HORIZONTAL FALSE
944 int DialogWidth = 240;
946 char Label[] = "HUD Adjuster";
949 int labelX = (DialogWidth / 2) -
950 (puGetStringWidth( puGetDefaultLabelFont(), Label ) / 2);
955 int slider_width = 220;
956 int slider_title_x = 15;
957 int slider_value_x = 160;
958 float slider_delta = 0.05f;
960 puFont HUDalphaLegendFont;
961 puFont HUDalphaLabelFont;
962 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
964 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
965 int horiz_slider_height = puGetStringHeight (HUDalphaLabelFont) +
966 puGetStringDescender (HUDalphaLabelFont) +
967 PUSTR_TGAP + PUSTR_BGAP + 5;
970 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
972 * horiz_slider_height ); */
975 HUDalphaDialogMessage = new puText ( labelX,
977 * horiz_slider_height );
978 HUDalphaDialogMessage -> setDefaultValue ( Label );
979 HUDalphaDialogMessage -> getDefaultValue ( &s );
980 HUDalphaDialogMessage -> setLabel ( s );
982 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
983 slider_width, HORIZONTAL ) ;
984 HUDalphaHS0-> setDelta ( slider_delta ) ;
985 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
986 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
987 HUDalphaHS0-> setCallback ( alpha_adj ) ;
990 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
991 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
992 HUDalphaTitle-> getDefaultValue ( &s ) ;
993 HUDalphaTitle-> setLabel ( s ) ;
995 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
996 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
997 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
1000 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
1001 HUDalphaOkButton-> setLegend ( gui_msg_OK );
1002 HUDalphaOkButton-> makeReturnDefault ( TRUE );
1003 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
1006 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
1007 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
1008 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
1010 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1016 void fgHUDReshape(void) {
1018 // this chunk of code is not necessarily thread safe if the
1019 // compiler optimizer reorders these statements. Note that
1020 // "delete ptr" does not set "ptr = NULL". We have to do that
1022 fntRenderer *tmp = HUDtext;
1027 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
1029 HUDtext = new fntRenderer();
1030 HUDtext -> setFont ( guiFntHandle ) ;
1031 HUDtext -> setPointSize ( HUD_TextSize ) ;
1032 HUD_TextList.setFont( HUDtext );
1036 static void set_hud_color(float r, float g, float b) {
1037 fgGetBool("/sim/hud/antialiased") ?
1038 glColor4f(r,g,b,hud_trans_alpha) :
1045 // Performs a once around the list of calls to instruments installed in
1046 // the HUD object with requests for redraw. Kinda. It will when this is
1049 void fgUpdateHUD( void ) {
1051 static const float normal_aspect = float(640) / float(480);
1052 // note: win_ratio is Y/X
1053 float current_aspect = 1.0f/globals->get_current_view()->get_win_ratio();
1054 if( current_aspect > normal_aspect ) {
1055 float aspect_adjust = current_aspect / normal_aspect;
1056 float adjust = 320.0f*aspect_adjust - 320.0f;
1057 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1059 float aspect_adjust = normal_aspect / current_aspect;
1060 float adjust = 240.0f*aspect_adjust - 240.0f;
1061 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1065 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1066 GLfloat x_end, GLfloat y_end )
1069 // int day_night_sw = current_aircraft.controls->day_night_switch;
1070 int day_night_sw = global_day_night_switch;
1071 int hud_displays = HUD_deque.size();
1072 instr_item *pHUDInstr;
1073 // float line_width;
1075 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1079 HUD_TextList.erase();
1080 HUD_LineList.erase();
1081 // HUD_StippleLineList.erase();
1083 pHUDInstr = HUD_deque[0];
1084 brightness = pHUDInstr->get_brightness();
1085 // brightness = HUD_deque.at(0)->get_brightness();
1087 glMatrixMode(GL_PROJECTION);
1091 gluOrtho2D(x_start, x_end, y_start, y_end);
1092 glMatrixMode(GL_MODELVIEW);
1096 glDisable(GL_DEPTH_TEST);
1097 glDisable(GL_LIGHTING);
1099 static const SGPropertyNode * antialiased_node
1100 = fgGetNode("/sim/hud/antialiased");
1102 if( antialiased_node->getBoolValue() ) {
1103 glEnable(GL_LINE_SMOOTH);
1104 // glEnable(GL_BLEND);
1105 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1106 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1112 if( day_night_sw == DAY) {
1116 set_hud_color (0.1f, 0.9f, 0.1f);
1120 set_hud_color (0.1f, 0.7f, 0.0f);
1124 set_hud_color (0.0f, 0.6f, 0.0f);
1128 set_hud_color( 0.0f, 0.0f, 0.0f);
1132 set_hud_color (0.1f, 0.9f, 0.1f);
1135 if( day_night_sw == NIGHT) {
1139 set_hud_color (0.9f, 0.1f, 0.1f);
1143 set_hud_color (0.7f, 0.0f, 0.1f);
1147 set_hud_color (0.6f, 0.0f, 0.0f);
1151 set_hud_color( 0.0f, 0.0f, 0.0f);
1155 set_hud_color (0.6f, 0.0f, 0.0f);
1157 } else { // Just in case default
1158 set_hud_color (0.1f, 0.9f, 0.1f);
1162 deque < instr_item * > :: iterator current = HUD_deque.begin();
1163 deque < instr_item * > :: iterator last = HUD_deque.end();
1165 for ( ; current != last; ++current ) {
1166 pHUDInstr = *current;
1168 if( pHUDInstr->enabled()) {
1169 // fgPrintf( SG_COCKPIT, SG_DEBUG, "HUD Code %d Status %d\n",
1170 // hud->code, hud->status );
1176 char *gmt_str = get_formated_gmt_time();
1177 HUD_TextList.add( fgText(40, 10, gmt_str, 0) );
1179 #ifdef FG_NETWORK_OLK
1180 if ( net_hud_display ) {
1187 // extern bool fgAPAltitudeEnabled( void );
1188 // extern bool fgAPHeadingEnabled( void );
1189 // extern bool fgAPWayPointEnabled( void );
1190 // extern char *fgAPget_TargetDistanceStr( void );
1191 // extern char *fgAPget_TargetHeadingStr( void );
1192 // extern char *fgAPget_TargetAltitudeStr( void );
1193 // extern char *fgAPget_TargetLatLonStr( void );
1196 // char scratch[128];
1197 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1199 if( current_autopilot->get_HeadingEnabled() ) {
1200 HUD_TextList.add( fgText( 40, apY,
1201 current_autopilot->get_TargetHeadingStr()) );
1204 if( current_autopilot->get_AltitudeEnabled() ) {
1205 HUD_TextList.add( fgText( 40, apY,
1206 current_autopilot->get_TargetAltitudeStr()) );
1209 if( current_autopilot->get_HeadingMode() ==
1210 FGAutopilot::FG_HEADING_WAYPOINT )
1213 wpstr = current_autopilot->get_TargetWP1Str();
1214 if ( strlen( wpstr ) ) {
1215 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1218 wpstr = current_autopilot->get_TargetWP2Str();
1219 if ( strlen( wpstr ) ) {
1220 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1223 wpstr = current_autopilot->get_TargetWP3Str();
1224 if ( strlen( wpstr ) ) {
1225 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1230 HUD_TextList.draw();
1232 HUD_LineList.draw();
1234 // glEnable(GL_LINE_STIPPLE);
1235 // glLineStipple( 1, 0x00FF );
1236 // HUD_StippleLineList.draw();
1237 // glDisable(GL_LINE_STIPPLE);
1239 if( antialiased_node->getBoolValue() ) {
1240 // glDisable(GL_BLEND);
1241 glDisable(GL_LINE_SMOOTH);
1245 glEnable(GL_DEPTH_TEST);
1246 glEnable(GL_LIGHTING);
1247 glMatrixMode(GL_PROJECTION);
1249 glMatrixMode(GL_MODELVIEW);