]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lat.cxx
Small tweaks to initialization sequence and logic so we can default to
[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,digit )  TextString( text, x , y,digit ) //suma
7 #else
8 #define textString( x , y, text, font,digit )  puDrawString ( guiFnt, text, x, y ); //suma
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                                           int                   digit): //suma
28                            instr_item( x, y, width, height,
29                                        data_source, scale_data,options, working,digit), //suma
30                            pformat  ( label_format      ),
31                            pre_str  ( pre_label_string  ),
32                            post_str ( post_label_string ),
33                            justify  ( justification     ),
34                            fontSize ( font_size         ),
35                            blink    ( blinking          )
36 {
37   if( pre_str != NULL) {
38     if( post_str != NULL ) {
39       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
40       }
41     else {
42       sprintf( format_buffer, "%s%s",   pre_str, pformat );
43       }
44     }
45   else {
46     if( post_str != NULL ) {
47       sprintf( format_buffer, "%s%s",   pformat, post_str );
48       }
49     } // else do nothing if both pre and post strings are nulls. Interesting.
50
51 }
52
53 // I put this in to make it easy to construct a class member using the current
54 // C code.
55
56
57 lat_label :: ~lat_label()
58 {
59 }
60
61 // Copy constructor
62 lat_label :: lat_label( const lat_label & image) :
63                               instr_item((const instr_item &)image),
64                               pformat    ( image.pformat    ),
65                               pre_str  ( image.pre_str  ),
66                               post_str ( image.post_str ),
67                               blink    ( image.blink    )
68 {
69   if( pre_str != NULL) {
70     if( post_str != NULL ) {
71       sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
72       }
73     else {
74       sprintf( format_buffer, "%s%s",   pre_str, pformat );
75       }
76     }
77   else {
78     if( post_str != NULL ) {
79       sprintf( format_buffer, "%s%s",   pformat, post_str );
80       }
81     } // else do nothing if both pre and post strings are nulls. Interesting.
82
83 }
84
85 lat_label & lat_label ::operator = (const lat_label & rhs )
86 {
87   if( !(this == &rhs)) {
88     instr_item::operator = (rhs);
89     pformat      = rhs.pformat;
90     fontSize   = rhs.fontSize;
91     blink      = rhs.blink;
92     justify    = rhs.justify;
93     pre_str    = rhs.pre_str;
94     post_str   = rhs.post_str;
95     strcpy(format_buffer,rhs.format_buffer);    
96     }
97   return *this;
98 }
99
100 //
101 // draw                    Draws a label anywhere in the HUD
102 //
103 //
104 void lat_label ::
105 draw( void )       // Required method in base class
106 {
107   char label_buffer[80];
108   int posincr;
109   int lenstr;
110   RECT  scrn_rect = get_location();
111 //  float lat = get_value();
112   
113   if( data_available() ) {
114 //        sprintf( label_buffer, format_buffer, coord_format_lat(lat) );
115           sprintf( label_buffer, format_buffer,
116                            coord_format_lat( get_value()) );
117     }
118   else {
119      sprintf( label_buffer, format_buffer );
120   }
121     
122 #ifdef DEBUGHUD
123   fgPrintf( SG_COCKPIT, SG_DEBUG,  format_buffer );
124   fgPrintf( SG_COCKPIT, SG_DEBUG,  "\n" );
125   fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
126   fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
127 #endif
128
129   lenstr = getStringWidth(label_buffer);
130                                                 
131   if( justify == RIGHT_JUST ) {
132           posincr = scrn_rect.right - lenstr;
133   }else if( justify == CENTER_JUST ) {
134           posincr = get_span() - (lenstr/2);
135   }  else {  //  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, get_digits()); //suma
142     }
143   else  {
144     if( fontSize == LARGE ) {
145       textString( scrn_rect.left + posincr, scrn_rect.top,
146                   label_buffer, GLUT_BITMAP_9_BY_15,get_digits()); //suma
147       }
148     }
149 }
150