]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lat.cxx
remove the rest of the static variables (except one); cleanup
[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, digit)  TextString(text, x , y ,digit)
7 #else
8 #define textString(x, y, text, digit)  puDrawString(guiFnt, text, x, y)
9 #endif
10
11 //======================= Top of instr_label class =========================
12 lat_label::lat_label(int           x,
13                      int           y,
14                      UINT          width,
15                      UINT          height,
16                      FLTFNPTR      data_source,
17                      const char   *label_format,
18                      const char   *pre_label_string,
19                      const char   *post_label_string,
20                      float         scale_data,
21                      UINT          options,
22                      fgLabelJust   justification,
23                      int           font_size,
24                      int           blinking,
25                      bool          working ,
26                      int           digit) :
27     instr_item( x, y, width, height,
28                 data_source, scale_data,options, working,digit),
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         else
40             sprintf( format_buffer, "%s%s",   pre_str, pformat );
41
42     } else if (post_str != NULL) {
43             sprintf( format_buffer, "%s%s",   pformat, post_str );
44     } // else do nothing if both pre and post strings are nulls. Interesting.
45
46 }
47
48 // I put this in to make it easy to construct a class member using the current
49 // C code.
50
51
52 lat_label::~lat_label()
53 {
54 }
55
56
57 // Copy constructor
58 lat_label::lat_label( const lat_label & image) :
59                       instr_item((const instr_item &)image),
60                       pformat    ( image.pformat  ),
61                       pre_str    ( image.pre_str  ),
62                       post_str   ( image.post_str ),
63                       blink      ( image.blink    )
64 {
65     if (pre_str != NULL) {
66         if (post_str != NULL)
67             sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
68         else
69             sprintf( format_buffer, "%s%s",   pre_str, pformat );
70
71     } else if (post_str != NULL) {
72         sprintf( format_buffer, "%s%s",   pformat, post_str );
73     } // else do nothing if both pre and post strings are nulls. Interesting.
74
75 }
76
77
78 //
79 // draw                    Draws a label anywhere in the HUD
80 //
81 //
82 void lat_label::draw( void )       // Required method in base class
83 {
84     char label_buffer[80];
85     int posincr;
86     int lenstr;
87     RECT  scrn_rect = get_location();
88     // float lat = get_value();
89
90     if (data_available()) {
91 //      // sprintf( label_buffer, format_buffer, coord_format_lat(lat) );
92         sprintf( label_buffer, format_buffer,
93                 coord_format_lat( get_value()) );
94
95     } else {
96         sprintf( label_buffer, format_buffer );
97     }
98
99 #ifdef DEBUGHUD
100     fgPrintf( SG_COCKPIT, SG_DEBUG, format_buffer );
101     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
102     fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
103     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
104 #endif
105
106     lenstr = getStringWidth(label_buffer);
107
108     if (justify == RIGHT_JUST)
109         posincr = scrn_rect.right - lenstr;
110     else if (justify == CENTER_JUST)
111         posincr = get_span() - (lenstr/2);
112     else // justify == LEFT_JUST
113         posincr = 0;
114
115     if (fontSize == HUD_FONT_SMALL) {
116         textString( scrn_rect.left + posincr, scrn_rect.top,
117                 label_buffer, get_digits());
118
119     } else if (fontSize == HUD_FONT_LARGE) {
120         textString( scrn_rect.left + posincr, scrn_rect.top,
121                 label_buffer, get_digits());
122     }
123 }
124
125