]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
ecb693e5750de24cc1bed199517be9c22336b8b4
[flightgear.git] / src / Cockpit / hud_labl.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 instr_label::instr_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          latitude,
27         bool          longitude,
28         bool          label_box,
29         bool          working,
30         int           digit) :
31     instr_item( x, y, width, height,
32                 data_source,scale_data,options, working, digit),
33     pformat  ( label_format      ),
34     pre_str  ( pre_label_string  ),
35     post_str ( post_label_string ),
36     justify  ( justification     ),
37     fontSize ( font_size         ),
38     blink    ( blinking          ),
39     lat      ( latitude          ),
40     lon      ( longitude         ),
41     lbox     ( label_box         )
42 {
43     if (pre_str != NULL) {
44         if (post_str != NULL )
45             sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
46         else
47             sprintf( format_buffer, "%s%s",   pre_str, pformat );
48
49     } else if (post_str != NULL) {
50             sprintf( format_buffer, "%s%s",   pformat, post_str );
51     } // else do nothing if both pre and post strings are nulls. Interesting.
52
53 }
54
55
56 instr_label::~instr_label()
57 {
58 }
59
60
61 // Copy constructor
62 instr_label::instr_label(const instr_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     lat        ( image.lat      ),
69     lon        ( image.lon      ),
70     lbox       ( image.lbox     )
71
72 {
73     if (pre_str != NULL) {
74         if (post_str != NULL)
75             sprintf( format_buffer, "%s%s%s", pre_str, pformat, post_str );
76         else
77             sprintf( format_buffer, "%s%s",   pre_str, pformat );
78
79     } else if (post_str != NULL) {
80             sprintf( format_buffer, "%s%s",   pformat, post_str );
81     } // else do nothing if both pre and post strings are nulls. Interesting.
82
83 }
84
85
86 //
87 // draw                    Draws a label anywhere in the HUD
88 //
89 //
90 void instr_label::draw( void )
91 {
92     char label_buffer[80];
93     int posincr;
94     int lenstr;
95     RECT  scrn_rect = get_location();
96
97     if (data_available()) {
98         if (lat)
99             sprintf( label_buffer, format_buffer, coord_format_lat(get_value()) );
100         else if (lon)
101             sprintf( label_buffer, format_buffer, coord_format_lon(get_value()) );
102         else {
103             if (lbox) {// Box for label
104                 float x = scrn_rect.left;
105                 float y = scrn_rect.top;
106                 float w = scrn_rect.right;
107                 float h = HUD_TextSize;
108
109                 glPushMatrix();
110                 glLoadIdentity();
111
112                 glBegin(GL_LINES);
113                 glVertex2f( x - 2.0,  y - 2.0);
114                 glVertex2f( x + w + 2.0, y - 2.0);
115                 glVertex2f( x + w + 2.0, y + h + 2.0);
116                 glVertex2f( x - 2.0,  y + h + 2.0);
117                 glEnd();
118
119                 glEnable(GL_LINE_STIPPLE);
120                 glLineStipple( 1, 0xAAAA );
121
122                 glBegin(GL_LINES);
123                 glVertex2f( x + w + 2.0, y - 2.0);
124                 glVertex2f( x + w + 2.0, y + h + 2.0);
125                 glVertex2f( x - 2.0,  y + h + 2.0);
126                 glVertex2f( x - 2.0,  y - 2.0);
127                 glEnd();
128
129                 glDisable(GL_LINE_STIPPLE);
130                 glPopMatrix();
131             }
132             sprintf( label_buffer, format_buffer, get_value()*data_scaling() );
133         }
134
135     } else {
136 //    sprintf( label_buffer, format_buffer );
137     }
138
139     lenstr = getStringWidth( label_buffer );
140
141
142 #ifdef DEBUGHUD
143     fgPrintf( SG_COCKPIT, SG_DEBUG,  format_buffer );
144     fgPrintf( SG_COCKPIT, SG_DEBUG,  "\n" );
145     fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer );
146     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n" );
147 #endif
148     lenstr = strlen( label_buffer );
149
150     if (justify == RIGHT_JUST) {
151         posincr = scrn_rect.right - lenstr;
152     } else if (justify == CENTER_JUST) {
153         posincr = get_span() - (lenstr/2); //  -lenstr*4;
154     } else {
155         //  justify == LEFT_JUST
156         posincr = 0;  // 0;
157     }
158
159     if (fontSize == HUD_FONT_SMALL) {
160         textString( scrn_rect.left + posincr, scrn_rect.top,
161                     label_buffer, get_digits());
162
163     } else if (fontSize == HUD_FONT_LARGE) {
164         textString( scrn_rect.left + posincr, scrn_rect.top,
165                     label_buffer, get_digits());
166     }
167 }
168