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
41 #include <stdio.h> // char related functions
42 #include <string.h> // strcmp()
46 #include <simgear/constants.h>
47 #include <simgear/debug/logstream.hxx>
48 #include <simgear/misc/props.hxx>
49 #include <simgear/misc/sg_path.hxx>
50 //#include <simgear/math/fg_random.h>
51 //#include <simgear/math/polar3d.hxx>
53 #include <Aircraft/aircraft.hxx>
54 #include <Autopilot/newauto.hxx>
56 #include <Main/globals.hxx>
57 #include <Main/fg_props.hxx>
59 #include <NetworkOLK/network.h>
61 #include <Scenery/scenery.hxx>
62 //#include <Time/fg_timer.hxx>
64 #if defined ( __sun__ ) || defined ( __sgi )
66 extern void *memmove(void *, const void *, size_t);
74 // The following routines obtain information concerning the aircraft's
75 // current state and return it to calling instrument display routines.
76 // They should eventually be member functions of the aircraft.
79 deque< instr_item * > HUD_deque;
81 fgTextList HUD_TextList;
82 fgLineList HUD_LineList;
83 fgLineList HUD_StippleLineList;
85 fntRenderer *HUDtext = 0;
86 float HUD_TextSize = 0;
90 static float hud_trans_alpha = 0.67f;
93 //$$$ begin - added, Neetha, 28 Nov 2k
101 static float span_units;
102 static float division_units;
103 static float minor_division = 0;
104 static UINT screen_hole;
107 static string loadfn;
109 static float maxValue;
110 static float minValue;
111 static float scaling;
112 static UINT major_divs;
113 static UINT minor_divs;
114 static UINT modulator;
115 static int dp_showing = 0;
116 static string label_format;
117 static string prelabel;
118 static string postlabel;
121 static float maxBankAngle;
122 static float maxSlipAngle;
123 static UINT gap_width;
124 static bool latitude;
125 static bool longitude;
126 static bool tick_bottom;
127 static bool tick_top;
128 static bool tick_right;
129 static bool tick_left;
130 static bool cap_bottom;
132 static bool cap_right;
133 static bool cap_left;
134 static float marker_off;
136 static bool enable_pointer;
137 static string type_pointer;
138 static bool frl_spot;
140 static bool vel_vector;
144 static bool climb_dive;
146 static float glide_slope_val;
147 static bool worm_energy;
148 static bool waypoint;
149 static string type_tick;//hud
150 static string length_tick;//hud
151 static bool label_box;//hud
152 static int digits; //suma
153 static float radius; //suma
154 static int divisions; //suma
155 static int zoom; //suma
156 static int zenith; //suma
157 static int nadir ; //suma
158 static int hat; //suma
159 static bool tsi; //suma
160 static float rad; //suma
163 static FLTFNPTR load_fn;
164 static fgLabelJust justification;
165 static const char *pre_label_string = 0;
166 static const char *post_label_string = 0;
168 int readHud( istream &input );
169 int readInstrument ( const SGPropertyNode * node);
170 static instr_item * readLadder ( const SGPropertyNode * node);
171 static instr_item * readCard ( const SGPropertyNode * node);
172 static instr_item * readLabel( const SGPropertyNode * node);
173 static instr_item * readTBI( const SGPropertyNode * node);
174 //$$$ end - added, Neetha, 28 Nov 2k
176 void fgHUDalphaInit( void );
182 locRECT( UINT left, UINT top, UINT right, UINT bottom);
183 RECT get_rect(void) { return rect;}
186 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
191 rect.bottom = bottom;
197 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
205 void drawOneLine( RECT &rect)
208 glVertex2f(rect.left, rect.top);
209 glVertex2f(rect.right, rect.bottom);
214 // The following code deals with painting the "instrument" on the display
216 /* textString - Bitmap font string */
218 void textString( int x, int y, char *msg, void *font,int digit) //suma
222 // puDrawString ( NULL, msg, x, y );
225 glutBitmapCharacter(font, *msg);
232 /* strokeString - Stroke font string */
233 void strokeString(int x, int y, char *msg, void *font, float theta)
238 float sintheta,costheta;
243 glRotatef(theta * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
244 sintheta = sin(theta);
245 costheta = cos(theta);
246 xx = (int)(x * costheta + y * sintheta);
247 yy = (int)(y * costheta - x * sintheta);
248 glTranslatef( xx, yy, 0);
249 glScalef(.1, .1, 0.0);
250 while( (c=*msg++) ) {
251 glutStrokeCharacter(font, c);
257 int getStringWidth ( char *str )
259 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;
376 if (loadfn=="anzg") {
378 } else if (loadfn=="heading") {
379 load_fn = get_heading;
380 } else if (loadfn=="aoa") {
382 } else if (loadfn=="climb") {
383 load_fn = get_climb_rate;
384 } else if (loadfn=="altitude") {
385 load_fn = get_altitude;
386 } else if (loadfn=="agl") {
388 } else if (loadfn=="speed") {
390 } else if (loadfn=="view_direction") {
391 load_fn = get_view_direction;
392 } else if (loadfn=="aileronval") {
393 load_fn = get_aileronval;
394 } else if (loadfn=="elevatorval") {
395 load_fn = get_elevatorval;
396 } else if (loadfn=="rudderval") {
397 load_fn = get_rudderval;
398 } else if (loadfn=="throttleval") {
399 load_fn = get_throttleval;
403 if ( (type == "dial") | (type == "tape") ) {
404 p = (instr_item *) new hud_card( x,
412 major_divs, minor_divs,
436 p = (instr_item *) new gauge_instr( x, // x
440 load_fn, // data source
444 major_divs, minor_divs,
454 readLabel(const SGPropertyNode * node)
458 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? LARGE : SMALL;
460 name = node->getStringValue("name");
461 x = node->getIntValue("x");
462 y = node->getIntValue("y");
463 width = node->getIntValue("width");
464 height = node->getIntValue("height");
465 loadfn = node->getStringValue("data_source");
466 label_format = node->getStringValue("label_format");
467 prelabel = node->getStringValue("pre_label_string");
468 postlabel = node->getStringValue("post_label_string");
469 scaling = node->getFloatValue("scale_data");
470 options = node->getIntValue("options");
471 justi = node->getIntValue("justification");
472 blinking = node->getIntValue("blinking");
473 latitude = node->getBoolValue("latitude",false);
474 longitude = node->getBoolValue("longitude",false);
475 label_box = node->getBoolValue("label_box",false);//hud
476 working = node->getBoolValue("working");
477 digits = node->getIntValue("digits"); //suma
480 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
484 justification = LEFT_JUST;
487 justification = CENTER_JUST;
490 justification = RIGHT_JUST;
495 if ( prelabel == "NULL" ) {
496 pre_label_string = NULL;
498 if ( prelabel == "blank" ) {
499 pre_label_string = " ";
501 pre_label_string = prelabel.c_str();
505 if ( postlabel == "blank" ) {
506 post_label_string = " ";
508 if ( postlabel == "NULL" ) {
509 post_label_string = NULL;
511 if ( postlabel == "units" ) {
512 post_label_string = units;
514 post_label_string = postlabel.c_str();
519 if ( loadfn== "aux1" ) {
521 } else if ( loadfn == "aux2" ) {
523 } else if ( loadfn == "aux3" ) {
525 } else if ( loadfn == "aux4" ) {
527 } else if ( loadfn == "aux5" ) {
529 } else if ( loadfn == "aux6" ) {
531 } else if ( loadfn == "aux7" ) {
533 } else if ( loadfn == "aux8" ) {
535 } else if ( loadfn == "aux9" ) {
537 } else if ( loadfn == "aux10" ) {
539 } else if ( loadfn == "aux11" ) {
541 } else if ( loadfn == "aux12" ) {
543 } else if ( loadfn == "aux13" ) {
545 } else if ( loadfn == "aux14" ) {
547 } else if ( loadfn == "aux15" ) {
549 } else if ( loadfn == "aux16" ) {
551 } else if ( loadfn == "aux17" ) {
553 } else if ( loadfn == "aux18" ) {
555 } else if ( loadfn == "ax" ) {
557 } else if ( loadfn == "speed" ) {
559 } else if ( loadfn == "mach" ) {
561 } else if ( loadfn == "altitude" ) {
562 load_fn = get_altitude;
563 } else if ( loadfn == "agl" ) {
565 } else if ( loadfn == "framerate" ) {
566 load_fn = get_frame_rate;
567 } else if ( loadfn == "heading" ) {
568 load_fn = get_heading;
569 } else if ( loadfn == "fov" ) {
571 } else if ( loadfn == "vfc_tris_culled" ) {
572 load_fn = get_vfc_tris_culled;
573 } else if ( loadfn == "vfc_tris_drawn" ) {
574 load_fn = get_vfc_tris_drawn;
575 } else if ( loadfn == "aoa" ) {
577 } else if ( loadfn == "latitude" ) {
578 load_fn = get_latitude;
579 } else if ( loadfn == "anzg" ) {
581 } else if ( loadfn == "longitude" ) {
582 load_fn = get_longitude;
583 } else if (loadfn=="throttleval") {
584 load_fn = get_throttleval;
587 p = (instr_item *) new instr_label ( x,
592 label_format.c_str(),
610 readTBI(const SGPropertyNode * node)
615 name = node->getStringValue("name");
616 x = node->getIntValue("x");
617 y = node->getIntValue("y");
618 width = node->getIntValue("width");
619 height = node->getIntValue("height");
620 maxBankAngle = node->getFloatValue("maxBankAngle");
621 maxSlipAngle = node->getFloatValue("maxSlipAngle");
622 gap_width = node->getIntValue("gap_width");
623 working = node->getBoolValue("working");
624 tsi = node->getBoolValue("tsi"); //suma
625 rad = node->getFloatValue("rad"); //suma
627 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
630 p = (instr_item *) new fgTBI_instr( x,
647 int readInstrument(const SGPropertyNode * node)
649 static const SGPropertyNode *startup_units_node
650 = fgGetNode("/sim/startup/units");
654 if ( !strcmp(startup_units_node->getStringValue(), "feet") ) {
655 strcpy(units, " ft");
660 const SGPropertyNode * ladder_group = node->getNode("ladders");
662 if (ladder_group != 0) {
663 int nLadders = ladder_group->nChildren();
664 for (int j = 0; j < nLadders; j++) {
666 HIptr = readLadder(ladder_group->getChild(j));
667 HUD_deque.insert( HUD_deque.begin(), HIptr);
672 const SGPropertyNode * card_group = node->getNode("cards");
673 if (card_group != 0) {
674 int nCards = card_group->nChildren();
675 for (int j = 0; j < nCards; j++) {
677 HIptr = readCard(card_group->getChild(j));
678 HUD_deque.insert( HUD_deque.begin(), HIptr);
683 const SGPropertyNode * label_group = node->getNode("labels");
684 if (label_group != 0) {
685 int nLabels = label_group->nChildren();
686 for (int j = 0; j < nLabels; j++) {
688 HIptr = readLabel(label_group->getChild(j));
689 HUD_deque.insert( HUD_deque.begin(), HIptr);
694 const SGPropertyNode * tbi_group = node->getNode("tbis");
695 if (tbi_group != 0) {
696 int nTbis = tbi_group->nChildren();
697 for (int j = 0; j < nTbis; j++) {
699 HIptr = readTBI(tbi_group->getChild(j));
700 HUD_deque.insert( HUD_deque.begin(), HIptr);
705 }//end readinstrument
708 int readHud( istream &input )
714 readProperties(input, &root);
715 } catch (const sg_exception &e) {
716 guiErrorMessage("Error reading HUD: ", e);
721 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
722 root.getStringValue("name"));
725 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
728 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
730 const SGPropertyNode * instrument_group = root.getChild("instruments");
731 int nInstruments = instrument_group->nChildren();
733 for (int i = 0; i < nInstruments; i++) {
735 const SGPropertyNode * node = instrument_group->getChild(i);
737 SGPath path( globals->get_fg_root() );
738 path.append(node->getStringValue("path"));
740 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
746 SGPropertyNode root2;
748 readProperties(path.str(), &root2);
749 } catch (const sg_exception &e) {
750 guiErrorMessage("Error reading HUD instrument: ", e);
753 readInstrument(&root2);
760 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
766 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
769 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
770 SGPath path(globals->get_fg_root());
771 path.append(hud_path);
773 ifstream input(path.c_str());
775 SG_LOG(SG_INPUT, SG_ALERT,
776 "Cannot read Hud configuration from " << path.str());
785 return 0; // For now. Later we may use this for an error code.
789 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
794 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
796 SGPath path(globals->get_fg_root());
797 path.append("Huds/Minimal/default.xml");
800 ifstream input(path.c_str());
802 SG_LOG(SG_INPUT, SG_ALERT,
803 "Cannot read Hud configuration from " << path.str());
809 return 0; // For now. Later we may use this for an error code.
812 //$$$ End - added, Neetha, 28 Nov 2k
814 static int global_day_night_switch = DAY;
816 void HUD_masterswitch( bool incr )
818 if ( fgGetBool("/sim/hud/visibility") ) {
819 if ( global_day_night_switch == DAY ) {
820 global_day_night_switch = NIGHT;
822 fgSetBool("/sim/hud/visibility", false);
825 fgSetBool("/sim/hud/visibility", true);
826 global_day_night_switch = DAY;
830 void HUD_brightkey( bool incr_bright )
832 instr_item *pHUDInstr = HUD_deque[0];
833 int brightness = pHUDInstr->get_brightness();
835 if( fgGetBool("/sim/hud/visibility") ) {
840 brightness = BRT_BLACK;
844 brightness = BRT_LIGHT;
848 brightness = BRT_MEDIUM;
852 brightness = BRT_DARK;
856 brightness = BRT_BLACK;
862 brightness = BRT_MEDIUM;
866 brightness = BRT_DARK;
870 brightness = BRT_BLACK;
874 brightness = BRT_LIGHT;
878 fgSetBool("/sim/hud/visibility", false);
882 fgSetBool("/sim/hud/visibility", true);
885 pHUDInstr->SetBrightness( brightness );
889 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
891 static puDialogBox *HUDalphaDialog;
892 static puText *HUDalphaText;
893 static puSlider *HUDalphaHS0;
894 //static puText *HUDtextText;
895 //static puSlider *HUDalphaHS1;
896 static char SliderText[2][ 8 ];
898 static void alpha_adj( puObject *hs ) {
901 hs-> getValue ( &val ) ;
902 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
903 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
904 hud_trans_alpha = val;
905 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
906 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
909 void fgHUDalphaAdjust( puObject * ) {
910 fgSetBool("/sim/hud/antialiased", true);
911 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
914 static void goAwayHUDalphaAdjust (puObject *)
916 FG_POP_PUI_DIALOG( HUDalphaDialog );
919 static void cancelHUDalphaAdjust (puObject *)
921 fgSetBool("/sim/hud/antialiased", false);
922 FG_POP_PUI_DIALOG( HUDalphaDialog );
925 // Done once at system initialization
926 void fgHUDalphaInit( void ) {
928 // printf("fgHUDalphaInit\n");
929 #define HORIZONTAL FALSE
933 int DialogWidth = 240;
935 char Label[] = "HUD Adjuster";
938 int labelX = (DialogWidth / 2) -
939 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
944 int slider_width = 220;
945 int slider_title_x = 15;
946 int slider_value_x = 160;
947 float slider_delta = 0.05f;
949 puFont HUDalphaLegendFont;
950 puFont HUDalphaLabelFont;
951 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
953 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
954 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
955 HUDalphaLabelFont.getStringDescender() +
956 PUSTR_TGAP + PUSTR_BGAP + 5;
959 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
961 * horiz_slider_height ); */
964 HUDalphaDialogMessage = new puText ( labelX,
966 * horiz_slider_height );
967 HUDalphaDialogMessage -> setDefaultValue ( Label );
968 HUDalphaDialogMessage -> getDefaultValue ( &s );
969 HUDalphaDialogMessage -> setLabel ( s );
971 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
972 slider_width, HORIZONTAL ) ;
973 HUDalphaHS0-> setDelta ( slider_delta ) ;
974 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
975 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
976 HUDalphaHS0-> setCallback ( alpha_adj ) ;
979 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
980 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
981 HUDalphaTitle-> getDefaultValue ( &s ) ;
982 HUDalphaTitle-> setLabel ( s ) ;
984 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
985 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
986 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
989 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
990 HUDalphaOkButton-> setLegend ( gui_msg_OK );
991 HUDalphaOkButton-> makeReturnDefault ( TRUE );
992 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
995 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
996 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
997 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
999 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1005 void fgHUDReshape(void) {
1007 // this chunk of code is not necessarily thread safe if the
1008 // compiler optimizer reorders these statements. Note that
1009 // "delete ptr" does not set "ptr = NULL". We have to do that
1011 fntRenderer *tmp = HUDtext;
1016 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
1018 HUDtext = new fntRenderer();
1019 HUDtext -> setFont ( guiFntHandle ) ;
1020 HUDtext -> setPointSize ( HUD_TextSize ) ;
1021 HUD_TextList.setFont( HUDtext );
1025 static void set_hud_color(float r, float g, float b) {
1026 fgGetBool("/sim/hud/antialiased") ?
1027 glColor4f(r,g,b,hud_trans_alpha) :
1034 // Performs a once around the list of calls to instruments installed in
1035 // the HUD object with requests for redraw. Kinda. It will when this is
1038 void fgUpdateHUD( void ) {
1040 static const float normal_aspect = float(640) / float(480);
1041 // note: aspect_ratio is Y/X
1042 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1043 if( current_aspect > normal_aspect ) {
1044 float aspect_adjust = current_aspect / normal_aspect;
1045 float adjust = 320.0f*aspect_adjust - 320.0f;
1046 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1048 float aspect_adjust = normal_aspect / current_aspect;
1049 float adjust = 240.0f*aspect_adjust - 240.0f;
1050 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1054 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1055 GLfloat x_end, GLfloat y_end )
1058 // int day_night_sw = current_aircraft.controls->day_night_switch;
1059 int day_night_sw = global_day_night_switch;
1060 int hud_displays = HUD_deque.size();
1061 instr_item *pHUDInstr;
1062 // float line_width;
1064 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1068 HUD_TextList.erase();
1069 HUD_LineList.erase();
1070 // HUD_StippleLineList.erase();
1072 pHUDInstr = HUD_deque[0];
1073 brightness = pHUDInstr->get_brightness();
1074 // brightness = HUD_deque.at(0)->get_brightness();
1076 glMatrixMode(GL_PROJECTION);
1080 gluOrtho2D(x_start, x_end, y_start, y_end);
1081 glMatrixMode(GL_MODELVIEW);
1085 glDisable(GL_DEPTH_TEST);
1086 glDisable(GL_LIGHTING);
1088 static const SGPropertyNode * antialiased_node
1089 = fgGetNode("/sim/hud/antialiased");
1091 if( antialiased_node->getBoolValue() ) {
1092 glEnable(GL_LINE_SMOOTH);
1093 // glEnable(GL_BLEND);
1094 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1095 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1101 if( day_night_sw == DAY) {
1105 set_hud_color (0.1f, 0.9f, 0.1f);
1109 set_hud_color (0.1f, 0.7f, 0.0f);
1113 set_hud_color (0.0f, 0.6f, 0.0f);
1117 set_hud_color( 0.0f, 0.0f, 0.0f);
1121 set_hud_color (0.1f, 0.9f, 0.1f);
1124 if( day_night_sw == NIGHT) {
1128 set_hud_color (0.9f, 0.1f, 0.1f);
1132 set_hud_color (0.7f, 0.0f, 0.1f);
1136 set_hud_color (0.6f, 0.0f, 0.0f);
1140 set_hud_color( 0.0f, 0.0f, 0.0f);
1144 set_hud_color (0.6f, 0.0f, 0.0f);
1146 } else { // Just in case default
1147 set_hud_color (0.1f, 0.9f, 0.1f);
1151 deque < instr_item * > :: iterator current = HUD_deque.begin();
1152 deque < instr_item * > :: iterator last = HUD_deque.end();
1154 for ( ; current != last; ++current ) {
1155 pHUDInstr = *current;
1157 if( pHUDInstr->enabled()) {
1158 // fgPrintf( SG_COCKPIT, SG_DEBUG, "HUD Code %d Status %d\n",
1159 // hud->code, hud->status );
1165 char *gmt_str = get_formated_gmt_time();
1166 HUD_TextList.add( fgText(40, 10, gmt_str, 0) );
1168 #ifdef FG_NETWORK_OLK
1169 if ( net_hud_display ) {
1176 // extern bool fgAPAltitudeEnabled( void );
1177 // extern bool fgAPHeadingEnabled( void );
1178 // extern bool fgAPWayPointEnabled( void );
1179 // extern char *fgAPget_TargetDistanceStr( void );
1180 // extern char *fgAPget_TargetHeadingStr( void );
1181 // extern char *fgAPget_TargetAltitudeStr( void );
1182 // extern char *fgAPget_TargetLatLonStr( void );
1185 // char scratch[128];
1186 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1188 if( globals->get_autopilot()->get_HeadingEnabled() ) {
1189 HUD_TextList.add( fgText( 40, apY,
1190 globals->get_autopilot()->get_TargetHeadingStr()) );
1193 if( globals->get_autopilot()->get_AltitudeEnabled() ) {
1194 HUD_TextList.add( fgText( 40, apY,
1195 globals->get_autopilot()->get_TargetAltitudeStr()) );
1198 if( globals->get_autopilot()->get_HeadingMode() ==
1199 FGAutopilot::FG_HEADING_WAYPOINT )
1202 wpstr = globals->get_autopilot()->get_TargetWP1Str();
1203 if ( strlen( wpstr ) ) {
1204 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1207 wpstr = globals->get_autopilot()->get_TargetWP2Str();
1208 if ( strlen( wpstr ) ) {
1209 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1212 wpstr = globals->get_autopilot()->get_TargetWP3Str();
1213 if ( strlen( wpstr ) ) {
1214 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1219 HUD_TextList.draw();
1221 HUD_LineList.draw();
1223 // glEnable(GL_LINE_STIPPLE);
1224 // glLineStipple( 1, 0x00FF );
1225 // HUD_StippleLineList.draw();
1226 // glDisable(GL_LINE_STIPPLE);
1228 if( antialiased_node->getBoolValue() ) {
1229 // glDisable(GL_BLEND);
1230 glDisable(GL_LINE_SMOOTH);
1234 glEnable(GL_DEPTH_TEST);
1235 glEnable(GL_LIGHTING);
1236 glMatrixMode(GL_PROJECTION);
1238 glMatrixMode(GL_MODELVIEW);