]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
Merge branch 'jmt/gps' into next
[flightgear.git] / src / Cockpit / hud_labl.cxx
1
2 #ifdef HAVE_CONFIG_H
3 #  include <config.h>
4 #endif
5
6 #include "hud.hxx"
7
8 #ifdef USE_HUD_TextList
9 #define textString(x, y, text, digit)  TextString(text, x , y ,digit)
10 #else
11 #define textString(x, y, text, digit)  puDrawString(guiFnt, text, x, y)
12 #endif
13
14 FLTFNPTR get_func(const char *name);   // FIXME
15
16 instr_label::instr_label(const SGPropertyNode *node) :
17     instr_item(
18             node->getIntValue("x"),
19             node->getIntValue("y"),
20             node->getIntValue("width"),
21             node->getIntValue("height"),
22             NULL /* node->getStringValue("data_source") */,     // FIXME
23             node->getFloatValue("scale_data"),
24             node->getIntValue("options"),
25             node->getBoolValue("working", true),
26             node->getIntValue("digits")),
27     pformat(node->getStringValue("label_format")),
28     fontSize(fgGetInt("/sim/startup/xsize") > 1000 ? HUD_FONT_LARGE : HUD_FONT_SMALL),  // FIXME
29     blink(node->getIntValue("blinking")),
30     lat(node->getBoolValue("latitude", false)),
31     lon(node->getBoolValue("longitude", false)),
32     lbox(node->getBoolValue("label_box", false)),
33     lon_node(fgGetNode("/position/longitude-string", true)),
34     lat_node(fgGetNode("/position/latitude-string", true))
35 {
36     SG_LOG(SG_INPUT, SG_BULK, "Done reading instr_label instrument "
37             << node->getStringValue("name", "[unnamed]"));
38
39     set_data_source(get_func(node->getStringValue("data_source")));
40
41     int just = node->getIntValue("justification");
42     if (just == 0)
43         justify = LEFT_JUST;
44     else if (just == 1)
45         justify = CENTER_JUST;
46     else if (just == 2)
47         justify = RIGHT_JUST;
48
49     string pre_str(node->getStringValue("pre_label_string"));
50     if (pre_str== "NULL")
51         pre_str.clear();
52     else if (pre_str == "blank")
53         pre_str = " ";
54
55     const char *units = strcmp(fgGetString("/sim/startup/units"), "feet") ? " m" : " ft";  // FIXME
56
57     string post_str(node->getStringValue("post_label_string"));
58     if (post_str== "NULL")
59         post_str.clear();
60     else if (post_str == "blank")
61         post_str = " ";
62     else if (post_str == "units")
63         post_str = units;
64
65     format_buffer = pre_str + pformat;
66     format_buffer += post_str;
67 }
68
69
70 void instr_label::draw(void)
71 {
72     char label_buffer[80];
73     int posincr;
74     int lenstr;
75     RECT scrn_rect = get_location();
76
77     memset( label_buffer, 0, sizeof( label_buffer));
78     if (data_available()) {
79         if (lat)
80             snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), lat_node->getStringValue());
81         else if (lon)
82             snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), lon_node->getStringValue());
83         else {
84             if (lbox) {// Box for label
85                 float x = scrn_rect.left;
86                 float y = scrn_rect.top;
87                 float w = scrn_rect.right;
88                 float h = HUD_TextSize;
89
90                 glPushMatrix();
91                 glLoadIdentity();
92
93                 glBegin(GL_LINES);
94                 glVertex2f(x - 2.0,  y - 2.0);
95                 glVertex2f(x + w + 2.0, y - 2.0);
96                 glVertex2f(x + w + 2.0, y + h + 2.0);
97                 glVertex2f(x - 2.0,  y + h + 2.0);
98                 glEnd();
99
100                 glEnable(GL_LINE_STIPPLE);
101                 glLineStipple(1, 0xAAAA);
102
103                 glBegin(GL_LINES);
104                 glVertex2f(x + w + 2.0, y - 2.0);
105                 glVertex2f(x + w + 2.0, y + h + 2.0);
106                 glVertex2f(x - 2.0, y + h + 2.0);
107                 glVertex2f(x - 2.0, y - 2.0);
108                 glEnd();
109
110                 glDisable(GL_LINE_STIPPLE);
111                 glPopMatrix();
112             }
113             snprintf(label_buffer, sizeof(label_buffer)-1, format_buffer.c_str(), get_value() * data_scaling());
114         }
115
116     } else {
117         snprintf(label_buffer, sizeof( label_buffer) -1, format_buffer.c_str());
118     }
119
120     lenstr = getStringWidth(label_buffer);
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     lenstr = strlen(label_buffer);
129
130     if (justify == RIGHT_JUST)
131         posincr = scrn_rect.right - lenstr;
132     else if (justify == CENTER_JUST)
133         posincr = get_span() - (lenstr / 2); //  -lenstr*4;
134     else // justify == LEFT_JUST
135         posincr = 0;
136
137     if (fontSize == HUD_FONT_SMALL) {
138         textString(scrn_rect.left + posincr, scrn_rect.top,
139                 label_buffer, get_digits());
140
141     } else if (fontSize == HUD_FONT_LARGE) {
142         textString(scrn_rect.left + posincr, scrn_rect.top,
143                 label_buffer, get_digits());
144     }
145 }