]> git.mxchange.org Git - flightgear.git/blobdiff - src/Cockpit/hud_card.cxx
Fix two bugs in the new autopilot code
[flightgear.git] / src / Cockpit / hud_card.cxx
index 7f8deddb5c8adb2956fb2dfbf57027d21e7fd438..746e9317a5510a471d3c4bae828b2629dd1f63bc 100644 (file)
@@ -7,7 +7,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include <plib/sg.h>
 #include "hud.hxx"
 
 #ifdef USE_HUD_TextList
@@ -16,6 +15,7 @@
 #define textString(x, y, text, digit)  puDrawString(guiFnt, text, x, y)
 #endif
 
+FLTFNPTR get_func(const char *name);   // FIXME
 
 hud_card::hud_card(const SGPropertyNode *node) :
     instr_scale(
@@ -32,7 +32,7 @@ hud_card::hud_card(const SGPropertyNode *node) :
             node->getIntValue("major_divs"),
             node->getIntValue("minor_divs"),
             node->getIntValue("modulator"),
-            node->getBoolValue("working")),
+            node->getBoolValue("working", true)),
     val_span(node->getFloatValue("value_span")),    // FIXME
     type(node->getStringValue("type")),
     draw_tick_bottom(node->getBoolValue("tick_bottom", false)),
@@ -56,42 +56,10 @@ hud_card::hud_card(const SGPropertyNode *node) :
     Maj_div(node->getIntValue("major_divs")),          // FIXME dup
     Min_div(node->getIntValue("minor_divs"))           // FIXME dup
 {
-    SG_LOG(SG_INPUT, SG_INFO, "Done reading dial/tape instrument "
+    SG_LOG(SG_INPUT, SG_BULK, "Done reading dial/tape instrument "
             << node->getStringValue("name", "[unnamed]"));
 
-    string loadfn = node->getStringValue("loadfn");
-    float (*load_fn)(void);
-    if (loadfn == "anzg")
-        load_fn = get_anzg;
-    else if (loadfn == "heading")
-        load_fn = get_heading;
-    else if (loadfn == "aoa")
-        load_fn = get_aoa;
-    else if (loadfn == "climb")
-        load_fn = get_climb_rate;
-    else if (loadfn == "altitude")
-        load_fn = get_altitude;
-    else if (loadfn == "agl")
-        load_fn = get_agl;
-    else if (loadfn == "speed")
-        load_fn = get_speed;
-    else if (loadfn == "view_direction")
-        load_fn = get_view_direction;
-    else if (loadfn == "aileronval")
-        load_fn = get_aileronval;
-    else if (loadfn == "elevatorval")
-        load_fn = get_elevatorval;
-    else if (loadfn == "elevatortrimval")
-        load_fn = get_elev_trimval;
-    else if (loadfn == "rudderval")
-        load_fn = get_rudderval;
-    else if (loadfn == "throttleval")
-        load_fn = get_throttleval;
-    else
-        load_fn = 0;
-
-    set_data_source(load_fn);
-
+    set_data_source(get_func(node->getStringValue("loadfn")));
     half_width_units = range_to_show() / 2.0;
 }
 
@@ -370,8 +338,8 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
 
             // draw scale or tape
 
-//            last = FloatToInt(vmax)+1;
-//            i = FloatToInt(vmin);
+//            last = float_to_int(vmax)+1;
+//            i = float_to_int(vmin);
             last = (int)vmax + 1; // N
             i = (int)vmin; // N
 
@@ -401,8 +369,80 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
                         else
                             k = i;
 
+                        bool major_tick_drawn = false;
+
+                        // Major ticks
+                        if (div_max()) {
+                            if (!(k % (int)div_max())) {
+                                major_tick_drawn = true;
+                                if (modulo()) {
+                                    disp_val = i % (int) modulo(); // ?????????
+                                    if (disp_val < 0) {
+                                        while (disp_val < 0)
+                                            disp_val += modulo();
+                                    }
+                                } else {
+                                    disp_val = i;
+                                }
+
+                                lenstr = sprintf(TextScale, "%d",
+                                        float_to_int(disp_val * data_scaling()/*+.5*/));
+                                // (int)(disp_val  * data_scaling() +.5));
+                                /* if (((marker_ys - 8) > scrn_rect.top) &&
+                                   ((marker_ys + 8) < (height))){ */
+                                // huds_both
+                                if (huds_both(options)) {
+                                    // drawOneLine(scrn_rect.left, marker_ys,
+                                    //              marker_xs,      marker_ys);
+                                    // drawOneLine(marker_xs, marker_ys,
+                                    //              scrn_rect.left + scrn_rect.right,
+                                    //              marker_ys);
+                                    if (tick_type == "line") {
+                                        glBegin(GL_LINE_STRIP);
+                                        glVertex2f(scrn_rect.left, marker_ys);
+                                        glVertex2f(marker_xs, marker_ys);
+                                        glVertex2f(width, marker_ys);
+                                        glEnd();
+
+                                    } else if (tick_type == "circle") {
+                                        circles(scrn_rect.left, (float)marker_ys, 5.0);
+
+                                    } else {
+                                        glBegin(GL_LINE_STRIP);
+                                        glVertex2f(scrn_rect.left, marker_ys);
+                                        glVertex2f(marker_xs, marker_ys);
+                                        glVertex2f(width, marker_ys);
+                                        glEnd();
+                                    }
+
+                                    if (!huds_notext(options))
+                                        textString (marker_xs + 2, marker_ys, TextScale, 0);
+
+                                } else {
+                                    /* Changes are made to draw a circle when tick_type="circle" */
+                                    // anything other than huds_both
+                                    if (tick_type == "line")
+                                        drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
+                                    else if (tick_type == "circle")
+                                        circles((float)marker_xs + 4, (float)marker_ys, 5.0);
+                                    else
+                                        drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
+
+                                    if (!huds_notext(options)) {
+                                        if (huds_left(options)) {
+                                            textString(marker_xs - 8 * lenstr - 2,
+                                                    marker_ys - 4, TextScale, 0);
+                                        } else {
+                                            textString(marker_xe + 3 * lenstr,
+                                                    marker_ys - 4, TextScale, 0);
+                                        } //End if huds_left
+                                    } //End if !huds_notext
+                                }  //End if huds-both
+                            }  // End if draw major ticks
+                        }   // End if major ticks
+
                         // Minor ticks
-                        if (div_min()) {
+                        if (div_min() && !major_tick_drawn) {
                             // if ((i % div_min()) == 0) {
                             if (!(k % (int)div_min())) {
                                 if (((marker_ys - 5) > scrn_rect.top)
@@ -481,74 +521,6 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
                             } //end draw minor ticks
                         }  //end minor ticks
 
-                        // Major ticks
-                        if (div_max()) {
-                            if (!(k % (int)div_max())) {
-                                if (modulo()) {
-                                    disp_val = i % (int) modulo(); // ?????????
-                                    if (disp_val < 0) {
-                                        while (disp_val < 0)
-                                            disp_val += modulo();
-                                    }
-                                } else {
-                                    disp_val = i;
-                                }
-
-                                lenstr = sprintf(TextScale, "%d",
-                                        FloatToInt(disp_val * data_scaling()/*+.5*/));
-                                // (int)(disp_val  * data_scaling() +.5));
-                                /* if (((marker_ys - 8) > scrn_rect.top) &&
-                                   ((marker_ys + 8) < (height))){ */
-                                // huds_both
-                                if (huds_both(options)) {
-                                    // drawOneLine(scrn_rect.left, marker_ys,
-                                    //              marker_xs,      marker_ys);
-                                    // drawOneLine(marker_xs, marker_ys,
-                                    //              scrn_rect.left + scrn_rect.right,
-                                    //              marker_ys);
-                                    if (tick_type == "line") {
-                                        glBegin(GL_LINE_STRIP);
-                                        glVertex2f(scrn_rect.left, marker_ys);
-                                        glVertex2f(marker_xs, marker_ys);
-                                        glVertex2f(width, marker_ys);
-                                        glEnd();
-
-                                    } else if (tick_type == "circle") {
-                                        circles(scrn_rect.left, (float)marker_ys, 5.0);
-
-                                    } else {
-                                        glBegin(GL_LINE_STRIP);
-                                        glVertex2f(scrn_rect.left, marker_ys);
-                                        glVertex2f(marker_xs, marker_ys);
-                                        glVertex2f(width, marker_ys);
-                                        glEnd();
-                                    }
-
-                                    if (!huds_notext(options))
-                                        textString (marker_xs + 2, marker_ys, TextScale, 0);
-
-                                } else {
-                                    /* Changes are made to draw a circle when tick_type="circle" */
-                                    // anything other than huds_both
-                                    if (tick_type == "line")
-                                        drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
-                                    else if (tick_type == "circle")
-                                        circles((float)marker_xs + 4, (float)marker_ys, 5.0);
-                                    else
-                                        drawOneLine(marker_xs, marker_ys, marker_xe, marker_ys);
-
-                                    if (!huds_notext(options)) {
-                                        if (huds_left(options)) {
-                                            textString(marker_xs - 8 * lenstr - 2,
-                                                    marker_ys - 4, TextScale, 0);
-                                        } else {
-                                            textString(marker_xe + 3 * lenstr,
-                                                    marker_ys - 4, TextScale, 0);
-                                        } //End if huds_left
-                                    } //End if !huds_notext
-                                }  //End if huds-both
-                            }  // End if draw major ticks
-                        }   // End if major ticks
                     }  // End condition
                 }  // End for
             }  //end of zoom
@@ -673,8 +645,8 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
 
             // printf("vmin = %d  vmax = %d\n", (int)vmin, (int)vmax);
 
-            //  last = FloatToInt(vmax)+1;
-            //  i    = FloatToInt(vmin);
+            //  last = float_to_int(vmax)+1;
+            //  i    = float_to_int(vmin);
 
             if (zoom == 1) {
                 zoomed_scale((int)vmin,(int)vmax);
@@ -699,50 +671,7 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
                         else
                             k = i;
 
-                        if (div_min()) {
-                            //          if ((i % (int)div_min()) == 0) {
-                            //draw minor ticks
-                            if (!(k % (int)div_min())) {
-                                // draw in ticks only if they aren't too close to the edge.
-                                if (((marker_xs - 5) > scrn_rect.left)
-                                        && ((marker_xs + 5)< (scrn_rect.left + scrn_rect.right))) {
-
-                                    if (huds_both(options)) {
-                                        if (tick_length == "variable") {
-                                            drawOneLine(marker_xs, scrn_rect.top,
-                                                    marker_xs, marker_ys - 4);
-                                            drawOneLine(marker_xs, marker_ye + 4,
-                                                    marker_xs, height);
-                                        } else {
-                                            drawOneLine(marker_xs, scrn_rect.top,
-                                                    marker_xs, marker_ys);
-                                            drawOneLine(marker_xs, marker_ye,
-                                                    marker_xs, height);
-                                        }
-                                        // glBegin(GL_LINES);
-                                        // glVertex2f(marker_xs, scrn_rect.top);
-                                        // glVertex2f(marker_xs, marker_ys - 4);
-                                        // glVertex2f(marker_xs, marker_ye + 4);
-                                        // glVertex2f(marker_xs, scrn_rect.top + scrn_rect.bottom);
-                                        // glEnd();
-
-                                    } else {
-                                        if (huds_top(options)) {
-                                            //draw minor ticks
-                                            if (tick_length == "variable")
-                                                drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye - 4);
-                                            else
-                                                drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
-
-                                        } else if (tick_length == "variable") {
-                                            drawOneLine(marker_xs, marker_ys + 4, marker_xs, marker_ye);
-                                        } else {
-                                            drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
-                                        }
-                                    }
-                                }
-                            } //end draw minor ticks
-                        } //end minor ticks
+                        bool major_tick_drawn = false;
 
                         //major ticks
                         if (div_max()) {
@@ -751,6 +680,7 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
                             //     draw major ticks
 
                             if (!(k % (int)div_max())) {
+                                major_tick_drawn = true;
                                 if (modulo()) {
                                     disp_val = i % (int) modulo(); // ?????????
                                     if (disp_val < 0) {
@@ -764,7 +694,7 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
                                 // printf("%d\n", (int)(disp_val  * (double)data_scaling() + 0.5));
                                 lenstr = sprintf(TextScale, "%d",
                                         // (int)(disp_val  * data_scaling() +.5));
-                                        FloatToInt(disp_val * data_scaling()/*+.5*/));
+                                        float_to_int(disp_val * data_scaling()/*+.5*/));
 
                                 // Draw major ticks and text only if far enough from the edge.
                                 if (((marker_xs - 10)> scrn_rect.left)
@@ -801,6 +731,52 @@ void hud_card::draw(void) //  (HUD_scale * pscale)
                                 }
                             }  //end draw major ticks
                         } //endif major ticks
+
+                        if (div_min() && !major_tick_drawn) {
+                            //          if ((i % (int)div_min()) == 0) {
+                            //draw minor ticks
+                            if (!(k % (int)div_min())) {
+                                // draw in ticks only if they aren't too close to the edge.
+                                if (((marker_xs - 5) > scrn_rect.left)
+                                        && ((marker_xs + 5)< (scrn_rect.left + scrn_rect.right))) {
+
+                                    if (huds_both(options)) {
+                                        if (tick_length == "variable") {
+                                            drawOneLine(marker_xs, scrn_rect.top,
+                                                    marker_xs, marker_ys - 4);
+                                            drawOneLine(marker_xs, marker_ye + 4,
+                                                    marker_xs, height);
+                                        } else {
+                                            drawOneLine(marker_xs, scrn_rect.top,
+                                                    marker_xs, marker_ys);
+                                            drawOneLine(marker_xs, marker_ye,
+                                                    marker_xs, height);
+                                        }
+                                        // glBegin(GL_LINES);
+                                        // glVertex2f(marker_xs, scrn_rect.top);
+                                        // glVertex2f(marker_xs, marker_ys - 4);
+                                        // glVertex2f(marker_xs, marker_ye + 4);
+                                        // glVertex2f(marker_xs, scrn_rect.top + scrn_rect.bottom);
+                                        // glEnd();
+
+                                    } else {
+                                        if (huds_top(options)) {
+                                            //draw minor ticks
+                                            if (tick_length == "variable")
+                                                drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye - 4);
+                                            else
+                                                drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
+
+                                        } else if (tick_length == "variable") {
+                                            drawOneLine(marker_xs, marker_ys + 4, marker_xs, marker_ye);
+                                        } else {
+                                            drawOneLine(marker_xs, marker_ys, marker_xs, marker_ye);
+                                        }
+                                    }
+                                }
+                            } //end draw minor ticks
+                        } //end minor ticks
+
                     }   //end condition
                 } //end for
             }  //end zoom