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