]> git.mxchange.org Git - flightgear.git/blob - src/Cockpit/hud_labl.cxx
remove lon/lat string representation generating functions; this is now
[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     pre_str(node->getStringValue("pre_label_string")),
29     post_str(node->getStringValue("post_label_string")),
30     fontSize(fgGetInt("/sim/startup/xsize") > 1000 ? HUD_FONT_LARGE : HUD_FONT_SMALL),  // FIXME
31     blink(node->getIntValue("blinking")),
32     lat(node->getBoolValue("latitude", false)),
33     lon(node->getBoolValue("longitude", false)),
34     lbox(node->getBoolValue("label_box", false)),
35     lon_node(fgGetNode("/position/longitude-string", true)),
36     lat_node(fgGetNode("/position/latitude-string", true))
37 {
38     SG_LOG(SG_INPUT, SG_INFO, "Done reading instr_label instrument "
39             << node->getStringValue("name", "[unnamed]"));
40
41     set_data_source(get_func(node->getStringValue("data_source")));
42
43     int just = node->getIntValue("justification");
44     if (just == 0)
45         justify = LEFT_JUST;
46     else if (just == 1)
47         justify = CENTER_JUST;
48     else if (just == 2)
49         justify = RIGHT_JUST;
50
51     if (!strcmp(pre_str, "NULL"))
52         pre_str = NULL;
53     else if (!strcmp(pre_str, "blank"))
54         pre_str = " ";
55
56     const char *units = strcmp(fgGetString("/sim/startup/units"), "feet") ? " m" : " ft";  // FIXME
57
58     if (!strcmp(post_str, "blank"))
59         post_str = " ";
60     else if (!strcmp(post_str, "NULL"))
61         post_str = NULL;
62     else if (!strcmp(post_str, "units"))
63         post_str = units;
64
65
66     if (pre_str != NULL) {
67         if (post_str != NULL)
68             sprintf(format_buffer, "%s%s%s", pre_str, pformat, post_str);
69         else
70             sprintf(format_buffer, "%s%s", pre_str, pformat);
71
72     } else if (post_str != NULL) {
73             sprintf(format_buffer, "%s%s", pformat, post_str);
74     } else {
75             strcpy(format_buffer, pformat);                     // FIXME
76     }
77 }
78
79
80 void instr_label::draw(void)
81 {
82     char label_buffer[80];
83     int posincr;
84     int lenstr;
85     RECT scrn_rect = get_location();
86
87     if (data_available()) {
88         if (lat)
89             snprintf(label_buffer, 80, format_buffer, lat_node->getStringValue());
90         else if (lon)
91             snprintf(label_buffer, 80, format_buffer, lon_node->getStringValue());
92         else {
93             if (lbox) {// Box for label
94                 float x = scrn_rect.left;
95                 float y = scrn_rect.top;
96                 float w = scrn_rect.right;
97                 float h = HUD_TextSize;
98
99                 glPushMatrix();
100                 glLoadIdentity();
101
102                 glBegin(GL_LINES);
103                 glVertex2f(x - 2.0,  y - 2.0);
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                 glEnd();
108
109                 glEnable(GL_LINE_STIPPLE);
110                 glLineStipple(1, 0xAAAA);
111
112                 glBegin(GL_LINES);
113                 glVertex2f(x + w + 2.0, y - 2.0);
114                 glVertex2f(x + w + 2.0, y + h + 2.0);
115                 glVertex2f(x - 2.0, y + h + 2.0);
116                 glVertex2f(x - 2.0, y - 2.0);
117                 glEnd();
118
119                 glDisable(GL_LINE_STIPPLE);
120                 glPopMatrix();
121             }
122             sprintf(label_buffer, format_buffer, get_value() * data_scaling());
123         }
124
125     } else {
126         sprintf(label_buffer, format_buffer);
127     }
128
129     lenstr = getStringWidth(label_buffer);
130
131 #ifdef DEBUGHUD
132     fgPrintf( SG_COCKPIT, SG_DEBUG, format_buffer);
133     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n");
134     fgPrintf( SG_COCKPIT, SG_DEBUG, label_buffer);
135     fgPrintf( SG_COCKPIT, SG_DEBUG, "\n");
136 #endif
137     lenstr = strlen(label_buffer);
138
139     if (justify == RIGHT_JUST)
140         posincr = scrn_rect.right - lenstr;
141     else if (justify == CENTER_JUST)
142         posincr = get_span() - (lenstr / 2); //  -lenstr*4;
143     else // justify == LEFT_JUST
144         posincr = 0;
145
146     if (fontSize == HUD_FONT_SMALL) {
147         textString(scrn_rect.left + posincr, scrn_rect.top,
148                 label_buffer, get_digits());
149
150     } else if (fontSize == HUD_FONT_LARGE) {
151         textString(scrn_rect.left + posincr, scrn_rect.top,
152                 label_buffer, get_digits());
153     }
154 }
155
156