- //default to zoom=0
- last = (int)vmax + 1;
- i = (int)vmin;
- for (; i < last; i++) {
- // for (i = (int)vmin; i <= (int)vmax; i++) {
- // printf("<*> i = %d\n", i);
- condition = true;
- if (!modulo() && i < _input.min())
- condition = false;
-
- // printf("<**> i = %d\n", i);
- if (condition) {
- // marker_xs = scrn_rect.left + (int)((i - vmin) * factor() + .5);
- marker_xs = scrn_rect.left + (((i - vmin) * factor()/*+ .5f*/));
-
- if (oddtype == 1)
- k = i + 1; //enable ticks at odd values
- else
- k = i;
-
- if (_minor_divs) {
- // if ((i % (int)_minor_divs) == 0) {
- //draw minor ticks
- if (!(k % (int)_minor_divs)) {
- // 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 (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) {
- // printf("i = %d\n", i);
- // if ((i % (int)_major_divs)==0) {
- // draw major ticks
-
- if (!(k % (int)_major_divs)) {
- if (modulo()) {
- disp_val = i % (int) modulo(); // ?????????
- if (disp_val < 0) {
- while (disp_val<0)
- disp_val += modulo();
- }
- } else {
- disp_val = i;
- }
- // printf("disp_val = %d\n", disp_val);
- // printf("%d\n", (int)(disp_val * (double)data_scaling() + 0.5));
- lenstr = snprintf(buf, BUFSIZE, "%d",
- // (int)(disp_val * data_scaling() +.5));
- int(disp_val * _input.factor() /*+.5*/)); // was data_scaling() ... makes no sense at all
-
- // Draw major ticks and text only if far enough from the edge.
- if (((marker_xs - 10)> scrn_rect.left)
- && ((marker_xs + 10) < (scrn_rect.left + scrn_rect.right))) {
- 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);
- }
- } else {
- draw_line(marker_xs, marker_ys, marker_xs, 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);
- }
- }
- }
- }
- } //end draw major ticks
- } //endif major ticks
- } //end condition
- } //end for
- } //end zoom
- } //end horizontal/vertical scale
-} //draw
-
+ 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 ?
+
+ float vstart = floorf(vmin / _major_divs) * _major_divs;
+
+ // FIXME consider oddtype
+ for (int i = 0; ; i++) {
+ float v = vstart + i * _minor_divs;
+
+ if (!modulo() && (v < _input.min() || v > _input.max()))
+ continue;
+
+ float x = _x + (v - vmin) * factor();
+
+ 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 {
+ draw_line(x, _y, x, marker_ys);
+ draw_line(x, marker_ye, x, height);
+ }
+ // 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(x, marker_ys, x, marker_ye);
+ }
+ }