]> git.mxchange.org Git - flightgear.git/commitdiff
- fix unzoomed tapes (TODO: restore tick length)
authormfranz <mfranz>
Thu, 6 Jul 2006 14:30:18 +0000 (14:30 +0000)
committermfranz <mfranz>
Thu, 6 Jul 2006 14:30:18 +0000 (14:30 +0000)
- get rid of braindead "struct Rect", where top meant y, and bottom meant height
- cleanup^3

src/Instrumentation/HUD/HUD.hxx
src/Instrumentation/HUD/HUD_dial.cxx
src/Instrumentation/HUD/HUD_gauge.cxx
src/Instrumentation/HUD/HUD_instrument.cxx
src/Instrumentation/HUD/HUD_label.cxx
src/Instrumentation/HUD/HUD_ladder.cxx
src/Instrumentation/HUD/HUD_runway.cxx
src/Instrumentation/HUD/HUD_scale.cxx
src/Instrumentation/HUD/HUD_tape.cxx
src/Instrumentation/HUD/HUD_tbi.cxx

index 5b0142abbe9d2b4d1fa5068619890aeceb2c8e47..678b197762d731c4175752a0c8194b9774aca8aa 100644 (file)
@@ -204,10 +204,6 @@ public:
         float x, y;
     } Point;
 
-    typedef struct {
-        float top, bottom, left, right;
-    } Rect;
-
     // called from Main/renderer.cxx to draw 2D and 3D HUD
     void draw();
 
@@ -377,16 +373,10 @@ public:
     virtual bool isEnabled();
 
 protected:
-    inline Rect  get_location()   const { return _scrn_pos; }
     inline float get_span()       const { return _scr_span; }
     inline Point get_centroid()   const { return _mid_span; }
     inline int   get_digits()     const { return _digits; }
 
-    inline float get_x()      const { return _scrn_pos.left; }
-    inline float get_y()      const { return _scrn_pos.top; }
-    inline float get_width()  const { return _scrn_pos.right; }
-    inline float get_height() const { return _scrn_pos.bottom; }
-
     inline bool option_vert()    const { return (_options & VERT) == VERT; }
     inline bool option_left()    const { return (_options & LEFT) == LEFT; }
     inline bool option_right()   const { return (_options & RIGHT) == RIGHT; }
@@ -406,11 +396,10 @@ protected:
     HUD         *_hud;
     string      _name;
     int         _options;
+    float       _x, _y, _w, _h;
 
 private:
     SGCondition *_condition;
-    Rect        _scrn_pos;      // Framing - affects scale dimensions
-                                // and orientation. Vert vs Horz, etc.
     float       _disp_factor;   // Multiply by to get numbers shown on scale.
     float       _scr_span;      // Working values for draw;
     Point       _mid_span;
@@ -473,8 +462,8 @@ protected:
     inline float range_to_show() const { return _range_shown; }
 
     Input _input;
-    unsigned int _major_divs;  // major division marker units
-    unsigned int _minor_divs;  // minor division marker units
+    float _major_divs;  // major division marker units
+    float _minor_divs;  // minor division marker units
 
 private:
     float _range_shown;     // Width Units.
@@ -639,7 +628,7 @@ private:
     unsigned short _stipple_center; // stipple pattern of the center line of the runway
     bool   _draw_arrow;             // draw arrow when runway is not visible in HUD
     bool   _draw_arrow_always;      // always draws arrow
-    Rect   _location;
+    float  _left, _right, _top, _bottom;
     Point  _center;
 };
 
index 10ca025b97a591febd8de2c0f222897395489b85..af917eeffe6c7fc14d4953ef4165523e0887e33f 100644 (file)
@@ -38,20 +38,14 @@ void HUD::Dial::draw(void)
     const int BUFSIZE = 80;
     char buf[BUFSIZE];
 
-    Rect scrn_rect = get_location();
-
-    float x, y;
-    float i;
-    y = scrn_rect.top;
-    x = scrn_rect.left;
     glEnable(GL_POINT_SMOOTH);
     glPointSize(3.0);
 
     float incr = 360.0 / _divisions;
-    for (i = 0.0; i < 360.0; i += incr) {
+    for (float i = 0.0; i < 360.0; i += incr) {
         float i1 = i * SGD_DEGREES_TO_RADIANS;
-        float x1 = x + _radius * cos(i1);
-        float y1 = y + _radius * sin(i1);
+        float x1 = _x + _radius * cos(i1);
+        float y1 = _y + _radius * sin(i1);
 
         glBegin(GL_POINTS);
         glVertex2f(x1, y1);
@@ -66,8 +60,8 @@ void HUD::Dial::draw(void)
     float theta = _input.getFloatValue();
 
     float theta1 = -theta * SGD_DEGREES_TO_RADIANS + offset;
-    float x1 = x + _radius * cos(theta1);
-    float y1 = y + _radius * sin(theta1);
+    float x1 = _x + _radius * cos(theta1);
+    float y1 = _y + _radius * sin(theta1);
     float x2 = x1 - r1 * cos(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
     float y2 = y1 - r1 * sin(theta1 - 30.0 * SGD_DEGREES_TO_RADIANS);
     float x3 = x1 - r1 * cos(theta1 + 30.0 * SGD_DEGREES_TO_RADIANS);
@@ -82,11 +76,11 @@ void HUD::Dial::draw(void)
     int l = abs((int)theta);
     if (l) {
         if (l < 10)
-            draw_text(x, y, buf, 0);
+            draw_text(_x, _y, buf, 0);
         else if (l < 100)
-            draw_text(x - 1.0, y, buf, 0);
+            draw_text(_x - 1.0, _y, buf, 0);
         else if (l < 360)
-            draw_text(x - 2.0, y, buf, 0);
+            draw_text(_x - 2.0, _y, buf, 0);
     }
 }
 
index 63b569fabb69c12a7ed747e8c2239739dc9ac59e..5c9e99df0115c4a47ad8a37f80f12479bf0f57cd 100644 (file)
@@ -53,31 +53,30 @@ void HUD::Gauge::draw(void)
     float vmax = _input.max();
     Point mid_scr = get_centroid();
     float cur_value = _input.getFloatValue();
-    Rect  scrn_rect = get_location();
 
-    width = scrn_rect.left + scrn_rect.right;
-    height = scrn_rect.top + scrn_rect.bottom;
-    bottom_4 = scrn_rect.bottom / 4.0;
+    width = _x + _w;                                           // FIXME huh?
+    height = _y + _h;
+    bottom_4 = _h / 4.0;
 
     // Draw the basic markings for the scale...
     if (option_vert()) { // Vertical scale
         // Bottom tick bar
-        draw_line(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
+        draw_line(_x, _y, width, _y);
 
         // Top tick bar
-        draw_line( scrn_rect.left, height, width, height);
+        draw_line(_x, height, width, height);
 
-        marker_xs = scrn_rect.left;
+        marker_xs = _x;
         marker_xe = width;
 
         if (option_left()) { // Read left, so line down right side
-            draw_line(width, scrn_rect.top, width, height);
-            marker_xs  = marker_xe - scrn_rect.right / 3.0;   // Adjust tick
+            draw_line(width, _y, width, height);
+            marker_xs  = marker_xe - _w / 3.0;   // Adjust tick
         }
 
         if (option_right()) {     // Read  right, so down left sides
-            draw_line(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
-            marker_xe = scrn_rect.left + scrn_rect.right / 3.0;   // Adjust tick
+            draw_line(_x, _y, _x, height);
+            marker_xe = _x + _w / 3.0;   // Adjust tick
         }
 
         // At this point marker x_start and x_end values are transposed.
@@ -98,7 +97,7 @@ void HUD::Gauge::draw(void)
 
             for (; i < last; i++) {
                 // Calculate the location of this tick
-                marker_ys = scrn_rect.top + (i - vmin) * factor()/* +.5f*/;
+                marker_ys = _y + (i - vmin) * factor()/* +.5f*/;
 
                 // We compute marker_ys even though we don't know if we will use
                 // either major or minor divisions. Simpler.
@@ -106,7 +105,7 @@ void HUD::Gauge::draw(void)
                 if (_minor_divs) {                  // Minor tick marks
                     if (!(i % (int)_minor_divs)) {
                         if (option_left() && option_right()) {
-                            draw_line(scrn_rect.left, marker_ys, marker_xs - 3, marker_ys);
+                            draw_line(_x, marker_ys, marker_xs - 3, marker_ys);
                             draw_line(marker_xe + 3, marker_ys, width, marker_ys);
 
                         } else if (option_left()) {
@@ -124,7 +123,7 @@ void HUD::Gauge::draw(void)
                 if (_major_divs) {                  // Major tick mark
                     if (!(i % (int)_major_divs)) {
                         if (option_left() && option_right()) {
-                            draw_line(scrn_rect.left, marker_ys, marker_xs, marker_ys);
+                            draw_line(_x, marker_ys, marker_xs, marker_ys);
                             draw_line(marker_xe, marker_ys, width, marker_ys);
                         } else {
                             draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
@@ -158,14 +157,14 @@ void HUD::Gauge::draw(void)
         // 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 + ((cur_value - vmin) * factor() /*+.5f*/);
-        //    text_x = marker_xs - scrn_rect.left;
+        text_y = _y + ((cur_value - vmin) * factor() /*+.5f*/);
+        //    text_x = marker_xs - _x;
 
         if (option_right()) {
             glBegin(GL_LINE_STRIP);
-            glVertex2f(scrn_rect.left, text_y + 5);
+            glVertex2f(_x, text_y + 5);
             glVertex2f(marker_xe, text_y);
-            glVertex2f(scrn_rect.left, text_y - 5);
+            glVertex2f(_x, text_y - 5);
             glEnd();
         }
         if (option_left()) {
@@ -179,33 +178,33 @@ void HUD::Gauge::draw(void)
 
     } else {                             // Horizontal scale by default
         // left tick bar
-        draw_line(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
+        draw_line(_x, _y, _x, height);
 
         // right tick bar
-        draw_line(width, scrn_rect.top, width, height );
+        draw_line(width, _y, width, height );
 
-        marker_ys = scrn_rect.top;                       // Starting point for
+        marker_ys = _y;                       // Starting point for
         marker_ye = height;                              // tick y location calcs
-        marker_xs = scrn_rect.left + (cur_value - vmin) * factor() /*+ .5f*/;
+        marker_xs = _x + (cur_value - vmin) * factor() /*+ .5f*/;
 
         if (option_top()) {
             // Bottom box line
-            draw_line(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
+            draw_line(_x, _y, width, _y);
 
-            marker_ye = scrn_rect.top + scrn_rect.bottom / 2.0;   // Tick point adjust
+            marker_ye = _y + _h / 2.0;   // Tick point adjust
             // Bottom arrow
             glBegin(GL_LINE_STRIP);
-            glVertex2f(marker_xs - bottom_4, scrn_rect.top);
+            glVertex2f(marker_xs - bottom_4, _y);
             glVertex2f(marker_xs, marker_ye);
-            glVertex2f(marker_xs + bottom_4, scrn_rect.top);
+            glVertex2f(marker_xs + bottom_4, _y);
             glEnd();
         }
 
         if (option_bottom()) {
             // Top box line
-            draw_line(scrn_rect.left, height, width, height);
+            draw_line(_x, height, width, height);
             // Tick point adjust
-            marker_ys = height - scrn_rect.bottom / 2.0;
+            marker_ys = height - _h / 2.0;
 
             // Top arrow
             glBegin(GL_LINE_STRIP);
@@ -224,16 +223,16 @@ void HUD::Gauge::draw(void)
                     condition = false;
 
             if (condition) {
-                marker_xs = scrn_rect.left + (i - vmin) * factor()/* +.5f*/;
-                //        marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5f);
+                marker_xs = _x + (i - vmin) * factor()/* +.5f*/;
+                //        marker_xs = _x + (int)((i - vmin) * factor() + .5f);
                 if (_minor_divs) {
                     if (!(i % (int)_minor_divs)) {
                         // draw in ticks only if they aren't too close to the edge.
-                        if (((marker_xs + 5) > scrn_rect.left)
+                        if (((marker_xs + 5) > _x)
                                || ((marker_xs - 5) < (width))) {
 
                             if (option_both()) {
-                                draw_line(marker_xs, scrn_rect.top, marker_xs, marker_ys - 4);
+                                draw_line(marker_xs, _y, marker_xs, marker_ys - 4);
                                 draw_line(marker_xs, marker_ye + 4, marker_xs, height);
 
                             } else if (option_top()) {
@@ -261,10 +260,10 @@ void HUD::Gauge::draw(void)
                         lenstr = text_width(buf);
 
                         // Draw major ticks and text only if far enough from the edge.
-                        if (((marker_xs - 10) > scrn_rect.left)
+                        if (((marker_xs - 10) > _x)
                                 && ((marker_xs + 10) < width)) {
                             if (option_both()) {
-                                draw_line(marker_xs, scrn_rect.top, marker_xs, marker_ys);
+                                draw_line(marker_xs, _y, marker_xs, marker_ys);
                                 draw_line(marker_xs, marker_ye, marker_xs, height);
 
                                 if (!option_notext())
@@ -277,7 +276,7 @@ void HUD::Gauge::draw(void)
                                     if (option_top())
                                         draw_text(marker_xs - lenstr, height - 10, buf, 0);
                                     else
-                                        draw_text(marker_xs - lenstr, scrn_rect.top, buf, 0);
+                                        draw_text(marker_xs - lenstr, _y, buf, 0);
                                 }
                             }
                         }
index 2e78acdb37b019cb8f4821e9c67e32abb3790de9..122ce99fe7acb49aff413b44d734cd44adcf3402 100644 (file)
@@ -39,10 +39,10 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
     if (node)
         _condition = sgReadCondition(globals->get_props(), node);
 
-    _scrn_pos.left = n->getIntValue("x") + x;
-    _scrn_pos.top = n->getIntValue("y") + y;
-    _scrn_pos.right = n->getIntValue("width");
-    _scrn_pos.bottom = n->getIntValue("height");
+    _x = n->getIntValue("x") + x;
+    _y = n->getIntValue("y") + y;
+    _w = n->getIntValue("width");
+    _h = n->getIntValue("height");
 
     vector<SGPropertyNode_ptr> opt = n->getChildren("option");
     for (unsigned int i = 0; i < opt.size(); i++) {
@@ -79,13 +79,13 @@ HUD::Item::Item(HUD *hud, const SGPropertyNode *n, float x, float y) :
     // the span values according to orientation
 
     if (_options & VERT) {
-        _scr_span = _scrn_pos.bottom;
+        _scr_span = _h;
     } else {
-        _scr_span = _scrn_pos.right;
+        _scr_span = _w;
     }
 
-    _mid_span.x = _scrn_pos.left + _scrn_pos.right / 2.0;
-    _mid_span.y = _scrn_pos.top + _scrn_pos.bottom / 2.0;
+    _mid_span.x = _x + _w / 2.0;
+    _mid_span.y = _y + _h / 2.0;
 }
 
 
index 7e40b07feff9f049851b955cce91dbb78ae85dc4..4cb3c8aba7dbc0ec179efd88747ebb73eeb103cf 100644 (file)
@@ -78,32 +78,27 @@ void HUD::Label::draw(void)
     if (!(_mode == NONE || _input.isValid() && blink()))
         return;
 
-    Rect scrn_rect = get_location();
-
     if (_box) {
-        float x = scrn_rect.left;
-        float y = scrn_rect.top;
-        float w = scrn_rect.right;
         float h = _hud->_font_size;                    // FIXME
 
         glPushMatrix();
         glLoadIdentity();
 
         glBegin(GL_LINES);
-        glVertex2f(x - 2.0,  y - 2.0);
-        glVertex2f(x + w + 2.0, y - 2.0);
-        glVertex2f(x + w + 2.0, y + h + 2.0);
-        glVertex2f(x - 2.0,  y + h + 2.0);
+        glVertex2f(_x - 2.0,  _y - 2.0);
+        glVertex2f(_x + _w + 2.0, _y - 2.0);
+        glVertex2f(_x + _w + 2.0, _y + h + 2.0);
+        glVertex2f(_x - 2.0,  _y + h + 2.0);
         glEnd();
 
         glEnable(GL_LINE_STIPPLE);
         glLineStipple(1, 0xAAAA);
 
         glBegin(GL_LINES);
-        glVertex2f(x + w + 2.0, y - 2.0);
-        glVertex2f(x + w + 2.0, y + h + 2.0);
-        glVertex2f(x - 2.0, y + h + 2.0);
-        glVertex2f(x - 2.0, y - 2.0);
+        glVertex2f(_x + _w + 2.0, _y - 2.0);
+        glVertex2f(_x + _w + 2.0, _y + h + 2.0);
+        glVertex2f(_x - 2.0, _y + h + 2.0);
+        glVertex2f(_x - 2.0, _y - 2.0);
         glEnd();
 
         glDisable(GL_LINE_STIPPLE);
@@ -129,16 +124,16 @@ void HUD::Label::draw(void)
     float lenstr = text_width(buf);
 
     if (_halign == RIGHT_ALIGN)
-        posincr = scrn_rect.right - lenstr;
+        posincr = _w - lenstr;
     else if (_halign == CENTER_ALIGN)
-        posincr = get_span() - (lenstr / 2);           // FIXME get_span() ? really?
+        posincr = (_w - lenstr) / 2.0;
     else // LEFT_ALIGN
         posincr = 0;
 
     if (_fontsize == FONT_SMALL)
-        draw_text(scrn_rect.left + posincr, scrn_rect.top, buf, get_digits());
+        draw_text(_x + posincr, _y, buf, get_digits());
     else if (_fontsize == FONT_LARGE)
-        draw_text(scrn_rect.left + posincr, scrn_rect.top, buf, get_digits());
+        draw_text(_x + posincr, _y, buf, get_digits());
 }
 
 
index 1332bf07784cc0a1e6e8634dc454c2e5c757ee77..629185c5ba98b231f6cd0ca701d9e02a1ddf401b 100644 (file)
@@ -98,9 +98,8 @@ void HUD::Ladder::draw(void)
     GLdouble eqn_right[4] = {1.0, 0.0, 0.0, 100.0};
 
     Point centroid = get_centroid();
-    Rect box = get_location();
 
-    float half_span = box.right / 2.0;
+    float half_span = _w / 2.0;
     float roll_value = _roll.getFloatValue() * SGD_DEGREES_TO_RADIANS;         // FIXME rad/deg conversion
     alpha = get__aoa();
     pla = get__throttleval();
index 61a2ac2f9a640f480d3d311235472896e30d2c9c..4d9377fbbfd81f4c028c808b191fba5d0ffc1b2a 100644 (file)
@@ -63,10 +63,10 @@ HUD::Runway::Runway(HUD *hud, const SGPropertyNode *node, float x, float y) :
     _center.x = _view[2] / 2;
     _center.y = _view[3] / 2;
 
-    _location.left = _center.x - (get_width() / 2) + get_x();
-    _location.right = _center.x + (get_width() / 2) + get_x();
-    _location.bottom = _center.y - (get_height() / 2) + get_y();
-    _location.top = _center.y + (get_height() / 2) + get_y();
+    _left = _center.x - (_w / 2) + _x;
+    _right = _center.x + (_w / 2) + _x;
+    _bottom = _center.y - (_h / 2) + _y;
+    _top = _center.y + (_h / 2) + _y;
 }
 
 
@@ -218,12 +218,12 @@ bool HUD::Runway::drawLine(const sgdVec3& a1, const sgdVec3& a2, const sgdVec3&
     sgdVec3 p1, p2;
     sgdCopyVec3(p1, point1);
     sgdCopyVec3(p2, point2);
-    bool p1Inside = (p1[0] >= _location.left && p1[0] <= _location.right
-            && p1[1] >= _location.bottom && p1[1] <= _location.top);
+    bool p1Inside = (p1[0] >= _left && p1[0] <= _right
+            && p1[1] >= _bottom && p1[1] <= _top);
     bool p1Insight = (p1[2] >= 0.0 && p1[2] < 1.0);
     bool p1Valid = p1Insight && p1Inside;
-    bool p2Inside = (p2[0] >= _location.left && p2[0] <= _location.right
-            && p2[1] >= _location.bottom && p2[1] <= _location.top);
+    bool p2Inside = (p2[0] >= _left && p2[0] <= _right
+            && p2[1] >= _bottom && p2[1] <= _top);
     bool p2Insight = (p2[2] >= 0.0 && p2[2] < 1.0);
     bool p2Valid = p2Insight && p2Inside;
 
@@ -284,9 +284,9 @@ void HUD::Runway::boundPoint(const sgdVec3& v, sgdVec3& m)
 {
     double y = v[1];
     if (m[1] < v[1])
-        y = _location.bottom;
+        y = _bottom;
     else if (m[1] > v[1])
-        y = _location.top;
+        y = _top;
 
     if (m[0] == v[0]) {
         m[1] = y;
@@ -297,87 +297,87 @@ void HUD::Runway::boundPoint(const sgdVec3& v, sgdVec3& m)
     m[0] = (y - v[1]) / slope + v[0];
     m[1] = y;
 
-    if (m[0] < _location.left) {
-        m[0] = _location.left;
-        m[1] = slope * (_location.left - v[0]) + v[1];
+    if (m[0] < _left) {
+        m[0] = _left;
+        m[1] = slope * (_left - v[0]) + v[1];
 
-    } else if (m[0] > _location.right) {
-        m[0] = _location.right;
-        m[1] = slope * (_location.right - v[0]) + v[1];
+    } else if (m[0] > _right) {
+        m[0] = _right;
+        m[1] = slope * (_right - v[0]) + v[1];
     }
 }
 
 
 bool HUD::Runway::boundOutsidePoints(sgdVec3& v, sgdVec3& m)
 {
-    bool pointsInvalid = (v[1] > _location.top && m[1] > _location.top) ||
-                         (v[1] < _location.bottom && m[1] < _location.bottom) ||
-                         (v[0] > _location.right && m[0] > _location.right) ||
-                         (v[0] < _location.left && m[0] < _location.left);
+    bool pointsInvalid = (v[1] > _top && m[1] > _top) ||
+                         (v[1] < _bottom && m[1] < _bottom) ||
+                         (v[0] > _right && m[0] > _right) ||
+                         (v[0] < _left && m[0] < _left);
     if (pointsInvalid)
         return false;
 
     if (m[0] == v[0]) {//x's are equal, vertical line
         if (m[1] > v[1]) {
-            m[1] = _location.top;
-            v[1] = _location.bottom;
+            m[1] = _top;
+            v[1] = _bottom;
         } else {
-            v[1] = _location.top;
-            m[1] = _location.bottom;
+            v[1] = _top;
+            m[1] = _bottom;
         }
         return true;
     }
 
     if (m[1] == v[1]) { //y's are equal, horizontal line
         if (m[0] > v[0]) {
-            m[0] = _location.right;
-            v[0] = _location.left;
+            m[0] = _right;
+            v[0] = _left;
         } else {
-            v[0] = _location.right;
-            m[0] = _location.left;
+            v[0] = _right;
+            m[0] = _left;
         }
         return true;
     }
 
     double slope = (m[1] - v[1]) / (m[0] - v[0]);
     double b = v[1] - (slope * v[0]);
-    double y1 = slope * _location.left + b;
-    double y2 = slope * _location.right + b;
-    double x1 = (_location.bottom - b) / slope;
-    double x2 = (_location.top - b) / slope;
+    double y1 = slope * _left + b;
+    double y2 = slope * _right + b;
+    double x1 = (_bottom - b) / slope;
+    double x2 = (_top - b) / slope;
     int counter = 0;
 
-    if  (y1 >= _location.bottom && y1 <= _location.top) {
-        v[0] = _location.left;
+    if (y1 >= _bottom && y1 <= _top) {
+        v[0] = _left;
         v[1] = y1;
         counter++;
     }
 
-    if (y2 >= _location.bottom && y2 <= _location.top) {
+    if (y2 >= _bottom && y2 <= _top) {
         if (counter > 0) {
-            m[0] = _location.right;
+            m[0] = _right;
             m[1] = y2;
         } else {
-            v[0] = _location.right;
+            v[0] = _right;
             v[1] = y2;
         }
         counter++;
     }
 
-    if (x1 >= _location.left && x1 <= _location.right) {
+    if (x1 >= _left && x1 <= _right) {
         if (counter > 0) {
             m[0] = x1;
-            m[1] = _location.bottom;
+            m[1] = _bottom;
         } else {
             v[0] = x1;
-            v[1] = _location.bottom;
+            v[1] = _bottom;
         }
         counter++;
     }
 
-    if (x2 >= _location.left && x2 <= _location.right) {
+    if (x2 >= _left && x2 <= _right) {
         m[0] = x1;
-        m[1] = _location.bottom;
+        m[1] = _bottom;
         counter++;
     }
     return (counter == 2);
@@ -396,7 +396,7 @@ void HUD::Runway::drawArrow()
     theta = -theta;
     glMatrixMode(GL_MODELVIEW);
     glPushMatrix();
-    glTranslated((_location.right + _location.left) / 2.0,(_location.top + _location.bottom) / 2.0, 0.0);
+    glTranslated((_right + _left) / 2.0, (_top + _bottom) / 2.0, 0.0);
     glRotated(theta, 0.0, 0.0, 1.0);
     glTranslated(0.0, _arrow_radius, 0.0);
     glScaled(_arrow_scale, _arrow_scale, 0.0);
index e1e3354d75a0630287eddefe62748f1180cf9dc2..13090e914e1b114ed1ee83cf543648f55fd304cd 100644 (file)
@@ -37,8 +37,8 @@
 HUD::Scale::Scale( HUD *hud, const SGPropertyNode *n, float x, float y) :
     Item(hud, n, x, y),
     _input(n->getNode("input", false)),
-    _major_divs(n->getIntValue("major-divisions")),
-    _minor_divs(n->getIntValue("minor-divisions")),
+    _major_divs(n->getFloatValue("major-divisions")),
+    _minor_divs(n->getFloatValue("minor-divisions")),
     _modulo(n->getIntValue("modulo"))
 {
     if (n->hasValue("display-span"))
index 1219f2e0d5233b9c29acd137faad73c4a21547b9..486fa9a22c73aac5b9bb840d02319728b9fe900b 100644 (file)
@@ -65,8 +65,8 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
     float height, width;
     const int BUFSIZE = 80;
     char buf[BUFSIZE];
-    int disp_val = 0;
-    int oddtype, k; //odd or even values for ticks
+    int oddtype;
+//    int k; //odd or even values for ticks            // FIXME odd scale
 
     Point mid_scr = get_centroid();
     float cur_value = _input.getFloatValue();
@@ -76,10 +76,8 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
     else
         oddtype = 0; //draw ticks at even values
 
-    Rect scrn_rect = get_location();
-
-    height = scrn_rect.top + scrn_rect.bottom;
-    width = scrn_rect.left + scrn_rect.right;
+    height = _y + _h;                  // FIXME huh?
+    width = _x + _w;
 
 
     if (_pointer) {
@@ -102,26 +100,30 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
     }
 
 
+///////////////////////////////////////////////////////////////////////////////
+// VERTICAL SCALE
+///////////////////////////////////////////////////////////////////////////////
+
     // Draw the basic markings for the scale...
 
     if (option_vert()) { // Vertical scale
         // Bottom tick bar
         if (_draw_tick_bottom)
-            draw_line(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
+            draw_line(_x, _y, width, _y);
 
         // Top tick bar
         if (_draw_tick_top)
-            draw_line(scrn_rect.left, height, width, height);
+            draw_line(_x, height, width, height);
 
-        marker_xs = scrn_rect.left;  // x start
+        marker_xs = _x;  // x start
         marker_xe = width;           // x extent
         marker_ye = height;
 
         //    glBegin(GL_LINES);
 
         // Bottom tick bar
-        //    glVertex2f(marker_xs, scrn_rect.top);
-        //    glVertex2f(marker_xe, scrn_rect.top);
+        //    glVertex2f(marker_xs, _y);
+        //    glVertex2f(marker_xe, _y);
 
         // Top tick bar
         //    glVertex2f(marker_xs, marker_ye);
@@ -138,14 +140,12 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
         if (option_left()) {    // Calculate x marker offset
 
             if (_draw_cap_right)
-                draw_line(marker_xe, scrn_rect.top, marker_xe, marker_ye);
+                draw_line(marker_xe, _y, marker_xe, marker_ye);
 
-            marker_xs  = marker_xe - scrn_rect.right / 3;   // Adjust tick xs
+            marker_xs  = marker_xe - _w / 3 + 0.5;   // Adjust tick xs
 
-            // draw_line(marker_xs, mid_scr.y,
-            //              marker_xe, mid_scr.y + scrn_rect.right / 6);
-            // draw_line(marker_xs, mid_scr.y,
-            //              marker_xe, mid_scr.y - scrn_rect.right / 6);
+            // draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y + _w / 6);
+            // draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y - _w / 6);
 
             // draw pointer
             if (_pointer) {
@@ -156,18 +156,18 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
                         float range, wth;
 
                         if (_input.min() >= 0.0)
-                            ycentre = scrn_rect.top;
+                            ycentre = _y;
                         else if (_input.max() + _input.min() == 0.0)
                             ycentre = mid_scr.y;
                         else if (oddtype)
-                            ycentre = scrn_rect.top + (1.0 - _input.min()) * scrn_rect.bottom
+                            ycentre = _y + (1.0 - _input.min()) * _h
                                     / (_input.max() - _input.min());
                         else
-                            ycentre = scrn_rect.top + _input.min() * scrn_rect.bottom
+                            ycentre = _y + _input.min() * _h
                                     / (_input.max() - _input.min());
 
-                        range = scrn_rect.bottom;
-                        wth = scrn_rect.left + scrn_rect.right;
+                        range = _h;
+                        wth = _x + _w;
 
                         if (oddtype)
                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
@@ -183,54 +183,52 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
 
                 } else {
                     // default to fixed
-                    fixed(_marker_offset + marker_xe, text_y + scrn_rect.right / 6,
+                    fixed(_marker_offset + marker_xe, text_y + _w / 6,
                             _marker_offset + marker_xs, text_y, _marker_offset + marker_xe,
-                            text_y - scrn_rect.right / 6);
-                }//end pointer type
-            } //if pointer
-        } //end vertical/left
+                            text_y - _w / 6);
+                } // end pointer type
+            } // if pointer
+        } // end vertical/left
 
 
         // begin vertical/right
-        //First draw capping lines and pointers
+        // First draw capping lines and pointers
         if (option_right()) {
 
             if (_draw_cap_left)
-                draw_line(scrn_rect.left, scrn_rect.top, scrn_rect.left, marker_ye);
+                draw_line(_x, _y, _x, marker_ye);
 
-            marker_xe = scrn_rect.left + scrn_rect.right / 3;     // Adjust tick xe
+            marker_xe = _x + _w / 3 - 0.5;     // Adjust tick xe
             // Indicator carrot
-            // draw_line(scrn_rect.left, mid_scr.y +  scrn_rect.right / 6,
-            //              marker_xe, mid_scr.y);
-            // draw_line(scrn_rect.left, mid_scr.y -  scrn_rect.right / 6,
-            //              marker_xe, mid_scr.y);
+            // draw_line(_x, mid_scr.y +  _w / 6, marker_xe, mid_scr.y);
+            // draw_line(_x, mid_scr.y -  _w / 6, marker_xe, mid_scr.y);
 
             // draw pointer
             if (_pointer) {
                 if (_pointer_type == MOVING) {
                     if (!_zoom) {
-                        //type-fixed & _zoom=1, behaviour to be defined
+                        // type-fixed & _zoom=1, behaviour to be defined
                         // Code for Moving Type Pointer
                         float ycentre, ypoint, xpoint;
                         float range;
 
                         if (_input.min() >= 0.0)
-                            ycentre = scrn_rect.top;
+                            ycentre = _y;
                         else if (_input.max() + _input.min() == 0.0)
                             ycentre = mid_scr.y;
                         else if (oddtype)
-                            ycentre = scrn_rect.top + (1.0 - _input.min()) * scrn_rect.bottom / (_input.max() - _input.min());
+                            ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
                         else
-                            ycentre = scrn_rect.top + _input.min() * scrn_rect.bottom / (_input.max() - _input.min());
+                            ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
 
-                        range = scrn_rect.bottom;
+                        range = _h;
 
                         if (oddtype)
                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
                         else
                             ypoint = ycentre + (cur_value * range / _val_span);
 
-                        xpoint = scrn_rect.left - _marker_offset;
+                        xpoint = _x - _marker_offset;
                         draw_line(xpoint, ycentre, xpoint, ypoint);
                         draw_line(xpoint, ypoint, xpoint + _marker_offset, ypoint);
                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint + 5.0);
@@ -239,12 +237,12 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
 
                 } else {
                     // default to fixed
-                    fixed(-_marker_offset + scrn_rect.left, text_y +  scrn_rect.right / 6,
-                            -_marker_offset + marker_xe, text_y, -_marker_offset + scrn_rect.left,
-                            text_y - scrn_rect.right / 6);
+                    fixed(-_marker_offset + _x, text_y +  _w / 6,
+                            -_marker_offset + marker_xe, text_y, -_marker_offset + _x,
+                            text_y - _w / 6);
                 }
-            } //if pointer
-        }  //end vertical/right
+            } // if pointer
+        } // end vertical/right
 
 
         // At this point marker x_start and x_end values are transposed.
@@ -262,196 +260,174 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
             zoomed_scale((int)vmin, (int)vmax);
         } else {
 
-            for (int i = (int)vmin; i < (int)vmax + 1; i++) {
-                if (!modulo() && i < _input.min())
-                    continue;
+//#############################################################################
+
+            int div_ratio;
+            if (_minor_divs != 0.0f)
+                div_ratio = int(_major_divs / _minor_divs + 0.5f);
+            else
+                div_ratio = 0, _minor_divs = _major_divs;                      // FIXME move that into Scale/Constructor ?
 
-                // Calculate the location of this tick
-                marker_ys = scrn_rect.top + ((i - vmin) * factor());
-                // Block calculation artifact from drawing ticks below min coordinate.
-                // Calculation here accounts for text height.
+            float vstart = floorf(vmin / _major_divs) * _major_divs;
 
-                if ((marker_ys < (scrn_rect.top + 4)) || (marker_ys > (height - 4)))
+            // FIXME consider oddtype
+            for (int i = 0; ; i++) {
+                float v = vstart + i * _minor_divs;
+
+                if (!modulo() && (v < _input.min() || v > _input.max()))
                     continue;
 
-                if (oddtype)
-                    k = i + 1; //enable ticks at odd values
-                else
-                    k = i;
+                float y = _y + (v - vmin) * factor();
+
+                if (y < _y + 4)
+                    continue;
+                if (y > height - 4)
+                    break;
 
+                if (div_ratio && i % div_ratio) { // minor div
+                    if (option_both()) {
+                        if (_tick_type == LINE) {
+                            if (_tick_length == VARIABLE) {
+                                draw_line(_x, y, marker_xs, y);
+                                draw_line(marker_xe, y, width, y);
+                            } else {
+                                draw_line(_x, y, marker_xs, y);
+                                draw_line(marker_xe, y, width, y);
+                            }
 
-                // Minor ticks
-                if (_minor_divs) {
-                    // if ((i % _minor_divs) == 0) {
-                    if (!(k % (int)_minor_divs)) {
-                        if (marker_ys < scrn_rect.top + 5 || (marker_ys + 5) > height)
-                            continue;
+                        } else if (_tick_type == CIRCLE) {
+                            draw_bullet(_x, y, 3.0);
 
-                        //vertical/left OR vertical/right
-                        if (option_both()) {
+                        } else {
+                            // if neither line nor circle draw default as line
+                            draw_line(_x, y, marker_xs, y);
+                            draw_line(marker_xe, y, width, y);
+                        }
+                        // glBegin(GL_LINES);
+                        // glVertex2f(_x, y);
+                        // glVertex2f(marker_xs,      y);
+                        // glVertex2f(marker_xe,      y);
+                        // glVertex2f(_x + _w,  y);
+                        // glEnd();
+                        // anything other than huds_both
+
+                    } else {
+                        if (option_left()) {
                             if (_tick_type == LINE) {
                                 if (_tick_length == VARIABLE) {
-                                    draw_line(scrn_rect.left, marker_ys, marker_xs, marker_ys);
-                                    draw_line(marker_xe, marker_ys, width, marker_ys);
+                                    draw_line(marker_xs + 4, y, marker_xe, y);
                                 } else {
-                                    draw_line(scrn_rect.left, marker_ys, marker_xs, marker_ys);
-                                    draw_line(marker_xe, marker_ys, width, marker_ys);
+                                    draw_line(marker_xs, y, marker_xe, y);
                                 }
-
                             } else if (_tick_type == CIRCLE) {
-                                draw_bullet(scrn_rect.left, marker_ys, 3.0);
-
+                                draw_bullet(marker_xs + 4, y, 3.0);
                             } else {
-                                // if neither line nor circle draw default as line
-                                draw_line(scrn_rect.left, marker_ys, marker_xs, marker_ys);
-                                draw_line(marker_xe, marker_ys, width, marker_ys);
+                                draw_line(marker_xs + 4, y, marker_xe, y);
                             }
-                            // glBegin(GL_LINES);
-                            // glVertex2f(scrn_rect.left, marker_ys);
-                            // glVertex2f(marker_xs,      marker_ys);
-                            // glVertex2f(marker_xe,      marker_ys);
-                            // glVertex2f(scrn_rect.left + scrn_rect.right,  marker_ys);
-                            // glEnd();
-                            // anything other than huds_both
 
-                        } else {
-                            if (option_left()) {
-                                if (_tick_type == LINE) {
-                                    if (_tick_length == VARIABLE) {
-                                        draw_line(marker_xs + 4, marker_ys, marker_xe, marker_ys);
-                                    } else {
-                                        draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
-                                    }
-                                } else if (_tick_type == CIRCLE) {
-                                    draw_bullet(marker_xs + 4, marker_ys, 3.0);
+                        }  else {
+                            if (_tick_type == LINE) {
+                                if (_tick_length == VARIABLE) {
+                                    draw_line(marker_xs, y, marker_xe - 4, y);
                                 } else {
-                                    draw_line(marker_xs + 4, marker_ys, marker_xe, marker_ys);
+                                    draw_line(marker_xs, y, marker_xe, y);
                                 }
 
-                            }  else {
-                                if (_tick_type == LINE) {
-                                    if (_tick_length == VARIABLE) {
-                                        draw_line(marker_xs, marker_ys, marker_xe - 4, marker_ys);
-                                    } else {
-                                        draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
-                                    }
-
-                                } else if (_tick_type == CIRCLE) {
-                                    draw_bullet(marker_xe - 4, marker_ys, 3.0);
-                                } else {
-                                    draw_line(marker_xs, marker_ys, marker_xe - 4, marker_ys);
-                                }
+                            } else if (_tick_type == CIRCLE) {
+                                draw_bullet(marker_xe - 4, y, 3.0);
+                            } else {
+                                draw_line(marker_xs, y, marker_xe - 4, y);
                             }
-                        } // end huds both
-                    } // end draw minor ticks
-                } // end minor ticks
+                        }
+                    } // end huds both
 
+                } else { // major div
+                    lenstr = snprintf(buf, BUFSIZE, "%d", int(v));
 
-                // Major ticks
-                if (_major_divs) {
-                    if (!(k % (int)_major_divs)) {
+                    if (option_both()) {
+                        // draw_line(_x, y, marker_xs, y);
+                        // draw_line(marker_xs, y, _x + _w, y);
+                        if (_tick_type == LINE) {
+                            glBegin(GL_LINE_STRIP);
+                            glVertex2f(_x, y);
+                            glVertex2f(marker_xs, y);
+                            glVertex2f(width, y);
+                            glEnd();
+
+                        } else if (_tick_type == CIRCLE) {
+                            draw_bullet(_x, y, 5.0);
 
-                        if (modulo()) {
-                            disp_val = i % (int) modulo();
-                            if (disp_val < 0) {
-                                while (disp_val < 0)
-                                    disp_val += modulo();
-                            }
                         } else {
-                            disp_val = i;
+                            glBegin(GL_LINE_STRIP);
+                            glVertex2f(_x, y);
+                            glVertex2f(marker_xs, y);
+                            glVertex2f(width, y);
+                            glEnd();
                         }
 
-                        // FIXME  int lenstr??
-                        lenstr = snprintf(buf, BUFSIZE, "%d", int(disp_val * _input.factor()));   // was data_scaling ... makes no sense at all
-
-                        if (option_both()) {
-                            // 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();
+                        if (!option_notext())
+                            draw_text(marker_xs + 2, y, buf, 0);
 
-                            } else if (_tick_type == CIRCLE) {
-                                draw_bullet(scrn_rect.left, 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 (!option_notext())
-                                draw_text(marker_xs + 2, marker_ys, buf, 0);
+                    } else {
+                        /* Changes are made to draw a circle when tick_type=CIRCLE */
+                        // anything other than option_both
+                        if (_tick_type == LINE)
+                            draw_line(marker_xs, y, marker_xe, y);
+                        else if (_tick_type == CIRCLE)
+                            draw_bullet(marker_xs + 4, y, 5.0);
+                        else
+                            draw_line(marker_xs, y, marker_xe, y);
 
-                        } else {
-                            /* Changes are made to draw a circle when tick_type=CIRCLE */
-                            // anything other than option_both
-                            if (_tick_type == LINE)
-                                draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
-                            else if (_tick_type == CIRCLE)
-                                draw_bullet(marker_xs + 4, marker_ys, 5.0);
+                        if (!option_notext()) {
+                            if (option_left())
+                                draw_text(marker_xs - 8 * lenstr - 2, y - 4, buf, 0);
                             else
-                                draw_line(marker_xs, marker_ys, marker_xe, marker_ys);
-
-                            if (!option_notext()) {
-                                if (option_left())
-                                    draw_text(marker_xs - 8 * lenstr - 2, marker_ys - 4, buf, 0);
-                                else
-                                    draw_text(marker_xe + 3 * lenstr, marker_ys - 4, buf, 0);
-                            }
-                        } // End if huds-both
-                    } // End if draw major ticks
-                } // End if major ticks
-            } // End for
+                                draw_text(marker_xe + 3 * lenstr, y - 4, buf, 0);
+                        }
+                    } // End if huds-both
+                }
+            }
         } // end of zoom
-        // End if VERTICAL SCALE TYPE (tape loop yet to be closed)
 
 
+///////////////////////////////////////////////////////////////////////////////
+// HORIZONTAL SCALE
+///////////////////////////////////////////////////////////////////////////////
+
 
     } else {
-        // Horizontal scale by default
         // left tick bar
         if (_draw_tick_left)
-            draw_line(scrn_rect.left, scrn_rect.top, scrn_rect.left, height);
+            draw_line(_x, _y, _x, height);
 
         // right tick bar
         if (_draw_tick_right)
-            draw_line(width, scrn_rect.top, width, height);
+            draw_line(width, _y, width, height);
 
-        marker_ys = scrn_rect.top;    // Starting point for
+        marker_ys = _y;    // Starting point for
         marker_ye = height;           // tick y location calcs
         marker_xe = width;
-        marker_xs = scrn_rect.left + ((cur_value - vmin) * factor());
+        marker_xs = _x + ((cur_value - vmin) * factor());
 
         //    glBegin(GL_LINES);
         // left tick bar
-        //    glVertex2f(scrn_rect.left, scrn_rect.top);
-        //    glVertex2f(scrn_rect.left, marker_ye);
+        //    glVertex2f(_x, _y);
+        //    glVertex2f(_x, marker_ye);
 
         // right tick bar
-        //    glVertex2f(marker_xe, scrn_rect.top);
+        //    glVertex2f(marker_xe, _y);
         //    glVertex2f(marker_xe, marker_ye);
         //    glEnd();
 
         if (option_top()) {
             if (_draw_cap_bottom)
-                draw_line(scrn_rect.left, scrn_rect.top, width, scrn_rect.top);
+                draw_line(_x, _y, width, _y);
 
             // Tick point adjust
-            marker_ye  = scrn_rect.top + scrn_rect.bottom / 2;
+            marker_ye  = _y + _h / 2;
             // Bottom arrow
-            // draw_line(mid_scr.x, marker_ye,
-            //              mid_scr.x - scrn_rect.bottom / 4, scrn_rect.top);
-            // draw_line(mid_scr.x, marker_ye,
-            //              mid_scr.x + scrn_rect.bottom / 4, scrn_rect.top);
+            // draw_line(mid_scr.x, marker_ye, mid_scr.x - _h / 4, _y);
+            // draw_line(mid_scr.x, marker_ye, mid_scr.x + _h / 4, _y);
             // draw pointer
             if (_pointer) {
                 if (_pointer_type == MOVING) {
@@ -459,9 +435,9 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
                         //Code for Moving Type Pointer
 
                         float xcentre = mid_scr.x;
-                        float range = scrn_rect.right;
+                        float range = _w;
                         float xpoint = xcentre + (cur_value * range / _val_span);
-                        float ypoint = scrn_rect.top - _marker_offset;
+                        float ypoint = _y - _marker_offset;
                         draw_line(xcentre, ypoint, xpoint, ypoint);
                         draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
                         draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
@@ -470,25 +446,21 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
 
                 } else {
                     //default to fixed
-                    fixed(marker_xs - scrn_rect.bottom / 4, scrn_rect.top, marker_xs,
-                            marker_ye, marker_xs + scrn_rect.bottom / 4, scrn_rect.top);
+                    fixed(marker_xs - _h / 4, _y, marker_xs,
+                            marker_ye, marker_xs + _h / 4, _y);
                 }
-            }  //if pointer
-        } //End Horizontal scale/top
+            }
+        } // End Horizontal scale/top
 
         if (option_bottom()) {
             if (_draw_cap_top)
-                draw_line(scrn_rect.left, height, width, height);
+                draw_line(_x, height, width, height);
 
             // Tick point adjust
-            marker_ys = height - scrn_rect.bottom / 2;
+            marker_ys = height - _h / 2;
             // Top arrow
-            //      draw_line(mid_scr.x + scrn_rect.bottom / 4,
-            //                   scrn_rect.top + scrn_rect.bottom,
-            //                   mid_scr.x, marker_ys);
-            //      draw_line(mid_scr.x - scrn_rect.bottom / 4,
-            //                   scrn_rect.top + scrn_rect.bottom,
-            //                   mid_scr.x , marker_ys);
+            // draw_line(mid_scr.x + _h / 4, _y + _h, mid_scr.x, marker_ys);
+            // draw_line(mid_scr.x - _h / 4, _y + _h, mid_scr.x , marker_ys);
 
             // draw pointer
             if (_pointer) {
@@ -497,8 +469,8 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
                         //Code for Moving Type Pointer
 
                         float xcentre = mid_scr.x ;
-                        float range = scrn_rect.right;
-                        float hgt = scrn_rect.top + scrn_rect.bottom;
+                        float range = _w;
+                        float hgt = _y + _h;
                         float xpoint = xcentre + (cur_value * range / _val_span);
                         float ypoint = hgt + _marker_offset;
                         draw_line(xcentre, ypoint, xpoint, ypoint);
@@ -507,8 +479,8 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
                         draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
                     }
                 } else {
-                    fixed(marker_xs + scrn_rect.bottom / 4, height, marker_xs, marker_ys,
-                            marker_xs - scrn_rect.bottom / 4, height);
+                    fixed(marker_xs + _h / 4, height, marker_xs, marker_ys,
+                            marker_xs - _h / 4, height);
                 }
             }
         } //end horizontal scale bottom
@@ -517,102 +489,91 @@ void HUD::Tape::draw(void) //  (HUD_scale * pscale)
         if (_zoom) {
             zoomed_scale((int)vmin,(int)vmax);
         } else {
+            int div_ratio;                                     // FIXME abstract that out of hor/vert
+            if (_minor_divs != 0.0f)
+                div_ratio = int(_major_divs / _minor_divs + 0.5f);
+            else
+                div_ratio = 0, _minor_divs = _major_divs;                      // FIXME move that into Scale/Constructor ?
 
-            for (int i = (int)vmin; i < (int)vmax + 1; i++) {
-                if (!modulo() && i < _input.min())
-                    continue;
+            float vstart = floorf(vmin / _major_divs) * _major_divs;
 
-                marker_xs = scrn_rect.left + (i - vmin) * factor();
+            // FIXME consider oddtype
+            for (int i = 0; ; i++) {
+                float v = vstart + i * _minor_divs;
 
-                if (oddtype)
-                    k = i + 1;
-                else
-                    k = i;
+                if (!modulo() && (v < _input.min() || v > _input.max()))
+                    continue;
 
-                if (_minor_divs) {
-                    // draw minor ticks
-                    if (!(k % (int)_minor_divs)) {
-                        // draw in ticks only if they aren't too close to the edge.
-                        if (marker_xs < scrn_rect.left + 5 || marker_xs + 5 > scrn_rect.left + scrn_rect.right)
-                            continue;
+                float x = _x + (v - vmin) * factor();
 
-                        if (option_both()) {
-                            if (_tick_length == VARIABLE) {
-                                draw_line(marker_xs, scrn_rect.top, marker_xs, marker_ys - 4);
-                                draw_line(marker_xs, marker_ye + 4, marker_xs, height);
-                            } else {
-                                draw_line(marker_xs, scrn_rect.top, marker_xs, marker_ys);
-                                draw_line(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 (option_top()) {
-                                // draw minor ticks
-                                if (_tick_length == VARIABLE)
-                                    draw_line(marker_xs, marker_ys, marker_xs, marker_ye - 4);
-                                else
-                                    draw_line(marker_xs, marker_ys, marker_xs, marker_ye);
-
-                            } else if (_tick_length == VARIABLE) {
-                                draw_line(marker_xs, marker_ys + 4, marker_xs, marker_ye);
-                            } else {
-                                draw_line(marker_xs, marker_ys, marker_xs, marker_ye);
-                            }
-                        }
-                    } // end draw minor ticks
-                } // end minor ticks
-
-                // major ticks
-                if (_major_divs) {
-
-                    if (!(k % (int)_major_divs)) {
-                        if (modulo()) {
-                            disp_val = i % (int) modulo();
-                            if (disp_val < 0) {
-                                while (disp_val<0)
-                                    disp_val += modulo();
-                            }
+                if (x < _x + 4)
+                    continue;
+                if (x > width - 4)
+                    break;
+
+                if (div_ratio && i % div_ratio) { // minor div
+                    if (option_both()) {
+                        if (_tick_length == VARIABLE) {
+                            draw_line(x, _y, x, marker_ys - 4);
+                            draw_line(x, marker_ye + 4, x, height);
                         } else {
-                            disp_val = i;
+                            draw_line(x, _y, x, marker_ys);
+                            draw_line(x, marker_ye, x, height);
                         }
-                        lenstr = snprintf(buf, BUFSIZE, "%d", int(disp_val * _input.factor()));  // was data_scaling() ... makes no sense at all
-
-                        // Draw major ticks and text only if far enough from the edge.
-                        if (marker_xs > scrn_rect.left + 10 || marker_xs + 10 < scrn_rect.left + scrn_rect.right)
-                            continue;
-
-                        if (option_both()) {
-                            // draw_line(marker_xs, scrn_rect.top,
-                            //              marker_xs, marker_ys);
-                            // draw_line(marker_xs, marker_ye,
-                            //              marker_xs, scrn_rect.top + scrn_rect.bottom);
-                            glBegin(GL_LINE_STRIP);
-                            glVertex2f(marker_xs, scrn_rect.top);
-                            glVertex2f(marker_xs, marker_ye);
-                            glVertex2f(marker_xs, height);
-                            glEnd();
-
-                            if (!option_notext())
-                                draw_text(marker_xs - 4 * lenstr, marker_ys + 4, buf, 0);
+                        // glBegin(GL_LINES);
+                        // glVertex2f(x, _y);
+                        // glVertex2f(x, marker_ys - 4);
+                        // glVertex2f(x, marker_ye + 4);
+                        // glVertex2f(x, _y + _h);
+                        // glEnd();
+
+                    } else {
+                        if (option_top()) {
+                            // draw minor ticks
+                            if (_tick_length == VARIABLE)
+                                draw_line(x, marker_ys, x, marker_ye - 4);
+                            else
+                                draw_line(x, marker_ys, x, marker_ye);
 
+                        } else if (_tick_length == VARIABLE) {
+                            draw_line(x, marker_ys + 4, x, marker_ye);
                         } else {
-                            draw_line(marker_xs, marker_ys, marker_xs, marker_ye);
+                            draw_line(x, marker_ys, x, marker_ye);
+                        }
+                    }
 
-                            if (!option_notext()) {
-                                if (option_top())
-                                    draw_text(marker_xs - 4 * lenstr, height - 10, buf, 0);
-                                else
-                                    draw_text(marker_xs - 4 * lenstr, scrn_rect.top, buf, 0);
-                            }
+                } else { // major divs
+                    lenstr = snprintf(buf, BUFSIZE, "%d", int(v));
+
+                    // Draw major ticks and text only if far enough from the edge.                     // FIXME
+                    if (x < _x + 10 || x + 10 > _x + _w)
+                        continue;
+
+                    if (option_both()) {
+                        // draw_line(x, _y,
+                        //              x, marker_ys);
+                        // draw_line(x, marker_ye,
+                        //              x, _y + _h);
+                        glBegin(GL_LINE_STRIP);
+                        glVertex2f(x, _y);
+                        glVertex2f(x, marker_ye);
+                        glVertex2f(x, height);
+                        glEnd();
+
+                        if (!option_notext())
+                            draw_text(x - 4 * lenstr, marker_ys + 4, buf, 0);
+
+                    } else {
+                        draw_line(x, marker_ys, x, marker_ye);
+
+                        if (!option_notext()) {
+                            if (option_top())
+                                draw_text(x - 4 * lenstr, height - 10, buf, 0);
+                            else
+                                draw_text(x - 4 * lenstr, _y, buf, 0);
                         }
-                    } // end draw major ticks
-                } // endif major ticks
+                    }
+                }
             } // end for
         } // end zoom
     } // end horizontal/vertical scale
@@ -633,7 +594,6 @@ void HUD::Tape::fixed(float x1, float y1, float x2, float y2, float x3, float y3
 void HUD::Tape::zoomed_scale(int first, int last)
 {
     Point mid_scr = get_centroid();
-    Rect scrn_rect = get_location();
     const int BUFSIZE = 80;
     char buf[BUFSIZE];
     int data[80];
@@ -652,11 +612,11 @@ void HUD::Tape::zoomed_scale(int first, int last)
     int centre = a / 2;
 
     if (option_vert()) {
-        x = scrn_rect.left;
-        y = scrn_rect.top;
-        w = scrn_rect.left + scrn_rect.right;
-        h = scrn_rect.top + scrn_rect.bottom;
-        bottom = scrn_rect.bottom;
+        x = _x;
+        y = _y;
+        w = _x + _w;
+        h = _y + _h;
+        bottom = _h;
 
         float xstart, yfirst, ycentre, ysecond;
 
@@ -670,7 +630,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
         float factor = range / 10.0;
 
         float hgt1 = bottom * 30.0 / 100.0;
-        int  incrs = ((int)_val_span - (_major_divs * 2)) / _major_divs ;
+        int  incrs = ((int)_val_span - (_major_divs * 2)) / _major_divs ;              // FIXME wtf?
         int  incr = incrs / 2;
         float factors = hgt1 / incr;
 
@@ -680,7 +640,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
         static float wth;
 
         ycent = mid_scr.y;
-        wth = scrn_rect.left + scrn_rect.right;
+        wth = _x + _w;
 
         if (cur_value <= data[centre + 1])
             if (cur_value > data[centre]) {
@@ -801,7 +761,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
 
             // to draw moving type pointer for right option
             //begin
-            xpoint = scrn_rect.left;
+            xpoint = _x;
 
             if (_pointer_type == MOVING) {
                 draw_line(xpoint, ycent, xpoint, ypoint);
@@ -815,11 +775,11 @@ void HUD::Tape::zoomed_scale(int first, int last)
 
     } else {
         //horizontal scale
-        x = scrn_rect.left;
-        y = scrn_rect.top;
-        w = scrn_rect.left + scrn_rect.right;
-        h = scrn_rect.top + scrn_rect.bottom;
-        bottom = scrn_rect.right;
+        x = _x;
+        y = _y;
+        w = _x + _w;
+        h = _y + _h;
+        bottom = _w;
 
         float ystart, xfirst, xcentre, xsecond;
 
@@ -913,7 +873,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
             //this is for moving pointer for top option
             //begin
 
-            ypoint = scrn_rect.top + scrn_rect.bottom + 10.0;
+            ypoint = _y + _h + 10.0;
 
             if (_pointer_type == MOVING) {
                 draw_line(xcent, ypoint, xpoint, ypoint);
@@ -964,7 +924,7 @@ void HUD::Tape::zoomed_scale(int first, int last)
             //this is for movimg pointer for bottom option
             //begin
 
-            ypoint = scrn_rect.top - 10.0;
+            ypoint = _y - 10.0;
             if (_pointer_type == MOVING) {
                 draw_line(xcent, ypoint, xpoint, ypoint);
                 draw_line(xpoint, ypoint, xpoint, ypoint + 10.0);
index 7d893efff243ed1b6645abb628fc6e9412154dcb..eb4c1d5a2574b44abbea779eb71ffe597b0f2d24 100644 (file)
@@ -48,13 +48,12 @@ void HUD::TurnBankIndicator::draw(void)
     float sideslip = _sideslip.getFloatValue();
 
     float span = get_span();
-    Rect My_box = get_location();
     Point centroid = get_centroid();
 
     float cen_x = centroid.x;
     float cen_y = centroid.y;
 
-    float tee_height = My_box.bottom;
+    float tee_height = _h;
     float tee = -tee_height;
     float ss_const = 2 * sideslip * span / 40.0;  // sideslip angle pixels per deg (width represents 40 deg)
 
@@ -92,10 +91,10 @@ void HUD::TurnBankIndicator::draw(void)
 
 
     } else { // draw MIL-STD 1878B/4.2.2.4 bank scale
-        draw_line(cen_x - 1.0, My_box.top, cen_x + 1.0, My_box.top);
-        draw_line(cen_x - 1.0, My_box.top, cen_x - 1.0, My_box.top + 10.0);
-        draw_line(cen_x + 1.0, My_box.top, cen_x + 1.0, My_box.top + 10.0);
-        draw_line(cen_x - 1.0, My_box.top + 10.0, cen_x + 1.0, My_box.top + 10.0);
+        draw_line(cen_x - 1.0, _y, cen_x + 1.0, _y);
+        draw_line(cen_x - 1.0, _y, cen_x - 1.0, _y + 10.0);
+        draw_line(cen_x + 1.0, _y, cen_x + 1.0, _y + 10.0);
+        draw_line(cen_x - 1.0, _y + 10.0, cen_x + 1.0, _y + 10.0);
 
         float x1, y1, x2, y2, x3, y3, x4, y4, x5, y5;
         float xc, yc;
@@ -103,8 +102,8 @@ void HUD::TurnBankIndicator::draw(void)
         float r1 = r - 10.0;
         float r2 = r - 5.0;
 
-        xc = My_box.left + My_box.right / 2.0 ;
-        yc = My_box.top + r;
+        xc = _x + _w / 2.0;                // FIXME redunant, no?
+        yc = _y + r;
 
         // first n last lines
         x1 = xc + r * cos(255.0 * SGD_DEGREES_TO_RADIANS);