X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCockpit%2Fhud_labl.cxx;h=d19fed05696da5f33f462dcbf281898f00577699;hb=5f134cdec82692e4a414af302a8f30c3825ebe64;hp=ceaeaf05f0d3b390f52a989a11a21b1ccd7a449e;hpb=d336553d75f35aebe282ce16cdb0be64635bbbba;p=flightgear.git diff --git a/src/Cockpit/hud_labl.cxx b/src/Cockpit/hud_labl.cxx index ceaeaf05f..d19fed056 100644 --- a/src/Cockpit/hud_labl.cxx +++ b/src/Cockpit/hud_labl.cxx @@ -1,4 +1,7 @@ -#include
+ +#ifdef HAVE_CONFIG_H +# include +#endif #include "hud.hxx" @@ -22,13 +25,13 @@ instr_label::instr_label(const SGPropertyNode *node) : node->getBoolValue("working", true), node->getIntValue("digits")), pformat(node->getStringValue("label_format")), - pre_str(node->getStringValue("pre_label_string")), - post_str(node->getStringValue("post_label_string")), fontSize(fgGetInt("/sim/startup/xsize") > 1000 ? HUD_FONT_LARGE : HUD_FONT_SMALL), // FIXME blink(node->getIntValue("blinking")), lat(node->getBoolValue("latitude", false)), lon(node->getBoolValue("longitude", false)), - lbox(node->getBoolValue("label_box", false)) + lbox(node->getBoolValue("label_box", false)), + lon_node(fgGetNode("/position/longitude-string", true)), + lat_node(fgGetNode("/position/latitude-string", true)) { SG_LOG(SG_INPUT, SG_INFO, "Done reading instr_label instrument " << node->getStringValue("name", "[unnamed]")); @@ -43,32 +46,24 @@ instr_label::instr_label(const SGPropertyNode *node) : else if (just == 2) justify = RIGHT_JUST; - if (!strcmp(pre_str, "NULL")) - pre_str = NULL; - else if (!strcmp(pre_str, "blank")) + string pre_str(node->getStringValue("pre_label_string")); + if (pre_str== "NULL") + pre_str.clear(); + else if (pre_str == "blank") pre_str = " "; const char *units = strcmp(fgGetString("/sim/startup/units"), "feet") ? " m" : " ft"; // FIXME - if (!strcmp(post_str, "blank")) + string post_str(node->getStringValue("post_label_string")); + if (post_str== "NULL") + post_str.clear(); + else if (post_str == "blank") post_str = " "; - else if (!strcmp(post_str, "NULL")) - post_str = NULL; - else if (!strcmp(post_str, "units")) + else if (post_str == "units") post_str = units; - - if (pre_str != NULL) { - if (post_str != NULL) - sprintf(format_buffer, "%s%s%s", pre_str, pformat, post_str); - else - sprintf(format_buffer, "%s%s", pre_str, pformat); - - } else if (post_str != NULL) { - sprintf(format_buffer, "%s%s", pformat, post_str); - } else { - strcpy(format_buffer, pformat); // FIXME - } + format_buffer = pre_str + pformat; + format_buffer += post_str; } @@ -79,11 +74,12 @@ void instr_label::draw(void) int lenstr; RECT scrn_rect = get_location(); + memset( label_buffer, 0, sizeof( label_buffer)); if (data_available()) { if (lat) - sprintf(label_buffer, format_buffer, coord_format_lat(get_value())); + snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), lat_node->getStringValue()); else if (lon) - sprintf(label_buffer, format_buffer, coord_format_lon(get_value())); + snprintf(label_buffer, sizeof( label_buffer)-1, format_buffer.c_str(), lon_node->getStringValue()); else { if (lbox) {// Box for label float x = scrn_rect.left; @@ -114,11 +110,11 @@ void instr_label::draw(void) glDisable(GL_LINE_STIPPLE); glPopMatrix(); } - sprintf(label_buffer, format_buffer, get_value() * data_scaling()); + snprintf(label_buffer, sizeof(label_buffer)-1, format_buffer.c_str(), get_value() * data_scaling()); } } else { - sprintf(label_buffer, format_buffer); + snprintf(label_buffer, sizeof( label_buffer) -1, format_buffer.c_str()); } lenstr = getStringWidth(label_buffer); @@ -147,5 +143,3 @@ void instr_label::draw(void) label_buffer, get_digits()); } } - -