]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_lon.cxx
remove the rest of the static variables (except one); cleanup
[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, 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 lon_label::lon_label(
13         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) :
28     instr_item( x, y, width, height,
29                 data_source, scale_data,options, working,digit ),
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         else
41             sprintf( format_buffer, "%s%s",   pre_str, pformat );
42
43     } else if (post_str != NULL) {
44             sprintf( format_buffer, "%s%s",   pformat, post_str );
45     } // else do nothing if both pre and post strings are nulls. Interesting.
46
47 }
48
49
50 lon_label::~lon_label()
51 {
52 }
53
54
55 // Copy constructor
56 lon_label::lon_label( const lon_label & image) :
57     instr_item((const instr_item &)image),
58     pformat    ( image.pformat    ),
59     pre_str    ( image.pre_str  ),
60     post_str   ( image.post_str ),
61     blink      ( image.blink    )
62 {
63     if (pre_str != NULL) {
64         if (post_str != NULL)
65             sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
66         else
67             sprintf( format_buffer, "%s%s",   pre_str, pformat );
68
69     } else if (post_str != NULL) {
70             sprintf( format_buffer, "%s%s",   pformat, post_str );
71     } // else do nothing if both pre and post strings are nulls. Interesting.
72 }
73
74
75 //
76 // draw                    Draws a label anywhere in the HUD
77 //
78 //
79 void lon_label::draw( void )
80 {
81     char label_buffer[80];
82     int posincr;
83     int lenstr;
84     RECT  scrn_rect = get_location();
85     float lon = get_value();
86
87     if ( data_available() ) {
88         lenstr = sprintf( label_buffer, format_buffer, coord_format_lon(lon) );
89     } else {
90         lenstr = sprintf( label_buffer, format_buffer );
91     }
92
93 #ifdef DEBUGHUD
94     fgPrintf( SG_COCKPIT, SG_DEBUG, format_buffer );
95     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
96     fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
97     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
98 #endif
99
100     lenstr = getStringWidth(label_buffer);
101
102     if (justify == RIGHT_JUST)
103         posincr = scrn_rect.right - lenstr;
104     else if (justify == CENTER_JUST)
105       posincr = get_span() - (lenstr/2);
106     else //  justify == LEFT_JUST
107       posincr = 0;
108
109     if (fontSize == HUD_FONT_SMALL) {
110         textString( scrn_rect.left + posincr, scrn_rect.top,
111                     label_buffer, get_digits());
112
113     } else if (fontSize == HUD_FONT_LARGE) {
114         textString( scrn_rect.left + posincr, scrn_rect.top,
115                     label_buffer, get_digits());
116     }
117 }
118
119