1 #include <Main/fg_props.hxx>
5 #ifdef USE_HUD_TextList
6 #define textString(x, y, text, digit) TextString(text, x , y ,digit)
8 #define textString(x, y, text, digit) puDrawString(guiFnt, text, x, y)
11 FLTFNPTR get_func(const char *name); // FIXME
13 instr_label::instr_label(const SGPropertyNode *node) :
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))
33 SG_LOG(SG_INPUT, SG_INFO, "Done reading instr_label instrument "
34 << node->getStringValue("name", "[unnamed]"));
36 set_data_source(get_func(node->getStringValue("data_source")));
38 int just = node->getIntValue("justification");
42 justify = CENTER_JUST;
46 if (!strcmp(pre_str, "NULL"))
48 else if (!strcmp(pre_str, "blank"))
51 const char *units = strcmp(fgGetString("/sim/startup/units"), "feet") ? " m" : " ft"; // FIXME
53 if (!strcmp(post_str, "blank"))
55 else if (!strcmp(post_str, "NULL"))
57 else if (!strcmp(post_str, "units"))
61 if (pre_str != NULL) {
63 sprintf(format_buffer, "%s%s%s", pre_str, pformat, post_str);
65 sprintf(format_buffer, "%s%s", pre_str, pformat);
67 } else if (post_str != NULL) {
68 sprintf(format_buffer, "%s%s", pformat, post_str);
70 strcpy(format_buffer, pformat); // FIXME
75 void instr_label::draw(void)
77 char label_buffer[80];
80 RECT scrn_rect = get_location();
82 if (data_available()) {
84 sprintf(label_buffer, format_buffer, coord_format_lat(get_value()));
86 sprintf(label_buffer, format_buffer, coord_format_lon(get_value()));
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;
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);
104 glEnable(GL_LINE_STIPPLE);
105 glLineStipple(1, 0xAAAA);
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);
114 glDisable(GL_LINE_STIPPLE);
117 sprintf(label_buffer, format_buffer, get_value() * data_scaling());
121 sprintf(label_buffer, format_buffer);
124 lenstr = getStringWidth(label_buffer);
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");
132 lenstr = strlen(label_buffer);
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
141 if (fontSize == HUD_FONT_SMALL) {
142 textString(scrn_rect.left + posincr, scrn_rect.top,
143 label_buffer, get_digits());
145 } else if (fontSize == HUD_FONT_LARGE) {
146 textString(scrn_rect.left + posincr, scrn_rect.top,
147 label_buffer, get_digits());