]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
- fix two bugs
[flightgear.git] / src / Cockpit / hud_labl.cxx
1 #include <Main/fg_props.hxx>
2
3 #include "hud.hxx"
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 // FIXME
12 extern float get_aux1(), get_aux2(), get_aux3(), get_aux4(), get_aux5(), get_aux6();
13 extern float get_aux7(), get_aux8(), get_aux9(), get_aux10(), get_aux11(), get_aux12();
14 extern float get_aux13(), get_aux14(), get_aux15(), get_aux16(), get_aux17(), get_aux18();
15 extern float get_Ax(), get_speed(), get_mach(), get_altitude(), get_agl(), get_frame_rate();
16 extern float get_heading(), get_fov(), get_vfc_tris_culled(), get_vfc_tris_drawn(), get_aoa();
17 extern float get_latitude(), get_anzg(), get_longitude(), get_throttleval();
18
19 instr_label::instr_label(const SGPropertyNode *node) :
20     instr_item(
21             node->getIntValue("x"),
22             node->getIntValue("y"),
23             node->getIntValue("width"),
24             node->getIntValue("height"),
25             NULL /* node->getStringValue("data_source") */,     // FIXME
26             node->getFloatValue("scale_data"),
27             node->getIntValue("options"),
28             node->getBoolValue("working"),
29             node->getIntValue("digits")),
30     pformat(node->getStringValue("label_format")),
31     pre_str(node->getStringValue("pre_label_string")),
32     post_str(node->getStringValue("post_label_string")),
33     fontSize(fgGetInt("/sim/startup/xsize") > 1000 ? HUD_FONT_LARGE : HUD_FONT_SMALL),  // FIXME
34     blink(node->getIntValue("blinking")),
35     lat(node->getBoolValue("latitude", false)),
36     lon(node->getBoolValue("longitude", false)),
37     lbox(node->getBoolValue("label_box", false))
38 {
39     SG_LOG(SG_INPUT, SG_INFO, "Done reading instr_label instrument "
40             << node->getStringValue("name", "[none]"));
41
42     string loadfn = node->getStringValue("data_source");        // FIXME
43     float (*load_fn)(void);
44 #ifdef ENABLE_SP_FMDS
45     if (loadfn == "aux1")
46         load_fn = get_aux1;
47     else if (loadfn == "aux2")
48         load_fn = get_aux2;
49     else if (loadfn == "aux3")
50         load_fn = get_aux3;
51     else if (loadfn == "aux4")
52         load_fn = get_aux4;
53     else if (loadfn == "aux5")
54         load_fn = get_aux5;
55     else if (loadfn == "aux6")
56         load_fn = get_aux6;
57     else if (loadfn == "aux7")
58         load_fn = get_aux7;
59     else if (loadfn == "aux8")
60         load_fn = get_aux8;
61     else if (loadfn == "aux9")
62         load_fn = get_aux9;
63     else if (loadfn == "aux10")
64         load_fn = get_aux10;
65     else if (loadfn == "aux11")
66         load_fn = get_aux11;
67     else if (loadfn == "aux12")
68         load_fn = get_aux12;
69     else if (loadfn == "aux13")
70         load_fn = get_aux13;
71     else if (loadfn == "aux14")
72         load_fn = get_aux14;
73     else if (loadfn == "aux15")
74         load_fn = get_aux15;
75     else if (loadfn == "aux16")
76         load_fn = get_aux16;
77     else if (loadfn == "aux17")
78         load_fn = get_aux17;
79     else if (loadfn == "aux18")
80         load_fn = get_aux18;
81     else
82 #endif
83     if (loadfn == "ax")
84         load_fn = get_Ax;
85     else if (loadfn == "speed")
86         load_fn = get_speed;
87     else if (loadfn == "mach")
88         load_fn = get_mach;
89     else if (loadfn == "altitude")
90         load_fn = get_altitude;
91     else if (loadfn == "agl")
92         load_fn = get_agl;
93     else if (loadfn == "framerate")
94         load_fn = get_frame_rate;
95     else if (loadfn == "heading")
96         load_fn = get_heading;
97     else if (loadfn == "fov")
98         load_fn = get_fov;
99     else if (loadfn == "vfc_tris_culled")
100         load_fn = get_vfc_tris_culled;
101     else if (loadfn == "vfc_tris_drawn")
102         load_fn = get_vfc_tris_drawn;
103     else if (loadfn == "aoa")
104         load_fn = get_aoa;
105     else if (loadfn == "latitude")
106         load_fn = get_latitude;
107     else if (loadfn == "anzg")
108         load_fn = get_anzg;
109     else if (loadfn == "longitude")
110         load_fn = get_longitude;
111     else if (loadfn =="throttleval")
112         load_fn = get_throttleval;
113     else
114         load_fn = 0;
115
116     set_data_source(load_fn);
117
118     int just = node->getIntValue("justification");
119     if (just == 0)
120         justify = LEFT_JUST;
121     else if (just == 1)
122         justify = CENTER_JUST;
123     else if (just == 2)
124         justify = RIGHT_JUST;
125
126     if (!strcmp(pre_str, "NULL"))
127         pre_str = NULL;
128     else if (!strcmp(pre_str, "blank"))
129         pre_str = " ";
130
131     const char *units = strcmp(fgGetString("/sim/startup/units"), "feet") ? " m" : " ft";  // FIXME
132
133     if (!strcmp(post_str, "blank"))
134         post_str = " ";
135     else if (!strcmp(post_str, "NULL"))
136         post_str = NULL;
137     else if (!strcmp(post_str, "units"))
138         post_str = units;
139
140
141     if (pre_str != NULL) {
142         if (post_str != NULL)
143             sprintf(format_buffer, "%s%s%s", pre_str, pformat, post_str);
144         else
145             sprintf(format_buffer, "%s%s", pre_str, pformat);
146
147     } else if (post_str != NULL) {
148             sprintf(format_buffer, "%s%s", pformat, post_str);
149     } else {
150             strcpy(format_buffer, pformat);                     // FIXME
151     }
152 }
153
154
155 void instr_label::draw(void)
156 {
157     char label_buffer[80];
158     int posincr;
159     int lenstr;
160     RECT scrn_rect = get_location();
161
162     if (data_available()) {
163         if (lat)
164             sprintf(label_buffer, format_buffer, coord_format_lat(get_value()));
165         else if (lon)
166             sprintf(label_buffer, format_buffer, coord_format_lon(get_value()));
167         else {
168             if (lbox) {// Box for label
169                 float x = scrn_rect.left;
170                 float y = scrn_rect.top;
171                 float w = scrn_rect.right;
172                 float h = HUD_TextSize;
173
174                 glPushMatrix();
175                 glLoadIdentity();
176
177                 glBegin(GL_LINES);
178                 glVertex2f(x - 2.0,  y - 2.0);
179                 glVertex2f(x + w + 2.0, y - 2.0);
180                 glVertex2f(x + w + 2.0, y + h + 2.0);
181                 glVertex2f(x - 2.0,  y + h + 2.0);
182                 glEnd();
183
184                 glEnable(GL_LINE_STIPPLE);
185                 glLineStipple(1, 0xAAAA);
186
187                 glBegin(GL_LINES);
188                 glVertex2f(x + w + 2.0, y - 2.0);
189                 glVertex2f(x + w + 2.0, y + h + 2.0);
190                 glVertex2f(x - 2.0, y + h + 2.0);
191                 glVertex2f(x - 2.0, y - 2.0);
192                 glEnd();
193
194                 glDisable(GL_LINE_STIPPLE);
195                 glPopMatrix();
196             }
197             sprintf(label_buffer, format_buffer, get_value() * data_scaling());
198         }
199
200     } else {
201         sprintf(label_buffer, format_buffer);
202     }
203
204     lenstr = getStringWidth(label_buffer);
205
206 #ifdef DEBUGHUD
207     fgPrintf( SG_COCKPIT, SG_DEBUG, format_buffer);
208     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n");
209     fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer);
210     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n");
211 #endif
212     lenstr = strlen(label_buffer);
213
214     if (justify == RIGHT_JUST)
215         posincr = scrn_rect.right - lenstr;
216     else if (justify == CENTER_JUST)
217         posincr = get_span() - (lenstr / 2); //  -lenstr*4;
218     else // justify == LEFT_JUST
219         posincr = 0;
220
221     if (fontSize == HUD_FONT_SMALL) {
222         textString(scrn_rect.left + posincr, scrn_rect.top,
223                 label_buffer, get_digits());
224
225     } else if (fontSize == HUD_FONT_LARGE) {
226         textString(scrn_rect.left + posincr, scrn_rect.top,
227                 label_buffer, get_digits());
228     }
229 }
230
231