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