]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/HUD/HUD_tape.cxx
- fix unzoomed tapes (TODO: restore tick length)
[flightgear.git] / src / Instrumentation / HUD / HUD_tape.cxx
1 // HUD_tape.cxx -- HUD Tape Instrument
2 //
3 // Written by Michele America, started September 1997.
4 //
5 // Copyright (C) 1997  Michele F. America  [micheleamerica#geocities:com]
6 // Copyright (C) 2006  Melchior FRANZ  [mfranz#aon:at]
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21
22 #include "HUD.hxx"
23
24
25 HUD::Tape::Tape(HUD *hud, const SGPropertyNode *n, float x, float y) :
26     Scale(hud, n, x, y),
27     _draw_tick_bottom(n->getBoolValue("tick-bottom", false)),
28     _draw_tick_top(n->getBoolValue("tick-top", false)),
29     _draw_tick_right(n->getBoolValue("tick-right", false)),
30     _draw_tick_left(n->getBoolValue("tick-left", false)),
31     _draw_cap_bottom(n->getBoolValue("cap-bottom", false)),
32     _draw_cap_top(n->getBoolValue("cap-top", false)),
33     _draw_cap_right(n->getBoolValue("cap-right", false)),
34     _draw_cap_left(n->getBoolValue("cap-left", false)),
35     _marker_offset(n->getFloatValue("marker-offset", 0.0)),
36     _pointer(n->getBoolValue("enable-pointer", true)),
37     _zoom(n->getIntValue("zoom"))
38 {
39     _half_width_units = range_to_show() / 2.0;
40
41     const char *s;
42     s = n->getStringValue("pointer-type");
43     _pointer_type = strcmp(s, "moving") ? FIXED : MOVING;    // "fixed", "moving"
44
45     s = n->getStringValue("tick-type");
46     _tick_type = strcmp(s, "circle") ? LINE : CIRCLE;        // "circle", "line"
47
48     s = n->getStringValue("tick-length");                    // "variable", "constant"
49     _tick_length = strcmp(s, "constant") ? VARIABLE : CONSTANT;
50 }
51
52
53 void HUD::Tape::draw(void) //  (HUD_scale * pscale)
54 {
55     if (!_input.isValid())
56         return;
57
58     float vmin = 0.0, vmax = 0.0;
59     float marker_xs;
60     float marker_xe;
61     float marker_ys;
62     float marker_ye;
63     float text_x = 0.0, text_y = 0.0;
64     int lenstr;
65     float height, width;
66     const int BUFSIZE = 80;
67     char buf[BUFSIZE];
68     int oddtype;
69 //    int k; //odd or even values for ticks             // FIXME odd scale
70
71     Point mid_scr = get_centroid();
72     float cur_value = _input.getFloatValue();
73
74     if (int(floor(_input.max() + 0.5)) & 1)
75         oddtype = 1; //draw ticks at odd values
76     else
77         oddtype = 0; //draw ticks at even values
78
79     height = _y + _h;                   // FIXME huh?
80     width = _x + _w;
81
82
83     if (_pointer) {
84         if (_pointer_type == MOVING) {
85             vmin = _input.min();
86             vmax = _input.max();
87
88         } else { // FIXED
89             vmin = cur_value - _half_width_units; // width units == needle travel
90             vmax = cur_value + _half_width_units; // or picture unit span.
91             text_x = mid_scr.x;
92             text_y = mid_scr.y;
93         }
94
95     } else {
96         vmin = cur_value - _half_width_units; // width units == needle travel
97         vmax = cur_value + _half_width_units; // or picture unit span.
98         text_x = mid_scr.x;
99         text_y = mid_scr.y;
100     }
101
102
103 ///////////////////////////////////////////////////////////////////////////////
104 // VERTICAL SCALE
105 ///////////////////////////////////////////////////////////////////////////////
106
107     // Draw the basic markings for the scale...
108
109     if (option_vert()) { // Vertical scale
110         // Bottom tick bar
111         if (_draw_tick_bottom)
112             draw_line(_x, _y, width, _y);
113
114         // Top tick bar
115         if (_draw_tick_top)
116             draw_line(_x, height, width, height);
117
118         marker_xs = _x;  // x start
119         marker_xe = width;           // x extent
120         marker_ye = height;
121
122         //    glBegin(GL_LINES);
123
124         // Bottom tick bar
125         //    glVertex2f(marker_xs, _y);
126         //    glVertex2f(marker_xe, _y);
127
128         // Top tick bar
129         //    glVertex2f(marker_xs, marker_ye);
130         //    glVertex2f(marker_xe, marker_ye);
131         //    glEnd();
132
133
134         // We do not use else in the following so that combining the
135         // two options produces a "caged" display with double
136         // carrots. The same is done for horizontal card indicators.
137
138         // begin vertical/left
139         //First draw capping lines and pointers
140         if (option_left()) {    // Calculate x marker offset
141
142             if (_draw_cap_right)
143                 draw_line(marker_xe, _y, marker_xe, marker_ye);
144
145             marker_xs  = marker_xe - _w / 3 + 0.5;   // Adjust tick xs
146
147             // draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y + _w / 6);
148             // draw_line(marker_xs, mid_scr.y, marker_xe, mid_scr.y - _w / 6);
149
150             // draw pointer
151             if (_pointer) {
152                 if (_pointer_type == MOVING) {
153                     if (!_zoom) {
154                         //Code for Moving Type Pointer
155                         float ycentre, ypoint, xpoint;
156                         float range, wth;
157
158                         if (_input.min() >= 0.0)
159                             ycentre = _y;
160                         else if (_input.max() + _input.min() == 0.0)
161                             ycentre = mid_scr.y;
162                         else if (oddtype)
163                             ycentre = _y + (1.0 - _input.min()) * _h
164                                     / (_input.max() - _input.min());
165                         else
166                             ycentre = _y + _input.min() * _h
167                                     / (_input.max() - _input.min());
168
169                         range = _h;
170                         wth = _x + _w;
171
172                         if (oddtype)
173                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
174                         else
175                             ypoint = ycentre + (cur_value * range / _val_span);
176
177                         xpoint = wth + _marker_offset;
178                         draw_line(xpoint, ycentre, xpoint, ypoint);
179                         draw_line(xpoint, ypoint, xpoint - _marker_offset, ypoint);
180                         draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint + 5.0);
181                         draw_line(xpoint - _marker_offset, ypoint, xpoint - 5.0, ypoint - 5.0);
182                     } // !_zoom
183
184                 } else {
185                     // default to fixed
186                     fixed(_marker_offset + marker_xe, text_y + _w / 6,
187                             _marker_offset + marker_xs, text_y, _marker_offset + marker_xe,
188                             text_y - _w / 6);
189                 } // end pointer type
190             } // if pointer
191         } // end vertical/left
192
193
194         // begin vertical/right
195         // First draw capping lines and pointers
196         if (option_right()) {
197
198             if (_draw_cap_left)
199                 draw_line(_x, _y, _x, marker_ye);
200
201             marker_xe = _x + _w / 3 - 0.5;     // Adjust tick xe
202             // Indicator carrot
203             // draw_line(_x, mid_scr.y +  _w / 6, marker_xe, mid_scr.y);
204             // draw_line(_x, mid_scr.y -  _w / 6, marker_xe, mid_scr.y);
205
206             // draw pointer
207             if (_pointer) {
208                 if (_pointer_type == MOVING) {
209                     if (!_zoom) {
210                         // type-fixed & _zoom=1, behaviour to be defined
211                         // Code for Moving Type Pointer
212                         float ycentre, ypoint, xpoint;
213                         float range;
214
215                         if (_input.min() >= 0.0)
216                             ycentre = _y;
217                         else if (_input.max() + _input.min() == 0.0)
218                             ycentre = mid_scr.y;
219                         else if (oddtype)
220                             ycentre = _y + (1.0 - _input.min()) * _h / (_input.max() - _input.min());
221                         else
222                             ycentre = _y + _input.min() * _h / (_input.max() - _input.min());
223
224                         range = _h;
225
226                         if (oddtype)
227                             ypoint = ycentre + ((cur_value - 1.0) * range / _val_span);
228                         else
229                             ypoint = ycentre + (cur_value * range / _val_span);
230
231                         xpoint = _x - _marker_offset;
232                         draw_line(xpoint, ycentre, xpoint, ypoint);
233                         draw_line(xpoint, ypoint, xpoint + _marker_offset, ypoint);
234                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint + 5.0);
235                         draw_line(xpoint + _marker_offset, ypoint, xpoint + 5.0, ypoint - 5.0);
236                     }
237
238                 } else {
239                     // default to fixed
240                     fixed(-_marker_offset + _x, text_y +  _w / 6,
241                             -_marker_offset + marker_xe, text_y, -_marker_offset + _x,
242                             text_y - _w / 6);
243                 }
244             } // if pointer
245         } // end vertical/right
246
247
248         // At this point marker x_start and x_end values are transposed.
249         // To keep this from confusing things they are now swapped.
250         if (option_both())
251             marker_ye = marker_xs, marker_xs = marker_xe, marker_xe = marker_ye;
252
253
254
255         // Work through from bottom to top of scale. Calculating where to put
256         // minor and major ticks.
257
258         // draw scale or tape
259         if (_zoom) {
260             zoomed_scale((int)vmin, (int)vmax);
261         } else {
262
263 //#############################################################################
264
265             int div_ratio;
266             if (_minor_divs != 0.0f)
267                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
268             else
269                 div_ratio = 0, _minor_divs = _major_divs;                       // FIXME move that into Scale/Constructor ?
270
271             float vstart = floorf(vmin / _major_divs) * _major_divs;
272
273             // FIXME consider oddtype
274             for (int i = 0; ; i++) {
275                 float v = vstart + i * _minor_divs;
276
277                 if (!modulo() && (v < _input.min() || v > _input.max()))
278                     continue;
279
280                 float y = _y + (v - vmin) * factor();
281
282                 if (y < _y + 4)
283                     continue;
284                 if (y > height - 4)
285                     break;
286
287                 if (div_ratio && i % div_ratio) { // minor div
288                     if (option_both()) {
289                         if (_tick_type == LINE) {
290                             if (_tick_length == VARIABLE) {
291                                 draw_line(_x, y, marker_xs, y);
292                                 draw_line(marker_xe, y, width, y);
293                             } else {
294                                 draw_line(_x, y, marker_xs, y);
295                                 draw_line(marker_xe, y, width, y);
296                             }
297
298                         } else if (_tick_type == CIRCLE) {
299                             draw_bullet(_x, y, 3.0);
300
301                         } else {
302                             // if neither line nor circle draw default as line
303                             draw_line(_x, y, marker_xs, y);
304                             draw_line(marker_xe, y, width, y);
305                         }
306                         // glBegin(GL_LINES);
307                         // glVertex2f(_x, y);
308                         // glVertex2f(marker_xs,      y);
309                         // glVertex2f(marker_xe,      y);
310                         // glVertex2f(_x + _w,  y);
311                         // glEnd();
312                         // anything other than huds_both
313
314                     } else {
315                         if (option_left()) {
316                             if (_tick_type == LINE) {
317                                 if (_tick_length == VARIABLE) {
318                                     draw_line(marker_xs + 4, y, marker_xe, y);
319                                 } else {
320                                     draw_line(marker_xs, y, marker_xe, y);
321                                 }
322                             } else if (_tick_type == CIRCLE) {
323                                 draw_bullet(marker_xs + 4, y, 3.0);
324                             } else {
325                                 draw_line(marker_xs + 4, y, marker_xe, y);
326                             }
327
328                         }  else {
329                             if (_tick_type == LINE) {
330                                 if (_tick_length == VARIABLE) {
331                                     draw_line(marker_xs, y, marker_xe - 4, y);
332                                 } else {
333                                     draw_line(marker_xs, y, marker_xe, y);
334                                 }
335
336                             } else if (_tick_type == CIRCLE) {
337                                 draw_bullet(marker_xe - 4, y, 3.0);
338                             } else {
339                                 draw_line(marker_xs, y, marker_xe - 4, y);
340                             }
341                         }
342                     } // end huds both
343
344                 } else { // major div
345                     lenstr = snprintf(buf, BUFSIZE, "%d", int(v));
346
347                     if (option_both()) {
348                         // draw_line(_x, y, marker_xs, y);
349                         // draw_line(marker_xs, y, _x + _w, y);
350                         if (_tick_type == LINE) {
351                             glBegin(GL_LINE_STRIP);
352                             glVertex2f(_x, y);
353                             glVertex2f(marker_xs, y);
354                             glVertex2f(width, y);
355                             glEnd();
356
357                         } else if (_tick_type == CIRCLE) {
358                             draw_bullet(_x, y, 5.0);
359
360                         } else {
361                             glBegin(GL_LINE_STRIP);
362                             glVertex2f(_x, y);
363                             glVertex2f(marker_xs, y);
364                             glVertex2f(width, y);
365                             glEnd();
366                         }
367
368                         if (!option_notext())
369                             draw_text(marker_xs + 2, y, buf, 0);
370
371                     } else {
372                         /* Changes are made to draw a circle when tick_type=CIRCLE */
373                         // anything other than option_both
374                         if (_tick_type == LINE)
375                             draw_line(marker_xs, y, marker_xe, y);
376                         else if (_tick_type == CIRCLE)
377                             draw_bullet(marker_xs + 4, y, 5.0);
378                         else
379                             draw_line(marker_xs, y, marker_xe, y);
380
381                         if (!option_notext()) {
382                             if (option_left())
383                                 draw_text(marker_xs - 8 * lenstr - 2, y - 4, buf, 0);
384                             else
385                                 draw_text(marker_xe + 3 * lenstr, y - 4, buf, 0);
386                         }
387                     } // End if huds-both
388                 }
389             }
390         } // end of zoom
391
392
393 ///////////////////////////////////////////////////////////////////////////////
394 // HORIZONTAL SCALE
395 ///////////////////////////////////////////////////////////////////////////////
396
397
398     } else {
399         // left tick bar
400         if (_draw_tick_left)
401             draw_line(_x, _y, _x, height);
402
403         // right tick bar
404         if (_draw_tick_right)
405             draw_line(width, _y, width, height);
406
407         marker_ys = _y;    // Starting point for
408         marker_ye = height;           // tick y location calcs
409         marker_xe = width;
410         marker_xs = _x + ((cur_value - vmin) * factor());
411
412         //    glBegin(GL_LINES);
413         // left tick bar
414         //    glVertex2f(_x, _y);
415         //    glVertex2f(_x, marker_ye);
416
417         // right tick bar
418         //    glVertex2f(marker_xe, _y);
419         //    glVertex2f(marker_xe, marker_ye);
420         //    glEnd();
421
422         if (option_top()) {
423             if (_draw_cap_bottom)
424                 draw_line(_x, _y, width, _y);
425
426             // Tick point adjust
427             marker_ye  = _y + _h / 2;
428             // Bottom arrow
429             // draw_line(mid_scr.x, marker_ye, mid_scr.x - _h / 4, _y);
430             // draw_line(mid_scr.x, marker_ye, mid_scr.x + _h / 4, _y);
431             // draw pointer
432             if (_pointer) {
433                 if (_pointer_type == MOVING) {
434                     if (!_zoom) {
435                         //Code for Moving Type Pointer
436
437                         float xcentre = mid_scr.x;
438                         float range = _w;
439                         float xpoint = xcentre + (cur_value * range / _val_span);
440                         float ypoint = _y - _marker_offset;
441                         draw_line(xcentre, ypoint, xpoint, ypoint);
442                         draw_line(xpoint, ypoint, xpoint, ypoint + _marker_offset);
443                         draw_line(xpoint, ypoint + _marker_offset, xpoint + 5.0, ypoint + 5.0);
444                         draw_line(xpoint, ypoint + _marker_offset, xpoint - 5.0, ypoint + 5.0);
445                     }
446
447                 } else {
448                     //default to fixed
449                     fixed(marker_xs - _h / 4, _y, marker_xs,
450                             marker_ye, marker_xs + _h / 4, _y);
451                 }
452             }
453         } // End Horizontal scale/top
454
455         if (option_bottom()) {
456             if (_draw_cap_top)
457                 draw_line(_x, height, width, height);
458
459             // Tick point adjust
460             marker_ys = height - _h / 2;
461             // Top arrow
462             // draw_line(mid_scr.x + _h / 4, _y + _h, mid_scr.x, marker_ys);
463             // draw_line(mid_scr.x - _h / 4, _y + _h, mid_scr.x , marker_ys);
464
465             // draw pointer
466             if (_pointer) {
467                 if (_pointer_type == MOVING) {
468                     if (!_zoom) {
469                         //Code for Moving Type Pointer
470
471                         float xcentre = mid_scr.x ;
472                         float range = _w;
473                         float hgt = _y + _h;
474                         float xpoint = xcentre + (cur_value * range / _val_span);
475                         float ypoint = hgt + _marker_offset;
476                         draw_line(xcentre, ypoint, xpoint, ypoint);
477                         draw_line(xpoint, ypoint, xpoint, ypoint - _marker_offset);
478                         draw_line(xpoint, ypoint - _marker_offset, xpoint + 5.0, ypoint - 5.0);
479                         draw_line(xpoint, ypoint - _marker_offset, xpoint - 5.0, ypoint - 5.0);
480                     }
481                 } else {
482                     fixed(marker_xs + _h / 4, height, marker_xs, marker_ys,
483                             marker_xs - _h / 4, height);
484                 }
485             }
486         } //end horizontal scale bottom
487
488
489         if (_zoom) {
490             zoomed_scale((int)vmin,(int)vmax);
491         } else {
492             int div_ratio;                                      // FIXME abstract that out of hor/vert
493             if (_minor_divs != 0.0f)
494                 div_ratio = int(_major_divs / _minor_divs + 0.5f);
495             else
496                 div_ratio = 0, _minor_divs = _major_divs;                       // FIXME move that into Scale/Constructor ?
497
498             float vstart = floorf(vmin / _major_divs) * _major_divs;
499
500             // FIXME consider oddtype
501             for (int i = 0; ; i++) {
502                 float v = vstart + i * _minor_divs;
503
504                 if (!modulo() && (v < _input.min() || v > _input.max()))
505                     continue;
506
507                 float x = _x + (v - vmin) * factor();
508
509                 if (x < _x + 4)
510                     continue;
511                 if (x > width - 4)
512                     break;
513
514                 if (div_ratio && i % div_ratio) { // minor div
515                     if (option_both()) {
516                         if (_tick_length == VARIABLE) {
517                             draw_line(x, _y, x, marker_ys - 4);
518                             draw_line(x, marker_ye + 4, x, height);
519                         } else {
520                             draw_line(x, _y, x, marker_ys);
521                             draw_line(x, marker_ye, x, height);
522                         }
523                         // glBegin(GL_LINES);
524                         // glVertex2f(x, _y);
525                         // glVertex2f(x, marker_ys - 4);
526                         // glVertex2f(x, marker_ye + 4);
527                         // glVertex2f(x, _y + _h);
528                         // glEnd();
529
530                     } else {
531                         if (option_top()) {
532                             // draw minor ticks
533                             if (_tick_length == VARIABLE)
534                                 draw_line(x, marker_ys, x, marker_ye - 4);
535                             else
536                                 draw_line(x, marker_ys, x, marker_ye);
537
538                         } else if (_tick_length == VARIABLE) {
539                             draw_line(x, marker_ys + 4, x, marker_ye);
540                         } else {
541                             draw_line(x, marker_ys, x, marker_ye);
542                         }
543                     }
544
545                 } else { // major divs
546                     lenstr = snprintf(buf, BUFSIZE, "%d", int(v));
547
548                     // Draw major ticks and text only if far enough from the edge.                      // FIXME
549                     if (x < _x + 10 || x + 10 > _x + _w)
550                         continue;
551
552                     if (option_both()) {
553                         // draw_line(x, _y,
554                         //              x, marker_ys);
555                         // draw_line(x, marker_ye,
556                         //              x, _y + _h);
557                         glBegin(GL_LINE_STRIP);
558                         glVertex2f(x, _y);
559                         glVertex2f(x, marker_ye);
560                         glVertex2f(x, height);
561                         glEnd();
562
563                         if (!option_notext())
564                             draw_text(x - 4 * lenstr, marker_ys + 4, buf, 0);
565
566                     } else {
567                         draw_line(x, marker_ys, x, marker_ye);
568
569                         if (!option_notext()) {
570                             if (option_top())
571                                 draw_text(x - 4 * lenstr, height - 10, buf, 0);
572                             else
573                                 draw_text(x - 4 * lenstr, _y, buf, 0);
574                         }
575                     }
576                 }
577             } // end for
578         } // end zoom
579     } // end horizontal/vertical scale
580 }
581
582
583
584 void HUD::Tape::fixed(float x1, float y1, float x2, float y2, float x3, float y3)
585 {
586     glBegin(GL_LINE_STRIP);
587     glVertex2f(x1, y1);
588     glVertex2f(x2, y2);
589     glVertex2f(x3, y3);
590     glEnd();
591 }
592
593
594 void HUD::Tape::zoomed_scale(int first, int last)
595 {
596     Point mid_scr = get_centroid();
597     const int BUFSIZE = 80;
598     char buf[BUFSIZE];
599     int data[80];
600
601     float x, y, w, h, bottom;
602     float cur_value = _input.getFloatValue();
603     int a = 0;
604
605     while (first <= last) {
606         if ((first % (int)_major_divs) == 0) {
607             data[a] = first;
608             a++ ;
609         }
610         first++;
611     }
612     int centre = a / 2;
613
614     if (option_vert()) {
615         x = _x;
616         y = _y;
617         w = _x + _w;
618         h = _y + _h;
619         bottom = _h;
620
621         float xstart, yfirst, ycentre, ysecond;
622
623         float hgt = bottom * 20.0 / 100.0;  // 60% of height should be zoomed
624         yfirst = mid_scr.y - hgt;
625         ycentre = mid_scr.y;
626         ysecond = mid_scr.y + hgt;
627         float range = hgt * 2;
628
629         int i;
630         float factor = range / 10.0;
631
632         float hgt1 = bottom * 30.0 / 100.0;
633         int  incrs = ((int)_val_span - (_major_divs * 2)) / _major_divs ;               // FIXME wtf?
634         int  incr = incrs / 2;
635         float factors = hgt1 / incr;
636
637         // begin
638         //this is for moving type pointer
639         static float ycent, ypoint, xpoint;                                     // FIXME really static?
640         static float wth;
641
642         ycent = mid_scr.y;
643         wth = _x + _w;
644
645         if (cur_value <= data[centre + 1])
646             if (cur_value > data[centre]) {
647                 ypoint = ycent + ((cur_value - data[centre]) * hgt / _major_divs);
648             }
649
650         if (cur_value >= data[centre - 1])
651             if (cur_value <= data[centre]) {
652                 ypoint = ycent - ((data[centre] - cur_value) * hgt / _major_divs);
653             }
654
655         if (cur_value < data[centre - 1])
656             if (cur_value >= _input.min()) {
657                 float diff  = _input.min() - data[centre - 1];
658                 float diff1 = cur_value - data[centre - 1];
659                 float val = (diff1 * hgt1) / diff;
660
661                 ypoint = ycent - hgt - val;
662             }
663
664         if (cur_value > data[centre + 1])
665             if (cur_value <= _input.max()) {
666                 float diff  = _input.max() - data[centre + 1];
667                 float diff1 = cur_value - data[centre + 1];
668                 float val = (diff1 * hgt1) / diff;
669
670                 ypoint = ycent + hgt + val;
671             }
672
673         if (option_left()) {
674             xstart = w;
675
676             draw_line(xstart, ycentre, xstart - 5.0, ycentre); //centre tick
677
678             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes not sense at all
679
680             if (!option_notext())
681                 draw_text(x, ycentre, buf, 0);
682
683             for (i = 1; i < 5; i++) {
684                 yfirst += factor;
685                 ycentre += factor;
686                 draw_bullet(xstart - 2.5, yfirst, 3.0);
687                 draw_bullet(xstart - 2.5, ycentre, 3.0);
688             }
689
690             yfirst = mid_scr.y - hgt;
691
692             for (i = 0; i <= incr; i++) {
693                 draw_line(xstart, yfirst, xstart - 5.0, yfirst);
694                 draw_line(xstart, ysecond, xstart - 5.0, ysecond);
695
696                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor()));  // was data_scaling() ... makes no sense at all
697
698                 if (!option_notext())
699                     draw_text(x, yfirst, buf, 0);
700
701                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
702
703                 if (!option_notext())
704                     draw_text(x, ysecond, buf, 0);
705
706                 yfirst -= factors;
707                 ysecond += factors;
708
709             }
710
711             //to draw moving type pointer for left option
712             //begin
713             xpoint = wth + 10.0;
714
715             if (_pointer_type == MOVING) {
716                 draw_line(xpoint, ycent, xpoint, ypoint);
717                 draw_line(xpoint, ypoint, xpoint - 10.0, ypoint);
718                 draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint + 5.0);
719                 draw_line(xpoint - 10.0, ypoint, xpoint - 5.0, ypoint - 5.0);
720             }
721             //end
722
723         } else {
724             //option_right
725             xstart = (x + w) / 2;
726
727             draw_line(xstart, ycentre, xstart + 5.0, ycentre); //centre tick
728
729             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
730
731             if (!option_notext())
732                 draw_text(w, ycentre, buf, 0);
733
734             for (i = 1; i < 5; i++) {
735                 yfirst += factor;
736                 ycentre += factor;
737                 draw_bullet(xstart + 2.5, yfirst, 3.0);
738                 draw_bullet(xstart + 2.5, ycentre, 3.0);
739             }
740
741             yfirst = mid_scr.y - hgt;
742
743             for (i = 0; i <= incr; i++) {
744                 draw_line(xstart, yfirst, xstart + 5.0, yfirst);
745                 draw_line(xstart, ysecond, xstart + 5.0, ysecond);
746
747                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
748
749                 if (!option_notext())
750                     draw_text(w, yfirst, buf, 0);
751
752                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor()));
753
754                 if (!option_notext())
755                     draw_text(w, ysecond, buf, 0);
756
757                 yfirst -= factors;
758                 ysecond += factors;
759
760             }
761
762             // to draw moving type pointer for right option
763             //begin
764             xpoint = _x;
765
766             if (_pointer_type == MOVING) {
767                 draw_line(xpoint, ycent, xpoint, ypoint);
768                 draw_line(xpoint, ypoint, xpoint + 10.0, ypoint);
769                 draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint + 5.0);
770                 draw_line(xpoint + 10.0, ypoint, xpoint + 5.0, ypoint - 5.0);
771             }
772             //end
773         }//end option_right /left
774         //end of vertical scale
775
776     } else {
777         //horizontal scale
778         x = _x;
779         y = _y;
780         w = _x + _w;
781         h = _y + _h;
782         bottom = _w;
783
784         float ystart, xfirst, xcentre, xsecond;
785
786         float hgt = bottom * 20.0 / 100.0;  // 60% of height should be zoomed
787         xfirst = mid_scr.x - hgt;
788         xcentre = mid_scr.x;
789         xsecond = mid_scr.x + hgt;
790         float range = hgt * 2;
791
792         int i;
793         float factor = range / 10.0;
794
795         float hgt1 = bottom * 30.0 / 100.0;
796         int  incrs = ((int)_val_span - (_major_divs * 2)) / _major_divs ;
797         int  incr = incrs / 2;
798         float factors = hgt1 / incr;
799
800
801         //Code for Moving Type Pointer
802         //begin
803         static float xcent, xpoint, ypoint;                             // FIXME really static?
804
805         xcent = mid_scr.x;
806
807         if (cur_value <= data[centre + 1])
808             if (cur_value > data[centre]) {
809                 xpoint = xcent + ((cur_value - data[centre]) * hgt / _major_divs);
810             }
811
812         if (cur_value >= data[centre - 1])
813             if (cur_value <= data[centre]) {
814                 xpoint = xcent - ((data[centre] - cur_value) * hgt / _major_divs);
815             }
816
817         if (cur_value < data[centre - 1])
818             if (cur_value >= _input.min()) {
819                 float diff = _input.min() - data[centre - 1];
820                 float diff1 = cur_value - data[centre - 1];
821                 float val = (diff1 * hgt1) / diff;
822
823                 xpoint = xcent - hgt - val;
824             }
825
826
827         if (cur_value > data[centre + 1])
828             if (cur_value <= _input.max()) {
829                 float diff = _input.max() - data[centre + 1];
830                 float diff1 = cur_value - data[centre + 1];
831                 float val = (diff1 * hgt1) / diff;
832
833                 xpoint = xcent + hgt + val;
834             }
835
836         //end
837         if (option_top()) {
838             ystart = h;
839             draw_line(xcentre, ystart, xcentre, ystart - 5.0); //centre tick
840
841             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor()));  // was data_scaling() ... makes no sense at all
842
843             if (!option_notext())
844                 draw_text(xcentre - 10.0, y, buf, 0);
845
846             for (i = 1; i < 5; i++) {
847                 xfirst += factor;
848                 xcentre += factor;
849                 draw_bullet(xfirst, ystart - 2.5, 3.0);
850                 draw_bullet(xcentre, ystart - 2.5, 3.0);
851             }
852
853             xfirst = mid_scr.x - hgt;
854
855             for (i = 0; i <= incr; i++) {
856                 draw_line(xfirst, ystart, xfirst,  ystart - 5.0);
857                 draw_line(xsecond, ystart, xsecond, ystart - 5.0);
858
859                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
860
861                 if (!option_notext())
862                     draw_text(xfirst - 10.0, y, buf, 0);
863
864                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
865
866                 if (!option_notext())
867                     draw_text(xsecond - 10.0, y, buf, 0);
868
869
870                 xfirst -= factors;
871                 xsecond += factors;
872             }
873             //this is for moving pointer for top option
874             //begin
875
876             ypoint = _y + _h + 10.0;
877
878             if (_pointer_type == MOVING) {
879                 draw_line(xcent, ypoint, xpoint, ypoint);
880                 draw_line(xpoint, ypoint, xpoint, ypoint - 10.0);
881                 draw_line(xpoint, ypoint - 10.0, xpoint + 5.0, ypoint - 5.0);
882                 draw_line(xpoint, ypoint - 10.0, xpoint - 5.0, ypoint - 5.0);
883             }
884             //end of top option
885
886         } else {
887             //else option_bottom
888             ystart = (y + h) / 2;
889
890             //draw_line(xstart, yfirst,  xstart - 5.0, yfirst);
891             draw_line(xcentre, ystart, xcentre, ystart + 5.0); //centre tick
892
893             snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre] * _input.factor())); // was data_scaling() ... makes no sense at all
894
895             if (!option_notext())
896                 draw_text(xcentre - 10.0, h, buf, 0);
897
898             for (i = 1; i < 5; i++) {
899                 xfirst += factor;
900                 xcentre += factor;
901                 draw_bullet(xfirst, ystart + 2.5, 3.0);
902                 draw_bullet(xcentre, ystart + 2.5, 3.0);
903             }
904
905             xfirst = mid_scr.x - hgt;
906
907             for (i = 0; i <= incr; i++) {
908                 draw_line(xfirst, ystart, xfirst, ystart + 5.0);
909                 draw_line(xsecond, ystart, xsecond, ystart + 5.0);
910
911                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre - i - 1] * _input.factor())); // was data_scaling() ... makes no sense at all
912
913                 if (!option_notext())
914                     draw_text(xfirst - 10.0, h, buf, 0);
915
916                 snprintf(buf, BUFSIZE, "%3.0f\n", float(data[centre + i + 1] * _input.factor())); // was data_scaling() ... makes no sense at all
917
918                 if (!option_notext())
919                     draw_text(xsecond - 10.0, h, buf, 0);
920
921                 xfirst -= factors;
922                 xsecond   += factors;
923             }
924             //this is for movimg pointer for bottom option
925             //begin
926
927             ypoint = _y - 10.0;
928             if (_pointer_type == MOVING) {
929                 draw_line(xcent, ypoint, xpoint, ypoint);
930                 draw_line(xpoint, ypoint, xpoint, ypoint + 10.0);
931                 draw_line(xpoint, ypoint + 10.0, xpoint + 5.0, ypoint + 5.0);
932                 draw_line(xpoint, ypoint + 10.0, xpoint - 5.0, ypoint + 5.0);
933             }
934         }//end hud_top or hud_bottom
935     }  //end of horizontal/vertical scales
936 }//end draw
937
938