]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lat.cxx
Fixed a bug in radiostack->search() when switching freq. to a different
[flightgear.git] / src / Cockpit / hud_lat.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 lat_label ::
13          lat_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 lat_label :: ~lat_label()
57 {
58 }
59
60 // Copy constructor
61 lat_label :: lat_label( const lat_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 lat_label & lat_label ::operator = (const lat_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 lat_label ::
104 draw( void )       // Required method in base class
105 {
106   char label_buffer[80];
107   int posincr;
108   int lenstr;
109   RECT  scrn_rect = get_location();
110 //  float lat = get_value();
111   
112   if( data_available() ) {
113 //        sprintf( label_buffer, format_buffer, coord_format_lat(lat) );
114           sprintf( label_buffer, format_buffer,
115                            coord_format_lat( get_value()) );
116     }
117   else {
118      sprintf( label_buffer, format_buffer );
119   }
120     
121 #ifdef DEBUGHUD
122   fgPrintf( FG_COCKPIT, FG_DEBUG,  format_buffer );
123   fgPrintf( FG_COCKPIT, FG_DEBUG,  "\n" );
124   fgPrintf( FG_COCKPIT, FG_DEBUG, label_buffer );
125   fgPrintf( FG_COCKPIT, FG_DEBUG, "\n" );
126 #endif
127
128   lenstr = getStringWidth(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);
134   }  else {  //  justify == LEFT_JUST
135       posincr = 0;  // 0;
136   }
137   
138   if( fontSize == SMALL ) {
139     textString( scrn_rect.left + posincr, scrn_rect.top,
140                 label_buffer, GLUT_BITMAP_8_BY_13);
141     }
142   else  {
143     if( fontSize == LARGE ) {
144       textString( scrn_rect.left + posincr, scrn_rect.top,
145                   label_buffer, GLUT_BITMAP_9_BY_15);
146       }
147     }
148 }
149