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
45 #include <simgear/constants.h>
46 #include <simgear/debug/logstream.hxx>
47 #include <simgear/misc/props.hxx>
48 //#include <simgear/math/fg_random.h>
49 //#include <simgear/math/polar3d.hxx>
51 #include <Aircraft/aircraft.hxx>
52 #include <Autopilot/newauto.hxx>
54 #include <Main/globals.hxx>
55 #include <Main/fg_props.hxx>
57 #include <NetworkOLK/network.h>
59 #include <Scenery/scenery.hxx>
60 //#include <Time/fg_timer.hxx>
62 #if defined ( __sun__ ) || defined ( __sgi )
64 extern void *memmove(void *, const void *, size_t);
72 // The following routines obtain information concerning the aircraft's
73 // current state and return it to calling instrument display routines.
74 // They should eventually be member functions of the aircraft.
77 deque< instr_item * > HUD_deque;
79 fgTextList HUD_TextList;
80 fgLineList HUD_LineList;
81 fgLineList HUD_StippleLineList;
83 fntRenderer *HUDtext = 0;
84 float HUD_TextSize = 0;
88 static float hud_trans_alpha = 0.67f;
91 //$$$ begin - added, Neetha, 28 Nov 2k
99 static float span_units;
100 static float division_units;
101 static float minor_division = 0;
102 static UINT screen_hole;
105 static string loadfn;
107 static float maxValue;
108 static float minValue;
109 static float scaling;
110 static UINT major_divs;
111 static UINT minor_divs;
112 static UINT modulator;
113 static int dp_showing = 0;
114 static string label_format;
115 static string prelabel;
116 static string postlabel;
119 static float maxBankAngle;
120 static float maxSlipAngle;
121 static UINT gap_width;
122 static bool latitude;
123 static bool longitude;
124 static bool tick_bottom;
125 static bool tick_top;
126 static bool tick_right;
127 static bool tick_left;
128 static bool cap_bottom;
130 static bool cap_right;
131 static bool cap_left;
132 static float marker_off;
134 static bool enable_pointer;
135 static string type_pointer;
136 static bool frl_spot;
138 static bool vel_vector;
142 static bool climb_dive;
144 static float glide_slope_val;
145 static bool worm_energy;
146 static bool waypoint;
147 static string type_tick;//hud
148 static string length_tick;//hud
149 static bool label_box;//hud
150 static int digits; //suma
151 static float radius; //suma
152 static int divisions; //suma
153 static int zoom; //suma
154 static int zenith; //suma
155 static int nadir ; //suma
156 static int hat; //suma
157 static bool tsi; //suma
158 static float rad; //suma
161 static FLTFNPTR load_fn;
162 static fgLabelJust justification;
163 static const char *pre_label_string = 0;
164 static const char *post_label_string = 0;
166 int readHud( istream &input );
167 int readInstrument ( const SGPropertyNode * node);
168 static instr_item * readLadder ( const SGPropertyNode * node);
169 static instr_item * readCard ( const SGPropertyNode * node);
170 static instr_item * readLabel( const SGPropertyNode * node);
171 static instr_item * readTBI( const SGPropertyNode * node);
172 //$$$ end - added, Neetha, 28 Nov 2k
174 void fgHUDalphaInit( void );
180 locRECT( UINT left, UINT top, UINT right, UINT bottom);
181 RECT get_rect(void) { return rect;}
184 locRECT :: locRECT( UINT left, UINT top, UINT right, UINT bottom)
189 rect.bottom = bottom;
195 void drawOneLine( UINT x1, UINT y1, UINT x2, UINT y2)
203 void drawOneLine( RECT &rect)
206 glVertex2f(rect.left, rect.top);
207 glVertex2f(rect.right, rect.bottom);
212 // The following code deals with painting the "instrument" on the display
214 /* textString - Bitmap font string */
216 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;
241 glRotatef(theta * SGD_RADIANS_TO_DEGREES, 0.0, 0.0, 1.0);
242 sintheta = sin(theta);
243 costheta = cos(theta);
244 xx = (int)(x * costheta + y * sintheta);
245 yy = (int)(y * costheta - x * sintheta);
246 glTranslatef( xx, yy, 0);
247 glScalef(.1, .1, 0.0);
248 while( (c=*msg++) ) {
249 glutStrokeCharacter(font, c);
255 int getStringWidth ( char *str )
257 if ( HUDtext && str ) {
259 guiFntHandle->getBBox ( str, HUD_TextSize, 0, &l, &r, NULL, NULL ) ;
260 return FloatToInt( r - l );
266 //========================= End of Class Implementations===================
269 // Constructs a HUD object and then adds in instruments. At the present
270 // the instruments are hard coded into the routine. Ultimately these need
271 // to be defined by the aircraft's instrumentation records so that the
272 // display for a Piper Cub doesn't show the speed range of a North American
273 // mustange and the engine readouts of a B36!
278 //$$$ begin - added, Neetha, 28 Nov 2k
280 readLadder(const SGPropertyNode * node)
285 name = node->getStringValue("name");
286 x = node->getIntValue("x");
287 y = node->getIntValue("y");
288 width = node->getIntValue("width");
289 height = node->getIntValue("height");
290 factor = node->getFloatValue("compression_factor");
291 span_units = node->getFloatValue("span_units");
292 division_units = node->getFloatValue("division_units");
293 screen_hole = node->getIntValue("screen_hole");
294 lbl_pos = node->getIntValue("lbl_pos");
295 frl_spot = node->getBoolValue("enable_frl",false);
296 target = node->getBoolValue("enable_target_spot",false);
297 vel_vector = node->getBoolValue("enable_velocity_vector",false);
298 drift = node->getBoolValue("enable_drift_marker",false);
299 alpha = node->getBoolValue("enable_alpha_bracket",false);
300 energy = node->getBoolValue("enable_energy_marker",false);
301 climb_dive = node->getBoolValue("enable_climb_dive_marker",false);
302 glide = node->getBoolValue("enable_glide_slope_marker",false);
303 glide_slope_val = node->getFloatValue("glide_slope",-4.0);
304 worm_energy = node->getBoolValue("enable_energy_marker",false);
305 waypoint = node->getBoolValue("enable_waypoint_marker",false);
306 working = node->getBoolValue("working");
307 zenith = node->getIntValue("zenith"); //suma
308 nadir = node->getIntValue("nadir"); //suma
309 hat = node->getIntValue("hat");
312 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
315 p = (instr_item *) new HudLadder( name, x, y,
316 width, height, factor,
318 span_units, division_units, minor_division,
319 screen_hole, lbl_pos, frl_spot, target, vel_vector,
320 drift, alpha, energy, climb_dive,
321 glide, glide_slope_val, worm_energy,
322 waypoint, working, zenith, nadir, hat);
329 readCard(const SGPropertyNode * node)
334 name = node->getStringValue("name");
335 x = node->getIntValue("x");
336 y = node->getIntValue("y");
337 width = node->getIntValue("width");
338 height = node->getIntValue("height");
339 loadfn = node->getStringValue("loadfn");
340 options = node->getIntValue("options");
341 maxValue = node->getFloatValue("maxValue");
342 minValue = node->getFloatValue("minValue");
343 scaling = node->getFloatValue("disp_scaling");
344 major_divs = node->getIntValue("major_divs");
345 minor_divs = node->getIntValue("minor_divs");
346 modulator = node->getIntValue("modulator");
347 span_units = node->getFloatValue("value_span");
348 type = node->getStringValue("type");
349 tick_bottom = node->getBoolValue("tick_bottom",false);
350 tick_top = node->getBoolValue("tick_top",false);
351 tick_right = node->getBoolValue("tick_right",false);
352 tick_left = node->getBoolValue("tick_left",false);
353 cap_bottom = node->getBoolValue("cap_bottom",false);
354 cap_top = node->getBoolValue("cap_top",false);
355 cap_right = node->getBoolValue("cap_right",false);
356 cap_left = node->getBoolValue("cap_left",false);
357 marker_off = node->getFloatValue("marker_offset",0.0);
358 enable_pointer = node->getBoolValue("enable_pointer",true);
359 type_pointer = node->getStringValue("pointer_type");
360 type_tick = node->getStringValue("tick_type");//hud Can be 'circle' or 'line'
361 length_tick = node->getStringValue("tick_length");//hud For variable length
362 working = node->getBoolValue("working");
363 radius = node->getFloatValue("radius"); //suma
364 divisions = node->getIntValue("divisions"); //suma
365 zoom = node->getIntValue("zoom"); //suma
367 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
371 span_units = maxValue - minValue;
374 if (loadfn=="anzg") {
376 } else if (loadfn=="heading") {
377 load_fn = get_heading;
378 } else if (loadfn=="aoa") {
380 } else if (loadfn=="climb") {
381 load_fn = get_climb_rate;
382 } else if (loadfn=="altitude") {
383 load_fn = get_altitude;
384 } else if (loadfn=="agl") {
386 } else if (loadfn=="speed") {
388 } else if (loadfn=="view_direction") {
389 load_fn = get_view_direction;
390 } else if (loadfn=="aileronval") {
391 load_fn = get_aileronval;
392 } else if (loadfn=="elevatorval") {
393 load_fn = get_elevatorval;
394 } else if (loadfn=="rudderval") {
395 load_fn = get_rudderval;
396 } else if (loadfn=="throttleval") {
397 load_fn = get_throttleval;
401 if ( (type == "dial") | (type == "tape") ) {
402 p = (instr_item *) new hud_card( x,
410 major_divs, minor_divs,
434 p = (instr_item *) new gauge_instr( x, // x
438 load_fn, // data source
442 major_divs, minor_divs,
452 readLabel(const SGPropertyNode * node)
456 int font_size = (fgGetInt("/sim/startup/xsize") > 1000) ? LARGE : SMALL;
458 name = node->getStringValue("name");
459 x = node->getIntValue("x");
460 y = node->getIntValue("y");
461 width = node->getIntValue("width");
462 height = node->getIntValue("height");
463 loadfn = node->getStringValue("data_source");
464 label_format = node->getStringValue("label_format");
465 prelabel = node->getStringValue("pre_label_string");
466 postlabel = node->getStringValue("post_label_string");
467 scaling = node->getFloatValue("scale_data");
468 options = node->getIntValue("options");
469 justi = node->getIntValue("justification");
470 blinking = node->getIntValue("blinking");
471 latitude = node->getBoolValue("latitude",false);
472 longitude = node->getBoolValue("longitude",false);
473 label_box = node->getBoolValue("label_box",false);//hud
474 working = node->getBoolValue("working");
475 digits = node->getIntValue("digits"); //suma
478 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
482 justification = LEFT_JUST;
485 justification = CENTER_JUST;
488 justification = RIGHT_JUST;
493 if ( prelabel == "NULL" ) {
494 pre_label_string = NULL;
496 if ( prelabel == "blank" ) {
497 pre_label_string = " ";
499 pre_label_string = prelabel.c_str();
503 if ( postlabel == "blank" ) {
504 post_label_string = " ";
506 if ( postlabel == "NULL" ) {
507 post_label_string = NULL;
509 if ( postlabel == "units" ) {
510 post_label_string = units;
512 post_label_string = postlabel.c_str();
517 if ( loadfn== "aux1" ) {
519 } else if ( loadfn == "aux2" ) {
521 } else if ( loadfn == "aux3" ) {
523 } else if ( loadfn == "aux4" ) {
525 } else if ( loadfn == "aux5" ) {
527 } else if ( loadfn == "aux6" ) {
529 } else if ( loadfn == "aux7" ) {
531 } else if ( loadfn == "aux8" ) {
533 } else if ( loadfn == "aux9" ) {
535 } else if ( loadfn == "aux10" ) {
537 } else if ( loadfn == "aux11" ) {
539 } else if ( loadfn == "aux12" ) {
541 } else if ( loadfn == "aux13" ) {
543 } else if ( loadfn == "aux14" ) {
545 } else if ( loadfn == "aux15" ) {
547 } else if ( loadfn == "aux16" ) {
549 } else if ( loadfn == "aux17" ) {
551 } else if ( loadfn == "aux18" ) {
553 } else if ( loadfn == "ax" ) {
555 } else if ( loadfn == "speed" ) {
557 } else if ( loadfn == "mach" ) {
559 } else if ( loadfn == "altitude" ) {
560 load_fn = get_altitude;
561 } else if ( loadfn == "agl" ) {
563 } else if ( loadfn == "framerate" ) {
564 load_fn = get_frame_rate;
565 } else if ( loadfn == "heading" ) {
566 load_fn = get_heading;
567 } else if ( loadfn == "fov" ) {
569 } else if ( loadfn == "vfc_tris_culled" ) {
570 load_fn = get_vfc_tris_culled;
571 } else if ( loadfn == "vfc_tris_drawn" ) {
572 load_fn = get_vfc_tris_drawn;
573 } else if ( loadfn == "aoa" ) {
575 } else if ( loadfn == "latitude" ) {
576 load_fn = get_latitude;
577 } else if ( loadfn == "anzg" ) {
579 } else if ( loadfn == "longitude" ) {
580 load_fn = get_longitude;
581 } else if (loadfn=="throttleval") {
582 load_fn = get_throttleval;
585 p = (instr_item *) new instr_label ( x,
590 label_format.c_str(),
608 readTBI(const SGPropertyNode * node)
613 name = node->getStringValue("name");
614 x = node->getIntValue("x");
615 y = node->getIntValue("y");
616 width = node->getIntValue("width");
617 height = node->getIntValue("height");
618 maxBankAngle = node->getFloatValue("maxBankAngle");
619 maxSlipAngle = node->getFloatValue("maxSlipAngle");
620 gap_width = node->getIntValue("gap_width");
621 working = node->getBoolValue("working");
622 tsi = node->getBoolValue("tsi"); //suma
623 rad = node->getFloatValue("rad"); //suma
625 SG_LOG(SG_INPUT, SG_INFO, "Done reading instrument " << name);
628 p = (instr_item *) new fgTBI_instr( x,
645 int readInstrument(const SGPropertyNode * node)
650 if ( fgGetString("/sim/startup/units") == "feet" ) {
651 strcpy(units, " ft");
656 const SGPropertyNode * ladder_group = node->getNode("ladders");
658 if (ladder_group != 0) {
659 int nLadders = ladder_group->nChildren();
660 for (int j = 0; j < nLadders; j++) {
662 HIptr = readLadder(ladder_group->getChild(j));
663 HUD_deque.insert( HUD_deque.begin(), HIptr);
668 const SGPropertyNode * card_group = node->getNode("cards");
669 if (card_group != 0) {
670 int nCards = card_group->nChildren();
671 for (int j = 0; j < nCards; j++) {
673 HIptr = readCard(card_group->getChild(j));
674 HUD_deque.insert( HUD_deque.begin(), HIptr);
679 const SGPropertyNode * label_group = node->getNode("labels");
680 if (label_group != 0) {
681 int nLabels = label_group->nChildren();
682 for (int j = 0; j < nLabels; j++) {
684 HIptr = readLabel(label_group->getChild(j));
685 HUD_deque.insert( HUD_deque.begin(), HIptr);
690 const SGPropertyNode * tbi_group = node->getNode("tbis");
691 if (tbi_group != 0) {
692 int nTbis = tbi_group->nChildren();
693 for (int j = 0; j < nTbis; j++) {
695 HIptr = readTBI(tbi_group->getChild(j));
696 HUD_deque.insert( HUD_deque.begin(), HIptr);
701 }//end readinstrument
704 int readHud( istream &input )
710 readProperties(input, &root);
711 } catch (const sg_exception &e) {
712 guiErrorMessage("Error reading HUD: ", e);
717 SG_LOG(SG_INPUT, SG_INFO, "Read properties for " <<
718 root.getStringValue("name"));
721 HUD_deque.erase( HUD_deque.begin(), HUD_deque.end()); // empty the HUD deque
724 SG_LOG(SG_INPUT, SG_INFO, "Reading Hud instruments");
726 const SGPropertyNode * instrument_group = root.getChild("instruments");
727 int nInstruments = instrument_group->nChildren();
729 for (int i = 0; i < nInstruments; i++) {
731 const SGPropertyNode * node = instrument_group->getChild(i);
733 SGPath path( globals->get_fg_root() );
734 path.append(node->getStringValue("path"));
736 SG_LOG(SG_INPUT, SG_INFO, "Reading Instrument "
742 SGPropertyNode root2;
744 readProperties(path.str(), &root2);
745 } catch (const sg_exception &e) {
746 guiErrorMessage("Error reading HUD instrument: ", e);
749 readInstrument(&root2);
756 int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
762 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
765 fgGetString("/sim/hud/path", "Huds/Default/default.xml");
766 SGPath path(globals->get_fg_root());
767 path.append(hud_path);
769 ifstream input(path.c_str());
771 SG_LOG(SG_INPUT, SG_ALERT,
772 "Cannot read Hud configuration from " << path.str());
781 return 0; // For now. Later we may use this for an error code.
785 int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
790 SG_LOG( SG_COCKPIT, SG_INFO, "Initializing current aircraft HUD" );
792 SGPath path(globals->get_fg_root());
793 path.append("Huds/Minimal/default.xml");
796 ifstream input(path.c_str());
798 SG_LOG(SG_INPUT, SG_ALERT,
799 "Cannot read Hud configuration from " << path.str());
805 return 0; // For now. Later we may use this for an error code.
808 //$$$ End - added, Neetha, 28 Nov 2k
810 static int global_day_night_switch = DAY;
812 void HUD_masterswitch( bool incr )
814 if ( fgGetBool("/sim/hud/visibility") ) {
815 if ( global_day_night_switch == DAY ) {
816 global_day_night_switch = NIGHT;
818 fgSetBool("/sim/hud/visibility", false);
821 fgSetBool("/sim/hud/visibility", true);
822 global_day_night_switch = DAY;
826 void HUD_brightkey( bool incr_bright )
828 instr_item *pHUDInstr = HUD_deque[0];
829 int brightness = pHUDInstr->get_brightness();
831 if( fgGetBool("/sim/hud/visibility") ) {
836 brightness = BRT_BLACK;
840 brightness = BRT_LIGHT;
844 brightness = BRT_MEDIUM;
848 brightness = BRT_DARK;
852 brightness = BRT_BLACK;
858 brightness = BRT_MEDIUM;
862 brightness = BRT_DARK;
866 brightness = BRT_BLACK;
870 brightness = BRT_LIGHT;
874 fgSetBool("/sim/hud/visibility", false);
878 fgSetBool("/sim/hud/visibility", true);
881 pHUDInstr->SetBrightness( brightness );
885 #define fgAP_CLAMP(val,min,max) ( (val) = (val) > (max) ? (max) : (val) < (min) ? (min) : (val) )
887 static puDialogBox *HUDalphaDialog;
888 static puText *HUDalphaText;
889 static puSlider *HUDalphaHS0;
890 //static puText *HUDtextText;
891 //static puSlider *HUDalphaHS1;
892 static char SliderText[2][ 8 ];
894 static void alpha_adj( puObject *hs ) {
897 hs-> getValue ( &val ) ;
898 fgAP_CLAMP ( val, 0.1, 1.0 ) ;
899 // printf ( "maxroll_adj( %p ) %f %f\n", hs, val, MaxRollAdjust * val ) ;
900 hud_trans_alpha = val;
901 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
902 HUDalphaText -> setLabel ( SliderText[ 0 ] ) ;
905 void fgHUDalphaAdjust( puObject * ) {
906 fgSetBool("/sim/hud/antialiased", true);
907 FG_PUSH_PUI_DIALOG( HUDalphaDialog );
910 static void goAwayHUDalphaAdjust (puObject *)
912 FG_POP_PUI_DIALOG( HUDalphaDialog );
915 static void cancelHUDalphaAdjust (puObject *)
917 fgSetBool("/sim/hud/antialiased", false);
918 FG_POP_PUI_DIALOG( HUDalphaDialog );
921 // Done once at system initialization
922 void fgHUDalphaInit( void ) {
924 // printf("fgHUDalphaInit\n");
925 #define HORIZONTAL FALSE
929 int DialogWidth = 240;
931 char Label[] = "HUD Adjuster";
934 int labelX = (DialogWidth / 2) -
935 ( puGetDefaultLabelFont().getStringWidth( Label ) / 2);
940 int slider_width = 220;
941 int slider_title_x = 15;
942 int slider_value_x = 160;
943 float slider_delta = 0.05f;
945 puFont HUDalphaLegendFont;
946 puFont HUDalphaLabelFont;
947 puGetDefaultFonts ( &HUDalphaLegendFont, &HUDalphaLabelFont );
949 HUDalphaDialog = new puDialogBox ( DialogX, DialogY ); {
950 int horiz_slider_height = HUDalphaLabelFont.getStringHeight() +
951 HUDalphaLabelFont.getStringDescender() +
952 PUSTR_TGAP + PUSTR_BGAP + 5;
955 HUDalphaFrame = new puFrame ( 0, 0, DialogWidth,
957 * horiz_slider_height ); */
960 HUDalphaDialogMessage = new puText ( labelX,
962 * horiz_slider_height );
963 HUDalphaDialogMessage -> setDefaultValue ( Label );
964 HUDalphaDialogMessage -> getDefaultValue ( &s );
965 HUDalphaDialogMessage -> setLabel ( s );
967 HUDalphaHS0 = new puSlider ( slider_x, slider_y,
968 slider_width, HORIZONTAL ) ;
969 HUDalphaHS0-> setDelta ( slider_delta ) ;
970 HUDalphaHS0-> setValue ( hud_trans_alpha ) ;
971 HUDalphaHS0-> setCBMode ( PUSLIDER_DELTA ) ;
972 HUDalphaHS0-> setCallback ( alpha_adj ) ;
975 HUDalphaTitle = new puText ( slider_title_x, slider_y ) ;
976 HUDalphaTitle-> setDefaultValue ( "Alpha" ) ;
977 HUDalphaTitle-> getDefaultValue ( &s ) ;
978 HUDalphaTitle-> setLabel ( s ) ;
980 HUDalphaText = new puText ( slider_value_x, slider_y ) ;
981 sprintf( SliderText[ 0 ], "%05.2f", hud_trans_alpha );
982 HUDalphaText-> setLabel ( SliderText[ 0 ] ) ;
985 HUDalphaOkButton = new puOneShot ( 10, 10, 60, 45 );
986 HUDalphaOkButton-> setLegend ( gui_msg_OK );
987 HUDalphaOkButton-> makeReturnDefault ( TRUE );
988 HUDalphaOkButton-> setCallback ( goAwayHUDalphaAdjust );
991 HUDalphaNoButton = new puOneShot ( 160, 10, 230, 45 );
992 HUDalphaNoButton-> setLegend ( gui_msg_CANCEL );
993 HUDalphaNoButton-> setCallback ( cancelHUDalphaAdjust );
995 FG_FINALIZE_PUI_DIALOG( HUDalphaDialog );
1001 void fgHUDReshape(void) {
1003 // this chunk of code is not necessarily thread safe if the
1004 // compiler optimizer reorders these statements. Note that
1005 // "delete ptr" does not set "ptr = NULL". We have to do that
1007 fntRenderer *tmp = HUDtext;
1012 HUD_TextSize = fgGetInt("/sim/startup/xsize") / 60;
1014 HUDtext = new fntRenderer();
1015 HUDtext -> setFont ( guiFntHandle ) ;
1016 HUDtext -> setPointSize ( HUD_TextSize ) ;
1017 HUD_TextList.setFont( HUDtext );
1021 static void set_hud_color(float r, float g, float b) {
1022 fgGetBool("/sim/hud/antialiased") ?
1023 glColor4f(r,g,b,hud_trans_alpha) :
1030 // Performs a once around the list of calls to instruments installed in
1031 // the HUD object with requests for redraw. Kinda. It will when this is
1034 void fgUpdateHUD( void ) {
1036 static const float normal_aspect = float(640) / float(480);
1037 // note: aspect_ratio is Y/X
1038 float current_aspect = 1.0f/globals->get_current_view()->get_aspect_ratio();
1039 if( current_aspect > normal_aspect ) {
1040 float aspect_adjust = current_aspect / normal_aspect;
1041 float adjust = 320.0f*aspect_adjust - 320.0f;
1042 fgUpdateHUD( -adjust, 0.0f, 640.0f+adjust, 480.0f );
1044 float aspect_adjust = normal_aspect / current_aspect;
1045 float adjust = 240.0f*aspect_adjust - 240.0f;
1046 fgUpdateHUD( 0.0f, -adjust, 640.0f, 480.0f+adjust );
1050 void fgUpdateHUD( GLfloat x_start, GLfloat y_start,
1051 GLfloat x_end, GLfloat y_end )
1054 // int day_night_sw = current_aircraft.controls->day_night_switch;
1055 int day_night_sw = global_day_night_switch;
1056 int hud_displays = HUD_deque.size();
1057 instr_item *pHUDInstr;
1058 // float line_width;
1060 if( !hud_displays ) { // Trust everyone, but ALWAYS cut the cards!
1064 HUD_TextList.erase();
1065 HUD_LineList.erase();
1066 // HUD_StippleLineList.erase();
1068 pHUDInstr = HUD_deque[0];
1069 brightness = pHUDInstr->get_brightness();
1070 // brightness = HUD_deque.at(0)->get_brightness();
1072 glMatrixMode(GL_PROJECTION);
1076 gluOrtho2D(x_start, x_end, y_start, y_end);
1077 glMatrixMode(GL_MODELVIEW);
1081 glDisable(GL_DEPTH_TEST);
1082 glDisable(GL_LIGHTING);
1084 static const SGPropertyNode * antialiased_node
1085 = fgGetNode("/sim/hud/antialiased");
1087 if( antialiased_node->getBoolValue() ) {
1088 glEnable(GL_LINE_SMOOTH);
1089 // glEnable(GL_BLEND);
1090 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
1091 glHint(GL_LINE_SMOOTH_HINT,GL_DONT_CARE);
1097 if( day_night_sw == DAY) {
1101 set_hud_color (0.1f, 0.9f, 0.1f);
1105 set_hud_color (0.1f, 0.7f, 0.0f);
1109 set_hud_color (0.0f, 0.6f, 0.0f);
1113 set_hud_color( 0.0f, 0.0f, 0.0f);
1117 set_hud_color (0.1f, 0.9f, 0.1f);
1120 if( day_night_sw == NIGHT) {
1124 set_hud_color (0.9f, 0.1f, 0.1f);
1128 set_hud_color (0.7f, 0.0f, 0.1f);
1132 set_hud_color (0.6f, 0.0f, 0.0f);
1136 set_hud_color( 0.0f, 0.0f, 0.0f);
1140 set_hud_color (0.6f, 0.0f, 0.0f);
1142 } else { // Just in case default
1143 set_hud_color (0.1f, 0.9f, 0.1f);
1147 deque < instr_item * > :: iterator current = HUD_deque.begin();
1148 deque < instr_item * > :: iterator last = HUD_deque.end();
1150 for ( ; current != last; ++current ) {
1151 pHUDInstr = *current;
1153 if( pHUDInstr->enabled()) {
1154 // fgPrintf( SG_COCKPIT, SG_DEBUG, "HUD Code %d Status %d\n",
1155 // hud->code, hud->status );
1161 char *gmt_str = get_formated_gmt_time();
1162 HUD_TextList.add( fgText(40, 10, gmt_str, 0) );
1164 #ifdef FG_NETWORK_OLK
1165 if ( net_hud_display ) {
1172 // extern bool fgAPAltitudeEnabled( void );
1173 // extern bool fgAPHeadingEnabled( void );
1174 // extern bool fgAPWayPointEnabled( void );
1175 // extern char *fgAPget_TargetDistanceStr( void );
1176 // extern char *fgAPget_TargetHeadingStr( void );
1177 // extern char *fgAPget_TargetAltitudeStr( void );
1178 // extern char *fgAPget_TargetLatLonStr( void );
1181 // char scratch[128];
1182 // HUD_TextList.add( fgText( "AUTOPILOT", 20, apY) );
1184 if( current_autopilot->get_HeadingEnabled() ) {
1185 HUD_TextList.add( fgText( 40, apY,
1186 current_autopilot->get_TargetHeadingStr()) );
1189 if( current_autopilot->get_AltitudeEnabled() ) {
1190 HUD_TextList.add( fgText( 40, apY,
1191 current_autopilot->get_TargetAltitudeStr()) );
1194 if( current_autopilot->get_HeadingMode() ==
1195 FGAutopilot::FG_HEADING_WAYPOINT )
1198 wpstr = current_autopilot->get_TargetWP1Str();
1199 if ( strlen( wpstr ) ) {
1200 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1203 wpstr = current_autopilot->get_TargetWP2Str();
1204 if ( strlen( wpstr ) ) {
1205 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1208 wpstr = current_autopilot->get_TargetWP3Str();
1209 if ( strlen( wpstr ) ) {
1210 HUD_TextList.add( fgText( 40, apY, wpstr ) );
1215 HUD_TextList.draw();
1217 HUD_LineList.draw();
1219 // glEnable(GL_LINE_STIPPLE);
1220 // glLineStipple( 1, 0x00FF );
1221 // HUD_StippleLineList.draw();
1222 // glDisable(GL_LINE_STIPPLE);
1224 if( antialiased_node->getBoolValue() ) {
1225 // glDisable(GL_BLEND);
1226 glDisable(GL_LINE_SMOOTH);
1230 glEnable(GL_DEPTH_TEST);
1231 glEnable(GL_LIGHTING);
1232 glMatrixMode(GL_PROJECTION);
1234 glMatrixMode(GL_MODELVIEW);