2001-09-19 22:23:25 +00:00
|
|
|
#include "hud.hxx"
|
|
|
|
|
|
|
|
#ifdef USE_HUD_TextList
|
2006-06-14 10:30:10 +00:00
|
|
|
#define textString(x, y, text, digit) TextString(text, x , y ,digit)
|
2001-09-19 22:23:25 +00:00
|
|
|
#else
|
2006-06-14 10:30:10 +00:00
|
|
|
#define textString(x, y, text, digit) puDrawString(guiFnt, text, x, y)
|
2001-09-19 22:23:25 +00:00
|
|
|
#endif
|
|
|
|
|
2006-06-15 18:09:15 +00:00
|
|
|
FLTFNPTR get_func(const char *name); // FIXME
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
gauge_instr::gauge_instr(const SGPropertyNode *node) :
|
|
|
|
instr_scale(
|
|
|
|
node->getIntValue("x"),
|
|
|
|
node->getIntValue("y"),
|
|
|
|
node->getIntValue("width"),
|
|
|
|
node->getIntValue("height"),
|
|
|
|
0 /*load_fn*/,
|
|
|
|
node->getIntValue("options"),
|
|
|
|
node->getFloatValue("maxValue") - node->getFloatValue("minValue"), // Always shows span?
|
|
|
|
node->getFloatValue("maxValue"),
|
|
|
|
node->getFloatValue("minValue"),
|
|
|
|
node->getFloatValue("disp_scaling"),
|
|
|
|
node->getIntValue("major_divs"),
|
|
|
|
node->getIntValue("minor_divs"),
|
|
|
|
node->getIntValue("modulator"), // "rollover"
|
|
|
|
0, /* hud.cxx: static int dp_shoing = 0; */ // FIXME
|
2006-06-15 18:09:15 +00:00
|
|
|
node->getBoolValue("working", true))
|
2001-09-19 22:23:25 +00:00
|
|
|
{
|
2006-06-14 20:39:10 +00:00
|
|
|
SG_LOG(SG_INPUT, SG_INFO, "Done reading gauge instrument "
|
|
|
|
<< node->getStringValue("name", "[unnamed]"));
|
|
|
|
|
2006-06-15 18:09:15 +00:00
|
|
|
set_data_source(get_func(node->getStringValue("loadfn")));
|
2001-09-19 22:23:25 +00:00
|
|
|
}
|
|
|
|
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2001-09-19 22:23:25 +00:00
|
|
|
// As implemented, draw only correctly draws a horizontal or vertical
|
|
|
|
// scale. It should contain a variation that permits clock type displays.
|
|
|
|
// Now is supports "tickless" displays such as control surface indicators.
|
|
|
|
// This routine should be worked over before using. Current value would be
|
|
|
|
// fetched and not used if not commented out. Clearly that is intollerable.
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
void gauge_instr::draw(void)
|
2001-09-19 22:23:25 +00:00
|
|
|
{
|
2006-06-12 23:27:55 +00:00
|
|
|
float marker_xs, marker_xe;
|
|
|
|
float marker_ys, marker_ye;
|
2001-09-19 22:23:25 +00:00
|
|
|
int text_x, text_y;
|
|
|
|
int width, height, bottom_4;
|
|
|
|
int lenstr;
|
|
|
|
int i;
|
|
|
|
char TextScale[80];
|
|
|
|
bool condition;
|
|
|
|
int disp_val = 0;
|
2006-06-14 20:39:10 +00:00
|
|
|
float vmin = min_val();
|
|
|
|
float vmax = max_val();
|
|
|
|
POINT mid_scr = get_centroid();
|
|
|
|
float cur_value = get_value();
|
|
|
|
RECT scrn_rect = get_location();
|
|
|
|
UINT options = get_options();
|
2001-09-19 22:23:25 +00:00
|
|
|
|
|
|
|
width = scrn_rect.left + scrn_rect.right;
|
2006-06-14 20:39:10 +00:00
|
|
|
height = scrn_rect.top + scrn_rect.bottom;
|
2006-06-12 23:27:55 +00:00
|
|
|
bottom_4 = scrn_rect.bottom / 4;
|
2001-09-19 22:23:25 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
// Draw the basic markings for the scale...
|
|
|
|
if (huds_vert(options)) { // Vertical scale
|
|
|
|
// Bottom tick bar
|
|
|
|
drawOneLine(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
// Top tick bar
|
|
|
|
drawOneLine( scrn_rect.left, height, width, height);
|
2006-06-12 23:27:55 +00:00
|
|
|
|
|
|
|
marker_xs = scrn_rect.left;
|
|
|
|
marker_xe = width;
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_left(options)) { // Read left, so line down right side
|
|
|
|
drawOneLine(width, scrn_rect.top, width, height);
|
|
|
|
marker_xs = marker_xe - scrn_rect.right / 3.0; // Adjust tick
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_right(options)) { // Read right, so down left sides
|
|
|
|
drawOneLine(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
|
|
|
|
marker_xe = scrn_rect.left + scrn_rect.right / 3.0; // Adjust tick
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point marker x_start and x_end values are transposed.
|
|
|
|
// To keep this from confusing things they are now interchanged.
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_both(options)) {
|
2006-06-12 23:27:55 +00:00
|
|
|
marker_ye = marker_xs;
|
|
|
|
marker_xs = marker_xe;
|
|
|
|
marker_xe = marker_ye;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work through from bottom to top of scale. Calculating where to put
|
|
|
|
// minor and major ticks.
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (!huds_noticks(options)) { // If not no ticks...:)
|
2006-06-12 23:27:55 +00:00
|
|
|
// Calculate x marker offsets
|
2006-06-14 20:39:10 +00:00
|
|
|
int last = (int)vmax + 1; // FloatToInt(vmax)+1;
|
2006-06-12 23:27:55 +00:00
|
|
|
i = (int)vmin; //FloatToInt(vmin);
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
for (; i < last; i++) {
|
2006-06-12 23:27:55 +00:00
|
|
|
// Calculate the location of this tick
|
|
|
|
marker_ys = scrn_rect.top + (i - vmin) * factor()/* +.5f*/;
|
|
|
|
|
|
|
|
// We compute marker_ys even though we don't know if we will use
|
|
|
|
// either major or minor divisions. Simpler.
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (div_min()) { // Minor tick marks
|
|
|
|
if (!(i % (int)div_min())) {
|
|
|
|
if (huds_left(options) && huds_right(options)) {
|
|
|
|
drawOneLine(scrn_rect.left, marker_ys, marker_xs - 3, marker_ys);
|
|
|
|
drawOneLine(marker_xe + 3, marker_ys, width, marker_ys);
|
|
|
|
|
|
|
|
} else if (huds_left(options)) {
|
|
|
|
drawOneLine(marker_xs + 3, marker_ys, marker_xe, marker_ys);
|
|
|
|
} else {
|
|
|
|
drawOneLine(marker_xs, marker_ys, marker_xe - 3, marker_ys);
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now we work on the major divisions. Since these are also labeled
|
|
|
|
// and no labels are drawn otherwise, we label inside this if
|
|
|
|
// statement.
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (div_max()) { // Major tick mark
|
|
|
|
if (!(i % (int)div_max())) {
|
|
|
|
if (huds_left(options) && huds_right(options)) {
|
|
|
|
drawOneLine(scrn_rect.left, marker_ys, marker_xs, marker_ys);
|
|
|
|
drawOneLine(marker_xe, marker_ys, width, marker_ys);
|
|
|
|
} else {
|
|
|
|
drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (!huds_notext(options)) {
|
2006-06-12 23:27:55 +00:00
|
|
|
disp_val = i;
|
2006-06-14 20:39:10 +00:00
|
|
|
sprintf(TextScale, "%d",
|
|
|
|
FloatToInt(disp_val * data_scaling()/*+.5*/));
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
lenstr = getStringWidth(TextScale);
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_left(options) && huds_right(options)) {
|
2006-06-12 23:27:55 +00:00
|
|
|
text_x = mid_scr.x - lenstr/2 ;
|
2006-06-14 20:39:10 +00:00
|
|
|
|
|
|
|
} else if (huds_left(options)) {
|
|
|
|
text_x = FloatToInt(marker_xs - lenstr);
|
|
|
|
} else {
|
|
|
|
text_x = FloatToInt(marker_xe - lenstr);
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
// Now we know where to put the text.
|
|
|
|
text_y = FloatToInt(marker_ys);
|
2006-06-14 20:39:10 +00:00
|
|
|
textString(text_x, text_y, TextScale, 0);
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-14 20:39:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-12 23:27:55 +00:00
|
|
|
// Now that the scale is drawn, we draw in the pointer(s). Since labels
|
|
|
|
// have been drawn, text_x and text_y may be recycled. This is used
|
|
|
|
// with the marker start stops to produce a pointer for each side reading
|
|
|
|
|
|
|
|
text_y = scrn_rect.top + FloatToInt((cur_value - vmin) * factor() /*+.5f*/);
|
|
|
|
// text_x = marker_xs - scrn_rect.left;
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_right(options)) {
|
2006-06-12 23:27:55 +00:00
|
|
|
glBegin(GL_LINE_STRIP);
|
2006-06-14 20:39:10 +00:00
|
|
|
glVertex2f(scrn_rect.left, text_y + 5);
|
|
|
|
glVertex2f(FloatToInt(marker_xe), text_y);
|
|
|
|
glVertex2f(scrn_rect.left, text_y - 5);
|
2006-06-12 23:27:55 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_left(options)) {
|
2006-06-12 23:27:55 +00:00
|
|
|
glBegin(GL_LINE_STRIP);
|
2006-06-14 20:39:10 +00:00
|
|
|
glVertex2f(width, text_y + 5);
|
|
|
|
glVertex2f(FloatToInt(marker_xs), text_y);
|
|
|
|
glVertex2f(width, text_y - 5);
|
2006-06-12 23:27:55 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
// End if VERTICAL SCALE TYPE
|
|
|
|
|
|
|
|
} else { // Horizontal scale by default
|
2006-06-14 20:39:10 +00:00
|
|
|
// left tick bar
|
|
|
|
drawOneLine(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
// right tick bar
|
|
|
|
drawOneLine(width, scrn_rect.top, width, height );
|
2006-06-12 23:27:55 +00:00
|
|
|
|
|
|
|
marker_ys = scrn_rect.top; // Starting point for
|
|
|
|
marker_ye = height; // tick y location calcs
|
|
|
|
marker_xs = scrn_rect.left + (cur_value - vmin) * factor() /*+ .5f*/;
|
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
if (huds_top(options)) {
|
|
|
|
// Bottom box line
|
|
|
|
drawOneLine(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
|
2006-06-12 23:27:55 +00:00
|
|
|
|
2006-06-14 20:39:10 +00:00
|
|
|
marker_ye = scrn_rect.top + scrn_rect.bottom / 2.0; // Tick point adjust
|
2006-06-12 23:27:55 +00:00
|
|
|
// Bottom arrow
|
|
|
|
glBegin(GL_LINE_STRIP);
|
2006-06-14 20:39:10 +00:00
|
|
|
glVertex2f(marker_xs - bottom_4, scrn_rect.top);
|
|
|
|
glVertex2f(marker_xs, marker_ye);
|
|
|
|
glVertex2f(marker_xs + bottom_4, scrn_rect.top);
|
2006-06-12 23:27:55 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
2006-06-14 20:39:10 +00:00
|
|
|
|
|
|
|
if (huds_bottom(options)) {
|
2006-06-12 23:27:55 +00:00
|
|
|
// Top box line
|
2006-06-14 20:39:10 +00:00
|
|
|
drawOneLine(scrn_rect.left, height, width, height);
|
2006-06-12 23:27:55 +00:00
|
|
|
// Tick point adjust
|
|
|
|
marker_ys = height - scrn_rect.bottom / 2.0;
|
|
|
|
|
|
|
|
// Top arrow
|
|
|
|
glBegin(GL_LINE_STRIP);
|
2006-06-14 20:39:10 +00:00
|
|
|
glVertex2f(marker_xs + bottom_4, height);
|
|
|
|
glVertex2f(marker_xs, marker_ys );
|
|
|
|
glVertex2f(marker_xs - bottom_4, height);
|
2006-06-12 23:27:55 +00:00
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int last = (int)vmax + 1; //FloatToInt(vmax)+1;
|
|
|
|
i = (int)vmin; //FloatToInt(vmin);
|
2006-06-14 20:39:10 +00:00
|
|
|
for (; i <last ; i++) {
|
2006-06-12 23:27:55 +00:00
|
|
|
condition = true;
|
2006-06-14 20:39:10 +00:00
|
|
|
if (!modulo() && i < min_val())
|
2006-06-12 23:27:55 +00:00
|
|
|
condition = false;
|
2006-06-14 20:39:10 +00:00
|
|
|
|
|
|
|
if (condition) {
|
2006-06-12 23:27:55 +00:00
|
|
|
marker_xs = scrn_rect.left + (i - vmin) * factor()/* +.5f*/;
|
|
|
|
// marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
|
2006-06-14 20:39:10 +00:00
|
|
|
if (div_min()) {
|
|
|
|
if (!(i % (int)div_min())) {
|
2006-06-12 23:27:55 +00:00
|
|
|
// draw in ticks only if they aren't too close to the edge.
|
2006-06-14 20:39:10 +00:00
|
|
|
if (((marker_xs + 5) > scrn_rect.left)
|
|
|
|
|| ((marker_xs - 5) < (width))) {
|
|
|
|
|
|
|
|
if (huds_both(options)) {
|
|
|
|
drawOneLine(marker_xs, scrn_rect.top, marker_xs, marker_ys - 4);
|
|
|
|
drawOneLine(marker_xs, marker_ye + 4, marker_xs, height);
|
|
|
|
|
|
|
|
} else if (huds_top(options)) {
|
|
|
|
drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye - 4);
|
|
|
|
} else {
|
|
|
|
drawOneLine(marker_xs, marker_ys + 4, marker_xs, marker_ye);
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-06-14 20:39:10 +00:00
|
|
|
|
|
|
|
if (div_max()) {
|
|
|
|
if (!(i % (int)div_max())) {
|
2006-06-12 23:27:55 +00:00
|
|
|
if (modulo()) {
|
2006-06-14 20:39:10 +00:00
|
|
|
if (disp_val < 0) {
|
|
|
|
while (disp_val < 0)
|
2006-06-12 23:27:55 +00:00
|
|
|
disp_val += modulo();
|
|
|
|
}
|
|
|
|
disp_val = i % (int)modulo();
|
|
|
|
} else {
|
|
|
|
disp_val = i;
|
|
|
|
}
|
2006-06-14 20:39:10 +00:00
|
|
|
sprintf(TextScale, "%d",
|
|
|
|
FloatToInt(disp_val * data_scaling()/* +.5*/));
|
|
|
|
lenstr = getStringWidth(TextScale);
|
2006-06-12 23:27:55 +00:00
|
|
|
|
|
|
|
// Draw major ticks and text only if far enough from the edge.
|
2006-06-14 20:39:10 +00:00
|
|
|
if (((marker_xs - 10) > scrn_rect.left)
|
|
|
|
&& ((marker_xs + 10) < width)) {
|
|
|
|
if (huds_both(options)) {
|
|
|
|
drawOneLine(marker_xs, scrn_rect.top, marker_xs, marker_ys);
|
|
|
|
drawOneLine(marker_xs, marker_ye, marker_xs, height);
|
|
|
|
|
|
|
|
if (!huds_notext(options))
|
|
|
|
textString(marker_xs - lenstr, marker_ys + 4, TextScale, 0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
|
|
|
|
|
|
|
|
if (!huds_notext(options)) {
|
|
|
|
if (huds_top(options))
|
|
|
|
textString(marker_xs - lenstr, height - 10, TextScale, 0);
|
|
|
|
else
|
|
|
|
textString(marker_xs - lenstr, scrn_rect.top, TextScale, 0);
|
2006-06-12 23:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-09-19 22:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|