1 // hud.hxx -- hud defines and prototypes (initial draft)
3 // Written by Michele America, started September 1997.
5 // Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt
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.
28 # error This library requires C++
44 # include <values.h> // for MAXINT
47 #include <deque> // STL double ended queue
49 #include <fg_typedefs.h>
50 #include <fg_constants.h>
51 #include <Aircraft/aircraft.hxx>
52 #include <FDM/flight.hxx>
53 #include <Controls/controls.hxx>
63 int top, bottom, left, right;
67 // View mode definitions
69 enum VIEW_MODES{ HUD_VIEW, PANEL_VIEW, CHASE_VIEW, TOWER_VIEW };
71 // DAY, NIGHT and brightness levels need to be visible where dialogs and
72 // controls can be used to set intensity and appropriate color. This will
74 // Hud general constants
91 enum fgLabelJust{ LEFT_JUST, CENTER_JUST, RIGHT_JUST } ;
96 #define UPPER_CENTER 3
98 #define CENTER_RIGHT 5
100 #define LOWER_CENTER 7
102 #define CENTER_LEFT 9
103 #define SOLID_LINES 10
104 #define DASHED_LINES 11
105 #define DASHED_NEG_LINES 12
108 #define HORIZON_FIXED 1
109 #define HORIZON_MOVING 2
110 #define LABEL_COUNTER 1
111 #define LABEL_WARNING 2
113 #define HUDS_AUTOTICKS 0x0001
114 #define HUDS_VERT 0x0002
115 #define HUDS_HORZ 0x0000
116 #define HUDS_TOP 0x0004
117 #define HUDS_BOTTOM 0x0008
118 #define HUDS_LEFT HUDS_TOP
119 #define HUDS_RIGHT HUDS_BOTTOM
120 #define HUDS_BOTH (HUDS_LEFT | HUDS_RIGHT)
121 #define HUDS_NOTICKS 0x0010
122 #define HUDS_ARITHTIC 0x0020
123 #define HUDS_DECITICS 0x0040
124 #define HUDS_NOTEXT 0x0080
127 // #define HUD_VERTICAL 1
128 // #define HUD_HORIZONTAL 2
129 // #define HUD_FREEFLOAT 3
131 // Ladder orientation modes
132 // #define HUD_LEFT 1
133 // #define HUD_RIGHT 2
135 // #define HUD_BOTTOM 2
136 // #define HUD_V_LEFT 1
137 // #define HUD_V_RIGHT 2
138 // #define HUD_H_TOP 1
139 // #define HUD_H_BOTTOM 2
144 // #define HUD_NOLIM 2
145 // #define HUD_CIRC 3
147 // #define HUD_INSTR_LADDER 1
148 // #define HUD_INSTR_CLADDER 2
149 // #define HUD_INSTR_HORIZON 3
150 // #define HUD_INSTR_LABEL 4
152 extern double get_throttleval ( void );
153 extern double get_aileronval ( void );
154 extern double get_elevatorval ( void );
155 extern double get_elev_trimval( void );
156 extern double get_rudderval ( void );
157 extern double get_speed ( void );
158 extern double get_aoa ( void );
159 extern double get_roll ( void );
160 extern double get_pitch ( void );
161 extern double get_heading ( void );
162 extern double get_altitude ( void );
163 extern double get_agl ( void );
164 extern double get_sideslip ( void );
165 extern double get_frame_rate ( void );
166 extern double get_latitude ( void );
167 extern double get_lat_min ( void );
168 extern double get_longitude ( void );
169 extern double get_long_min ( void );
170 extern double get_fov ( void );
171 extern double get_vfc_ratio ( void );
172 extern double get_vfc_tris_drawn ( void );
173 extern double get_climb_rate ( void );
175 enum hudinstype{ HUDno_instr,
187 typedef struct gltagRGBTRIPLE { // rgbt
193 class instr_item { // An Abstract Base Class (ABC)
195 static UINT instances; // More than 64K instruments? Nah!
196 static int brightness;
197 static glRGBTRIPLE color;
200 RECT scrn_pos; // Framing - affects scale dimensions
201 // and orientation. Vert vs Horz, etc.
202 DBLFNPTR load_value_fn;
203 double disp_factor; // Multiply by to get numbers shown on scale.
207 UINT scr_span; // Working values for draw;
215 DBLFNPTR data_source,
218 bool working = true);
220 instr_item( const instr_item & image );
222 instr_item & operator = ( const instr_item & rhs );
223 virtual ~instr_item ();
225 int get_brightness ( void ) { return brightness;}
226 RECT get_location ( void ) { return scrn_pos; }
227 bool is_broken ( void ) { return broken; }
228 bool enabled ( void ) { return is_enabled;}
229 bool data_available ( void ) { return !!load_value_fn; }
230 double get_value ( void ) { return load_value_fn(); }
231 double data_scaling ( void ) { return disp_factor; }
232 UINT get_span ( void ) { return scr_span; }
233 POINT get_centroid ( void ) { return mid_span; }
234 UINT get_options ( void ) { return opts; }
236 virtual void display_enable( bool working ) { is_enabled = !! working;}
239 virtual void update( void );
240 virtual void break_display ( bool bad );
241 virtual void SetBrightness( int illumination_level ); // fgHUDSetBright...
242 void SetPosition ( int x, int y, UINT width, UINT height );
243 UINT get_Handle( void );
244 virtual void draw( void ) = 0; // Required method in derived classes
247 typedef deque< instr_item * > HudContainerType;
248 typedef HudContainerType::iterator HudIterator;
250 typedef instr_item *HIptr;
251 extern HudContainerType HUD_deque;
253 // instr_item This class has no other purpose than to maintain
254 // a linked list of instrument and derived class
258 class instr_label : public instr_item {
262 const char *post_str;
272 DBLFNPTR data_source,
273 const char *label_format,
274 const char *pre_label_string = 0,
275 const char *post_label_string = 0,
276 double scale_data = 1.0,
277 UINT options = HUDS_TOP,
278 fgLabelJust justification = CENTER_JUST,
279 int font_size = SMALL,
280 int blinking = NOBLINK,
281 bool working = true);
285 instr_label( const instr_label & image);
286 instr_label & operator = (const instr_label & rhs );
287 virtual void draw( void ); // Required method in base class
290 typedef instr_label * pInstlabel;
293 // instr_scale This class is an abstract base class for both moving
294 // scale and moving needle (fixed scale) indicators. It
295 // does not draw itself, but is not instanciable.
298 class instr_scale : public instr_item {
300 double range_shown; // Width Units.
301 double Maximum_value; // ceiling.
302 double Minimum_value; // Representation floor.
303 double scale_factor; // factor => screen units/range values.
304 UINT Maj_div; // major division marker units
305 UINT Min_div; // minor division marker units
306 UINT Modulo; // Roll over point
307 int signif_digits; // digits to show to the right.
317 double max_value = 100.0,
318 double min_value = 0.0,
319 double disp_scaling = 1.0,
320 UINT major_divs = 10,
324 bool working = true);
326 virtual ~instr_scale();
327 instr_scale( const instr_scale & image);
328 instr_scale & operator = (const instr_scale & rhs);
330 virtual void draw ( void ) {}; // No-op here. Defined in derived classes.
331 UINT div_min ( void ) { return Min_div;}
332 UINT div_max ( void ) { return Maj_div;}
333 double min_val ( void ) { return Minimum_value;}
334 double max_val ( void ) { return Maximum_value;}
335 UINT modulo ( void ) { return Modulo; }
336 double factor ( void ) { return scale_factor;}
337 double range_to_show( void ) { return range_shown;}
340 // hud_card_ This class displays the indicated quantity on
341 // a scale that moves past the pointer. It may be
342 // horizontal or vertical, read above(left) or below(right) of the base
345 class hud_card : public instr_scale {
348 double half_width_units;
357 double maxValue = 100.0,
358 double minValue = 0.0,
359 double disp_scaling = 1.0,
360 UINT major_divs = 10,
362 UINT modulator = 100,
364 double value_span = 100.0,
365 bool working = true);
368 hud_card( const hud_card & image);
369 hud_card & operator = (const hud_card & rhs );
370 // virtual void display_enable( bool setting );
371 virtual void draw( void ); // Required method in base class
374 typedef hud_card * pCardScale;
376 class guage_instr : public instr_scale {
386 double disp_scaling = 1.0,
387 double maxValue = 100,
389 UINT major_divs = 50,
393 bool working = true);
396 guage_instr( const guage_instr & image);
397 guage_instr & operator = (const guage_instr & rhs );
398 virtual void draw( void ); // Required method in base class
401 typedef guage_instr * pGuageInst;
403 // dual_instr_item This class was created to form the base class
404 // for both panel and HUD Turn Bank Indicators.
406 class dual_instr_item : public instr_item {
408 DBLFNPTR alt_data_source;
411 dual_instr_item ( int x,
415 DBLFNPTR chn1_source,
416 DBLFNPTR chn2_source,
418 UINT options = HUDS_TOP);
420 virtual ~dual_instr_item() {};
421 dual_instr_item( const dual_instr_item & image);
422 dual_instr_item & operator = (const dual_instr_item & rhs );
424 double current_ch1( void ) { return alt_data_source();}
425 double current_ch2( void ) { return get_value();}
426 virtual void draw ( void ) { }
429 class fgTBI_instr : public dual_instr_item {
440 DBLFNPTR chn1_source = get_roll,
441 DBLFNPTR chn2_source = get_sideslip,
442 double maxBankAngle = 45.0,
443 double maxSlipAngle = 5.0,
444 UINT gap_width = 5.0,
445 bool working = true);
447 fgTBI_instr( const fgTBI_instr & image);
448 fgTBI_instr & operator = (const fgTBI_instr & rhs );
452 UINT bank_limit( void ) { return BankLimit;}
453 UINT slew_limit( void ) { return SlewLimit;}
455 virtual void draw( void ); // Required method in base class
458 typedef fgTBI_instr * pTBI;
460 class HudLadder : public dual_instr_item {
476 DBLFNPTR ptch_source = get_roll,
477 DBLFNPTR roll_source = get_pitch,
478 double span_units = 45.0,
479 double division_units = 10.0,
480 double minor_division = 0.0,
481 UINT screen_hole = 70,
483 bool working = true );
487 HudLadder( const HudLadder & image );
488 HudLadder & operator = ( const HudLadder & rhs );
489 virtual void draw( void );
493 //using namespace std;
494 //deque <instr_item> * Hdeque_ptr;
496 extern void HUD_brightkey( bool incr_bright );
497 extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
498 extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
499 extern void fgUpdateHUD( void );
501 extern void drawOneLine ( UINT x1, UINT y1, UINT x2, UINT y2);
502 extern void drawOneLine ( RECT &rect);
503 extern void textString ( int x,
506 void *font = GLUT_BITMAP_8_BY_13);
507 extern void strokeString( int x,
510 void *font = GLUT_STROKE_ROMAN,
513 bool AddHUDInstrument( instr_item *pBlackBox );
514 void DrawHUD ( void );
515 bool DamageInstrument( INSTR_HANDLE unit );
516 bool RepairInstrument( INSTR_HANDLE unit );
519 void fgUpdateHUD ( Hptr hud );
520 void fgUpdateHUD2( Hptr hud ); // Future use?
521 void fgHUDSetTimeMode( Hptr hud, int time_of_day );