]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
Heading bug (and bfi) now deals with magnetic compass heading rather than
[flightgear.git] / src / Cockpit / hud_labl.cxx
1
2 #include "hud.hxx"
3
4
5 #ifdef USE_HUD_TextList
6 #define textString( x , y, text, font )  TextString( text, x , y )
7 #else
8 #define textString( x , y, text, font )  puDrawString ( guiFnt, text, x, y );
9 #endif
10
11 //======================= Top of instr_label class =========================
12 instr_label ::
13          instr_label( int           x,
14                       int           y,
15                       UINT          width,
16                       UINT          height,
17                       FLTFNPTR      data_source,
18                       const char   *label_format,
19                       const char   *pre_label_string,
20                       const char   *post_label_string,
21                       float        scale_data,
22                       UINT          options,
23                       fgLabelJust   justification,
24                       int           font_size,
25                       int           blinking,
26                       bool          working ):
27                            instr_item( x, y, width, height,
28                                        data_source, scale_data,options, working ),
29                            pformat  ( label_format      ),
30                            pre_str  ( pre_label_string  ),
31                            post_str ( post_label_string ),
32                            justify  ( justification     ),
33                            fontSize ( font_size         ),
34                            blink    ( blinking          )
35 {
36   if( pre_str != NULL) {
37     if( post_str != NULL ) {
38       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
39       }
40     else {
41       sprintf( format_buffer, "%s%s",   pre_str, pformat );
42       }
43     }
44   else {
45     if( post_str != NULL ) {
46       sprintf( format_buffer, "%s%s",   pformat, post_str );
47       }
48     } // else do nothing if both pre and post strings are nulls. Interesting.
49
50 }
51
52 // I put this in to make it easy to construct a class member using the current
53 // C code.
54
55
56 instr_label :: ~instr_label()
57 {
58 }
59
60 // Copy constructor
61 instr_label :: instr_label( const instr_label & image) :
62                               instr_item((const instr_item &)image),
63                               pformat    ( image.pformat    ),
64                               pre_str  ( image.pre_str  ),
65                               post_str ( image.post_str ),
66                               blink    ( image.blink    )
67 {
68   if( pre_str != NULL) {
69     if( post_str != NULL ) {
70       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
71       }
72     else {
73       sprintf( format_buffer, "%s%s",   pre_str, pformat );
74       }
75     }
76   else {
77     if( post_str != NULL ) {
78       sprintf( format_buffer, "%s%s",   pformat, post_str );
79       }
80     } // else do nothing if both pre and post strings are nulls. Interesting.
81
82 }
83
84 instr_label & instr_label ::operator = (const instr_label & rhs )
85 {
86   if( !(this == &rhs)) {
87     instr_item::operator = (rhs);
88     pformat      = rhs.pformat;
89     fontSize   = rhs.fontSize;
90     blink      = rhs.blink;
91     justify    = rhs.justify;
92     pre_str    = rhs.pre_str;
93     post_str   = rhs.post_str;
94     strcpy(format_buffer,rhs.format_buffer);    
95     }
96   return *this;
97 }
98
99 //
100 // draw                    Draws a label anywhere in the HUD
101 //
102 //
103 void instr_label ::
104 draw( void )       // Required method in base class
105 {
106 //  char format_buffer[80];
107   char label_buffer[80];
108   int posincr;
109   int lenstr;
110   RECT  scrn_rect = get_location();
111
112   if( data_available() ) {
113     sprintf( label_buffer, format_buffer, get_value() );
114     }
115   else {
116     sprintf( label_buffer, format_buffer );
117     }
118   
119   lenstr = getStringWidth( label_buffer );
120                                                 
121     
122 #ifdef DEBUGHUD
123   fgPrintf( FG_COCKPIT, FG_DEBUG,  format_buffer );
124   fgPrintf( FG_COCKPIT, FG_DEBUG,  "\n" );
125   fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
126   fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
127 #endif
128 //  lenstr = strlen( label_buffer );
129
130   if( justify == RIGHT_JUST ) {
131           posincr = scrn_rect.right - lenstr;
132   }else if( justify == CENTER_JUST ) {
133           posincr = get_span() - (lenstr/2); //  -lenstr*4;
134   }  else {
135       //  justify == LEFT_JUST
136       posincr = 0;  // 0;
137   }
138   
139   if( fontSize == SMALL ) {
140     textString( scrn_rect.left + posincr, scrn_rect.top,
141                 label_buffer, GLUT_BITMAP_8_BY_13);
142     }
143   else  {
144     if( fontSize == LARGE ) {
145       textString( scrn_rect.left + posincr, scrn_rect.top,
146                   label_buffer, GLUT_BITMAP_9_BY_15);
147       }
148     }
149 }
150