]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
Tweaks for Mips Irix compilers.
[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                      latitude,
27                       bool                      longitude,
28                       bool          working):
29                            instr_item( x, y, width, height,
30                                        data_source,scale_data,options, working ),
31                            pformat  ( label_format      ),
32                            pre_str  ( pre_label_string  ),
33                            post_str ( post_label_string ),
34                            justify  ( justification     ),
35                            fontSize ( font_size         ),
36                            blink    ( blinking          ),
37                                                    lat          ( latitude                      ),
38                                                    lon          ( longitude                     )
39
40 {
41   if( pre_str != NULL) {
42     if( post_str != NULL ) {
43       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
44       }
45     else {
46       sprintf( format_buffer, "%s%s",   pre_str, pformat );
47       }
48     }
49   else {
50     if( post_str != NULL ) {
51       sprintf( format_buffer, "%s%s",   pformat, post_str );
52       }
53     } // else do nothing if both pre and post strings are nulls. Interesting.
54
55 }
56
57 // I put this in to make it easy to construct a class member using the current
58 // C code.
59
60
61 instr_label :: ~instr_label()
62 {
63 }
64
65 // Copy constructor
66 instr_label :: instr_label( const instr_label & image) :
67                               instr_item((const instr_item &)image),
68                               pformat    ( image.pformat    ),
69                               pre_str  ( image.pre_str  ),
70                               post_str ( image.post_str ),
71                               blink    ( image.blink    ),
72                                                           lat      ( image.lat          ),
73                                                           lon      ( image.lon          )       
74
75 {
76   if( pre_str != NULL) {
77     if( post_str != NULL ) {
78       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
79       }
80     else {
81       sprintf( format_buffer, "%s%s",   pre_str, pformat );
82       }
83     }
84   else {
85     if( post_str != NULL ) {
86       sprintf( format_buffer, "%s%s",   pformat, post_str );
87       }
88     } // else do nothing if both pre and post strings are nulls. Interesting.
89
90 }
91
92 instr_label & instr_label ::operator = (const instr_label & rhs )
93 {
94   if( !(this == &rhs)) {
95     instr_item::operator = (rhs);
96     pformat      = rhs.pformat;
97     fontSize   = rhs.fontSize;
98     blink      = rhs.blink;
99     justify    = rhs.justify;
100     pre_str    = rhs.pre_str;
101     post_str   = rhs.post_str;
102     lat            = rhs.lat;
103     lon            = rhs.lon;
104
105
106     strcpy(format_buffer,rhs.format_buffer);    
107     }
108   return *this;
109 }
110
111 //
112 // draw                    Draws a label anywhere in the HUD
113 //
114 //
115 void instr_label ::
116 draw( void )       // Required method in base class
117 {
118 //  char format_buffer[80];
119   char label_buffer[80];
120   int posincr;
121   int lenstr;
122   RECT  scrn_rect = get_location();
123
124   if( data_available() ) {
125         if(lat)
126                 sprintf( label_buffer, format_buffer, coord_format_lat(get_value()) );
127         else
128         if(lon)    
129                 sprintf( label_buffer, format_buffer, coord_format_lon(get_value()) );
130         else
131                 sprintf( label_buffer, format_buffer, get_value() );
132     }
133   else {
134     sprintf( label_buffer, format_buffer );
135   }
136   
137   lenstr = getStringWidth( label_buffer );
138                                                 
139     
140 #ifdef DEBUGHUD
141   fgPrintf( FG_COCKPIT, FG_DEBUG,  format_buffer );
142   fgPrintf( FG_COCKPIT, FG_DEBUG,  "\n" );
143   fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
144   fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
145 #endif
146 //  lenstr = strlen( label_buffer );
147
148   if( justify == RIGHT_JUST ) {
149           posincr = scrn_rect.right - lenstr;
150   }else if( justify == CENTER_JUST ) {
151           posincr = get_span() - (lenstr/2); //  -lenstr*4;
152   }  else {
153       //  justify == LEFT_JUST
154       posincr = 0;  // 0;
155   }
156   
157   if( fontSize == SMALL ) {
158     textString( scrn_rect.left + posincr, scrn_rect.top,
159                 label_buffer, GLUT_BITMAP_8_BY_13);
160     }
161   else  {
162     if( fontSize == LARGE ) {
163       textString( scrn_rect.left + posincr, scrn_rect.top,
164                   label_buffer, GLUT_BITMAP_9_BY_15);
165       }
166     }
167 }
168