]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lon.cxx
- adjusted for no-value constructor for FGPanel
[flightgear.git] / src / Cockpit / hud_lon.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 lon_label ::
13          lon_label( int           x,
14                       int           y,
15                       UINT          width,
16                       UINT          height,
17                       FLTFNPTR      data_source,
18 //                      DBLFNPTR      data_source,                                      
19                       const char   *label_format,
20                       const char   *pre_label_string,
21                       const char   *post_label_string,
22                       float        scale_data,
23 //                      double        scale_data,                                       
24                       UINT          options,
25                       fgLabelJust   justification,
26                       int           font_size,
27                       int           blinking,
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 {
38   if( pre_str != NULL) {
39     if( post_str != NULL ) {
40       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
41       }
42     else {
43       sprintf( format_buffer, "%s%s",   pre_str, pformat );
44       }
45     }
46   else {
47     if( post_str != NULL ) {
48       sprintf( format_buffer, "%s%s",   pformat, post_str );
49       }
50     } // else do nothing if both pre and post strings are nulls. Interesting.
51
52 }
53
54 // I put this in to make it easy to construct a class member using the current
55 // C code.
56
57
58 lon_label :: ~lon_label()
59 {
60 }
61
62 // Copy constructor
63 lon_label :: lon_label( const lon_label & image) :
64                               instr_item((const instr_item &)image),
65                               pformat    ( image.pformat    ),
66                               pre_str  ( image.pre_str  ),
67                               post_str ( image.post_str ),
68                               blink    ( image.blink    )
69 {
70   if( pre_str != NULL) {
71     if( post_str != NULL ) {
72       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
73       }
74     else {
75       sprintf( format_buffer, "%s%s",   pre_str, pformat );
76       }
77     }
78   else {
79     if( post_str != NULL ) {
80       sprintf( format_buffer, "%s%s",   pformat, post_str );
81       }
82     } // else do nothing if both pre and post strings are nulls. Interesting.
83
84 }
85
86 lon_label & lon_label ::operator = (const lon_label & rhs )
87 {
88   if( !(this == &rhs)) {
89     instr_item::operator = (rhs);
90     pformat      = rhs.pformat;
91     fontSize   = rhs.fontSize;
92     blink      = rhs.blink;
93     justify    = rhs.justify;
94     pre_str    = rhs.pre_str;
95     post_str   = rhs.post_str;
96     strcpy(format_buffer,rhs.format_buffer);    
97     }
98   return *this;
99 }
100
101 //
102 // draw                    Draws a label anywhere in the HUD
103 //
104 //
105 void lon_label ::
106 draw( void )       // Required method in base class
107 {
108 //  char format_buffer[80];
109   char label_buffer[80];
110   int posincr;
111   int lenstr;
112   RECT  scrn_rect = get_location();
113   float lon = get_value();
114 //  double lon = get_value();  
115   if( data_available() ) {
116 //      char *lonstring = coord_format_lon(lon);
117     lenstr = sprintf( label_buffer, format_buffer, coord_format_lon(lon) );
118     }
119   else {
120     lenstr = sprintf( label_buffer, format_buffer );
121     }
122     
123 #ifdef DEBUGHUD
124   fgPrintf( SG_COCKPIT, SG_DEBUG,  format_buffer );
125   fgPrintf( SG_COCKPIT, SG_DEBUG,  "\n" );
126   fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
127   fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
128 #endif
129         
130         lenstr = getStringWidth(label_buffer);
131                                                 
132   if( justify == RIGHT_JUST ) {
133           posincr = scrn_rect.right - lenstr;
134   }else if( justify == CENTER_JUST ) {
135           posincr = get_span() - (lenstr/2);
136   }  else {
137       //  justify == LEFT_JUST
138       posincr = 0;
139   }
140   
141   if( fontSize == SMALL ) {
142     textString( scrn_rect.left + posincr, scrn_rect.top,
143                 label_buffer, GLUT_BITMAP_8_BY_13);
144     }
145   else  {
146     if( fontSize == LARGE ) {
147       textString( scrn_rect.left + posincr, scrn_rect.top,
148                   label_buffer, GLUT_BITMAP_9_BY_15);
149       }
150     }
151 }
152